Move protocol constants to their own file
MODIFY
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
@@ -18,6 +18,7 @@ using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Crypto;
using WalletWasabi.WabiSabi.Crypto.CredentialRequesting;
using WalletWasabi.WabiSabi.Models;
+using WalletWasabi.WabiSabi;
namespace WalletWasabi.Tests.Helpers
{
@@ -189,10 +190,10 @@ namespace WalletWasabi.Tests.Helpers
var zeroPresentables = CreateZeroCredentials(round);
var alice = round?.Alices.FirstOrDefault();
var (realAmountCredentialRequest, _) = amClient.CreateRequest(
- new[] { amount?.Satoshi ?? alice?.CalculateRemainingAmountCredentials(round!.FeeRate).Satoshi ?? 250L },
+ new[] { amount?.Satoshi ?? alice?.CalculateRemainingAmountCredentials(round!.FeeRate).Satoshi ?? ProtocolConstants.MaxVsizePerAlice },
zeroPresentables.amountCredentials);
var (realVsizeCredentialRequest, _) = vsClient.CreateRequest(
- new[] { vsize ?? alice?.CalculateRemainingSizeCredentials(round!.RegistrableVsizeCredentials) ?? 250L },
+ new[] { vsize ?? alice?.CalculateRemainingSizeCredentials(round!.RegistrableVsizeCredentials) ?? ProtocolConstants.MaxVsizePerAlice },
zeroPresentables.vsizeCredentials);
return (realAmountCredentialRequest, realVsizeCredentialRequest);
@@ -205,10 +206,10 @@ namespace WalletWasabi.Tests.Helpers
var zeroPresentables = CreateZeroCredentials(round);
var alice = round?.Alices.FirstOrDefault();
var (realAmountCredentialRequest, _) = amClient.CreateRequest(
- new[] { alice?.CalculateRemainingAmountCredentials(round!.FeeRate).Satoshi ?? 250L },
+ new[] { alice?.CalculateRemainingAmountCredentials(round!.FeeRate).Satoshi ?? ProtocolConstants.MaxVsizePerAlice },
zeroPresentables.amountCredentials);
var (realVsizeCredentialRequest, _) = vsClient.CreateRequest(
- new[] { alice?.CalculateRemainingSizeCredentials(round!.RegistrableVsizeCredentials) ?? 250L },
+ new[] { alice?.CalculateRemainingSizeCredentials(round!.RegistrableVsizeCredentials) ?? ProtocolConstants.MaxVsizePerAlice },
zeroPresentables.vsizeCredentials);
var (zeroAmountCredentialRequest, _) = amClient.CreateRequestForZeroAmount();
@@ -271,9 +272,9 @@ namespace WalletWasabi.Tests.Helpers
var alice = round?.Alices.FirstOrDefault();
var (amCredentialRequest, amValid) = amClient.CreateRequest(
- new[] { alice?.CalculateRemainingAmountCredentials(round!.FeeRate).Satoshi ?? 250L },
+ new[] { alice?.CalculateRemainingAmountCredentials(round!.FeeRate).Satoshi ?? ProtocolConstants.MaxVsizePerAlice },
zeroPresentables.amountCredentials);
- long startingWeightCredentialAmount = alice?.CalculateRemainingSizeCredentials(round!.RegistrableVsizeCredentials) ?? 250L;
+ long startingWeightCredentialAmount = alice?.CalculateRemainingSizeCredentials(round!.RegistrableVsizeCredentials) ?? ProtocolConstants.MaxVsizePerAlice;
var (vsCredentialRequest, weValid) = vsClient.CreateRequest(
new[] { startingWeightCredentialAmount },
zeroPresentables.vsizeCredentials);

MODIFY
WalletWasabi.Tests/UnitTests/WabiSabi/Client/ArenaClientTests.cs
WalletWasabi.Tests/UnitTests/WabiSabi/Client/ArenaClientTests.cs
@@ -8,6 +8,7 @@ using WalletWasabi.BitcoinCore.Rpc;
using WalletWasabi.Crypto.Randomness;
using WalletWasabi.Helpers;
using WalletWasabi.Tests.Helpers;
+using WalletWasabi.WabiSabi;
using WalletWasabi.WabiSabi.Backend;
using WalletWasabi.WabiSabi.Backend.Banning;
using WalletWasabi.WabiSabi.Backend.Models;
@@ -58,7 +59,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client
};
var inputVsize = Constants.P2wpkhInputVirtualSize;
- var inputRemainingVsizes = new[] { (long)ArenaClient.ProtocolMaxVsizePerAlice - inputVsize };
+ var inputRemainingVsizes = new[] { (long)ProtocolConstants.MaxVsizePerAlice - inputVsize };
// Phase: Input Registration
Assert.Equal(Phase.InputRegistration, round.Phase);
@@ -67,7 +68,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client
round.Id,
aliceId,
inputRemainingVsizes,
- amountCredentials.ZeroValue.Take(ArenaClient.ProtocolCredentialNumber),
+ amountCredentials.ZeroValue.Take(ProtocolConstants.CredentialNumber),
reissuanceAmounts);
Assert.Empty(amountCredentials.Valuable);
@@ -80,7 +81,7 @@ namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client
round.Id,
aliceId,
inputRemainingVsizes,
- amountCredentials.ZeroValue.Take(ArenaClient.ProtocolCredentialNumber),
+ amountCredentials.ZeroValue.Take(ProtocolConstants.CredentialNumber),
reissuanceAmounts);
Assert.Single(amountCredentials.Valuable, x => x.Amount.ToMoney() == reissuanceAmounts.First());

