Convert to `TryGetCurrentInputRegisterableRound([NotNullWhen(true)] out CoordinatorRound? coordinatorRound)`
MODIFY
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
WalletWasabi.Tests/RegressionTests/CoinJoinTests.cs
@@ -33,6 +33,7 @@ using WalletWasabi.Tests.Helpers;
using WalletWasabi.Tests.XunitConfiguration;
using WalletWasabi.Tor.Http;
using WalletWasabi.Tor.Http.Extensions;
+using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.Wallets;
using WalletWasabi.WebClients.Wasabi;
using Xunit;
@@ -147,9 +148,8 @@ namespace WalletWasabi.Tests.RegressionTests
Inputs = null,
};
- var round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
- var roundId = round.RoundId;
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out CoordinatorRound? round));
+ var roundId = round!.RoundId;
inputsRequest.RoundId = roundId;
var registeredAddresses = Array.Empty<BitcoinAddress>();
var signerPubKeys = round.MixingLevels.SignerPubKeys;
@@ -214,8 +214,7 @@ namespace WalletWasabi.Tests.RegressionTests
httpRequestException = await Assert.ThrowsAsync<HttpRequestException>(async () => await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputsRequest));
Assert.Equal($"{HttpStatusCode.BadRequest.ToReasonString()}\nProvided proof is invalid.", httpRequestException.Message);
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
var requester = new Requester();
uint256 msg = new(NBitcoin.Crypto.Hashes.SHA256(network.Consensus.ConsensusFactory.CreateTransaction().ToBytes()));
var nonce = round.NonceProvider.GetNextNonce();
@@ -231,8 +230,7 @@ namespace WalletWasabi.Tests.RegressionTests
roundConfig.Denomination = Money.Coins(0.01m); // exactly the same as our output
coordinator.RoundConfig.UpdateOrDefault(roundConfig, toFile: true);
coordinator.AbortAllRoundsInInputRegistration("");
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
roundId = round.RoundId;
inputsRequest.RoundId = roundId;
signerPubKeys = round.MixingLevels.SignerPubKeys;
@@ -242,9 +240,8 @@ namespace WalletWasabi.Tests.RegressionTests
roundConfig.Denomination = Money.Coins(0.00999999m); // one satoshi less than our output
coordinator.RoundConfig.UpdateOrDefault(roundConfig, toFile: true);
coordinator.AbortAllRoundsInInputRegistration("");
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
- roundId = round.RoundId;
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
+ roundId = round!.RoundId;
inputsRequest.RoundId = roundId;
signerPubKeys = round.MixingLevels.SignerPubKeys;
httpRequestException = await Assert.ThrowsAsync<HttpRequestException>(async () => await CreateNewAliceClientAsync(roundId, registeredAddresses, signerPubKeys, requesters, inputsRequest));
@@ -254,9 +251,8 @@ namespace WalletWasabi.Tests.RegressionTests
roundConfig.ConnectionConfirmationTimeout = 7;
coordinator.RoundConfig.UpdateOrDefault(roundConfig, toFile: true);
coordinator.AbortAllRoundsInInputRegistration("");
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
- roundId = round.RoundId;
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
+ roundId = round!.RoundId;
inputsRequest.RoundId = roundId;
signerPubKeys = round.MixingLevels.SignerPubKeys;
requester = new Requester();
@@ -301,10 +297,9 @@ namespace WalletWasabi.Tests.RegressionTests
await aliceClient.PostUnConfirmationAsync();
}
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
requester = new Requester();
- nonce = round.NonceProvider.GetNextNonce();
+ nonce = round!.NonceProvider.GetNextNonce();
blindedData = new BlindedOutputWithNonceIndex(nonce.N, requester.BlindScript(round.MixingLevels.GetBaseLevel().SignerKey.PubKey, nonce.R, key.PubKey.ScriptPubKey));
inputsRequest.BlindedOutputScripts = new[] { blindedData };
blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(blindedData.BlindedOutput.ToBytes()));
@@ -400,9 +395,8 @@ namespace WalletWasabi.Tests.RegressionTests
roundConfig.ConnectionConfirmationTimeout = 1; // One second.
coordinator.RoundConfig.UpdateOrDefault(roundConfig, toFile: true);
coordinator.AbortAllRoundsInInputRegistration("");
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
- roundId = round.RoundId;
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
+ roundId = round!.RoundId;
inputsRequest.RoundId = roundId;
signerPubKeys = round.MixingLevels.SignerPubKeys;
@@ -450,14 +444,13 @@ namespace WalletWasabi.Tests.RegressionTests
await rpc.GenerateAsync(1);
tx = await rpc.GetRawTransactionAsync(hash);
coin = tx.Outputs.GetCoins(witnessAddress.ScriptPubKey).Single();
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
requester = new Requester();
requesters = new[] { requester };
var bitcoinWitPubKeyAddress = new Key().GetAddress(ScriptPubKeyType.Segwit, network);
registeredAddresses = new[] { bitcoinWitPubKeyAddress };
Script script = bitcoinWitPubKeyAddress.ScriptPubKey;
- nonce = round.NonceProvider.GetNextNonce();
+ nonce = round!.NonceProvider.GetNextNonce();
blindedData = new BlindedOutputWithNonceIndex(nonce.N, requester.BlindScript(round.MixingLevels.GetBaseLevel().SignerKey.PubKey, nonce.R, script));
blindedOutputScriptsHash = new uint256(NBitcoin.Crypto.Hashes.SHA256(blindedData.BlindedOutput.ToBytes()));
@@ -502,8 +495,8 @@ namespace WalletWasabi.Tests.RegressionTests
roundConfig.ConnectionConfirmationTimeout = 60;
coordinator.RoundConfig.UpdateOrDefault(roundConfig, toFile: true);
coordinator.AbortAllRoundsInInputRegistration("");
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault();
- roundId = round.RoundId;
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
+ roundId = round!.RoundId;
inputsRequest.RoundId = roundId;
signerPubKeys = round.MixingLevels.SignerPubKeys;
httpRequestException = await Assert.ThrowsAsync<HttpRequestException>(async () => await aliceClient.PostConfirmationAsync());
@@ -567,9 +560,8 @@ namespace WalletWasabi.Tests.RegressionTests
}
}
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
- signerPubKeys = round.MixingLevels.SignerPubKeys;
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
+ signerPubKeys = round!.MixingLevels.SignerPubKeys;
roundId = round.RoundId;
var requester1 = new Requester();
@@ -722,9 +714,8 @@ namespace WalletWasabi.Tests.RegressionTests
coordinator.AbortAllRoundsInInputRegistration("");
var satoshiClient = new SatoshiClient(BackendClearnetHttpClient);
- var round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
- var roundId = round.RoundId;
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out CoordinatorRound? round));
+ var roundId = round!.RoundId;
// We have to 4 participant so, this data structure is for keeping track of
// important data for each of the participants in the coinjoin session.
@@ -880,10 +871,10 @@ namespace WalletWasabi.Tests.RegressionTests
var userInputData = new List<(Key key, BitcoinAddress inputAddress, uint256 txHash, Transaction tx, OutPoint input)>();
var activeOutputAddress = new Key().GetAddress(ScriptPubKeyType.Segwit, network);
var changeOutputAddress = new Key().GetAddress(ScriptPubKeyType.Segwit, network);
- CoordinatorRound round = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(round);
+
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out CoordinatorRound? round));
var requester = new Requester();
- var nonce = round.NonceProvider.GetNextNonce();
+ var nonce = round!.NonceProvider.GetNextNonce();
BlindedOutputWithNonceIndex blinded = new(nonce.N, requester.BlindScript(round.MixingLevels.GetBaseLevel().SignerKey.PubKey, nonce.R, activeOutputAddress.ScriptPubKey));
uint256 blindedOutputScriptsHash = new(NBitcoin.Crypto.Hashes.SHA256(blinded.BlindedOutput.ToBytes()));
@@ -934,12 +925,11 @@ namespace WalletWasabi.Tests.RegressionTests
var aliceClients = new List<Task<AliceClient4>>();
- var currentRound = coordinator.GetCurrentInputRegisterableRoundOrDefault()!;
- Assert.NotNull(currentRound);
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out CoordinatorRound? currentRound));
foreach (var user in inputRegistrationUsers)
{
- aliceClients.Add(CreateNewAliceClientAsync(currentRound.RoundId,
+ aliceClients.Add(CreateNewAliceClientAsync(currentRound!.RoundId,
new[] { user.activeOutputAddress },
currentRound.MixingLevels.SignerPubKeys,
new[] { user.requester },

MODIFY
WalletWasabi.Tests/RegressionTests/DosTests.cs
WalletWasabi.Tests/RegressionTests/DosTests.cs
@@ -72,9 +72,9 @@ namespace WalletWasabi.Tests.RegressionTests
List<(Key key, BitcoinAddress inputAddress, uint256 txHash, Transaction tx, OutPoint input)> userInputData = new();
var activeOutputAddress = new Key().GetAddress(ScriptPubKeyType.Segwit, network);
var changeOutputAddress = new Key().GetAddress(ScriptPubKeyType.Segwit, network);
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault();
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
Requester requester = new();
- var nonce = round.NonceProvider.GetNextNonce();
+ var nonce = round!.NonceProvider.GetNextNonce();
BlindedOutputWithNonceIndex blinded = new(nonce.N, requester.BlindScript(round.MixingLevels.GetBaseLevel().SignerKey.PubKey, nonce.R, activeOutputAddress.ScriptPubKey));
uint256 blindedOutputScriptsHash = new(Hashes.SHA256(blinded.BlindedOutput.ToBytes()));
@@ -103,7 +103,7 @@ namespace WalletWasabi.Tests.RegressionTests
var inputProof = new InputProofModel { Input = input, Proof = key.SignCompact(blindedOutputScriptsHash) };
inputProofModels.Add(inputProof);
- GetTxOutResponse getTxOutResponse = await rpc.GetTxOutAsync(input.Hash, (int)input.N, includeMempool: true);
+ GetTxOutResponse? getTxOutResponse = await rpc.GetTxOutAsync(input.Hash, (int)input.N, includeMempool: true);
// Check if inputs are unspent.
Assert.NotNull(getTxOutResponse);
@@ -147,7 +147,7 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Equal(roundId, aliceClient.RoundId);
}
- // Because it's valuetuple.
+ // Because it's a value tuple.
users.Add((user.requester, user.blinded, user.activeOutputAddress, user.changeOutputAddress, user.inputProofModels, user.userInputData, aliceClient, null));
}
@@ -195,10 +195,10 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Equal(0, bannedCount);
aliceClients.Clear();
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault();
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
foreach (var user in inputRegistrationUsers)
{
- aliceClients.Add(AliceClientBase.CreateNewAsync(round.RoundId, new[] { user.activeOutputAddress }, new[] { round.MixingLevels.GetBaseLevel().SignerKey.PubKey }, new[] { user.requester }, network, user.changeOutputAddress, new[] { user.blinded }, user.inputProofModels, BackendHttpClient));
+ aliceClients.Add(AliceClientBase.CreateNewAsync(round!.RoundId, new[] { user.activeOutputAddress }, new[] { round.MixingLevels.GetBaseLevel().SignerKey.PubKey }, new[] { user.requester }, network, user.changeOutputAddress, new[] { user.blinded }, user.inputProofModels, BackendHttpClient));
}
roundId = 0;
@@ -218,7 +218,7 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Equal(roundId, aliceClient.RoundId);
}
- // Because it's valuetuple.
+ // Because it's a value tuple.
users.Add((user.requester, user.blinded, user.activeOutputAddress, user.changeOutputAddress, user.inputProofModels, user.userInputData, aliceClient, null));
}
@@ -271,7 +271,7 @@ namespace WalletWasabi.Tests.RegressionTests
List<(BitcoinAddress changeOutputAddress, BlindedOutputWithNonceIndex blindedData, InputProofModel[] inputsProofs)> registerRequests = new();
AliceClient4? aliceClientBackup = null;
- CoordinatorRound round = coordinator.GetCurrentInputRegisterableRoundOrDefault();
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out CoordinatorRound? round));
for (int i = 0; i < roundConfig.AnonymitySet; i++)
{
var activeOutputAddress = new Key().GetAddress(ScriptPubKeyType.Segwit, network);
@@ -280,7 +280,7 @@ namespace WalletWasabi.Tests.RegressionTests
var inputAddress = inputKey.PubKey.GetAddress(ScriptPubKeyType.Segwit, network);
Requester requester = new();
- var nonce = round.NonceProvider.GetNextNonce();
+ var nonce = round!.NonceProvider.GetNextNonce();
BlindedOutputWithNonceIndex blinded = new(nonce.N, requester.BlindScript(round.MixingLevels.GetBaseLevel().SignerKey.PubKey, nonce.R, activeOutputAddress.ScriptPubKey));
uint256 blindedOutputScriptsHash = new(Hashes.SHA256(blinded.BlindedOutput.ToBytes()));
@@ -303,12 +303,11 @@ namespace WalletWasabi.Tests.RegressionTests
Assert.Equal(0, bannedCount);
int notedCount = coordinator.UtxoReferee.CountBanned(true);
Assert.Equal(anonymitySet, notedCount);
-
- round = coordinator.GetCurrentInputRegisterableRoundOrDefault();
+ Assert.True(coordinator.TryGetCurrentInputRegisterableRound(out round));
foreach (var registerRequest in registerRequests)
{
- await AliceClientBase.CreateNewAsync(round.RoundId, aliceClientBackup.RegisteredAddresses, round.MixingLevels.GetAllLevels().Select(x => x.SignerKey.PubKey), aliceClientBackup.Requesters, network, registerRequest.changeOutputAddress, new[] { registerRequest.blindedData }, registerRequest.inputsProofs, BackendHttpClient);
+ await AliceClientBase.CreateNewAsync(round!.RoundId, aliceClientBackup.RegisteredAddresses, round.MixingLevels.GetAllLevels().Select(x => x.SignerKey.PubKey), aliceClientBackup.Requesters, network, registerRequest.changeOutputAddress, new[] { registerRequest.blindedData }, registerRequest.inputsProofs, BackendHttpClient);
}
await WaitForTimeoutAsync();

MODIFY
WalletWasabi/CoinJoin/Coordinator/Coordinator.cs
WalletWasabi/CoinJoin/Coordinator/Coordinator.cs
@@ -342,9 +342,7 @@ namespace WalletWasabi.CoinJoin.Coordinator
{
IEnumerable<Alice> alicesDidntSign = round.GetAlicesByNot(AliceState.SignedCoinJoin, syncLock: false);
- CoordinatorRound? nextRound = GetCurrentInputRegisterableRoundOrDefault(syncLock: false);
-
- if (nextRound is { })
+ if (TryGetCurrentInputRegisterableRound(out CoordinatorRound? nextRound, syncLock: false))
{
int nextRoundAlicesCount = nextRound.CountAlices(syncLock: false);
var alicesSignedCount = round.AnonymitySet - alicesDidntSign.Count();
@@ -411,17 +409,19 @@ namespace WalletWasabi.CoinJoin.Coordinator
}
}
- public CoordinatorRound? GetCurrentInputRegisterableRoundOrDefault(bool syncLock = true)
+ public bool TryGetCurrentInputRegisterableRound([NotNullWhen(true)] out CoordinatorRound? coordinatorRound, bool syncLock = true)
{
if (syncLock)
{
using (RoundsListLock.Lock())
{
- return Rounds.FirstOrDefault(x => x.Status == CoordinatorRoundStatus.Running && x.Phase == RoundPhase.InputRegistration);
+ coordinatorRound = Rounds.FirstOrDefault(x => x.Status == CoordinatorRoundStatus.Running && x.Phase == RoundPhase.InputRegistration);
+ return coordinatorRound is not null;
}
}
- return Rounds.FirstOrDefault(x => x.Status == CoordinatorRoundStatus.Running && x.Phase == RoundPhase.InputRegistration);
+ coordinatorRound = Rounds.FirstOrDefault(x => x.Status == CoordinatorRoundStatus.Running && x.Phase == RoundPhase.InputRegistration);
+ return coordinatorRound is not null;
}
public bool TryGetRound(long roundId, [NotNullWhen(true)] out CoordinatorRound? coordinatorRound)

Convert to `TryGetCurrentInputRegisterableRound([NotNullWhen(true)] out CoordinatorRound? coordinatorRound)`