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 /miner | |
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 'miner')
-rw-r--r-- | miner/miner.go | 4 | ||||
-rw-r--r-- | miner/worker.go | 13 |
2 files changed, 11 insertions, 6 deletions
diff --git a/miner/miner.go b/miner/miner.go index e52cefaab..7cc25cdf7 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -51,8 +51,8 @@ type Miner struct { shouldStart int32 // should start indicates whether we should start after sync } -func New(eth core.Backend, mux *event.TypeMux, pow pow.PoW) *Miner { - miner := &Miner{eth: eth, mux: mux, pow: pow, worker: newWorker(common.Address{}, eth), canStart: 1} +func New(eth core.Backend, config *core.ChainConfig, mux *event.TypeMux, pow pow.PoW) *Miner { + miner := &Miner{eth: eth, mux: mux, pow: pow, worker: newWorker(config, common.Address{}, eth), canStart: 1} go miner.update() return miner diff --git a/miner/worker.go b/miner/worker.go index b3ddf9707..c45945b87 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -61,6 +61,7 @@ type uint64RingBuffer struct { // environment is the workers current environment and holds // all of the current state information type Work struct { + config *core.ChainConfig state *state.StateDB // apply state changes here ancestors *set.Set // ancestor set (used for checking uncle parent validity) family *set.Set // family set (used for checking uncle invalidity) @@ -89,6 +90,8 @@ type Result struct { // worker is the main object which takes care of applying messages to the new state type worker struct { + config *core.ChainConfig + mu sync.Mutex agents map[Agent]struct{} @@ -122,8 +125,9 @@ type worker struct { fullValidation bool } -func newWorker(coinbase common.Address, eth core.Backend) *worker { +func newWorker(config *core.ChainConfig, coinbase common.Address, eth core.Backend) *worker { worker := &worker{ + config: config, eth: eth, mux: eth.EventMux(), chainDb: eth.ChainDb(), @@ -285,7 +289,7 @@ func (self *worker) wait() { } auxValidator := self.eth.BlockChain().AuxValidator() - if err := core.ValidateHeader(auxValidator, block.Header(), parent.Header(), true, false); err != nil && err != core.BlockFutureErr { + if err := core.ValidateHeader(self.config, auxValidator, block.Header(), parent.Header(), true, false); err != nil && err != core.BlockFutureErr { glog.V(logger.Error).Infoln("Invalid header on mined block:", err) continue } @@ -371,6 +375,7 @@ func (self *worker) makeCurrent(parent *types.Block, header *types.Header) error return err } work := &Work{ + config: self.config, state: state, ancestors: set.New(), family: set.New(), @@ -470,7 +475,7 @@ func (self *worker) commitNewWork() { header := &types.Header{ ParentHash: parent.Hash(), Number: num.Add(num, common.Big1), - Difficulty: core.CalcDifficulty(uint64(tstamp), parent.Time().Uint64(), parent.Number(), parent.Difficulty()), + Difficulty: core.CalcDifficulty(self.config, uint64(tstamp), parent.Time().Uint64(), parent.Number(), parent.Difficulty()), GasLimit: core.CalcGasLimit(parent), GasUsed: new(big.Int), Coinbase: self.coinbase, @@ -657,7 +662,7 @@ func (env *Work) commitTransactions(mux *event.TypeMux, transactions types.Trans func (env *Work) commitTransaction(tx *types.Transaction, bc *core.BlockChain, gp *core.GasPool) (error, vm.Logs) { snap := env.state.Copy() - receipt, logs, _, err := core.ApplyTransaction(bc, gp, env.state, env.header, tx, env.header.GasUsed, nil) + receipt, logs, _, err := core.ApplyTransaction(env.config, bc, gp, env.state, env.header, tx, env.header.GasUsed, env.config.VmConfig) if err != nil { env.state.Set(snap) return err, nil |