Commit c1c895a3 authored by Jeffrey Wilcke's avatar Jeffrey Wilcke

core: fixed genesis write out to write only canon number

parent 73a576c9
...@@ -111,13 +111,22 @@ func GetBlockByNumber(db common.Database, number uint64) *types.Block { ...@@ -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
......
...@@ -27,6 +27,8 @@ import ( ...@@ -27,6 +27,8 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/logger"
"github.com/ethereum/go-ethereum/logger/glog"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
) )
...@@ -83,7 +85,12 @@ func WriteGenesisBlock(stateDb, blockDb common.Database, reader io.Reader) (*typ ...@@ -83,7 +85,12 @@ func WriteGenesisBlock(stateDb, blockDb common.Database, reader io.Reader) (*typ
block.Td = difficulty block.Td = difficulty
if block := GetBlockByHash(blockDb, block.Hash()); block != nil { if block := GetBlockByHash(blockDb, block.Hash()); block != nil {
return nil, fmt.Errorf("Block %x already in database", block.Hash()) glog.V(logger.Info).Infoln("Genesis block already in chain. Writing canonical number")
err := WriteCanonNumber(blockDb, block)
if err != nil {
return nil, err
}
return block, nil
} }
statedb.Sync() statedb.Sync()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment