Skip to content

Commit 8e68fc2

Browse files
committed
Add wtxids to recentRejects instead of txids
Previously, we only added txids to recentRejects if we were sure that the transaction couldn't have had the wrong witness (either because the witness was malleated or stripped). In preparation for wtxid-based relay, we can observe that txid == wtxid for transactions that have no witness, and add the wtxid of rejected transactions, provided the transaction wasn't a witness-stripped one. This means that we now add more data to the filter (as prior to this commit, any transaction with a witness that failed to be accepted was being skipped for inclusion in the filter) but witness malleation should still not interfere with relay of a valid segwit transaction, because the txid of a segwit transaction would not be added to the filter after failing validation. In the future, having wtxids in the recent rejects filter will allow us to skip downloading the same wtxid multiple times, once our peers use wtxids for transaction relay.
1 parent 144c385 commit 8e68fc2

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/net_processing.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2005,12 +2005,12 @@ void static ProcessOrphanTx(CConnman& connman, CTxMemPool& mempool, std::set<uin
20052005
// Has inputs but not accepted to mempool
20062006
// Probably non-standard or insufficient fee
20072007
LogPrint(BCLog::MEMPOOL, " removed orphan tx %s\n", orphanHash.ToString());
2008-
if (!orphanTx.HasWitness() && orphan_state.GetResult() != TxValidationResult::TX_WITNESS_MUTATED) {
2008+
if (orphanTx.HasWitness() || orphan_state.GetResult() != TxValidationResult::TX_WITNESS_MUTATED) {
20092009
// Do not use rejection cache for witness transactions or
20102010
// witness-stripped transactions, as they can have been malleated.
20112011
// See https://github.com/bitcoin/bitcoin/issues/8279 for details.
20122012
assert(recentRejects);
2013-
recentRejects->insert(orphanHash);
2013+
recentRejects->insert(orphanTx.GetWitnessHash());
20142014
}
20152015
EraseOrphanTx(orphanHash);
20162016
done = true;
@@ -2908,14 +2908,15 @@ void ProcessMessage(
29082908
// We will continue to reject this tx since it has rejected
29092909
// parents so avoid re-requesting it from other peers.
29102910
recentRejects->insert(tx.GetHash());
2911+
recentRejects->insert(tx.GetWitnessHash());
29112912
}
29122913
} else {
2913-
if (!tx.HasWitness() && state.GetResult() != TxValidationResult::TX_WITNESS_MUTATED) {
2914+
if (tx.HasWitness() || state.GetResult() != TxValidationResult::TX_WITNESS_MUTATED) {
29142915
// Do not use rejection cache for witness transactions or
29152916
// witness-stripped transactions, as they can have been malleated.
29162917
// See https://github.com/bitcoin/bitcoin/issues/8279 for details.
29172918
assert(recentRejects);
2918-
recentRejects->insert(tx.GetHash());
2919+
recentRejects->insert(tx.GetWitnessHash());
29192920
if (RecursiveDynamicUsage(*ptx) < 100000) {
29202921
AddToCompactExtraTransactions(ptx);
29212922
}

0 commit comments

Comments
 (0)