diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2016-03-02 06:32:43 +0800 |
---|---|---|
committer | Jeffrey Wilcke <geffobscura@gmail.com> | 2016-04-01 07:01:10 +0800 |
commit | f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c (patch) | |
tree | 02e31a0e31040980e30e3a835ff9eba73e419439 /core/blockchain.go | |
parent | 10d3466c934bd425a8c941270749a652a588527d (diff) | |
download | dexon-f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c.tar.gz dexon-f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c.tar.zst dexon-f0cbebb19f3137ee3ba0e66dadd1b5b9dbf98b1c.zip |
core: added basic chain configuration
Added chain configuration options and write out during genesis database
insertion. If no "config" was found, nothing is written to the database.
Configurations are written on a per genesis base. This means
that any chain (which is identified by it's genesis hash) can have their
own chain settings.
Diffstat (limited to 'core/blockchain.go')
-rw-r--r-- | core/blockchain.go | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/core/blockchain.go b/core/blockchain.go index 2c3c2bb5c..177a3bbce 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -80,11 +80,12 @@ const ( // included in the canonical one where as GetBlockByNumber always represents the // canonical chain. type BlockChain struct { + config *ChainConfig // chain & network configuration + hc *HeaderChain chainDb ethdb.Database eventMux *event.TypeMux genesisBlock *types.Block - vmConfig *vm.Config mu sync.RWMutex // global mutex for locking chain operations chainmu sync.RWMutex // blockchain insertion lock @@ -113,13 +114,14 @@ type BlockChain struct { // NewBlockChain returns a fully initialised block chain using information // available in the database. It initialiser the default Ethereum Validator and // Processor. -func NewBlockChain(chainDb ethdb.Database, pow pow.PoW, mux *event.TypeMux) (*BlockChain, error) { +func NewBlockChain(chainDb ethdb.Database, config *ChainConfig, pow pow.PoW, mux *event.TypeMux) (*BlockChain, error) { bodyCache, _ := lru.New(bodyCacheLimit) bodyRLPCache, _ := lru.New(bodyCacheLimit) blockCache, _ := lru.New(blockCacheLimit) futureBlocks, _ := lru.New(maxFutureBlocks) bc := &BlockChain{ + config: config, chainDb: chainDb, eventMux: mux, quit: make(chan struct{}), @@ -129,24 +131,21 @@ func NewBlockChain(chainDb ethdb.Database, pow pow.PoW, mux *event.TypeMux) (*Bl futureBlocks: futureBlocks, pow: pow, } - bc.SetValidator(NewBlockValidator(bc, pow)) - bc.SetProcessor(NewStateProcessor(bc)) + bc.SetValidator(NewBlockValidator(config, bc, pow)) + bc.SetProcessor(NewStateProcessor(config, bc)) gv := func() HeaderValidator { return bc.Validator() } var err error - bc.hc, err = NewHeaderChain(chainDb, gv, bc.getProcInterrupt) + bc.hc, err = NewHeaderChain(chainDb, config, gv, bc.getProcInterrupt) if err != nil { return nil, err } bc.genesisBlock = bc.GetBlockByNumber(0) if bc.genesisBlock == nil { - bc.genesisBlock, err = WriteDefaultGenesisBlock(chainDb) - if err != nil { - return nil, err - } - glog.V(logger.Info).Infoln("WARNING: Wrote default ethereum genesis block") + return nil, ErrNoGenesis } + if err := bc.loadLastState(); err != nil { return nil, err } @@ -163,10 +162,6 @@ func NewBlockChain(chainDb ethdb.Database, pow pow.PoW, mux *event.TypeMux) (*Bl return bc, nil } -func (self *BlockChain) SetConfig(vmConfig *vm.Config) { - self.vmConfig = vmConfig -} - func (self *BlockChain) getProcInterrupt() bool { return atomic.LoadInt32(&self.procInterrupt) == 1 } @@ -896,7 +891,7 @@ func (self *BlockChain) InsertChain(chain types.Blocks) (int, error) { return i, err } // Process block using the parent state as reference point. - receipts, logs, usedGas, err := self.processor.Process(block, statedb, self.vmConfig) + receipts, logs, usedGas, err := self.processor.Process(block, statedb, self.config.VmConfig) if err != nil { reportBlock(block, err) return i, err |