mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-28 08:52:31 +00:00
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:
parent
149d8176b0
commit
50b6e10b57
16
accept.go
16
accept.go
@ -91,6 +91,22 @@ func (b *BlockChain) maybeAcceptBlock(block *btcutil.Block, fastAdd bool) error
|
|||||||
return RuleError(str)
|
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 {
|
if !fastAdd {
|
||||||
// Reject version 1 blocks once a majority of the network has
|
// Reject version 1 blocks once a majority of the network has
|
||||||
// upgraded.
|
// upgraded.
|
||||||
|
@ -119,10 +119,10 @@ func (b *BlockChain) ProcessBlock(block *btcutil.Block, fastAdd bool) error {
|
|||||||
|
|
||||||
// Find the latest known checkpoint and perform some additional checks
|
// Find the latest known checkpoint and perform some additional checks
|
||||||
// based on the checkpoint. This provides a few nice properties such as
|
// based on the checkpoint. This provides a few nice properties such as
|
||||||
// preventing forks from blocks before the last checkpoint, rejecting
|
// preventing old side chain blocks before the last checkpoint,
|
||||||
// easy to mine, but otherwise bogus, blocks that could be used to eat
|
// rejecting easy to mine, but otherwise bogus, blocks that could be
|
||||||
// memory, and ensuring expected (versus claimed) proof of work
|
// used to eat memory, and ensuring expected (versus claimed) proof of
|
||||||
// requirements since the last checkpoint are met.
|
// work requirements since the last checkpoint are met.
|
||||||
blockHeader := &block.MsgBlock().Header
|
blockHeader := &block.MsgBlock().Header
|
||||||
checkpointBlock, err := b.findLatestKnownCheckpoint()
|
checkpointBlock, err := b.findLatestKnownCheckpoint()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user