From 900d7f6c075fd78e63503f31d267dbc16b3983d9 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Wed, 22 Jul 2020 17:19:43 -0700 Subject: [PATCH] p2p: enable fetching of orphans from wtxid peers Based on a commit by Anthony Towns. --- src/net_processing.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/net_processing.cpp b/src/net_processing.cpp index 5f8a73cece..36508aa099 100644 --- a/src/net_processing.cpp +++ b/src/net_processing.cpp @@ -2647,7 +2647,9 @@ void ProcessMessage( if (interruptMsgProc) return; - // ignore INVs that don't match wtxidrelay setting + // Ignore INVs that don't match wtxidrelay setting. + // Note that orphan parent fetching always uses MSG_TX GETDATAs regardless of the wtxidrelay setting. + // This is fine as no INV messages are involved in that process. if (State(pfrom.GetId())->m_wtxid_relay) { if (inv.IsMsgTx()) continue; } else { @@ -2931,9 +2933,11 @@ void ProcessMessage( TxValidationState state; - nodestate->m_tx_download.m_tx_announced.erase(hash); - nodestate->m_tx_download.m_tx_in_flight.erase(hash); - EraseTxRequest(hash); + for (uint256 hash : {txid, wtxid}) { + nodestate->m_tx_download.m_tx_announced.erase(hash); + nodestate->m_tx_download.m_tx_in_flight.erase(hash); + EraseTxRequest(hash); + } std::list lRemovedTxn; @@ -2985,17 +2989,15 @@ void ProcessMessage( uint32_t nFetchFlags = GetFetchFlags(pfrom); const auto current_time = GetTime(); - if (!State(pfrom.GetId())->m_wtxid_relay) { - for (const CTxIn& txin : tx.vin) { - // Here, we only have the txid (and not wtxid) of the - // inputs, so we only request parents from - // non-wtxid-relay peers. - // Eventually we should replace this with an improved - // protocol for getting all unconfirmed parents. - CInv _inv(MSG_TX | nFetchFlags, txin.prevout.hash); - pfrom.AddKnownTx(txin.prevout.hash); - if (!AlreadyHave(_inv, mempool)) RequestTx(State(pfrom.GetId()), ToGenTxid(_inv), current_time); - } + for (const CTxIn& txin : tx.vin) { + // Here, we only have the txid (and not wtxid) of the + // inputs, so we only request in txid mode, even for + // wtxidrelay peers. + // Eventually we should replace this with an improved + // protocol for getting all unconfirmed parents. + CInv _inv(MSG_TX | nFetchFlags, txin.prevout.hash); + pfrom.AddKnownTx(txin.prevout.hash); + if (!AlreadyHave(_inv, mempool)) RequestTx(State(pfrom.GetId()), ToGenTxid(_inv), current_time); } AddOrphanTx(ptx, pfrom.GetId());