|
|
@ -401,6 +401,12 @@ void UpdateBlockAvailability(NodeId nodeid, const uint256 &hash) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* When a peer sends us a valid block, instruct it to announce blocks to us
|
|
|
|
|
|
|
|
* using CMPCTBLOCK if possible by adding its nodeid to the end of
|
|
|
|
|
|
|
|
* lNodesAnnouncingHeaderAndIDs, and keeping that list under a certain size by
|
|
|
|
|
|
|
|
* removing the first element if necessary.
|
|
|
|
|
|
|
|
*/
|
|
|
|
void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman* connman) {
|
|
|
|
void MaybeSetPeerAsAnnouncingHeaderAndIDs(NodeId nodeid, CConnman* connman) {
|
|
|
|
AssertLockHeld(cs_main);
|
|
|
|
AssertLockHeld(cs_main);
|
|
|
|
CNodeState* nodestate = State(nodeid);
|
|
|
|
CNodeState* nodestate = State(nodeid);
|
|
|
@ -749,7 +755,11 @@ unsigned int LimitOrphanTxSize(unsigned int nMaxOrphans)
|
|
|
|
return nEvicted;
|
|
|
|
return nEvicted;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Requires cs_main.
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Mark a misbehaving peer to be banned depending upon the value of `-banscore`.
|
|
|
|
|
|
|
|
*
|
|
|
|
|
|
|
|
* Requires cs_main.
|
|
|
|
|
|
|
|
*/
|
|
|
|
void Misbehaving(NodeId pnode, int howmuch, const std::string& message)
|
|
|
|
void Misbehaving(NodeId pnode, int howmuch, const std::string& message)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (howmuch == 0)
|
|
|
|
if (howmuch == 0)
|
|
|
@ -808,6 +818,10 @@ PeerLogicValidation::PeerLogicValidation(CConnman* connmanIn, CScheduler &schedu
|
|
|
|
scheduler.scheduleEvery(std::bind(&PeerLogicValidation::CheckForStaleTipAndEvictPeers, this, consensusParams), EXTRA_PEER_CHECK_INTERVAL * 1000);
|
|
|
|
scheduler.scheduleEvery(std::bind(&PeerLogicValidation::CheckForStaleTipAndEvictPeers, this, consensusParams), EXTRA_PEER_CHECK_INTERVAL * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Evict orphan txn pool entries (EraseOrphanTx) based on a newly connected
|
|
|
|
|
|
|
|
* block. Also save the time of the last tip update.
|
|
|
|
|
|
|
|
*/
|
|
|
|
void PeerLogicValidation::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex, const std::vector<CTransactionRef>& vtxConflicted) {
|
|
|
|
void PeerLogicValidation::BlockConnected(const std::shared_ptr<const CBlock>& pblock, const CBlockIndex* pindex, const std::vector<CTransactionRef>& vtxConflicted) {
|
|
|
|
LOCK(g_cs_orphans);
|
|
|
|
LOCK(g_cs_orphans);
|
|
|
|
|
|
|
|
|
|
|
@ -828,7 +842,7 @@ void PeerLogicValidation::BlockConnected(const std::shared_ptr<const CBlock>& pb
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Erase orphan transactions include or precluded by this block
|
|
|
|
// Erase orphan transactions included or precluded by this block
|
|
|
|
if (vOrphanErase.size()) {
|
|
|
|
if (vOrphanErase.size()) {
|
|
|
|
int nErased = 0;
|
|
|
|
int nErased = 0;
|
|
|
|
for (uint256 &orphanHash : vOrphanErase) {
|
|
|
|
for (uint256 &orphanHash : vOrphanErase) {
|
|
|
@ -847,6 +861,10 @@ static std::shared_ptr<const CBlockHeaderAndShortTxIDs> most_recent_compact_bloc
|
|
|
|
static uint256 most_recent_block_hash;
|
|
|
|
static uint256 most_recent_block_hash;
|
|
|
|
static bool fWitnessesPresentInMostRecentCompactBlock;
|
|
|
|
static bool fWitnessesPresentInMostRecentCompactBlock;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Maintain state about the best-seen block and fast-announce a compact block
|
|
|
|
|
|
|
|
* to compatible peers.
|
|
|
|
|
|
|
|
*/
|
|
|
|
void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) {
|
|
|
|
void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& pblock) {
|
|
|
|
std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true);
|
|
|
|
std::shared_ptr<const CBlockHeaderAndShortTxIDs> pcmpctblock = std::make_shared<const CBlockHeaderAndShortTxIDs> (*pblock, true);
|
|
|
|
const CNetMsgMaker msgMaker(PROTOCOL_VERSION);
|
|
|
|
const CNetMsgMaker msgMaker(PROTOCOL_VERSION);
|
|
|
@ -888,6 +906,10 @@ void PeerLogicValidation::NewPoWValidBlock(const CBlockIndex *pindex, const std:
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Update our best height and announce any block hashes which weren't previously
|
|
|
|
|
|
|
|
* in chainActive to our peers.
|
|
|
|
|
|
|
|
*/
|
|
|
|
void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
|
|
|
|
void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
|
|
|
|
const int nNewHeight = pindexNew->nHeight;
|
|
|
|
const int nNewHeight = pindexNew->nHeight;
|
|
|
|
connman->SetBestHeight(nNewHeight);
|
|
|
|
connman->SetBestHeight(nNewHeight);
|
|
|
@ -920,6 +942,10 @@ void PeerLogicValidation::UpdatedBlockTip(const CBlockIndex *pindexNew, const CB
|
|
|
|
nTimeBestReceived = GetTime();
|
|
|
|
nTimeBestReceived = GetTime();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Handle invalid block rejection and consequent peer banning, maintain which
|
|
|
|
|
|
|
|
* peers announce compact blocks.
|
|
|
|
|
|
|
|
*/
|
|
|
|
void PeerLogicValidation::BlockChecked(const CBlock& block, const CValidationState& state) {
|
|
|
|
void PeerLogicValidation::BlockChecked(const CBlock& block, const CValidationState& state) {
|
|
|
|
LOCK(cs_main);
|
|
|
|
LOCK(cs_main);
|
|
|
|
|
|
|
|
|
|
|
|