Potentially fix anonySet decrease bug
After coinJoin, your new coin's anonimity set would decrease back to 1 until confirmation, altough it should have a new, increased anonimitySet value.
MODIFY
WalletWasabi.Tests/UnitTests/Transactions/TransactionProcessorTests.cs
WalletWasabi.Tests/UnitTests/Transactions/TransactionProcessorTests.cs
@@ -629,6 +629,50 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.Empty(matureTxs);
}
+ [Fact]
+ public async Task CorrectSpenderAsync()
+ {
+ var transactionProcessor = await CreateTransactionProcessorAsync();
+ SmartCoin? spentCoin = null;
+ transactionProcessor.WalletRelevantTransactionProcessed += (s, e) =>
+ {
+ if (e.NewlySpentCoins.Any())
+ {
+ spentCoin = e.NewlySpentCoins.Single();
+ }
+ };
+ var keys = transactionProcessor.KeyManager.GetKeys();
+ var tx0 = CreateCreditingTransaction(keys.First().P2wpkhScript, Money.Coins(1.0m));
+ transactionProcessor.Process(tx0);
+
+ var createdCoin = tx0.Transaction.Outputs.AsCoins().First();
+
+ // Spend the received coin
+ using Key key = new();
+ var tx1 = CreateSpendingTransaction(createdCoin, key.PubKey.ScriptPubKey);
+
+ transactionProcessor.Process(tx1);
+
+ var tx2 = new SmartTransaction(tx1.Transaction, tx1.Height, tx1.BlockHash, tx1.BlockIndex, tx1.Label, tx1.IsReplacement, tx1.FirstSeen);
+ var relevant = transactionProcessor.Process(tx2);
+
+ Assert.False(relevant.IsNews);
+ var coin = Assert.Single(transactionProcessor.Coins.AsAllCoinsView());
+ Assert.True(coin.IsSpent());
+ Assert.NotNull(spentCoin);
+ Assert.Equal(coin, spentCoin);
+
+ // Transaction store assertions
+ var mempool = transactionProcessor.TransactionStore.MempoolStore.GetTransactions();
+ Assert.Equal(2, mempool.Count());
+
+ var matureTxs = transactionProcessor.TransactionStore.ConfirmedStore.GetTransactions().ToArray();
+ Assert.Empty(matureTxs);
+
+ Assert.True(Object.ReferenceEquals(tx2, spentCoin?.SpenderTransaction));
+ Assert.False(Object.ReferenceEquals(tx1, spentCoin?.SpenderTransaction));
+ }
+
[Fact]
public async Task ReceiveTransactionWithDustForWalletAsync()
{

MODIFY
WalletWasabi/Blockchain/TransactionOutputs/SmartCoin.cs
WalletWasabi/Blockchain/TransactionOutputs/SmartCoin.cs
@@ -78,8 +78,10 @@ namespace WalletWasabi.Blockchain.TransactionOutputs
get => _spenderTransaction;
set
{
- if (RaiseAndSetIfChanged(ref _spenderTransaction, value))
+ if (!Object.ReferenceEquals(value, _spenderTransaction))
{
+ _spenderTransaction = value;
+ OnPropertyChanged(nameof(SpenderTransaction));
value?.WalletInputs.Add(this);
}
}

MODIFY
WalletWasabi/Blockchain/TransactionProcessing/TransactionProcessor.cs
WalletWasabi/Blockchain/TransactionProcessing/TransactionProcessor.cs
@@ -227,10 +227,10 @@ namespace WalletWasabi.Blockchain.TransactionProcessing
{
var alreadyKnown = coin.SpenderTransaction == tx;
result.SpentCoins.Add(coin);
+ Coins.Spend(coin, tx);
if (!alreadyKnown)
{
- Coins.Spend(coin, tx);
result.NewlySpentCoins.Add(coin);
}

Potentially fix anonySet decrease bug

After coinJoin, your new coin's anonimity set would decrease back to 1 until confirmation, altough it should have a new, increased anonimitySet value.