@@ -1422,47 +1422,38 @@ void PeerLogicValidation::BlockChecked(const CBlock& block, const BlockValidatio
1422
1422
//
1423
1423
1424
1424
1425
- bool static AlreadyHave (const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1425
+ bool static AlreadyHaveTx (const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1426
1426
{
1427
- switch (inv.type )
1427
+ assert (recentRejects);
1428
+ if (::ChainActive ().Tip ()->GetBlockHash () != hashRecentRejectsChainTip) {
1429
+ // If the chain tip has changed previously rejected transactions
1430
+ // might be now valid, e.g. due to a nLockTime'd tx becoming valid,
1431
+ // or a double-spend. Reset the rejects filter and give those
1432
+ // txs a second chance.
1433
+ hashRecentRejectsChainTip = ::ChainActive ().Tip ()->GetBlockHash ();
1434
+ recentRejects->reset ();
1435
+ }
1436
+
1428
1437
{
1429
- case MSG_TX:
1430
- case MSG_WITNESS_TX:
1431
- case MSG_WTX:
1432
- {
1433
- assert (recentRejects);
1434
- if (::ChainActive ().Tip ()->GetBlockHash () != hashRecentRejectsChainTip)
1435
- {
1436
- // If the chain tip has changed previously rejected transactions
1437
- // might be now valid, e.g. due to a nLockTime'd tx becoming valid,
1438
- // or a double-spend. Reset the rejects filter and give those
1439
- // txs a second chance.
1440
- hashRecentRejectsChainTip = ::ChainActive ().Tip ()->GetBlockHash ();
1441
- recentRejects->reset ();
1442
- }
1438
+ LOCK (g_cs_orphans);
1439
+ if (!inv.IsMsgWtx () && mapOrphanTransactions.count (inv.hash )) {
1440
+ return true ;
1441
+ } else if (inv.IsMsgWtx () && g_orphans_by_wtxid.count (inv.hash )) {
1442
+ return true ;
1443
+ }
1444
+ }
1443
1445
1444
- {
1445
- LOCK (g_cs_orphans);
1446
- if (!inv.IsMsgWtx () && mapOrphanTransactions.count (inv.hash )) {
1447
- return true ;
1448
- } else if (inv.IsMsgWtx () && g_orphans_by_wtxid.count (inv.hash )) {
1449
- return true ;
1450
- }
1451
- }
1446
+ {
1447
+ LOCK (g_cs_recent_confirmed_transactions);
1448
+ if (g_recent_confirmed_transactions->contains (inv.hash )) return true ;
1449
+ }
1452
1450
1453
- {
1454
- LOCK (g_cs_recent_confirmed_transactions);
1455
- if (g_recent_confirmed_transactions->contains (inv.hash )) return true ;
1456
- }
1451
+ return recentRejects->contains (inv.hash ) || mempool.exists (ToGenTxid (inv));
1452
+ }
1457
1453
1458
- return recentRejects->contains (inv.hash ) || mempool.exists (ToGenTxid (inv));
1459
- }
1460
- case MSG_BLOCK:
1461
- case MSG_WITNESS_BLOCK:
1462
- return LookupBlockIndex (inv.hash ) != nullptr ;
1463
- }
1464
- // Don't know what it is, just say we already got one
1465
- return true ;
1454
+ bool static AlreadyHaveBlock (const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
1455
+ {
1456
+ return LookupBlockIndex (inv.hash ) != nullptr ;
1466
1457
}
1467
1458
1468
1459
void RelayTransaction (const uint256& txid, const uint256& wtxid, const CConnman& connman)
@@ -2670,10 +2661,10 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
2670
2661
if (inv.IsMsgWtx ()) continue ;
2671
2662
}
2672
2663
2673
- bool fAlreadyHave = AlreadyHave (inv, m_mempool);
2674
- LogPrint (BCLog::NET, " got inv: %s %s peer=%d\n " , inv.ToString (), fAlreadyHave ? " have" : " new" , pfrom.GetId ());
2675
-
2676
2664
if (inv.type == MSG_BLOCK) {
2665
+ bool fAlreadyHave = AlreadyHaveBlock (inv, m_mempool);
2666
+ LogPrint (BCLog::NET, " got inv: %s %s peer=%d\n " , inv.ToString (), fAlreadyHave ? " have" : " new" , pfrom.GetId ());
2667
+
2677
2668
UpdateBlockAvailability (pfrom.GetId (), inv.hash );
2678
2669
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count (inv.hash )) {
2679
2670
// Headers-first is the primary method of announcement on
@@ -2684,6 +2675,9 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
2684
2675
best_block = &inv.hash ;
2685
2676
}
2686
2677
} else {
2678
+ bool fAlreadyHave = AlreadyHaveTx (inv, mempool);
2679
+ LogPrint (BCLog::NET, " got inv: %s %s peer=%d\n " , inv.ToString (), fAlreadyHave ? " have" : " new" , pfrom.GetId ());
2680
+
2687
2681
pfrom.AddKnownTx (inv.hash );
2688
2682
if (fBlocksOnly ) {
2689
2683
LogPrint (BCLog::NET, " transaction (%s) inv sent in violation of protocol, disconnecting peer=%d\n " , inv.hash .ToString (), pfrom.GetId ());
@@ -2963,7 +2957,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
2963
2957
// already; and an adversary can already relay us old transactions
2964
2958
// (older than our recency filter) if trying to DoS us, without any need
2965
2959
// for witness malleation.
2966
- if (!AlreadyHave (CInv (MSG_WTX, wtxid), m_mempool) &&
2960
+ if (!AlreadyHaveTx (CInv (MSG_WTX, wtxid), m_mempool) &&
2967
2961
AcceptToMemoryPool (m_mempool, state, ptx, &lRemovedTxn, false /* bypass_limits */ , 0 /* nAbsurdFee */ )) {
2968
2962
m_mempool.check (&::ChainstateActive ().CoinsTip ());
2969
2963
RelayTransaction (tx.GetHash (), tx.GetWitnessHash (), m_connman);
@@ -3017,7 +3011,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
3017
3011
// protocol for getting all unconfirmed parents.
3018
3012
CInv _inv (MSG_TX, parent_txid);
3019
3013
pfrom.AddKnownTx (parent_txid);
3020
- if (!AlreadyHave (_inv, m_mempool)) RequestTx (State (pfrom.GetId ()), ToGenTxid (_inv), current_time);
3014
+ if (!AlreadyHaveTx (_inv, m_mempool)) RequestTx (State (pfrom.GetId ()), ToGenTxid (_inv), current_time);
3021
3015
}
3022
3016
AddOrphanTx (ptx, pfrom.GetId ());
3023
3017
@@ -4568,7 +4562,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
4568
4562
// processing at a later time, see below)
4569
4563
tx_process_time.erase (tx_process_time.begin ());
4570
4564
CInv inv (gtxid.IsWtxid () ? MSG_WTX : (MSG_TX | GetFetchFlags (*pto)), gtxid.GetHash ());
4571
- if (!AlreadyHave (inv, m_mempool)) {
4565
+ if (!AlreadyHaveTx (inv, m_mempool)) {
4572
4566
// If this transaction was last requested more than 1 minute ago,
4573
4567
// then request.
4574
4568
const auto last_request_time = GetTxRequestTime (gtxid);
0 commit comments