Remove mixin (It was never used)
MODIFY
WalletWasabi.Tests/ModelTests.cs
WalletWasabi.Tests/ModelTests.cs
@@ -66,16 +66,16 @@ namespace WalletWasabi.Tests
var height = Height.MemPool;
var label = "foo";
- var coin = new SmartCoin(txId, index, scriptPubKey, amount, spentOutputs, height, tx.RBF, tx.GetMixin(index), label, txId);
+ var coin = new SmartCoin(txId, index, scriptPubKey, amount, spentOutputs, height, tx.RBF, tx.GetAnonymitySet(index), label, txId);
// If the txid or the index differs, equality should think it's a different coin.
- var differentCoin = new SmartCoin(txId, index + 1, scriptPubKey, amount, spentOutputs, height, tx.RBF, tx.GetMixin(index + 1), label, txId);
+ var differentCoin = new SmartCoin(txId, index + 1, scriptPubKey, amount, spentOutputs, height, tx.RBF, tx.GetAnonymitySet(index + 1), label, txId);
var differentOutput = tx.Outputs[1];
var differentSpentOutputs = new[]
{
new TxoRef(txId, 0)
};
// If the txid and the index is the same, equality should think it's the same coin.
- var sameCoin = new SmartCoin(txId, index, differentOutput.ScriptPubKey, differentOutput.Value, differentSpentOutputs, Height.Unknown, tx.RBF, tx.GetMixin(index), "boo", null);
+ var sameCoin = new SmartCoin(txId, index, differentOutput.ScriptPubKey, differentOutput.Value, differentSpentOutputs, Height.Unknown, tx.RBF, tx.GetAnonymitySet(index), "boo", null);
Assert.Equal(coin, sameCoin);
Assert.NotEqual(coin, differentCoin);
@@ -160,7 +160,7 @@ namespace WalletWasabi.Tests
var label = "foo";
var bannedUntil = DateTimeOffset.UtcNow;
- var coin = new SmartCoin(txId, index, scriptPubKey, amount, spentOutputs, height, tx.RBF, tx.GetMixin(index), label, txId);
+ var coin = new SmartCoin(txId, index, scriptPubKey, amount, spentOutputs, height, tx.RBF, tx.GetAnonymitySet(index), label, txId);
coin.BannedUntilUtc = bannedUntil;
var serialized = JsonConvert.SerializeObject(coin);

MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -1559,7 +1559,7 @@ namespace WalletWasabi.Tests
new WalletService.Operation(new Key().ScriptPubKey, Money.Coins(0.01m), "")
};
var tx1Res = wallet.BuildTransaction(password, operations, 2, allowUnconfirmed: true);
- Assert.Equal(2, tx1Res.OuterWalletOutputs.Single(x => x.ScriptPubKey == key.P2wpkhScript).Mixin);
+ Assert.Equal(3, tx1Res.OuterWalletOutputs.Single(x => x.ScriptPubKey == key.P2wpkhScript).AnonymitySet);
// Spend the unconfirmed coin (send it to ourself)
operations = new[] { new WalletService.Operation(key.PubKey.WitHash.ScriptPubKey, Money.Coins(0.5m), "") };
@@ -1869,7 +1869,7 @@ namespace WalletWasabi.Tests
// Test DelayedClientRoundRegistration logic.
ClientRoundRegistration first = null;
var second = new ClientRoundRegistration(aliceClient,
- new[] { new SmartCoin(uint256.One, 1, Script.Empty, Money.Zero, new[] { new TxoRef(uint256.One, 1) }, Height.Unknown, true, 1) },
+ new[] { new SmartCoin(uint256.One, 1, Script.Empty, Money.Zero, new[] { new TxoRef(uint256.One, 1) }, Height.Unknown, true, 2) },
BitcoinAddress.Create("12Rty3c8j3QiZSwLVaBtch6XUMZaja3RC7", Network.Main));
first = second;
second = null;
@@ -2941,7 +2941,7 @@ namespace WalletWasabi.Tests
var height = await rpc.GetBlockCountAsync();
var bechCoin = tx.Outputs.GetCoins(bech.ScriptPubKey).Single();
- var smartCoin = new SmartCoin(bechCoin, tx.Inputs.Select(x => new TxoRef(x.PrevOut)).ToArray(), height + 1, rbf: false, mixin: tx.GetMixin(bechCoin.Outpoint.N));
+ var smartCoin = new SmartCoin(bechCoin, tx.Inputs.Select(x => new TxoRef(x.PrevOut)).ToArray(), height + 1, rbf: false, anonymitySet: tx.GetAnonymitySet(bechCoin.Outpoint.N));
var chaumianClient = new CcjClient(synchronizer, rpc.Network, keyManager, new Uri(RegTestFixture.BackendEndPoint), null);
@@ -3046,10 +3046,10 @@ namespace WalletWasabi.Tests
var bech3Coin = tx3.Outputs.GetCoins(bech3.ScriptPubKey).Single();
var bech4Coin = tx4.Outputs.GetCoins(bech4.ScriptPubKey).Single();
- var smartCoin1 = new SmartCoin(bech1Coin, tx1.Inputs.Select(x => new TxoRef(x.PrevOut)).ToArray(), height, rbf: false, mixin: tx1.GetMixin(bech1Coin.Outpoint.N));
- var smartCoin2 = new SmartCoin(bech2Coin, tx2.Inputs.Select(x => new TxoRef(x.PrevOut)).ToArray(), height, rbf: false, mixin: tx2.GetMixin(bech2Coin.Outpoint.N));
- var smartCoin3 = new SmartCoin(bech3Coin, tx3.Inputs.Select(x => new TxoRef(x.PrevOut)).ToArray(), height, rbf: false, mixin: tx3.GetMixin(bech3Coin.Outpoint.N));
- var smartCoin4 = new SmartCoin(bech4Coin, tx4.Inputs.Select(x => new TxoRef(x.PrevOut)).ToArray(), height, rbf: false, mixin: tx4.GetMixin(bech4Coin.Outpoint.N));
+ var smartCoin1 = new SmartCoin(bech1Coin, tx1.Inputs.Select(x => new TxoRef(x.PrevOut)).ToArray(), height, rbf: false, anonymitySet: tx1.GetAnonymitySet(bech1Coin.Outpoint.N));
+ var smartCoin2 = new SmartCoin(bech2Coin, tx2.Inputs.Select(x => new TxoRef(x.PrevOut)).ToArray(), height, rbf: false, anonymitySet: tx2.GetAnonymitySet(bech2Coin.Outpoint.N));
+ var smartCoin3 = new SmartCoin(bech3Coin, tx3.Inputs.Select(x => new TxoRef(x.PrevOut)).ToArray(), height, rbf: false, anonymitySet: tx3.GetAnonymitySet(bech3Coin.Outpoint.N));
+ var smartCoin4 = new SmartCoin(bech4Coin, tx4.Inputs.Select(x => new TxoRef(x.PrevOut)).ToArray(), height, rbf: false, anonymitySet: tx4.GetAnonymitySet(bech4Coin.Outpoint.N));
var chaumianClient1 = new CcjClient(synchronizer, rpc.Network, keyManager, new Uri(RegTestFixture.BackendEndPoint), null);
var chaumianClient2 = new CcjClient(synchronizer, rpc.Network, keyManager, new Uri(RegTestFixture.BackendEndPoint), null);
@@ -3072,7 +3072,7 @@ namespace WalletWasabi.Tests
Assert.True(smartCoin2.CoinJoinInProgress);
// Make sure it doesn't throw.
- await chaumianClient1.DequeueCoinsFromMixAsync(new SmartCoin((network.Consensus.ConsensusFactory.CreateTransaction()).GetHash(), 1, new Script(), Money.Parse("3"), new TxoRef[] { new TxoRef((network.Consensus.ConsensusFactory.CreateTransaction()).GetHash(), 0) }, Height.MemPool, rbf: false, mixin: 0));
+ await chaumianClient1.DequeueCoinsFromMixAsync(new SmartCoin((network.Consensus.ConsensusFactory.CreateTransaction()).GetHash(), 1, new Script(), Money.Parse("3"), new TxoRef[] { new TxoRef((network.Consensus.ConsensusFactory.CreateTransaction()).GetHash(), 0) }, Height.MemPool, rbf: false, anonymitySet: 1));
Assert.True(2 == (await chaumianClient1.QueueCoinsToMixAsync(password, smartCoin1, smartCoin2)).Count());
await chaumianClient1.DequeueCoinsFromMixAsync(smartCoin1);

MODIFY
WalletWasabi/Extensions/NBitcoinExtensions.cs
WalletWasabi/Extensions/NBitcoinExtensions.cs
@@ -77,11 +77,7 @@ namespace NBitcoin
return me.GetIndistinguishableOutputs(includeSingle: true).Single(x => x.value == output.Value).count;
}
- public static int GetMixin(this Transaction me, uint outputIndex)
- {
- var output = me.Outputs[outputIndex];
- return me.GetIndistinguishableOutputs(includeSingle: true).Single(x => x.value == output.Value).count - 1;
- }
+ public static int GetAnonymitySet(this Transaction me, uint outputIndex) => GetAnonymitySet(me, (int)outputIndex);
/// <summary>
/// Careful, if it's in a legacy block then this won't work.

