@@ -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
@@ -798,6 +803,11 @@ void PeerLogicValidation::BlockChecked(const CBlock& block, const CValidationSta
798
803
Misbehaving (it->second .first , nDoS);
799
804
}
800
805
}
806
+ else if (state.IsValid () && !IsInitialBlockDownload () && mapBlocksInFlight.count (hash) == mapBlocksInFlight.size ()) {
807
+ if (it != mapBlockSource.end ()) {
808
+ MaybeSetPeerAsAnnouncingHeaderAndIDs (it->second .first , *connman);
809
+ }
810
+ }
801
811
if (it != mapBlockSource.end ())
802
812
mapBlockSource.erase (it);
803
813
}
@@ -1853,12 +1863,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
1853
1863
return true ;
1854
1864
}
1855
1865
1856
- if (!fAlreadyInFlight && mapBlocksInFlight.size () == 1 && pindex->pprev ->IsValid (BLOCK_VALID_CHAIN)) {
1857
- // We seem to be rather well-synced, so it appears pfrom was the first to provide us
1858
- // with this block! Let's get them to announce using compact blocks in the future.
1859
- MaybeSetPeerAsAnnouncingHeaderAndIDs (nodestate, pfrom, connman);
1860
- }
1861
-
1862
1866
BlockTransactionsRequest req;
1863
1867
for (size_t i = 0 ; i < cmpctblock.BlockTxCount (); i++) {
1864
1868
if (!partialBlock.IsTxAvailable (i))
@@ -2143,9 +2147,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
2143
2147
}
2144
2148
if (vGetData.size () > 0 ) {
2145
2149
if (nodestate->fSupportsDesiredCmpctVersion && vGetData.size () == 1 && mapBlocksInFlight.size () == 1 && pindexLast->pprev ->IsValid (BLOCK_VALID_CHAIN)) {
2146
- // We seem to be rather well-synced, so it appears pfrom was the first to provide us
2147
- // with this block! Let's get them to announce using compact blocks in the future.
2148
- MaybeSetPeerAsAnnouncingHeaderAndIDs (nodestate, pfrom, connman);
2149
2150
// In any case, we want to download using a compact block, not a regular one
2150
2151
vGetData[0 ] = CInv (MSG_CMPCT_BLOCK, vGetData[0 ].hash );
2151
2152
}
0 commit comments