"errors"
"math/rand"
+ "github.com/vapor/protocol"
"github.com/vapor/protocol/bc"
"github.com/vapor/protocol/bc/types"
)
+var (
+ ErrFoundHeaderByHash = errors.New("can't find header by hash")
+ ErrFoundHeaderByHeight = errors.New("can't find header by height")
+)
+
type mempool interface {
AddTx(tx *types.Tx)
}
func (c *Chain) GetHeaderByHash(hash *bc.Hash) (*types.BlockHeader, error) {
block, ok := c.blockMap[*hash]
if !ok {
- return nil, errors.New("can't find block")
+ return nil, ErrFoundHeaderByHash
}
return &block.BlockHeader, nil
}
func (c *Chain) GetHeaderByHeight(height uint64) (*types.BlockHeader, error) {
block, ok := c.heightMap[height]
if !ok {
- return nil, errors.New("can't find block")
+ return nil, ErrFoundHeaderByHeight
}
return &block.BlockHeader, nil
}
}
func (c *Chain) ProcessBlock(block *types.Block) (bool, error) {
+ if block.TransactionsMerkleRoot == bc.NewHash([32]byte{0x1}) {
+ return false, protocol.ErrBadStateRoot
+ }
+
if c.bestBlockHeader.Hash() == block.PreviousBlockHash {
c.heightMap[block.Height] = block
c.blockMap[block.Hash()] = block