Reject blocks that fork before previous checkpoint.

This commit adds an additional check to the block acceptance rules which
prevents new blocks that fork the main chain before the previous known
good checkpoint.  This prevents storage of new, otherwise valid, blocks
from building off of old blocks which are likely at a much easier
difficulty and therefore could be used to waste cache and disk space.

Note this is slightly different than the other existing check which
prevents blocks with a timestamp before the timestamp of the latest known
good checkpoint since that check effectively prevents old side chain
blocks that already existed (per the claimed timestamp).

ok drahn@
This commit is contained in:
Dave Collins 2014-02-21 13:02:59 -06:00
parent 149d8176b0
commit 50b6e10b57
2 changed files with 20 additions and 4 deletions

View file

@ -91,6 +91,22 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, fastAdd bool) error
return RuleError(str)
}
// Find the latest known good checkpoint and prevent blocks which fork
// the main chain before it. This prevents storage of new, otherwise
// valid, blocks which build off of old blocks that are likely at a
// much easier difficulty and therefore could be used to waste cache and
// disk space.
checkpointBlock, err := b.findLatestKnownCheckpoint()
if err != nil {
return err
}
if checkpointBlock != nil && blockHeight < checkpointBlock.Height() {
str := fmt.Sprintf("block at height %d forks the main chain "+
"before the previous checkpoint at height %d",
blockHeight, checkpointBlock.Height())
return RuleError(str)
}
if !fastAdd {
// Reject version 1 blocks once a majority of the network has
// upgraded.

View file

@ -119,10 +119,10 @@ func (b *BlockChain) ProcessBlock(block *btcutil.Block, fastAdd bool) error {
// Find the latest known checkpoint and perform some additional checks
// based on the checkpoint. This provides a few nice properties such as
// preventing forks from blocks before the last checkpoint, rejecting
// easy to mine, but otherwise bogus, blocks that could be used to eat
// memory, and ensuring expected (versus claimed) proof of work
// requirements since the last checkpoint are met.
// preventing old side chain blocks before the last checkpoint,
// rejecting easy to mine, but otherwise bogus, blocks that could be
// used to eat memory, and ensuring expected (versus claimed) proof of
// work requirements since the last checkpoint are met.
blockHeader := &block.MsgBlock().Header
checkpointBlock, err := b.findLatestKnownCheckpoint()
if err != nil {