From ff4d01765f6e853ad826d36a87424312797bc331 Mon Sep 17 00:00:00 2001 From: Dave Collins Date: Fri, 11 Jul 2014 09:36:53 -0500 Subject: [PATCH] Split time too old error into two distinct errors. This commit splits the two rule validation errors related to the timestamp being too old into two distince errors rather than grouping them under the same one. Thus there is now a new ErrCheckpointTimeTooNew in addition to the existing ErrTimeTooNew error. This allows the caller to detect the when a block is rejected due to a time-related checkpoint failure whereas before the combined error did not. --- error.go | 7 ++++++- error_test.go | 1 + process.go | 2 +- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/error.go b/error.go index 974d33c9..31853c59 100644 --- a/error.go +++ b/error.go @@ -62,10 +62,14 @@ const ( // checkpoint height does not match the expected one. ErrBadCheckpoint - // ErrForkTooOld indicates a block is attempted to fork the block chain + // ErrForkTooOld indicates a block is attempting to fork the block chain // before the most recent checkpoint. ErrForkTooOld + // ErrCheckpointTimeTooOld indicates a block has a timestamp before the + // most recent checkpoint. + ErrCheckpointTimeTooOld + // ErrNoTransactions indicates the block does not have a least one // transaction. A valid block must have at least the coinbase // transaction. @@ -190,6 +194,7 @@ var errorCodeStrings = map[ErrorCode]string{ ErrBadMerkleRoot: "ErrBadMerkleRoot", ErrBadCheckpoint: "ErrBadCheckpoint", ErrForkTooOld: "ErrForkTooOld", + ErrCheckpointTimeTooOld: "ErrCheckpointTimeTooOld", ErrNoTransactions: "ErrNoTransactions", ErrTooManyTransactions: "ErrTooManyTransactions", ErrNoTxInputs: "ErrNoTxInputs", diff --git a/error_test.go b/error_test.go index 20f6f58c..4f7b3398 100644 --- a/error_test.go +++ b/error_test.go @@ -28,6 +28,7 @@ func TestErrorCodeStringer(t *testing.T) { {btcchain.ErrBadMerkleRoot, "ErrBadMerkleRoot"}, {btcchain.ErrBadCheckpoint, "ErrBadCheckpoint"}, {btcchain.ErrForkTooOld, "ErrForkTooOld"}, + {btcchain.ErrCheckpointTimeTooOld, "ErrCheckpointTimeTooOld"}, {btcchain.ErrNoTransactions, "ErrNoTransactions"}, {btcchain.ErrTooManyTransactions, "ErrTooManyTransactions"}, {btcchain.ErrNoTxInputs, "ErrNoTxInputs"}, diff --git a/process.go b/process.go index e86103b1..55927afd 100644 --- a/process.go +++ b/process.go @@ -165,7 +165,7 @@ func (b *BlockChain) ProcessBlock(block *btcutil.Block, flags BehaviorFlags) (bo str := fmt.Sprintf("block %v has timestamp %v before "+ "last checkpoint timestamp %v", blockHash, blockHeader.Timestamp, checkpointTime) - return false, ruleError(ErrTimeTooOld, str) + return false, ruleError(ErrCheckpointTimeTooOld, str) } if !fastAdd { // Even though the checks prior to now have already ensured the