aboutsummaryrefslogtreecommitdiffstats
path: root/eth
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
parent5a810758dbe75dce9537d464ac0e5b5385b0e78f (diff)
downloaddexon-a32c51effda8682b292d04863aae7811f78abf7e.tar.gz
dexon-a32c51effda8682b292d04863aae7811f78abf7e.tar.zst
dexon-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')
-rw-r--r--eth/backend.go42
-rw-r--r--eth/protocol_test.go5
2 files changed, 29 insertions, 18 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)
diff --git a/eth/protocol_test.go b/eth/protocol_test.go
index 686380b40..77941852f 100644
--- a/eth/protocol_test.go
+++ b/eth/protocol_test.go
@@ -178,10 +178,11 @@ type testPeer struct {
}
func newProtocolManagerForTesting(txAdded chan<- []*types.Transaction) *ProtocolManager {
+ db, _ := ethdb.NewMemDatabase()
+ core.WriteTestNetGenesisBlock(db, db, 0)
var (
em = new(event.TypeMux)
- db, _ = ethdb.NewMemDatabase()
- chain, _ = core.NewChainManager(core.GenesisBlock(0, db), db, db, db, core.FakePow{}, em)
+ chain, _ = core.NewChainManager(db, db, db, core.FakePow{}, em)
txpool = &fakeTxPool{added: txAdded}
pm = NewProtocolManager(0, em, txpool, core.FakePow{}, chain)
)