|
|
@ -111,13 +111,22 @@ func GetBlockByNumber(db common.Database, number uint64) *types.Block { |
|
|
|
return GetBlockByHash(db, common.BytesToHash(key)) |
|
|
|
return GetBlockByHash(db, common.BytesToHash(key)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// WriteHead force writes the current head
|
|
|
|
// WriteCanonNumber writes the canonical hash for the given block
|
|
|
|
func WriteHead(db common.Database, block *types.Block) error { |
|
|
|
func WriteCanonNumber(db common.Database, block *types.Block) error { |
|
|
|
key := append(blockNumPre, block.Number().Bytes()...) |
|
|
|
key := append(blockNumPre, block.Number().Bytes()...) |
|
|
|
err := db.Put(key, block.Hash().Bytes()) |
|
|
|
err := db.Put(key, block.Hash().Bytes()) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return nil |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// WriteHead force writes the current head
|
|
|
|
|
|
|
|
func WriteHead(db common.Database, block *types.Block) error { |
|
|
|
|
|
|
|
err := WriteCanonNumber(db, block) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return err |
|
|
|
|
|
|
|
} |
|
|
|
err = db.Put([]byte("LastBlock"), block.Hash().Bytes()) |
|
|
|
err = db.Put([]byte("LastBlock"), block.Hash().Bytes()) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
return err |
|
|
|
return err |
|
|
|