Use txid as key in mapAlreadyAskedFor
Previously we used the CInv that would be sent to the peer announcing the transaction as the key, but using the txid instead allows us to decouple the p2p layer from the application logic (which relies on this map to avoid duplicate tx requests). (cherry picked from commit 7e91f632c70ff1848a152f24ee67a06796803943)
This commit is contained in:
parent
13d8f294ac
commit
44787c0179
|
@ -6629,7 +6629,7 @@ bool static ProcessMessage(const CChainParams& chainparams, CNode* pfrom, string
|
|||
CValidationState state;
|
||||
|
||||
pfrom->setAskFor.erase(inv.hash);
|
||||
mapAlreadyAskedFor.erase(inv);
|
||||
mapAlreadyAskedFor.erase(inv.hash);
|
||||
|
||||
if (!AlreadyHave(inv) && AcceptToMemoryPool(chainparams, mempool, state, tx, true, &fMissingInputs))
|
||||
{
|
||||
|
|
|
@ -76,7 +76,7 @@ CCriticalSection cs_vNodes;
|
|||
map<CInv, CDataStream> mapRelay;
|
||||
deque<pair<int64_t, CInv> > vRelayExpiration;
|
||||
CCriticalSection cs_mapRelay;
|
||||
limitedmap<CInv, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
|
||||
limitedmap<uint256, int64_t> mapAlreadyAskedFor(MAX_INV_SZ);
|
||||
|
||||
static deque<string> vOneShots;
|
||||
static CCriticalSection cs_vOneShots;
|
||||
|
@ -2318,7 +2318,7 @@ void CNode::AskFor(const CInv& inv)
|
|||
// We're using mapAskFor as a priority queue,
|
||||
// the key is the earliest time the request can be sent
|
||||
int64_t nRequestTime;
|
||||
limitedmap<CInv, int64_t>::const_iterator it = mapAlreadyAskedFor.find(inv);
|
||||
limitedmap<uint256, int64_t>::const_iterator it = mapAlreadyAskedFor.find(inv.hash);
|
||||
if (it != mapAlreadyAskedFor.end())
|
||||
nRequestTime = it->second;
|
||||
else
|
||||
|
@ -2337,7 +2337,7 @@ void CNode::AskFor(const CInv& inv)
|
|||
if (it != mapAlreadyAskedFor.end())
|
||||
mapAlreadyAskedFor.update(it, nRequestTime);
|
||||
else
|
||||
mapAlreadyAskedFor.insert(std::make_pair(inv, nRequestTime));
|
||||
mapAlreadyAskedFor.insert(std::make_pair(inv.hash, nRequestTime));
|
||||
mapAskFor.insert(std::make_pair(nRequestTime, inv));
|
||||
}
|
||||
|
||||
|
|
|
@ -167,7 +167,7 @@ extern CCriticalSection cs_vNodes;
|
|||
extern std::map<CInv, CDataStream> mapRelay;
|
||||
extern std::deque<std::pair<int64_t, CInv> > vRelayExpiration;
|
||||
extern CCriticalSection cs_mapRelay;
|
||||
extern limitedmap<CInv, int64_t> mapAlreadyAskedFor;
|
||||
extern limitedmap<uint256, int64_t> mapAlreadyAskedFor;
|
||||
|
||||
extern std::vector<std::string> vAddedNodes;
|
||||
extern CCriticalSection cs_vAddedNodes;
|
||||
|
|
Loading…
Reference in New Issue