mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
[net processing] Split AlreadyHave() into separate block and tx functions
This commit is contained in:
parent
39f1dc9445
commit
42ca5618ca
1 changed files with 39 additions and 45 deletions
|
@ -1422,17 +1422,10 @@ void PeerLogicValidation::BlockChecked(const CBlock& block, const BlockValidatio
|
|||
//
|
||||
|
||||
|
||||
bool static AlreadyHave(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
bool static AlreadyHaveTx(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
{
|
||||
switch (inv.type)
|
||||
{
|
||||
case MSG_TX:
|
||||
case MSG_WITNESS_TX:
|
||||
case MSG_WTX:
|
||||
{
|
||||
assert(recentRejects);
|
||||
if (::ChainActive().Tip()->GetBlockHash() != hashRecentRejectsChainTip)
|
||||
{
|
||||
if (::ChainActive().Tip()->GetBlockHash() != hashRecentRejectsChainTip) {
|
||||
// If the chain tip has changed previously rejected transactions
|
||||
// might be now valid, e.g. due to a nLockTime'd tx becoming valid,
|
||||
// or a double-spend. Reset the rejects filter and give those
|
||||
|
@ -1456,13 +1449,11 @@ bool static AlreadyHave(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LO
|
|||
}
|
||||
|
||||
return recentRejects->contains(inv.hash) || mempool.exists(ToGenTxid(inv));
|
||||
}
|
||||
case MSG_BLOCK:
|
||||
case MSG_WITNESS_BLOCK:
|
||||
}
|
||||
|
||||
bool static AlreadyHaveBlock(const CInv& inv, const CTxMemPool& mempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
|
||||
{
|
||||
return LookupBlockIndex(inv.hash) != nullptr;
|
||||
}
|
||||
// Don't know what it is, just say we already got one
|
||||
return true;
|
||||
}
|
||||
|
||||
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
|
|||
if (inv.IsMsgWtx()) continue;
|
||||
}
|
||||
|
||||
bool fAlreadyHave = AlreadyHave(inv, m_mempool);
|
||||
if (inv.type == MSG_BLOCK) {
|
||||
bool fAlreadyHave = AlreadyHaveBlock(inv, m_mempool);
|
||||
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
||||
|
||||
if (inv.type == MSG_BLOCK) {
|
||||
UpdateBlockAvailability(pfrom.GetId(), inv.hash);
|
||||
if (!fAlreadyHave && !fImporting && !fReindex && !mapBlocksInFlight.count(inv.hash)) {
|
||||
// Headers-first is the primary method of announcement on
|
||||
|
@ -2684,6 +2675,9 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
|
|||
best_block = &inv.hash;
|
||||
}
|
||||
} else {
|
||||
bool fAlreadyHave = AlreadyHaveTx(inv, mempool);
|
||||
LogPrint(BCLog::NET, "got inv: %s %s peer=%d\n", inv.ToString(), fAlreadyHave ? "have" : "new", pfrom.GetId());
|
||||
|
||||
pfrom.AddKnownTx(inv.hash);
|
||||
if (fBlocksOnly) {
|
||||
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
|
|||
// already; and an adversary can already relay us old transactions
|
||||
// (older than our recency filter) if trying to DoS us, without any need
|
||||
// for witness malleation.
|
||||
if (!AlreadyHave(CInv(MSG_WTX, wtxid), m_mempool) &&
|
||||
if (!AlreadyHaveTx(CInv(MSG_WTX, wtxid), m_mempool) &&
|
||||
AcceptToMemoryPool(m_mempool, state, ptx, &lRemovedTxn, false /* bypass_limits */, 0 /* nAbsurdFee */)) {
|
||||
m_mempool.check(&::ChainstateActive().CoinsTip());
|
||||
RelayTransaction(tx.GetHash(), tx.GetWitnessHash(), m_connman);
|
||||
|
@ -3017,7 +3011,7 @@ void PeerLogicValidation::ProcessMessage(CNode& pfrom, const std::string& msg_ty
|
|||
// protocol for getting all unconfirmed parents.
|
||||
CInv _inv(MSG_TX, parent_txid);
|
||||
pfrom.AddKnownTx(parent_txid);
|
||||
if (!AlreadyHave(_inv, m_mempool)) RequestTx(State(pfrom.GetId()), ToGenTxid(_inv), current_time);
|
||||
if (!AlreadyHaveTx(_inv, m_mempool)) RequestTx(State(pfrom.GetId()), ToGenTxid(_inv), current_time);
|
||||
}
|
||||
AddOrphanTx(ptx, pfrom.GetId());
|
||||
|
||||
|
@ -4568,7 +4562,7 @@ bool PeerLogicValidation::SendMessages(CNode* pto)
|
|||
// processing at a later time, see below)
|
||||
tx_process_time.erase(tx_process_time.begin());
|
||||
CInv inv(gtxid.IsWtxid() ? MSG_WTX : (MSG_TX | GetFetchFlags(*pto)), gtxid.GetHash());
|
||||
if (!AlreadyHave(inv, m_mempool)) {
|
||||
if (!AlreadyHaveTx(inv, m_mempool)) {
|
||||
// If this transaction was last requested more than 1 minute ago,
|
||||
// then request.
|
||||
const auto last_request_time = GetTxRequestTime(gtxid);
|
||||
|
|
Loading…
Add table
Reference in a new issue