Skip to content

Commit

Permalink
Filter out misbehaving node (#1101)
Browse files Browse the repository at this point in the history
Signed-off-by: Anthony Fieroni <[email protected]>
  • Loading branch information
bvbfan authored Feb 18, 2022
1 parent f0e6b25 commit 67fd693
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 49 deletions.
6 changes: 6 additions & 0 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,12 @@ static bool MaybePunishNode(NodeId nodeid, const CValidationState& state, bool v
case ValidationInvalidReason::TX_MEMPOOL_POLICY:
break;
}
if (state.GetRejectCode() == REJECT_CUSTOMTX
|| state.GetRejectReason() == "high-hash") {
LOCK(cs_main);
Misbehaving(nodeid, 100, message);
return true;
}
if (message != "") {
LogPrint(BCLog::NET, "peer=%d: %s\n", nodeid, message);
}
Expand Down
53 changes: 4 additions & 49 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3897,57 +3897,12 @@ bool CChainState::ActivateBestChainStep(CValidationState& state, const CChainPar
state = CValidationState();
if (!ConnectTip(state, chainparams, pindexConnect, pindexConnect == pindexMostWork ? pblock : std::shared_ptr<const CBlock>(), connectTrace, disconnectpool)) {
if (state.IsInvalid()) {
fContinue = false;
if (state.GetRejectReason() == "high-hash"
|| (pindexConnect == pindexMostWork
&& pindexConnect->nHeight >= chainparams.GetConsensus().FortCanningParkHeight
&& state.GetRejectCode() == REJECT_CUSTOMTX)) {
UpdateMempoolForReorg(disconnectpool, false);
return false;
// The block violates a consensus rule.
if (state.GetReason() != ValidationInvalidReason::BLOCK_MUTATED) {
InvalidChainFound(vpindexToConnect.front());
}
fContinue = false;
fInvalidFound = true;
InvalidChainFound(vpindexToConnect.front());
if (state.GetReason() == ValidationInvalidReason::BLOCK_MUTATED) {
// prior EunosHeight we shoutdown node on mutated block
if (ShutdownRequested()) {
return false;
}
// now block cannot be part of blockchain either
// but it can be produced by outdated/malicious masternode
// so we should not shutdown entire network
if (auto blockIndex = ChainActive()[vpindexToConnect.front()->nHeight]) {
auto checkPoint = GetLastCheckpoint(chainparams.Checkpoints());
if (checkPoint && blockIndex->nHeight > checkPoint->nHeight) {
disconnectBlocksTo(blockIndex);
}
}
}
if (pindexConnect == pindexMostWork
&& (pindexConnect->nHeight < chainparams.GetConsensus().EunosHeight
|| state.GetRejectCode() == REJECT_CUSTOMTX)) {
// NOTE: Invalidate blocks back to last checkpoint
auto &checkpoints = chainparams.Checkpoints().mapCheckpoints;
//calculate the latest suitable checkpoint block height
auto checkpointIt = checkpoints.lower_bound(pindexConnect->nHeight);
auto fallbackCheckpointBlockHeight = (checkpointIt != checkpoints.begin()) ? (--checkpointIt)->first : 0;

CBlockIndex *blockIndex = nullptr;
//check spv and anchors are available and try it first
if (spv::pspv && panchors) {
auto fallbackAnchor = panchors->GetLatestAnchorUpToDeFiHeight(pindexConnect->nHeight);
if (fallbackAnchor && (fallbackAnchor->anchor.height > fallbackCheckpointBlockHeight)) {
blockIndex = LookupBlockIndex(fallbackAnchor->anchor.blockHash);
}
}
if (!blockIndex && fallbackCheckpointBlockHeight > 0) {// it doesn't makes sense backward to genesis
blockIndex = LookupBlockIndex(checkpointIt->second);
}
//fallback
if (blockIndex) {
if (!disconnectBlocksTo(blockIndex))
return false;
}
}
break;
} else {
// A system error occurred (disk space, database error, ...).
Expand Down

0 comments on commit 67fd693

Please sign in to comment.