|
|
@ -395,19 +395,22 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void MaybeSetPeerAsAnnouncingHeaderAndIDs(const CNodeState* nodestate, CNode* pfrom, CConnman& connman) { |
|
|
|
void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman& connman) { |
|
|
|
if (!nodestate->fSupportsDesiredCmpctVersion) { |
|
|
|
AssertLockHeld(cs_main); |
|
|
|
|
|
|
|
CNodeState* nodestate = State(nodeid); |
|
|
|
|
|
|
|
if (!nodestate || !nodestate->fSupportsDesiredCmpctVersion) { |
|
|
|
// Never ask from peers who can't provide witnesses.
|
|
|
|
// Never ask from peers who can't provide witnesses.
|
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (nodestate->fProvidesHeaderAndIDs) { |
|
|
|
if (nodestate->fProvidesHeaderAndIDs) { |
|
|
|
for (std::list<NodeId>::iterator it = lNodesAnnouncingHeaderAndIDs.begin(); it != lNodesAnnouncingHeaderAndIDs.end(); it++) { |
|
|
|
for (std::list<NodeId>::iterator it = lNodesAnnouncingHeaderAndIDs.begin(); it != lNodesAnnouncingHeaderAndIDs.end(); it++) { |
|
|
|
if (*it == pfrom->GetId()) { |
|
|
|
if (*it == nodeid) { |
|
|
|
lNodesAnnouncingHeaderAndIDs.erase(it); |
|
|
|
lNodesAnnouncingHeaderAndIDs.erase(it); |
|
|
|
lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId()); |
|
|
|
lNodesAnnouncingHeaderAndIDs.push_back(nodeid); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
connman.ForNode(nodeid, [&connman](CNode* pfrom){ |
|
|
|
bool fAnnounceUsingCMPCTBLOCK = false; |
|
|
|
bool fAnnounceUsingCMPCTBLOCK = false; |
|
|
|
uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices() & NODE_WITNESS) ? 2 : 1; |
|
|
|
uint64_t nCMPCTBLOCKVersion = (pfrom->GetLocalServices() & NODE_WITNESS) ? 2 : 1; |
|
|
|
if (lNodesAnnouncingHeaderAndIDs.size() >= 3) { |
|
|
|
if (lNodesAnnouncingHeaderAndIDs.size() >= 3) { |
|
|
@ -422,6 +425,8 @@ void MaybeSetPeerAsAnnouncingHeaderAndIDs(const CNodeState* nodestate, CNode* pf |
|
|
|
fAnnounceUsingCMPCTBLOCK = true; |
|
|
|
fAnnounceUsingCMPCTBLOCK = true; |
|
|
|
connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion)); |
|
|
|
connman.PushMessage(pfrom, CNetMsgMaker(pfrom->GetSendVersion()).Make(NetMsgType::SENDCMPCT, fAnnounceUsingCMPCTBLOCK, nCMPCTBLOCKVersion)); |
|
|
|
lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId()); |
|
|
|
lNodesAnnouncingHeaderAndIDs.push_back(pfrom->GetId()); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -798,6 +803,11 @@ void PeerLogicValidation::BlockChecked(const CBlock& block, const CValidationSta |
|
|
|
Misbehaving(it->second.first, nDoS); |
|
|
|
Misbehaving(it->second.first, nDoS); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else if (state.IsValid() && !IsInitialBlockDownload() && mapBlocksInFlight.count(hash) == mapBlocksInFlight.size()) { |
|
|
|
|
|
|
|
if (it != mapBlockSource.end()) { |
|
|
|
|
|
|
|
MaybeSetPeerAsAnnouncingHeaderAndIDs(it->second.first, *connman); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
if (it != mapBlockSource.end()) |
|
|
|
if (it != mapBlockSource.end()) |
|
|
|
mapBlockSource.erase(it); |
|
|
|
mapBlockSource.erase(it); |
|
|
|
} |
|
|
|
} |
|
|
@ -1853,12 +1863,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (!fAlreadyInFlight && mapBlocksInFlight.size() == 1 && pindex->pprev->IsValid(BLOCK_VALID_CHAIN)) { |
|
|
|
|
|
|
|
// We seem to be rather well-synced, so it appears pfrom was the first to provide us
|
|
|
|
|
|
|
|
// with this block! Let's get them to announce using compact blocks in the future.
|
|
|
|
|
|
|
|
MaybeSetPeerAsAnnouncingHeaderAndIDs(nodestate, pfrom, connman); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BlockTransactionsRequest req; |
|
|
|
BlockTransactionsRequest req; |
|
|
|
for (size_t i = 0; i < cmpctblock.BlockTxCount(); i++) { |
|
|
|
for (size_t i = 0; i < cmpctblock.BlockTxCount(); i++) { |
|
|
|
if (!partialBlock.IsTxAvailable(i)) |
|
|
|
if (!partialBlock.IsTxAvailable(i)) |
|
|
@ -2143,9 +2147,6 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, |
|
|
|
} |
|
|
|
} |
|
|
|
if (vGetData.size() > 0) { |
|
|
|
if (vGetData.size() > 0) { |
|
|
|
if (nodestate->fSupportsDesiredCmpctVersion && vGetData.size() == 1 && mapBlocksInFlight.size() == 1 && pindexLast->pprev->IsValid(BLOCK_VALID_CHAIN)) { |
|
|
|
if (nodestate->fSupportsDesiredCmpctVersion && vGetData.size() == 1 && mapBlocksInFlight.size() == 1 && pindexLast->pprev->IsValid(BLOCK_VALID_CHAIN)) { |
|
|
|
// We seem to be rather well-synced, so it appears pfrom was the first to provide us
|
|
|
|
|
|
|
|
// with this block! Let's get them to announce using compact blocks in the future.
|
|
|
|
|
|
|
|
MaybeSetPeerAsAnnouncingHeaderAndIDs(nodestate, pfrom, connman); |
|
|
|
|
|
|
|
// In any case, we want to download using a compact block, not a regular one
|
|
|
|
// In any case, we want to download using a compact block, not a regular one
|
|
|
|
vGetData[0] = CInv(MSG_CMPCT_BLOCK, vGetData[0].hash); |
|
|
|
vGetData[0] = CInv(MSG_CMPCT_BLOCK, vGetData[0].hash); |
|
|
|
} |
|
|
|
} |
|
|
|