diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-07-26 04:13:27 +0800 |
---|---|---|
committer | Jeffrey Wilcke <jeffrey@ethereum.org> | 2015-07-26 04:13:27 +0800 |
commit | e86233abc9fefc58f52d8a7d9990ddbf8cfda02d (patch) | |
tree | 3a8ad9acc57bc63c3f14c14911df900ed264d759 | |
parent | 73a576c9af5038366f50509136a91a86d203fc6b (diff) | |
parent | c1c895a36b420d58431cf483bd3ed602227892fc (diff) | |
download | dexon-e86233abc9fefc58f52d8a7d9990ddbf8cfda02d.tar dexon-e86233abc9fefc58f52d8a7d9990ddbf8cfda02d.tar.gz dexon-e86233abc9fefc58f52d8a7d9990ddbf8cfda02d.tar.bz2 dexon-e86233abc9fefc58f52d8a7d9990ddbf8cfda02d.tar.lz dexon-e86233abc9fefc58f52d8a7d9990ddbf8cfda02d.tar.xz dexon-e86233abc9fefc58f52d8a7d9990ddbf8cfda02d.tar.zst dexon-e86233abc9fefc58f52d8a7d9990ddbf8cfda02d.zip |
Merge pull request #1525 from obscuren/genesis-write-fix
core: fixed genesis write out to write only canon number
-rw-r--r-- | core/chain_util.go | 13 | ||||
-rw-r--r-- | core/genesis.go | 9 |
2 files changed, 19 insertions, 3 deletions
diff --git a/core/chain_util.go b/core/chain_util.go index a67fdb135..38273d2f0 100644 --- a/core/chain_util.go +++ b/core/chain_util.go @@ -111,13 +111,22 @@ func GetBlockByNumber(db common.Database, number uint64) *types.Block { return GetBlockByHash(db, common.BytesToHash(key)) } -// WriteHead force writes the current head -func WriteHead(db common.Database, block *types.Block) error { +// WriteCanonNumber writes the canonical hash for the given block +func WriteCanonNumber(db common.Database, block *types.Block) error { key := append(blockNumPre, block.Number().Bytes()...) err := db.Put(key, block.Hash().Bytes()) if err != nil { 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()) if err != nil { return err diff --git a/core/genesis.go b/core/genesis.go index a88e88ea8..2f218724a 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -27,6 +27,8 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/state" "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" ) @@ -83,7 +85,12 @@ func WriteGenesisBlock(stateDb, blockDb common.Database, reader io.Reader) (*typ block.Td = difficulty 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() |