MODIFY
WalletWasabi/Helpers/Constants.cs
WalletWasabi/Helpers/Constants.cs
@@ -18,13 +18,12 @@ namespace WalletWasabi.Helpers
public const uint ProtocolVersionWitnessVersion = 70012;
- public const int WitnessScaleFactor = 4;
-
public const int P2wpkhInputSizeInBytes = 41;
public const int P2wpkhInputVirtualSize = 69;
public const int P2pkhInputSizeInBytes = 145;
public const int OutputSizeInBytes = 33;
+
// https://en.bitcoin.it/wiki/Bitcoin
// There are a maximum of 2,099,999,997,690,000 Bitcoin elements (called satoshis), which are currently most commonly measured in units of 100,000,000 known as BTC. Stated another way, no more than 21 million BTC can ever be created.
public const long MaximumNumberOfSatoshis = 2099999997690000;

MODIFY
WalletWasabi/WabiSabi/Backend/WabiSabiConfig.cs
WalletWasabi/WabiSabi/Backend/WabiSabiConfig.cs
@@ -58,9 +58,9 @@ namespace WalletWasabi.WabiSabi.Backend
/// The width of the rangeproofs are calculated from this, so don't choose stupid numbers.
/// Consider that it applies to registrations, not for inputs. This usually consists one input, but can be more.
/// </summary>
- [DefaultValue(250)]
+ [DefaultValue(ProtocolConstants.MaxVsizePerAlice)]
[JsonProperty(PropertyName = "RegistrableVsizeCredentials", DefaultValueHandling = DefaultValueHandling.Populate)]
- public uint RegistrableVsizeCredentials { get; set; } = 250;
+ public uint RegistrableVsizeCredentials { get; set; } = ProtocolConstants.MaxVsizePerAlice;
[DefaultValue(true)]
[JsonProperty(PropertyName = "AllowNotedInputRegistration", DefaultValueHandling = DefaultValueHandling.Populate)]

MODIFY
WalletWasabi/WabiSabi/Client/AliceClient.cs
WalletWasabi/WabiSabi/Client/AliceClient.cs
@@ -37,7 +37,7 @@ namespace WalletWasabi.WabiSabi.Client
private async Task<bool> ConfirmConnectionAsync()
{
var inputVsize = Constants.P2wpkhInputVirtualSize;
- var inputRemainingVsizes = new[] { (long)ArenaClient.ProtocolMaxVsizePerAlice - Coins.Count() * inputVsize };
+ var inputRemainingVsizes = new[] { (long)ProtocolConstants.MaxVsizePerAlice - Coins.Count() * inputVsize };
var amountCredentials = ArenaClient.AmountCredentialClient.Credentials;
@@ -56,7 +56,7 @@ namespace WalletWasabi.WabiSabi.Client
RoundId,
AliceId,
inputRemainingVsizes,
- amountCredentials.ZeroValue.Take(ArenaClient.ProtocolCredentialNumber),
+ amountCredentials.ZeroValue.Take(ProtocolConstants.CredentialNumber),
amountsToRequest)
.ConfigureAwait(false);
}

MODIFY
WalletWasabi/WabiSabi/Client/ArenaClient.cs
WalletWasabi/WabiSabi/Client/ArenaClient.cs
@@ -16,10 +16,6 @@ namespace WalletWasabi.WabiSabi.Client
{
public class ArenaClient
{
- public static readonly int ProtocolCredentialNumber = 2;
- public static readonly ulong ProtocolMaxAmountPerAlice = 4_300_000_000_000ul;
- public static readonly ulong ProtocolMaxVsizePerAlice = 250ul;
-
public ArenaClient(
CredentialIssuerParameters amountCredentialIssuerParameters,
CredentialIssuerParameters vsizeCredentialIssuerParameters,
@@ -28,8 +24,8 @@ namespace WalletWasabi.WabiSabi.Client
IArenaRequestHandler requestHandler,
WasabiRandom random)
{
- AmountCredentialClient = new WabiSabiClient(amountCredentialIssuerParameters, ProtocolCredentialNumber, random, ProtocolMaxAmountPerAlice, amountCredentialPool);
- VsizeCredentialClient = new WabiSabiClient(vsizeCredentialIssuerParameters, ProtocolCredentialNumber, random, ProtocolMaxVsizePerAlice, vsizeCredentialPool);
+ AmountCredentialClient = new WabiSabiClient(amountCredentialIssuerParameters, ProtocolConstants.CredentialNumber, random, ProtocolConstants.MaxAmountPerAlice, amountCredentialPool);
+ VsizeCredentialClient = new WabiSabiClient(vsizeCredentialIssuerParameters, ProtocolConstants.CredentialNumber, random, ProtocolConstants.MaxVsizePerAlice, vsizeCredentialPool);
RequestHandler = requestHandler;
}

ADD
WalletWasabi/WabiSabi/ProtocolContants.cs
+using NBitcoin;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Text;
+using System.Threading.Tasks;
+using WalletWasabi.Logging;
+using WalletWasabi.WabiSabi.Backend.Rounds;
+
+namespace WalletWasabi.WabiSabi
+{
+ public static class ProtocolConstants
+ {
+ public const int CredentialNumber = 2;
+ public const ulong MaxAmountPerAlice = 4_300_000_000_000ul;
+ public const uint MaxVsizePerAlice = 250;
+ }
+}
\ No newline at end of file

Move protocol constants to their own file