Fix banning spent coins
MODIFY
WalletWasabi.Tests/RegTests.cs
WalletWasabi.Tests/RegTests.cs
@@ -1552,17 +1552,11 @@ namespace WalletWasabi.Tests
offchainTxId.ToString(),
});
coordinator = new CcjCoordinator(network, folder, rpc, Global.Coordinator.RoundConfig);
- Assert.False(File.Exists(cjfile));
-
-
- coordinator = Global.Coordinator;
- Money denomination = new Money(0.2m, MoneyUnit.BTC);
- decimal coordinatorFeePercent = 0.2m;
- int anonymitySet = 2;
- int connectionConfirmationTimeout = 50;
- var roundConfig = new CcjRoundConfig(denomination, 2, coordinatorFeePercent, anonymitySet, 100, connectionConfirmationTimeout, 50, 50, 1);
- coordinator.UpdateRoundConfig(roundConfig);
- coordinator.FailAllRoundsInInputRegistration();
+ txIds = await File.ReadAllLinesAsync(cjfile);
+ Assert.Equal(1, txIds.Count());
+ Assert.Contains(coinbaseTxId.ToString(), txIds);
+ Assert.DoesNotContain(offchainTxId.ToString(), txIds);
+ Assert.DoesNotContain("This line is invalid (the file is corrupted)", txIds);
}
[Fact]

MODIFY
WalletWasabi/Services/CcjCoordinator.cs
WalletWasabi/Services/CcjCoordinator.cs
@@ -77,8 +77,8 @@ namespace WalletWasabi.Services
string[] allLines = File.ReadAllLines(CoinJoinsFilePath);
foreach (string line in allLines)
{
- uint256 txHash = new uint256(line);
try{
+ uint256 txHash = new uint256(line);
RPCResponse getRawTransactionResponse = RpcClient.SendCommand(RPCOperations.getrawtransaction, txHash.ToString(), true);
CoinJoins.Add(txHash);
if (getRawTransactionResponse.Result.Value<int>("confirmations") <= 0)
@@ -86,16 +86,16 @@ namespace WalletWasabi.Services
UnconfirmedCoinJoins.Add(txHash);
}
}
- catch(RPCException rpce)
- {
- if(rpce.RPCCode == RPCErrorCode.RPC_INVALID_ADDRESS_OR_KEY)
+ catch(Exception ex)
{
toRemove.Add(line);
- }
- else
- {
- throw;
- }
+ var rpce = ex as RPCException;
+
+ var logEntry = rpce!= null && rpce.RPCCode == RPCErrorCode.RPC_INVALID_ADDRESS_OR_KEY
+ ? $"CoinJoins file contains invalid transaction ID {line}"
+ : $"CoinJoins file got corrupted. Deleting offending line \"{line.Substring(0, 20)}\".";
+
+ Logger.LogWarning<CcjCoordinator>($"{logEntry}. {ex.GetType()}: {ex.Message}");
}
}
@@ -126,30 +126,24 @@ namespace WalletWasabi.Services
if (RoundConfig.DosSeverity <= 1) return;
var txId = tx.GetHash();
- var outputIndex = 0;
foreach(TxIn input in tx.Inputs)
{
OutPoint prevOut = input.PrevOut;
- if(!AnyRunningRoundContainsInput(prevOut, out _))
- {
var found = UtxoReferee.BannedUtxos.SingleOrDefault(x => x.Key == prevOut);
- if (found.Key != default)
+ if (found.Key == default) continue; // if coin is not banned
+
+ if(!AnyRunningRoundContainsInput(prevOut, out _))
{
int newSeverity = found.Value.severity + 1;
+ await UtxoReferee.UnbanAsync(prevOut); // since it's not an UTXO anymore
+
if(RoundConfig.DosSeverity >= newSeverity)
{
- var txCoins = tx.Outputs.Select(x=> new OutPoint(txId, outputIndex));
+ var txCoins = tx.Outputs.AsIndexedOutputs().Select(x=> x.ToCoin().Outpoint);
await UtxoReferee.BanUtxosAsync(newSeverity, found.Value.timeOfBan, txCoins.ToArray());
}
- await UtxoReferee.UnbanAsync(prevOut); // since it's not an UTXO anymore
- }
- }
- else
- {
- await UtxoReferee.UnbanAsync(prevOut); // since it's not an UTXO anymore
}
- outputIndex++;
}
}
}

Fix banning spent coins