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.
This commit is contained in:
parent
cc315d045e
commit
ff4d01765f
3 changed files with 8 additions and 2 deletions
7
error.go
7
error.go
|
@ -62,10 +62,14 @@ const (
|
||||||
// checkpoint height does not match the expected one.
|
// checkpoint height does not match the expected one.
|
||||||
ErrBadCheckpoint
|
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.
|
// before the most recent checkpoint.
|
||||||
ErrForkTooOld
|
ErrForkTooOld
|
||||||
|
|
||||||
|
// ErrCheckpointTimeTooOld indicates a block has a timestamp before the
|
||||||
|
// most recent checkpoint.
|
||||||
|
ErrCheckpointTimeTooOld
|
||||||
|
|
||||||
// ErrNoTransactions indicates the block does not have a least one
|
// ErrNoTransactions indicates the block does not have a least one
|
||||||
// transaction. A valid block must have at least the coinbase
|
// transaction. A valid block must have at least the coinbase
|
||||||
// transaction.
|
// transaction.
|
||||||
|
@ -190,6 +194,7 @@ var errorCodeStrings = map[ErrorCode]string{
|
||||||
ErrBadMerkleRoot: "ErrBadMerkleRoot",
|
ErrBadMerkleRoot: "ErrBadMerkleRoot",
|
||||||
ErrBadCheckpoint: "ErrBadCheckpoint",
|
ErrBadCheckpoint: "ErrBadCheckpoint",
|
||||||
ErrForkTooOld: "ErrForkTooOld",
|
ErrForkTooOld: "ErrForkTooOld",
|
||||||
|
ErrCheckpointTimeTooOld: "ErrCheckpointTimeTooOld",
|
||||||
ErrNoTransactions: "ErrNoTransactions",
|
ErrNoTransactions: "ErrNoTransactions",
|
||||||
ErrTooManyTransactions: "ErrTooManyTransactions",
|
ErrTooManyTransactions: "ErrTooManyTransactions",
|
||||||
ErrNoTxInputs: "ErrNoTxInputs",
|
ErrNoTxInputs: "ErrNoTxInputs",
|
||||||
|
|
|
@ -28,6 +28,7 @@ func TestErrorCodeStringer(t *testing.T) {
|
||||||
{btcchain.ErrBadMerkleRoot, "ErrBadMerkleRoot"},
|
{btcchain.ErrBadMerkleRoot, "ErrBadMerkleRoot"},
|
||||||
{btcchain.ErrBadCheckpoint, "ErrBadCheckpoint"},
|
{btcchain.ErrBadCheckpoint, "ErrBadCheckpoint"},
|
||||||
{btcchain.ErrForkTooOld, "ErrForkTooOld"},
|
{btcchain.ErrForkTooOld, "ErrForkTooOld"},
|
||||||
|
{btcchain.ErrCheckpointTimeTooOld, "ErrCheckpointTimeTooOld"},
|
||||||
{btcchain.ErrNoTransactions, "ErrNoTransactions"},
|
{btcchain.ErrNoTransactions, "ErrNoTransactions"},
|
||||||
{btcchain.ErrTooManyTransactions, "ErrTooManyTransactions"},
|
{btcchain.ErrTooManyTransactions, "ErrTooManyTransactions"},
|
||||||
{btcchain.ErrNoTxInputs, "ErrNoTxInputs"},
|
{btcchain.ErrNoTxInputs, "ErrNoTxInputs"},
|
||||||
|
|
|
@ -165,7 +165,7 @@ func (b *BlockChain) ProcessBlock(block *btcutil.Block, flags BehaviorFlags) (bo
|
||||||
str := fmt.Sprintf("block %v has timestamp %v before "+
|
str := fmt.Sprintf("block %v has timestamp %v before "+
|
||||||
"last checkpoint timestamp %v", blockHash,
|
"last checkpoint timestamp %v", blockHash,
|
||||||
blockHeader.Timestamp, checkpointTime)
|
blockHeader.Timestamp, checkpointTime)
|
||||||
return false, ruleError(ErrTimeTooOld, str)
|
return false, ruleError(ErrCheckpointTimeTooOld, str)
|
||||||
}
|
}
|
||||||
if !fastAdd {
|
if !fastAdd {
|
||||||
// Even though the checks prior to now have already ensured the
|
// Even though the checks prior to now have already ensured the
|
||||||
|
|
Loading…
Reference in a new issue