Fix reorg-ed coins to unconfirmed
MODIFY
WalletWasabi.Tests/UnitTests/Transactions/TransactionProcessorTests.cs
WalletWasabi.Tests/UnitTests/Transactions/TransactionProcessorTests.cs
@@ -738,8 +738,10 @@ namespace WalletWasabi.Tests.UnitTests.Transactions
Assert.Equal(scoinC.Clusters, changeCoinD.Clusters);
// reorg
+ Assert.True(changeCoinD.Confirmed);
transactionProcessor.UndoBlock(tx3.Height);
- Assert.DoesNotContain(changeCoinD, transactionProcessor.Coins);
+ Assert.False(changeCoinD.Confirmed);
+
Assert.Equal("A, B, C, D", changeCoinD.Clusters.Labels);
Assert.Equal(scoinA.Clusters, changeCoinD.Clusters);
Assert.Equal(scoinB.Clusters, changeCoinD.Clusters);

MODIFY
WalletWasabi/Coins/CoinsRegistry.cs
WalletWasabi/Coins/CoinsRegistry.cs
@@ -136,33 +136,18 @@ namespace WalletWasabi.Coins
}
}
- public ICoinsView RemoveFromBlock(Height blockHeight)
+ public void SwitchToUnconfirmFromBlock(Height blockHeight)
{
lock (Lock)
{
- var removedCoins = new List<SmartCoin>();
- var allCoins = AsAllCoinsViewNoLock();
- foreach (var toRemove in allCoins.AtBlockHeight(blockHeight).ToList())
- {
- var coinsToRemove = allCoins.DescendantOfAndSelf(toRemove).ToList();
- foreach (var coin in coinsToRemove)
- {
- if (coin.Unspent)
+ foreach (var coin in AsCoinsView().AtBlockHeight(blockHeight))
{
- if (Coins.Remove(coin))
+ var descendantCoins = DescendantOfAndSelf(coin);
+ foreach (var toSwitch in descendantCoins)
{
- InvalidateSnapshot = true;
- }
- }
- else
- {
- SpentCoins.Remove(toRemove);
- }
-
- removedCoins.Add(coin);
+ toSwitch.Height = Height.Mempool;
}
}
- return new CoinsView(removedCoins);
}
}

MODIFY
WalletWasabi/Transactions/TransactionProcessor.cs
WalletWasabi/Transactions/TransactionProcessor.cs
@@ -271,9 +271,9 @@ namespace WalletWasabi.Transactions
return walletRelevant;
}
- public ICoinsView UndoBlock(Height blockHeight)
+ public void UndoBlock(Height blockHeight)
{
- return Coins.RemoveFromBlock(blockHeight);
+ Coins.SwitchToUnconfirmFromBlock(blockHeight);
}
}
}

Fix reorg-ed coins to unconfirmed