@@ -395,33 +395,38 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) {
395
395
}
396
396
}
397
397
398
- void MaybeSetPeerAsAnnouncingHeaderAndIDs (const CNodeState* nodestate, CNode* pfrom, CConnman& connman) {
399
- if (!nodestate->fSupportsDesiredCmpctVersion ) {
398
+ void MaybeSetPeerAsAnnouncingHeaderAndIDs (NodeId nodeid, CConnman& connman) {
399
+ AssertLockHeld (cs_main);
400
+ CNodeState* nodestate = State (nodeid);
401
+ if (!nodestate || !nodestate->fSupportsDesiredCmpctVersion ) {
400
402
// Never ask from peers who can't provide witnesses.
401
403
return ;
402
404
}
403
405
if (nodestate->fProvidesHeaderAndIDs ) {
404
406
for (std::list<NodeId>::iterator it = lNodesAnnouncingHeaderAndIDs.begin (); it != lNodesAnnouncingHeaderAndIDs.end (); it++) {
405
- if (*it == pfrom-> GetId () ) {
407
+ if (*it == nodeid ) {
406
408
lNodesAnnouncingHeaderAndIDs.erase (it);
407
- lNodesAnnouncingHeaderAndIDs.push_back (pfrom-> GetId () );
409
+ lNodesAnnouncingHeaderAndIDs.push_back (nodeid );
408
410
return ;
409
411
}
410
412
}
411
- bool fAnnounceUsingCMPCTBLOCK = false ;
412
- uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices () & NODE_WITNESS) ? 2 : 1 ;
413
- if (lNodesAnnouncingHeaderAndIDs.size () >= 3 ) {
414
- // As per BIP152, we only get 3 of our peers to announce
415
- // blocks using compact encodings.
416
- connman.ForNode (lNodesAnnouncingHeaderAndIDs.front (), [&connman, fAnnounceUsingCMPCTBLOCK , nCMPCTBLOCKVersion](CNode* pnodeStop){
417
- connman.PushMessage (pnodeStop, CNetMsgMaker (pnodeStop->GetSendVersion ()).Make (NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK , nCMPCTBLOCKVersion));
418
- return true ;
419
- });
420
- lNodesAnnouncingHeaderAndIDs.pop_front ();
421
- }
422
- fAnnounceUsingCMPCTBLOCK = true ;
423
- connman.PushMessage (pfrom, CNetMsgMaker (pfrom->GetSendVersion ()).Make (NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK , nCMPCTBLOCKVersion));
424
- lNodesAnnouncingHeaderAndIDs.push_back (pfrom->GetId ());
413
+ connman.ForNode (nodeid, [&connman](CNode* pfrom){
414
+ bool fAnnounceUsingCMPCTBLOCK = false ;
415
+ uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices () & NODE_WITNESS) ? 2 : 1 ;
416
+ if (lNodesAnnouncingHeaderAndIDs.size () >= 3 ) {
417
+ // As per BIP152, we only get 3 of our peers to announce
418
+ // blocks using compact encodings.
419
+ connman.ForNode (lNodesAnnouncingHeaderAndIDs.front (), [&connman, fAnnounceUsingCMPCTBLOCK , nCMPCTBLOCKVersion](CNode* pnodeStop){
420
+ connman.PushMessage (pnodeStop, CNetMsgMaker (pnodeStop->GetSendVersion ()).Make (NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK , nCMPCTBLOCKVersion));
421
+ return true ;
422
+ });
423
+ lNodesAnnouncingHeaderAndIDs.pop_front ();
424
+ }
425
+ fAnnounceUsingCMPCTBLOCK = true ;
426
+ connman.PushMessage (pfrom, CNetMsgMaker (pfrom->GetSendVersion ()).Make (NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK , nCMPCTBLOCKVersion));
427
+ lNodesAnnouncingHeaderAndIDs.push_back (pfrom->GetId ());
428
+ return true ;
429
+ });
425
430
}
426
431
}
427
432
@@ -843,6 +848,11 @@ void PeerLogicValidation::BlockChecked(const CBlock& block, const CValidationSta
843
848
Misbehaving (it->second .first , nDoS);
844
849
}
845
850
}
851
+ else if (state.IsValid () && !IsInitialBlockDownload () && mapBlocksInFlight.count (hash) == mapBlocksInFlight.size ()) {
852
+ if (it != mapBlockSource.end ()) {
853
+ MaybeSetPeerAsAnnouncingHeaderAndIDs (it->second .first , *connman);
854
+ }
855
+ }
846
856
if (it != mapBlockSource.end ())
847
857
mapBlockSource.erase (it);
848
858
}
@@ -1972,12 +1982,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
1972
1982
return true ;
1973
1983
}
1974
1984
1975
- if (!fAlreadyInFlight && mapBlocksInFlight.size () == 1 && pindex->pprev ->IsValid (BLOCK_VALID_CHAIN)) {
1976
- // We seem to be rather well-synced, so it appears pfrom was the first to provide us
1977
- // with this block! Let's get them to announce using compact blocks in the future.
1978
- MaybeSetPeerAsAnnouncingHeaderAndIDs (nodestate, pfrom, connman);
1979
- }
1980
-
1981
1985
BlockTransactionsRequest req;
1982
1986
for (size_t i = 0 ; i < cmpctblock.BlockTxCount (); i++) {
1983
1987
if (!partialBlock.IsTxAvailable (i))
@@ -2267,9 +2271,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
2267
2271
}
2268
2272
if (vGetData.size () > 0 ) {
2269
2273
if (nodestate->fSupportsDesiredCmpctVersion && vGetData.size () == 1 && mapBlocksInFlight.size () == 1 && pindexLast->pprev ->IsValid (BLOCK_VALID_CHAIN)) {
2270
- // We seem to be rather well-synced, so it appears pfrom was the first to provide us
2271
- // with this block! Let's get them to announce using compact blocks in the future.
2272
- MaybeSetPeerAsAnnouncingHeaderAndIDs (nodestate, pfrom, connman);
2273
2274
// In any case, we want to download using a compact block, not a regular one
2274
2275
vGetData[0 ] = CInv (MSG_CMPCT_BLOCK, vGetData[0 ].hash );
2275
2276
}
0 commit comments