forked from TrueCloudLab/neoneo-go
core: add custom error to blockhain.go
Add InvalidBlockIndex error to AddBlock func
This commit is contained in:
parent
f72c321426
commit
d3063c26e1
1 changed files with 4 additions and 1 deletions
|
@ -52,6 +52,9 @@ var (
|
|||
// ErrPolicy is returned on attempt to add transaction that doesn't
|
||||
// comply with node's configured policy into the mempool.
|
||||
ErrPolicy = errors.New("not allowed by policy")
|
||||
// ErrInvalidBlockIndex is returned when trying to add block with index
|
||||
// other than expected height of the blockchain.
|
||||
ErrInvalidBlockIndex error = errors.New("invalid block index")
|
||||
)
|
||||
var (
|
||||
genAmount = []int{8, 7, 6, 5, 4, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}
|
||||
|
@ -307,7 +310,7 @@ func (bc *Blockchain) AddBlock(block *block.Block) error {
|
|||
|
||||
expectedHeight := bc.BlockHeight() + 1
|
||||
if expectedHeight != block.Index {
|
||||
return fmt.Errorf("expected block %d, but passed block %d", expectedHeight, block.Index)
|
||||
return ErrInvalidBlockIndex
|
||||
}
|
||||
|
||||
headerLen := bc.headerListLen()
|
||||
|
|
Loading…
Reference in a new issue