Skip to content

Commit 76a7705

Browse files
committed
Merge pull request #2910
d8b4b49 Don't store or send side-chain blocks lower than last checkpoint. (Ashley Holman)
2 parents 7f080fb + d8b4b49 commit 76a7705

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/main.cpp

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2276,6 +2276,11 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
22762276
return state.DoS(100, error("AcceptBlock() : rejected by checkpoint lock-in at %d", nHeight),
22772277
REJECT_CHECKPOINT, "checkpoint mismatch");
22782278

2279+
// Don't accept any forks from the main chain prior to last checkpoint
2280+
CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(mapBlockIndex);
2281+
if (pcheckpoint && nHeight < pcheckpoint->nHeight)
2282+
return state.DoS(100, error("AcceptBlock() : forked chain older than last checkpoint (height %d)", nHeight));
2283+
22792284
// Reject block.nVersion=1 blocks when 95% (75% on testnet) of the network has upgraded:
22802285
if (block.nVersion < 2)
22812286
{
@@ -3133,10 +3138,28 @@ void static ProcessGetData(CNode* pfrom)
31333138

31343139
if (inv.type == MSG_BLOCK || inv.type == MSG_FILTERED_BLOCK)
31353140
{
3136-
// Send block from disk
3141+
bool send = false;
31373142
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(inv.hash);
31383143
if (mi != mapBlockIndex.end())
31393144
{
3145+
// If the requested block is at a height below our last
3146+
// checkpoint, only serve it if it's in the checkpointed chain
3147+
int nHeight = mi->second->nHeight;
3148+
CBlockIndex* pcheckpoint = Checkpoints::GetLastCheckpoint(mapBlockIndex);
3149+
if (pcheckpoint && nHeight < pcheckpoint->nHeight) {
3150+
if (!chainActive.Contains(mi->second))
3151+
{
3152+
LogPrintf("ProcessGetData(): ignoring request for old block that isn't in the main chain\n");
3153+
} else {
3154+
send = true;
3155+
}
3156+
} else {
3157+
send = true;
3158+
}
3159+
}
3160+
if (send)
3161+
{
3162+
// Send block from disk
31403163
CBlock block;
31413164
ReadBlockFromDisk(block, (*mi).second);
31423165
if (inv.type == MSG_BLOCK)

0 commit comments

Comments
 (0)