MODIFY
WalletWasabi/Models/SmartCoin.cs
WalletWasabi/Models/SmartCoin.cs
@@ -35,7 +35,7 @@ namespace WalletWasabi.Models
private string _label;
private TxoRef[] _spentOutputs;
private bool _rbf;
- private int _mixin;
+ private int _anonymitySet;
private uint256 _spenderTransactionId;
private bool _coinJoinInProgress;
private DateTimeOffset? _bannedUntilUtc;
@@ -48,7 +48,6 @@ namespace WalletWasabi.Models
private bool _spentOrCoinJoinInProgress;
private bool _unspent;
private bool _isBanned;
- private int _anonymitySet;
private string _history;
#endregion Fields
@@ -175,20 +174,16 @@ namespace WalletWasabi.Models
}
}
- /// <summary>
- /// AnonymitySet - 1
- /// </summary>
[JsonProperty]
- public int Mixin
+ public int AnonymitySet
{
- get => _mixin;
- set
+ get => _anonymitySet;
+ private set
{
- if (value != _mixin)
+ if (value != _anonymitySet)
{
- _mixin = value;
- OnPropertyChanged(nameof(Mixin));
- SetAnonymitySet();
+ _anonymitySet = value;
+ OnPropertyChanged(nameof(AnonymitySet));
}
}
}
@@ -365,22 +360,6 @@ namespace WalletWasabi.Models
}
}
- /// <summary>
- /// Mixin + 1
- /// </summary>
- public int AnonymitySet
- {
- get => _anonymitySet;
- private set
- {
- if (value != _anonymitySet)
- {
- _anonymitySet = value;
- OnPropertyChanged(nameof(AnonymitySet));
- }
- }
- }
-
#endregion DependentProperties
#region PropertySetters
@@ -390,11 +369,6 @@ namespace WalletWasabi.Models
Confirmed = Height != Height.MemPool && Height != Height.Unknown;
}
- private void SetAnonymitySet()
- {
- AnonymitySet = Mixin + 1;
- }
-
private void SetUnspent()
{
Unspent = SpenderTransactionId is null;
@@ -417,12 +391,12 @@ namespace WalletWasabi.Models
#region Constructors
[JsonConstructor]
- public SmartCoin(uint256 transactionId, uint index, Script scriptPubKey, Money amount, TxoRef[] spentOutputs, Height height, bool rbf, int mixin, string label = "", uint256 spenderTransactionId = null, bool coinJoinInProgress = false, DateTimeOffset? bannedUntilUtc = null, bool spentAccordingToBackend = false, HdPubKey pubKey = null)
+ public SmartCoin(uint256 transactionId, uint index, Script scriptPubKey, Money amount, TxoRef[] spentOutputs, Height height, bool rbf, int anonymitySet, string label = "", uint256 spenderTransactionId = null, bool coinJoinInProgress = false, DateTimeOffset? bannedUntilUtc = null, bool spentAccordingToBackend = false, HdPubKey pubKey = null)
{
- Create(transactionId, index, scriptPubKey, amount, spentOutputs, height, rbf, mixin, label, spenderTransactionId, coinJoinInProgress, bannedUntilUtc, spentAccordingToBackend, pubKey);
+ Create(transactionId, index, scriptPubKey, amount, spentOutputs, height, rbf, anonymitySet, label, spenderTransactionId, coinJoinInProgress, bannedUntilUtc, spentAccordingToBackend, pubKey);
}
- public SmartCoin(Coin coin, TxoRef[] spentOutputs, Height height, bool rbf, int mixin, string label = "", uint256 spenderTransactionId = null, bool coinJoinInProgress = false, DateTimeOffset? bannedUntilUtc = null, bool spentAccordingToBackend = false, HdPubKey pubKey = null)
+ public SmartCoin(Coin coin, TxoRef[] spentOutputs, Height height, bool rbf, int anonymitySet, string label = "", uint256 spenderTransactionId = null, bool coinJoinInProgress = false, DateTimeOffset? bannedUntilUtc = null, bool spentAccordingToBackend = false, HdPubKey pubKey = null)
{
OutPoint outpoint = Guard.NotNull($"{coin}.{coin?.Outpoint}", coin?.Outpoint);
uint256 transactionId = outpoint.Hash;
@@ -430,10 +404,10 @@ namespace WalletWasabi.Models
Script scriptPubKey = Guard.NotNull($"{coin}.{coin?.ScriptPubKey}", coin?.ScriptPubKey);
Money amount = Guard.NotNull($"{coin}.{coin?.Amount}", coin?.Amount);
- Create(transactionId, index, scriptPubKey, amount, spentOutputs, height, rbf, mixin, label, spenderTransactionId, coinJoinInProgress, bannedUntilUtc, spentAccordingToBackend, pubKey);
+ Create(transactionId, index, scriptPubKey, amount, spentOutputs, height, rbf, anonymitySet, label, spenderTransactionId, coinJoinInProgress, bannedUntilUtc, spentAccordingToBackend, pubKey);
}
- private void Create(uint256 transactionId, uint index, Script scriptPubKey, Money amount, TxoRef[] spentOutputs, Height height, bool rbf, int mixin, string label, uint256 spenderTransactionId, bool coinJoinInProgress, DateTimeOffset? bannedUntilUtc, bool spentAccordingToBackend, HdPubKey pubKey)
+ private void Create(uint256 transactionId, uint index, Script scriptPubKey, Money amount, TxoRef[] spentOutputs, Height height, bool rbf, int anonymitySet, string label, uint256 spenderTransactionId, bool coinJoinInProgress, DateTimeOffset? bannedUntilUtc, bool spentAccordingToBackend, HdPubKey pubKey)
{
TransactionId = Guard.NotNull(nameof(transactionId), transactionId);
Index = Guard.NotNull(nameof(index), index);
@@ -443,7 +417,7 @@ namespace WalletWasabi.Models
Label = Guard.Correct(label);
SpentOutputs = Guard.NotNullOrEmpty(nameof(spentOutputs), spentOutputs);
RBF = rbf;
- Mixin = Guard.InRangeAndNotNull(nameof(mixin), mixin, 0, int.MaxValue);
+ AnonymitySet = Guard.InRangeAndNotNull(nameof(anonymitySet), anonymitySet, 1, int.MaxValue);
SpenderTransactionId = spenderTransactionId;
@@ -454,7 +428,6 @@ namespace WalletWasabi.Models
HdPubKey = pubKey;
SetConfirmed();
- SetAnonymitySet();
SetUnspent();
SetIsBanned();
SetSpentOrCoinJoinInProgress();

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -526,10 +526,10 @@ namespace WalletWasabi.Services
{
foundKey.SetKeyState(KeyState.Used, KeyManager);
List<SmartCoin> spentOwnCoins = Coins.Where(x => tx.Transaction.Inputs.Any(y => y.PrevOut.Hash == x.TransactionId && y.PrevOut.N == x.Index)).ToList();
- var mixin = tx.Transaction.GetMixin(i);
+ var anonset = tx.Transaction.GetAnonymitySet(i);
if (spentOwnCoins.Count != 0)
{
- mixin += spentOwnCoins.Min(x => x.Mixin);
+ anonset += spentOwnCoins.Min(x => x.AnonymitySet);
// Cleanup exposed links where the txo has been spent.
foreach (var input in spentOwnCoins.Select(x => x.GetTxoRef()))
@@ -538,7 +538,7 @@ namespace WalletWasabi.Services
}
}
- SmartCoin newCoin = new SmartCoin(txId, i, output.ScriptPubKey, output.Value, tx.Transaction.Inputs.ToTxoRefs().ToArray(), tx.Height, tx.Transaction.RBF, mixin, foundKey.Label, spenderTransactionId: null, false, pubKey: foundKey); // Don't inherit locked status from key, that's different.
+ SmartCoin newCoin = new SmartCoin(txId, i, output.ScriptPubKey, output.Value, tx.Transaction.Inputs.ToTxoRefs().ToArray(), tx.Height, tx.Transaction.RBF, anonset, foundKey.Label, spenderTransactionId: null, false, pubKey: foundKey); // Don't inherit locked status from key, that's different.
// If we didn't have it.
if (Coins.TryAdd(newCoin))
{
@@ -1150,9 +1150,9 @@ namespace WalletWasabi.Services
for (var i = 0U; i < tx.Outputs.Count; i++)
{
TxOut output = tx.Outputs[i];
- var mixin = tx.GetMixin(i) + spentCoins.Min(x => x.Mixin);
+ var anonset = tx.GetAnonymitySet(i) + spentCoins.Min(x => x.AnonymitySet);
var foundKey = KeyManager.GetKeys(KeyState.Clean).FirstOrDefault(x => output.ScriptPubKey == x.P2wpkhScript);
- var coin = new SmartCoin(tx.GetHash(), i, output.ScriptPubKey, output.Value, tx.Inputs.ToTxoRefs().ToArray(), Height.Unknown, tx.RBF, mixin, pubKey: foundKey);
+ var coin = new SmartCoin(tx.GetHash(), i, output.ScriptPubKey, output.Value, tx.Inputs.ToTxoRefs().ToArray(), Height.Unknown, tx.RBF, anonset, pubKey: foundKey);
if (foundKey != null)
{

Remove mixin (It was never used)