Skip to content

Commit

Permalink
Merge pull request #12301 from lontivero/full-rbf-1
Browse files Browse the repository at this point in the history
Double spending tx are considered replacement
  • Loading branch information
molnard committed Mar 13, 2024
2 parents c91abc9 + 3b57417 commit 92e4921
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -247,18 +247,18 @@ public async Task IgnoreDoubleSpendAsync()
var keys = transactionProcessor.KeyManager.GetKeys().ToArray();

// An unconfirmed segwit transaction for us
var tx0 = CreateCreditingTransaction(keys[0].PubKey.GetScriptPubKey(ScriptPubKeyType.Segwit), Money.Coins(1.0m));
var tx0 = CreateCreditingTransaction(keys[0].GetAssumedScriptPubKey(), Money.Coins(1.0m));

var createdCoin = tx0.Transaction.Outputs.AsCoins().First();

// Spend the received coin
var tx1 = CreateSpendingTransaction(createdCoin, keys[1].PubKey.GetScriptPubKey(ScriptPubKeyType.Segwit));
var tx1 = CreateSpendingTransaction(createdCoin, keys[1].GetAssumedScriptPubKey());

// Spend the same coin again
var tx2 = CreateSpendingTransaction(createdCoin, keys[2].PubKey.GetScriptPubKey(ScriptPubKeyType.Segwit));
var tx2 = CreateSpendingTransaction(createdCoin, keys[2].GetAssumedScriptPubKey());
var relevant = transactionProcessor.Process(tx0, tx1, tx2).Last();

Assert.False(relevant.IsNews);
Assert.True(relevant.IsNews);
Assert.Single(transactionProcessor.Coins, coin => !coin.IsSpent());
Assert.Single(transactionProcessor.Coins.AsAllCoinsView(), coin => coin.IsSpent());

Expand All @@ -267,7 +267,7 @@ public async Task IgnoreDoubleSpendAsync()
var mempool = transactionProcessor.TransactionStore.MempoolStore.GetTransactions();
Assert.Equal(2, mempool.Count);
Assert.Equal(tx0, mempool.First());
Assert.Equal(tx1, mempool.Last());
Assert.Equal(tx2, mempool.Last());
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ private ProcessedResult ProcessNoLock(SmartTransaction tx)
if (tx.Height == Height.Mempool)
{
// if the received transaction is spending at least one input already
// spent by a previous unconfirmed transaction signaling RBF then it is not a double
// spent by a previous unconfirmed transaction then it is not considered a double
// spending transaction but a replacement transaction.
var isReplacementTx = doubleSpentSpenders.Any(x => x.Transaction.IsRBF);
var isReplacementTx = doubleSpentSpenders.Any();
if (isReplacementTx)
{
// Undo the replaced transaction by removing the coins it created (if other coin
Expand All @@ -160,10 +160,6 @@ private ProcessedResult ProcessNoLock(SmartTransaction tx)
result.ReplacedCoins.AddRange(replaced);
result.RestoredCoins.AddRange(restored);
}
else if (doubleSpentSpenders.Count > 0)
{
return result;
}
}
else // new confirmation always enjoys priority
{
Expand Down

0 comments on commit 92e4921

Please sign in to comment.