Try to fix integration tests
MODIFY
WalletWasabi/Models/CoinsRegistry.cs
WalletWasabi/Models/CoinsRegistry.cs
@@ -51,6 +51,8 @@ namespace WalletWasabi.Models
{
var added = false;
lock (Lock)
+ {
+ if (!SpentCoins.Contains(coin))
{
added = Coins.Add(coin);
if (added)
@@ -62,15 +64,15 @@ namespace WalletWasabi.Models
InvalidateSnapshot = true;
}
}
+ }
return added;
}
public void Remove(SmartCoin coin)
{
- var coinsToRemove = AsCoinsView().DescendantOf(coin).ToList();
- coinsToRemove.Add(coin);
lock (Lock)
{
+ var coinsToRemove = DescendantOfAndSelf(coin).ToList();
foreach (var toRemove in coinsToRemove)
{
if (Coins.Remove(toRemove))
@@ -89,7 +91,7 @@ namespace WalletWasabi.Models
if (Coins.Remove(spentCoin))
{
SpentCoins.Add(spentCoin);
- var createdCoins = Coins.Where(x => x.TransactionId == spentCoin.SpenderTransactionId);
+ var createdCoins = CreatedBy(spentCoin.SpenderTransactionId);
foreach (var newCoin in createdCoins)
{
if (newCoin.AnonymitySet < PrivacyLevelThreshold)
@@ -104,6 +106,32 @@ namespace WalletWasabi.Models
}
}
+ public void RemoveFromBlock(Height blockHeight)
+ {
+ lock (Lock)
+ {
+ var allCoins = AsAllCoinsView();
+ foreach (var toRemove in allCoins.AtBlockHeight(blockHeight).ToList())
+ {
+ var coinsToRemove = allCoins.DescendantOfAndSelf(toRemove).ToList();
+ foreach (var coin in coinsToRemove)
+ {
+ if (coin.Unspent)
+ {
+ if (Coins.Remove(coin))
+ {
+ InvalidateSnapshot = true;
+ }
+ }
+ else
+ {
+ SpentCoins.Remove(toRemove);
+ }
+ }
+ }
+ }
+ }
+
public ICoinsView AsAllCoinsView()
{
lock (Lock)
@@ -142,6 +170,11 @@ namespace WalletWasabi.Models
return AsCoinsView().DescendantOf(coin);
}
+ public ICoinsView DescendantOfAndSelf(SmartCoin coin)
+ {
+ return AsCoinsView().DescendantOfAndSelf(coin);
+ }
+
public ICoinsView FilterBy(Func<SmartCoin, bool> expression)
{
return AsCoinsView().FilterBy(expression);

MODIFY
WalletWasabi/Models/CoinsView.cs
WalletWasabi/Models/CoinsView.cs
@@ -80,6 +80,11 @@ namespace WalletWasabi.Models
return new CoinsView(Generator(coin));
}
+ public ICoinsView DescendantOfAndSelf(SmartCoin coin)
+ {
+ return new CoinsView(DescendantOf(coin).Concat(new[] { coin }));
+ }
+
public ICoinsView FilterBy(Func<SmartCoin, bool> expression)
{
return new CoinsView(Coins.Where(expression));

MODIFY
WalletWasabi/Models/ICoinsView.cs
WalletWasabi/Models/ICoinsView.cs
@@ -18,6 +18,8 @@ namespace WalletWasabi.Models
ICoinsView DescendantOf(SmartCoin coin);
+ ICoinsView DescendantOfAndSelf(SmartCoin coin);
+
ICoinsView FilterBy(Func<SmartCoin, bool> expression);
ICoinsView OutPoints(IEnumerable<TxoRef> outPoints);

MODIFY
WalletWasabi/Services/TransactionProcessor.cs
WalletWasabi/Services/TransactionProcessor.cs
@@ -48,7 +48,7 @@ namespace WalletWasabi.Services
if (tx.Confirmed)
{
- foreach (var coin in Coins.Where(x => x.TransactionId == txId))
+ foreach (var coin in Coins.AsAllCoinsView().CreatedBy(txId))
{
coin.Height = tx.Height;
walletRelevant = true; // relevant
@@ -177,7 +177,7 @@ namespace WalletWasabi.Services
{
if (newCoin.Height != Height.Mempool) // Update the height of this old coin we already had.
{
- SmartCoin oldCoin = Coins.GetByOutPoint(new OutPoint(txId, i));
+ SmartCoin oldCoin = Coins.AsAllCoinsView().GetByOutPoint(new OutPoint(txId, i));
if (oldCoin != null) // Just to be sure, it is a concurrent collection.
{
oldCoin.Height = newCoin.Height;
@@ -222,10 +222,7 @@ namespace WalletWasabi.Services
public void UndoBlock(Height blockHeight)
{
- foreach (var toRemove in Coins.AtBlockHeight(blockHeight))
- {
- Coins.Remove(toRemove);
- }
+ Coins.RemoveFromBlock(blockHeight);
}
}
}

MODIFY
WalletWasabi/Services/WalletService.cs
WalletWasabi/Services/WalletService.cs
@@ -64,8 +64,8 @@ namespace WalletWasabi.Services
public ConcurrentDictionary<uint256, (Height height, DateTimeOffset dateTime)> ProcessedBlocks { get; }
- public ICoinsView Coins { get; }
- public ICoinsView AllCoins { get; }
+ public ICoinsView Coins { get; } // UTXOs
+ public ICoinsView AllCoins { get; } // all TXOs (spent and unspent)
public event EventHandler<FilterModel> NewFilterProcessed;

Try to fix integration tests