aboutsummaryrefslogtreecommitdiffstats
path: root/eth/backend.go
diff options
context:
space:
mode:
authorJeffrey Wilcke <geffobscura@gmail.com>2015-07-10 20:29:40 +0800
committerJeffrey Wilcke <geffobscura@gmail.com>2015-07-10 23:37:41 +0800
commita32c51effda8682b292d04863aae7811f78abf7e (patch)
treed721822cc10c929d5a2def0865c366e085ef99be /eth/backend.go
parent5a810758dbe75dce9537d464ac0e5b5385b0e78f (diff)
downloadgo-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar.gz
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar.bz2
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar.lz
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar.xz
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.tar.zst
go-tangerine-a32c51effda8682b292d04863aae7811f78abf7e.zip
cmd, core, eth, common: genesis preparation
Implemented the --genesis flag thru which we can set a custom genesis block, including the official Ethereum genesis block.
Diffstat (limited to 'eth/backend.go')
-rw-r--r--eth/backend.go42
1 files changed, 26 insertions, 16 deletions
diff --git a/eth/backend.go b/eth/backend.go
index 9c661ad54..e7250c019 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -75,6 +75,8 @@ type Config struct {
Name string
NetworkId int
GenesisNonce int
+ GenesisFile string
+ GenesisBlock *types.Block // used by block tests
BlockChainVersion int
SkipBcVersionCheck bool // e.g. blockchain export
@@ -283,22 +285,26 @@ func New(config *Config) (*Ethereum, error) {
db.Meter("eth/db/extra/")
}
nodeDb := filepath.Join(config.DataDir, "nodes")
+ glog.V(logger.Info).Infof("Protocol Versions: %v, Network Id: %v", ProtocolVersions, config.NetworkId)
- // Perform database sanity checks
- /*
- // The databases were previously tied to protocol versions. Currently we
- // are moving away from this decision as approaching Frontier. The below
- // check was left in for now but should eventually be just dropped.
-
- d, _ := blockDb.Get([]byte("ProtocolVersion"))
- protov := int(common.NewValue(d).Uint())
- if protov != config.ProtocolVersion && protov != 0 {
- path := filepath.Join(config.DataDir, "blockchain")
- return nil, fmt.Errorf("Database version mismatch. Protocol(%d / %d). `rm -rf %s`", protov, config.ProtocolVersion, path)
+ if len(config.GenesisFile) > 0 {
+ fr, err := os.Open(config.GenesisFile)
+ if err != nil {
+ return nil, err
}
- saveProtocolVersion(blockDb, config.ProtocolVersion)
- */
- glog.V(logger.Info).Infof("Protocol Versions: %v, Network Id: %v", ProtocolVersions, config.NetworkId)
+
+ block, err := core.WriteGenesisBlock(stateDb, blockDb, fr)
+ if err != nil {
+ return nil, err
+ }
+ glog.V(logger.Info).Infof("Successfully wrote genesis block. New genesis hash = %x\n", block.Hash())
+ }
+
+ // This is for testing only.
+ if config.GenesisBlock != nil {
+ core.WriteBlock(blockDb, config.GenesisBlock)
+ core.WriteHead(blockDb, config.GenesisBlock)
+ }
if !config.SkipBcVersionCheck {
b, _ := blockDb.Get([]byte("BlockchainVersion"))
@@ -344,9 +350,13 @@ func New(config *Config) (*Ethereum, error) {
} else {
eth.pow = ethash.New()
}
- genesis := core.GenesisBlock(uint64(config.GenesisNonce), stateDb)
- eth.chainManager, err = core.NewChainManager(genesis, blockDb, stateDb, extraDb, eth.pow, eth.EventMux())
+ //genesis := core.GenesisBlock(uint64(config.GenesisNonce), stateDb)
+ eth.chainManager, err = core.NewChainManager(blockDb, stateDb, extraDb, eth.pow, eth.EventMux())
if err != nil {
+ if err == core.ErrNoGenesis {
+ return nil, fmt.Errorf(`Genesis block not found. Please supply a genesis block with the "--genesis /path/to/file" argument`)
+ }
+
return nil, err
}
eth.txPool = core.NewTxPool(eth.EventMux(), eth.chainManager.State, eth.chainManager.GasLimit)