p2p: enable fetching of orphans from wtxid peers

Based on a commit by Anthony Towns.
This commit is contained in:
Pieter Wuille 2020-07-22 17:19:43 -07:00
parent 9efd86a908
commit 900d7f6c07

View File

@ -2647,7 +2647,9 @@ void ProcessMessage(
if (interruptMsgProc) if (interruptMsgProc)
return; 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 (State(pfrom.GetId())->m_wtxid_relay) {
if (inv.IsMsgTx()) continue; if (inv.IsMsgTx()) continue;
} else { } else {
@ -2931,9 +2933,11 @@ void ProcessMessage(
TxValidationState state; TxValidationState state;
nodestate->m_tx_download.m_tx_announced.erase(hash); for (uint256 hash : {txid, wtxid}) {
nodestate->m_tx_download.m_tx_in_flight.erase(hash); nodestate->m_tx_download.m_tx_announced.erase(hash);
EraseTxRequest(hash); nodestate->m_tx_download.m_tx_in_flight.erase(hash);
EraseTxRequest(hash);
}
std::list<CTransactionRef> lRemovedTxn; std::list<CTransactionRef> lRemovedTxn;
@ -2985,17 +2989,15 @@ void ProcessMessage(
uint32_t nFetchFlags = GetFetchFlags(pfrom); uint32_t nFetchFlags = GetFetchFlags(pfrom);
const auto current_time = GetTime<std::chrono::microseconds>(); const auto current_time = GetTime<std::chrono::microseconds>();
if (!State(pfrom.GetId())->m_wtxid_relay) { for (const CTxIn& txin : tx.vin) {
for (const CTxIn& txin : tx.vin) { // Here, we only have the txid (and not wtxid) of the
// Here, we only have the txid (and not wtxid) of the // inputs, so we only request in txid mode, even for
// inputs, so we only request parents from // wtxidrelay peers.
// non-wtxid-relay peers. // Eventually we should replace this with an improved
// Eventually we should replace this with an improved // protocol for getting all unconfirmed parents.
// protocol for getting all unconfirmed parents. CInv _inv(MSG_TX | nFetchFlags, txin.prevout.hash);
CInv _inv(MSG_TX | nFetchFlags, txin.prevout.hash); pfrom.AddKnownTx(txin.prevout.hash);
pfrom.AddKnownTx(txin.prevout.hash); if (!AlreadyHave(_inv, mempool)) RequestTx(State(pfrom.GetId()), ToGenTxid(_inv), current_time);
if (!AlreadyHave(_inv, mempool)) RequestTx(State(pfrom.GetId()), ToGenTxid(_inv), current_time);
}
} }
AddOrphanTx(ptx, pfrom.GetId()); AddOrphanTx(ptx, pfrom.GetId());