Improve the encapsulation of `CNode::filterInventoryKnown`.
Co-authored-by: Jack Grigg <jack@z.cash> Signed-off-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
parent
c5b8807ce7
commit
074e633798
10
src/main.cpp
10
src/main.cpp
|
@ -6757,7 +6757,7 @@ bool static ProcessMessage(const CChainParams& chainparams, CNode* pfrom, string
|
|||
}
|
||||
else
|
||||
{
|
||||
pfrom->AddKnownTx(WTxId(inv.hash, inv.hashAux));
|
||||
pfrom->AddKnownWTxId(WTxId(inv.hash, inv.hashAux));
|
||||
if (fBlocksOnly)
|
||||
LogPrint("net", "transaction (%s) inv sent in violation of protocol peer=%d\n", inv.hash.ToString(), pfrom->id);
|
||||
else if (!fAlreadyHave && !IsInitialBlockDownload(chainparams.GetConsensus()))
|
||||
|
@ -6906,7 +6906,7 @@ bool static ProcessMessage(const CChainParams& chainparams, CNode* pfrom, string
|
|||
|
||||
LOCK(cs_main);
|
||||
|
||||
pfrom->AddKnownTx(wtxid);
|
||||
pfrom->AddKnownWTxId(wtxid);
|
||||
|
||||
bool fMissingInputs = false;
|
||||
CValidationState state;
|
||||
|
@ -7730,7 +7730,7 @@ bool SendMessages(const Consensus::Params& params, CNode* pto)
|
|||
if (pto->pfilter) {
|
||||
if (!pto->pfilter->IsRelevantAndUpdate(*txinfo.tx)) continue;
|
||||
}
|
||||
pto->filterInventoryKnown.insert(hash);
|
||||
pto->AddKnownTxId(hash);
|
||||
vInv.push_back(inv);
|
||||
if (vInv.size() == MAX_INV_SZ) {
|
||||
pto->PushMessage("inv", vInv);
|
||||
|
@ -7765,7 +7765,7 @@ bool SendMessages(const Consensus::Params& params, CNode* pto)
|
|||
// Remove it from the to-be-sent set
|
||||
pto->setInventoryTxToSend.erase(it);
|
||||
// Check if not in the filter already
|
||||
if (pto->filterInventoryKnown.contains(hash)) {
|
||||
if (pto->HasKnownTxId(hash)) {
|
||||
continue;
|
||||
}
|
||||
// Not in the mempool anymore? don't bother sending it.
|
||||
|
@ -7800,7 +7800,7 @@ bool SendMessages(const Consensus::Params& params, CNode* pto)
|
|||
pto->PushMessage("inv", vInv);
|
||||
vInv.clear();
|
||||
}
|
||||
pto->filterInventoryKnown.insert(hash);
|
||||
pto->AddKnownTxId(hash);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
24
src/net.h
24
src/net.h
|
@ -307,6 +307,10 @@ public:
|
|||
CRollingBloomFilter addrKnown;
|
||||
mutable CCriticalSection cs_addrKnown;
|
||||
|
||||
// Inventory based relay
|
||||
// This filter is protected by cs_inventory and contains both txids and wtxids.
|
||||
CRollingBloomFilter filterInventoryKnown;
|
||||
|
||||
const uint64_t nKeyedNetGroup;
|
||||
|
||||
// Stored so we can pass a pointer to it across the Rust FFI for span.
|
||||
|
@ -340,8 +344,6 @@ public:
|
|||
int64_t nNextAddrSend;
|
||||
int64_t nNextLocalAddrSend;
|
||||
|
||||
// inventory based relay
|
||||
CRollingBloomFilter filterInventoryKnown;
|
||||
// Set of transaction ids we still have to announce.
|
||||
// They are sorted by the mempool before relay, so the order is not important.
|
||||
std::set<uint256> setInventoryTxToSend;
|
||||
|
@ -349,7 +351,7 @@ public:
|
|||
// There is no final sorting before sending, as they are always sent immediately
|
||||
// and in the order requested.
|
||||
std::vector<uint256> vInventoryBlockToSend;
|
||||
CCriticalSection cs_inventory;
|
||||
mutable CCriticalSection cs_inventory;
|
||||
std::set<WTxId> setAskFor;
|
||||
std::multimap<int64_t, CInv> mapAskFor;
|
||||
int64_t nNextInvSend;
|
||||
|
@ -485,7 +487,7 @@ public:
|
|||
}
|
||||
|
||||
|
||||
void AddKnownTx(const WTxId& wtxid)
|
||||
void AddKnownWTxId(const WTxId& wtxid)
|
||||
{
|
||||
LOCK(cs_inventory);
|
||||
if (!fDisconnect) {
|
||||
|
@ -493,6 +495,20 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
void AddKnownTxId(const uint256& txid)
|
||||
{
|
||||
LOCK(cs_inventory);
|
||||
if (!fDisconnect) {
|
||||
filterInventoryKnown.insert(txid);
|
||||
}
|
||||
}
|
||||
|
||||
bool HasKnownTxId(const uint256& txid) const
|
||||
{
|
||||
LOCK(cs_inventory);
|
||||
return filterInventoryKnown.contains(txid);
|
||||
}
|
||||
|
||||
void PushTxInventory(const WTxId& wtxid)
|
||||
{
|
||||
LOCK(cs_inventory);
|
||||
|
|
Loading…
Reference in New Issue