Skip to content

Commit 0a4f142

Browse files
committed
Further improve comments around recentRejects
1 parent 0e20cfe commit 0a4f142

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/net_processing.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ namespace {
190190
* million to make it highly unlikely for users to have issues with this
191191
* filter.
192192
*
193+
* We only need to add wtxids to this filter. For non-segwit
194+
* transactions, the txid == wtxid, so this only prevents us from
195+
* re-downloading non-segwit transactions when communicating with
196+
* non-wtxidrelay peers -- which is important for avoiding malleation
197+
* attacks that could otherwise interfere with transaction relay from
198+
* non-wtxidrelay peers. For communicating with wtxidrelay peers, having
199+
* the reject filter store wtxids is exactly what we want to avoid
200+
* redownload of a rejected transaction.
201+
*
193202
* Memory used: 1.3 MB
194203
*/
195204
std::unique_ptr<CRollingBloomFilter> recentRejects GUARDED_BY(cs_main);
@@ -2033,6 +2042,7 @@ void static ProcessOrphanTx(CConnman& connman, CTxMemPool& mempool, std::set<uin
20332042
// Probably non-standard or insufficient fee
20342043
LogPrint(BCLog::MEMPOOL, " removed orphan tx %s\n", orphanHash.ToString());
20352044
if (orphan_state.GetResult() != TxValidationResult::TX_WITNESS_STRIPPED) {
2045+
// We can add the wtxid of this transaction to our reject filter.
20362046
// Do not add txids of witness transactions or witness-stripped
20372047
// transactions to the filter, as they can have been malleated;
20382048
// adding such txids to the reject filter would potentially
@@ -3004,11 +3014,16 @@ void ProcessMessage(
30043014
LogPrint(BCLog::MEMPOOL, "not keeping orphan with rejected parents %s\n",tx.GetHash().ToString());
30053015
// We will continue to reject this tx since it has rejected
30063016
// parents so avoid re-requesting it from other peers.
3017+
// Here we add both the txid and the wtxid, as we know that
3018+
// regardless of what witness is provided, we will not accept
3019+
// this, so we don't need to allow for redownload of this txid
3020+
// from any of our non-wtxidrelay peers.
30073021
recentRejects->insert(tx.GetHash());
30083022
recentRejects->insert(tx.GetWitnessHash());
30093023
}
30103024
} else {
30113025
if (state.GetResult() != TxValidationResult::TX_WITNESS_STRIPPED) {
3026+
// We can add the wtxid of this transaction to our reject filter.
30123027
// Do not add txids of witness transactions or witness-stripped
30133028
// transactions to the filter, as they can have been malleated;
30143029
// adding such txids to the reject filter would potentially

0 commit comments

Comments
 (0)