aboutsummaryrefslogtreecommitdiffstats
path: root/core/chain_manager.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <jeffrey@ethereum.org>2015-06-09 04:43:41 +0800
committerJeffrey Wilcke <jeffrey@ethereum.org>2015-06-09 04:43:41 +0800
commit55b7c14554bc4faabc14aac6410b75f97c55cd4e (patch)
treef5a840d89417bb2b0273d8edd6d81b07299c3f58 /core/chain_manager.go
parent75522f95ce13b449123b60963ec1261d1e0507f1 (diff)
parent6244b10a8f74d92addf977994e5a9c0e457229bb (diff)
downloaddexon-55b7c14554bc4faabc14aac6410b75f97c55cd4e.tar
dexon-55b7c14554bc4faabc14aac6410b75f97c55cd4e.tar.gz
dexon-55b7c14554bc4faabc14aac6410b75f97c55cd4e.tar.bz2
dexon-55b7c14554bc4faabc14aac6410b75f97c55cd4e.tar.lz
dexon-55b7c14554bc4faabc14aac6410b75f97c55cd4e.tar.xz
dexon-55b7c14554bc4faabc14aac6410b75f97c55cd4e.tar.zst
dexon-55b7c14554bc4faabc14aac6410b75f97c55cd4e.zip
Merge pull request #1199 from obscuren/settable_genesis_nonce
core: settable genesis nonce
Diffstat (limited to 'core/chain_manager.go')
-rw-r--r--core/chain_manager.go24
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) {