Skip to content

Commit 02a337d

Browse files
TheBlueMattsipa
authored andcommitted
Dont remove a "preferred" cmpctblock peer if they provide a block
1 parent c901113 commit 02a337d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/main.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -485,9 +485,13 @@ void MaybeSetPeerAsAnnouncingHeaderAndIDs(const CNodeState* nodestate, CNode* pf
485485
return;
486486
}
487487
if (nodestate->fProvidesHeaderAndIDs) {
488-
BOOST_FOREACH(const NodeId nodeid, lNodesAnnouncingHeaderAndIDs)
489-
if (nodeid == pfrom->GetId())
488+
for (std::list<NodeId>::iterator it = lNodesAnnouncingHeaderAndIDs.begin(); it != lNodesAnnouncingHeaderAndIDs.end(); it++) {
489+
if (*it == pfrom->GetId()) {
490+
lNodesAnnouncingHeaderAndIDs.erase(it);
491+
lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId());
490492
return;
493+
}
494+
}
491495
bool fAnnounceUsingCMPCTBLOCK = false;
492496
uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices() & NODE_WITNESS) ? 2 : 1;
493497
if (lNodesAnnouncingHeaderAndIDs.size() >= 3) {
@@ -5731,6 +5735,12 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
57315735
return true;
57325736
}
57335737

5738+
if (!fAlreadyInFlight && mapBlocksInFlight.size() == 1 && pindex->pprev->IsValid(BLOCK_VALID_CHAIN)) {
5739+
// We seem to be rather well-synced, so it appears pfrom was the first to provide us
5740+
// with this block! Let's get them to announce using compact blocks in the future.
5741+
MaybeSetPeerAsAnnouncingHeaderAndIDs(nodestate, pfrom, connman);
5742+
}
5743+
57345744
BlockTransactionsRequest req;
57355745
for (size_t i = 0; i < cmpctblock.BlockTxCount(); i++) {
57365746
if (!partialBlock.IsTxAvailable(i))

0 commit comments

Comments
 (0)