Skip to content

Commit acd6642

Browse files
jnewberyjonatack
authored andcommitted
[net processing] Change AlreadyHaveTx() to take a GenTxid
1 parent 5fdfb80 commit acd6642

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

src/net_processing.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ void PeerLogicValidation::BlockChecked(const CBlock& block, const BlockValidatio
14221422
//
14231423

14241424

1425-
bool static AlreadyHaveTx(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1425+
bool static AlreadyHaveTx(const GenTxid& gtxid, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
14261426
{
14271427
assert(recentRejects);
14281428
if (::ChainActive().Tip()->GetBlockHash() != hashRecentRejectsChainTip) {
@@ -1436,19 +1436,19 @@ bool static AlreadyHaveTx(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_
14361436

14371437
{
14381438
LOCK(g_cs_orphans);
1439-
if (!inv.IsMsgWtx() && mapOrphanTransactions.count(inv.hash)) {
1439+
if (!gtxid.IsWtxid() && mapOrphanTransactions.count(gtxid.GetHash())) {
14401440
return true;
1441-
} else if (inv.IsMsgWtx() && g_orphans_by_wtxid.count(inv.hash)) {
1441+
} else if (gtxid.IsWtxid() && g_orphans_by_wtxid.count(gtxid.GetHash())) {
14421442
return true;
14431443
}
14441444
}
14451445

14461446
{
14471447
LOCK(g_cs_recent_confirmed_transactions);
1448-
if (g_recent_confirmed_transactions->contains(inv.hash)) return true;
1448+
if (g_recent_confirmed_transactions->contains(gtxid.GetHash())) return true;
14491449
}
14501450

1451-
return recentRejects->contains(inv.hash) || mempool.exists(ToGenTxid(inv));
1451+
return recentRejects->contains(gtxid.GetHash()) || mempool.exists(gtxid);
14521452
}
14531453

14541454
bool static AlreadyHaveBlock(const uint256& block_hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
@@ -2675,7 +2675,8 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
26752675
best_block = &inv.hash;
26762676
}
26772677
} else {
2678-
bool fAlreadyHave = AlreadyHaveTx(inv, mempool);
2678+
GenTxid gtxid = ToGenTxid(inv);
2679+
bool fAlreadyHave = AlreadyHaveTx(gtxid, mempool);
26792680
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
26802681

26812682
pfrom.AddKnownTx(inv.hash);
@@ -2684,7 +2685,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
26842685
pfrom.fDisconnect = true;
26852686
return;
26862687
} else if (!fAlreadyHave && !m_chainman.ActiveChainstate().IsInitialBlockDownload()) {
2687-
RequestTx(State(pfrom.GetId()), ToGenTxid(inv), current_time);
2688+
RequestTx(State(pfrom.GetId()), gtxid, current_time);
26882689
}
26892690
}
26902691
}
@@ -2957,7 +2958,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
29572958
// already; and an adversary can already relay us old transactions
29582959
// (older than our recency filter) if trying to DoS us, without any need
29592960
// for witness malleation.
2960-
if (!AlreadyHaveTx(CInv(MSG_WTX, wtxid), m_mempool) &&
2961+
if (!AlreadyHaveTx(GenTxid(/* is_wtxid=*/true, wtxid), m_mempool) &&
29612962
AcceptToMemoryPool(m_mempool, state, ptx, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
29622963
m_mempool.check(&::ChainstateActive().CoinsTip());
29632964
RelayTransaction(tx.GetHash(), tx.GetWitnessHash(), m_connman);
@@ -3009,9 +3010,9 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
30093010
// wtxidrelay peers.
30103011
// Eventually we should replace this with an improved
30113012
// protocol for getting all unconfirmed parents.
3012-
CInv _inv(MSG_TX, parent_txid);
3013+
GenTxid gtxid{/* is_wtxid=*/false, parent_txid};
30133014
pfrom.AddKnownTx(parent_txid);
3014-
if (!AlreadyHaveTx(_inv, m_mempool)) RequestTx(State(pfrom.GetId()), ToGenTxid(_inv), current_time);
3015+
if (!AlreadyHaveTx(gtxid, m_mempool)) RequestTx(State(pfrom.GetId()), gtxid, current_time);
30153016
}
30163017
AddOrphanTx(ptx, pfrom.GetId());
30173018

@@ -4562,7 +4563,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
45624563
// processing at a later time, see below)
45634564
tx_process_time.erase(tx_process_time.begin());
45644565
CInv inv(gtxid.IsWtxid() ? MSG_WTX : (MSG_TX | GetFetchFlags(*pto)), gtxid.GetHash());
4565-
if (!AlreadyHaveTx(inv, m_mempool)) {
4566+
if (!AlreadyHaveTx(ToGenTxid(inv), m_mempool)) {
45664567
// If this transaction was last requested more than 1 minute ago,
45674568
// then request.
45684569
const auto last_request_time = GetTxRequestTime(gtxid);

0 commit comments

Comments
 (0)