mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-05 14:06:27 -05:00
Deduplicate missing parents of orphan transactions
In the logic for requesting missing parents of orphan transactions, parent transactions with multiple outputs being spent by the given orphan were being processed multiple times. Fix this by deduplicating the set of missing parent txids first. Co-authored-by: Anthony Towns <aj@erisian.com.au>
This commit is contained in:
parent
8196176243
commit
4c0731f9c5
1 changed files with 15 additions and 4 deletions
|
@ -2990,8 +2990,19 @@ void ProcessMessage(
|
|||
else if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS)
|
||||
{
|
||||
bool fRejectedParents = false; // It may be the case that the orphans parents have all been rejected
|
||||
|
||||
// Deduplicate parent txids, so that we don't have to loop over
|
||||
// the same parent txid more than once down below.
|
||||
std::vector<uint256> unique_parents;
|
||||
unique_parents.reserve(tx.vin.size());
|
||||
for (const CTxIn& txin : tx.vin) {
|
||||
if (recentRejects->contains(txin.prevout.hash)) {
|
||||
// We start with all parents, and then remove duplicates below.
|
||||
unique_parents.push_back(txin.prevout.hash);
|
||||
}
|
||||
std::sort(unique_parents.begin(), unique_parents.end());
|
||||
unique_parents.erase(std::unique(unique_parents.begin(), unique_parents.end()), unique_parents.end());
|
||||
for (const uint256& parent_txid : unique_parents) {
|
||||
if (recentRejects->contains(parent_txid)) {
|
||||
fRejectedParents = true;
|
||||
break;
|
||||
}
|
||||
|
@ -3000,14 +3011,14 @@ void ProcessMessage(
|
|||
uint32_t nFetchFlags = GetFetchFlags(pfrom);
|
||||
const auto current_time = GetTime<std::chrono::microseconds>();
|
||||
|
||||
for (const CTxIn& txin : tx.vin) {
|
||||
for (const uint256& parent_txid : unique_parents) {
|
||||
// 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);
|
||||
CInv _inv(MSG_TX | nFetchFlags, parent_txid);
|
||||
pfrom.AddKnownTx(parent_txid);
|
||||
if (!AlreadyHave(_inv, mempool)) RequestTx(State(pfrom.GetId()), ToGenTxid(_inv), current_time);
|
||||
}
|
||||
AddOrphanTx(ptx, pfrom.GetId());
|
||||
|
|
Loading…
Add table
Reference in a new issue