diff options
author | obscuren <geffobscura@gmail.com> | 2015-06-08 18:12:13 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-06-09 00:33:43 +0800 |
commit | 6244b10a8f74d92addf977994e5a9c0e457229bb (patch) | |
tree | 30ad7e939d001e8a1400b76e4403546777c9f3aa /core/chain_manager.go | |
parent | c6faa18ec9630066683548ed410e364555fd838d (diff) | |
download | dexon-6244b10a8f74d92addf977994e5a9c0e457229bb.tar dexon-6244b10a8f74d92addf977994e5a9c0e457229bb.tar.gz dexon-6244b10a8f74d92addf977994e5a9c0e457229bb.tar.bz2 dexon-6244b10a8f74d92addf977994e5a9c0e457229bb.tar.lz dexon-6244b10a8f74d92addf977994e5a9c0e457229bb.tar.xz dexon-6244b10a8f74d92addf977994e5a9c0e457229bb.tar.zst dexon-6244b10a8f74d92addf977994e5a9c0e457229bb.zip |
core: settable genesis nonce
You can set the nonce of the block with `--genesisnonce`. When the
genesis nonce changes and it doesn't match with the first block in your
database it will fail. A new `datadir` must be given if the nonce of the
genesis block changes.
Diffstat (limited to 'core/chain_manager.go')
-rw-r--r-- | core/chain_manager.go | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/core/chain_manager.go b/core/chain_manager.go index 291e411ae..edd1cc742 100644 --- a/core/chain_manager.go +++ b/core/chain_manager.go @@ -109,16 +109,22 @@ type ChainManager struct { pow pow.PoW } -func NewChainManager(blockDb, stateDb common.Database, pow pow.PoW, mux *event.TypeMux) *ChainManager { +func NewChainManager(genesis *types.Block, blockDb, stateDb common.Database, pow pow.PoW, mux *event.TypeMux) (*ChainManager, error) { bc := &ChainManager{ - blockDb: blockDb, - stateDb: stateDb, - genesisBlock: GenesisBlock(stateDb), - eventMux: mux, - quit: make(chan struct{}), - cache: NewBlockCache(blockCacheLimit), - pow: pow, + blockDb: blockDb, + stateDb: stateDb, + eventMux: mux, + quit: make(chan struct{}), + cache: NewBlockCache(blockCacheLimit), + pow: pow, } + + // Check the genesis block given to the chain manager. If the genesis block mismatches block number 0 + // throw an error. If no block or the same block's found continue. + if g := bc.GetBlockByNumber(0); g != nil && g.Hash() != genesis.Hash() { + return nil, fmt.Errorf("Genesis mismatch. Maybe different nonce (%d vs %d)? %x / %x", g.Nonce(), genesis.Nonce(), g.Hash().Bytes()[:4], genesis.Hash().Bytes()[:4]) + } + bc.genesisBlock = genesis bc.setLastState() // Check the current state of the block hashes and make sure that we do not have any of the bad blocks in our chain @@ -144,7 +150,7 @@ func NewChainManager(blockDb, stateDb common.Database, pow pow.PoW, mux *event.T go bc.update() - return bc + return bc, nil } func (bc *ChainManager) SetHead(head *types.Block) { |