Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organize (move) client side CJ related code #12671

Merged
merged 5 commits into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions WalletWasabi.Daemon/Rpc/WasabiJsonRpcService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using WalletWasabi.Services;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.Batching;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using WalletWasabi.Wallets;
using JsonRpcResult = System.Collections.Generic.Dictionary<string, object?>;
using JsonRpcResultList = System.Collections.Immutable.ImmutableArray<System.Collections.Generic.Dictionary<string, object?>>;
Expand Down
3 changes: 2 additions & 1 deletion WalletWasabi.Fluent/Models/Wallets/CoinjoinModel.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using ReactiveUI;
using System.Threading.Tasks;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;

namespace WalletWasabi.Fluent.Models.Wallets;

[AutoInterface]
public partial class CoinjoinModel: ReactiveObject
public partial class CoinjoinModel : ReactiveObject
{
private CoinJoinManager? _coinJoinManager;

Expand Down
1 change: 1 addition & 0 deletions WalletWasabi.Tests/Helpers/WabiSabiFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
using WalletWasabi.Wallets;
using WalletWasabi.WebClients.Wasabi;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;

namespace WalletWasabi.Tests.Helpers;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using WalletWasabi.WabiSabi.Backend.Models;
using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using WalletWasabi.WabiSabi.Client.RoundStateAwaiters;
using WalletWasabi.WabiSabi.Models;
using WalletWasabi.Wallets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using WalletWasabi.WabiSabi.Backend.Models;
using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using WalletWasabi.WabiSabi.Client.RoundStateAwaiters;
using WalletWasabi.WabiSabi.Models;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using WalletWasabi.WabiSabi.Backend.DoSPrevention;
using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using WalletWasabi.WabiSabi.Client.RoundStateAwaiters;
using WalletWasabi.WabiSabi.Models;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
using WalletWasabi.WabiSabi.Backend.Models;
using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Backend.Rounds.CoinJoinStorage;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Models;
using Xunit;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;

namespace WalletWasabi.Tests.UnitTests.WabiSabi.Backend.PostRequests;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using Xunit;
using WalletWasabi.WabiSabi.Backend.Rounds.CoinJoinStorage;
using WalletWasabi.BitcoinCore.Mempool;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;

namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using WalletWasabi.WabiSabi.Backend.Rounds.CoinJoinStorage;
using WalletWasabi.WabiSabi.Backend.Statistics;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using WalletWasabi.WabiSabi.Client.RoundStateAwaiters;
using WalletWasabi.WabiSabi.Models;
using WalletWasabi.Wallets;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using NBitcoin;
using WalletWasabi.Tests.Helpers;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client.Decomp;
using WalletWasabi.Wallets;
using Xunit;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using WalletWasabi.Tests.Helpers;
using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using Xunit;

namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.Collections.Generic;
using NBitcoin;
using WalletWasabi.Helpers;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using Xunit;

namespace WalletWasabi.Tests.UnitTests.WabiSabi.Client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
using WalletWasabi.WabiSabi.Models;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
using WalletWasabi.BitcoinCore.Mempool;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;

namespace WalletWasabi.Tests.UnitTests.WabiSabi.Integration;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Xunit;
using Xunit.Abstractions;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;

namespace WalletWasabi.Tests.UnitTests.WabiSabi.Integration;

Expand Down
1 change: 1 addition & 0 deletions WalletWasabi/Services/SleepInhibitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using WalletWasabi.Helpers.PowerSaving;
using WalletWasabi.Logging;
using WalletWasabi.WabiSabi.Client;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using static WalletWasabi.Helpers.PowerSaving.LinuxInhibitorTask;

namespace WalletWasabi.Services;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
using WabiSabi.Crypto.ZeroKnowledge;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client;

public class AliceClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using WalletWasabi.WabiSabi.Models;
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client;

public class ArenaClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using WabiSabi.Crypto.ZeroKnowledge;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client;

public class ArenaResponse
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.Threading.Tasks;
using WabiSabi.Crypto.ZeroKnowledge;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client;

public class BobClient
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
using WalletWasabi.WabiSabi.Models.MultipartyTransaction;
using WalletWasabi.WebClients.Wasabi;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client;

public class CoinJoinClient
{
Expand Down Expand Up @@ -617,8 +617,7 @@ internal static bool SanityCheck(IEnumerable<TxOut> expectedOutputs, IEnumerable
var maximumSigningRequestDelay = TimeSpan.FromSeconds(50);
var scheduledDates = signingEndTime.GetScheduledDates(aliceClients.Count(), signingStartTime, maximumSigningRequestDelay);

var tasks = Enumerable.Zip(
aliceClients,
var tasks = aliceClients.Zip(
scheduledDates,
async (aliceClient, scheduledDate) =>
{
Expand Down Expand Up @@ -648,8 +647,7 @@ private async Task ReadyToSignAsync(IEnumerable<AliceClient> aliceClients, DateT
{
var scheduledDates = readyToSignEndTime.GetScheduledDates(aliceClients.Count(), DateTimeOffset.UtcNow, MaximumRequestDelay);

var tasks = Enumerable.Zip(
aliceClients,
var tasks = aliceClients.Zip(
scheduledDates,
async (aliceClient, scheduledDate) =>
{
Expand Down Expand Up @@ -741,7 +739,7 @@ private async Task<IEnumerable<TxOut>> ProceedWithOutputRegistrationPhaseAsync(u

// Splitting the remaining time.
// Both operations are done under output registration phase, so we have to do the random timing taking that into account.
var outputRegistrationEndTime = now + (remainingTime * 0.8); // 80% of the time.
var outputRegistrationEndTime = now + remainingTime * 0.8; // 80% of the time.
var readyToSignEndTime = outputRegistrationEndTime + remainingTime * 0.2; // 20% of the time.

CoinJoinClientProgress.SafeInvoke(this, new EnteringOutputRegistrationPhase(roundState, outputRegistrationPhaseEndTime));
Expand Down Expand Up @@ -842,7 +840,7 @@ private async Task<IEnumerable<TxOut>> ProceedWithOutputRegistrationPhaseAsync(u
private async Task<ImmutableArray<(AliceClient, PersonCircuit)>> ProceedWithInputRegAndConfirmAsync(IEnumerable<SmartCoin> smartCoins, RoundState roundState, CancellationToken cancellationToken)
{
// Because of the nature of the protocol, the input registration and the connection confirmation phases are done subsequently thus they have a merged timeout.
var timeUntilOutputReg = (roundState.InputRegistrationEnd - DateTimeOffset.UtcNow) + roundState.CoinjoinState.Parameters.ConnectionConfirmationTimeout;
var timeUntilOutputReg = roundState.InputRegistrationEnd - DateTimeOffset.UtcNow + roundState.CoinjoinState.Parameters.ConnectionConfirmationTimeout;

using CancellationTokenSource timeUntilOutputRegCts = new(timeUntilOutputReg + ExtraPhaseTimeoutMargin);
using CancellationTokenSource linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeUntilOutputRegCts.Token);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using WalletWasabi.WabiSabi.Client.StatusChangedEvents;

namespace WalletWasabi.Exceptions;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client;

public class CoinJoinClientException : Exception
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client;

public enum CoinJoinClientState
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
using WalletWasabi.Wallets;
using SecureRandom = WabiSabi.Crypto.Randomness.SecureRandom;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client;

public class CoinJoinCoinSelector
{
Expand Down Expand Up @@ -292,7 +292,7 @@ public ImmutableList<TCoin> SelectCoinsForRound<TCoin>(IEnumerable<TCoin> coins,
double winnerAnonLoss = GetAnonLoss(winner);

// Only stay in the while if we are above the liquidityClue (we are a whale) AND the weightedAnonLoss is not tolerable.
while ((winner.Sum(x => x.Amount) > liquidityClue) && (winnerAnonLoss > MaxWeightedAnonLoss))
while (winner.Sum(x => x.Amount) > liquidityClue && winnerAnonLoss > MaxWeightedAnonLoss)
{
List<TCoin> bestReducedWinner = winner;
var bestAnonLoss = winnerAnonLoss;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using WabiSabi.Crypto.Randomness;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client;

/// <summary>
/// Generator of randomness for <see cref="CoinJoinCoinSelector"/>.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using WabiSabi.Crypto.Randomness;
using WalletWasabi.Extensions;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client.Decomp;
using WalletWasabi.WabiSabi.Models;

namespace WalletWasabi.WabiSabi.Client;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Linq;
using WalletWasabi.Extensions;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client.Decomp;

/// <summary>
/// Notebook: https://github.com/lontivero/DecompositionsPlayground/blob/master/Notebook.ipynb
Expand Down Expand Up @@ -37,7 +37,7 @@ private static IEnumerable<(long Sum, int Count, ulong Decomposition)> InternalC
long sum,
int k)
{
accumulator = (accumulator << 8) | ((ulong)currentDenominationIdx & 0xff);
accumulator = accumulator << 8 | (ulong)currentDenominationIdx & 0xff;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done automatically.

var currentDenomination = denoms[currentDenominationIdx];
sum += currentDenomination;
var remaining = target - sum;
Expand Down Expand Up @@ -69,7 +69,7 @@ public static IEnumerable<long> ToRealValuesArray(ulong decomposition, int count
var list = new long[count];
for (var i = 0; i < count; i++)
{
var index = (decomposition >> (i * 8)) & 0xff;
var index = decomposition >> i * 8 & 0xff;
list[count - i - 1] = denoms[index];
}
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using WabiSabi.Crypto.Randomness;
using WalletWasabi.Extensions;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client.Decomp;

public static class DenominationBuilder
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Diagnostics.CodeAnalysis;
using WalletWasabi.Extensions;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client.Decomp;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad why this was not changed...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind GitHub displayed it wrong.


public record Output
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
using WalletWasabi.WabiSabi.Backend.Models;
using WalletWasabi.WabiSabi.Client.CredentialDependencies;

namespace WalletWasabi.WabiSabi.Client;
namespace WalletWasabi.WabiSabi.Client.CoinJoin.Client;

public class DependencyGraphTaskScheduler
{
public DependencyGraphTaskScheduler(DependencyGraph graph)
{
Graph = graph;
var allInEdges = Enum.GetValues<CredentialType>()
.SelectMany(type => Enumerable.Concat<RequestNode>(Graph.Reissuances, Graph.Outputs)
.SelectMany(type => Graph.Reissuances.Concat<RequestNode>(Graph.Outputs)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was done automatically.

.SelectMany(node => Graph.EdgeSets[type].InEdges(node)));
DependencyTasks = allInEdges.ToDictionary(edge => edge, _ => new TaskCompletionSource<Credential>(TaskCreationOptions.RunContinuationsAsynchronously));
}
Expand Down Expand Up @@ -205,6 +205,6 @@ private IEnumerable<(AliceClient AliceClient, InputNode Node)> PairAliceClientAn
throw new InvalidOperationException("Graph vs Alice inputs mismatch");
}

return Enumerable.Zip(aliceClients, inputNodes);
return aliceClients.Zip(inputNodes);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using WalletWasabi.Extensions;
using WalletWasabi.WabiSabi.Backend.Rounds;
using WalletWasabi.WabiSabi.Models;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client.Decomp;

namespace WalletWasabi.WabiSabi.Client;

Expand All @@ -29,7 +30,7 @@ public static UtxoSelectionParameters FromRoundParameters(RoundParameters roundP
.Min(x => x.EffectiveCost);
var smallestReasonableEffectiveDenomination =
smallestEffectiveDenom
?? throw new InvalidOperationException("Something's wrong with the denomination creation or with the parameters it got.");
?? throw new InvalidOperationException("Something's wrong with the denomination creation or with the parameters it got.");

return new(
roundParameters.AllowedInputAmounts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using WalletWasabi.Logging;
using WalletWasabi.WabiSabi.Backend.Models;
using WalletWasabi.WabiSabi.Client.Banning;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using WalletWasabi.WabiSabi.Client.CoinJoinProgressEvents;
using WalletWasabi.WabiSabi.Client.RoundStateAwaiters;
using WalletWasabi.WabiSabi.Client.StatusChangedEvents;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using WalletWasabi.WabiSabi.Client.CoinJoinProgressEvents;
using WalletWasabi.Wallets;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Threading;
using System.Threading.Tasks;
using WalletWasabi.Blockchain.TransactionOutputs;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;
using WalletWasabi.WabiSabi.Client.RoundStateAwaiters;
using WalletWasabi.Wallets;
using WalletWasabi.WebClients.Wasabi;
Expand Down
1 change: 1 addition & 0 deletions WalletWasabi/WabiSabi/Client/OutputProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using WalletWasabi.WabiSabi.Backend.Rounds;
using WabiSabi.Crypto.Randomness;
using WalletWasabi.WabiSabi.Client.Batching;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client.Decomp;

namespace WalletWasabi.WabiSabi.Client;

Expand Down
1 change: 1 addition & 0 deletions WalletWasabi/WabiSabi/Client/SmartRequestNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Threading;
using System.Threading.Tasks;
using WabiSabi.Crypto.ZeroKnowledge;
using WalletWasabi.WabiSabi.Client.CoinJoin.Client;

namespace WalletWasabi.WabiSabi.Client;

Expand Down