diff options
author | Wei-Ning Huang <aitjcize@gmail.com> | 2018-11-14 10:57:53 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-04-09 21:32:53 +0800 |
commit | 3a84568a63f64423683a1dbb9f46cee886a39270 (patch) | |
tree | 070d3478a6f2031b447148ee1d51a952565c02ab /core/evm.go | |
parent | c1138b576524413f8d5755f77aaebd759d6317fc (diff) | |
download | dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar.gz dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar.bz2 dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar.lz dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar.xz dexon-3a84568a63f64423683a1dbb9f46cee886a39270.tar.zst dexon-3a84568a63f64423683a1dbb9f46cee886a39270.zip |
core: validate DKG set with correct nodeset in round-2 (#19)
* vendor: sync consensus core
* core: validate DKG set with correct nodeset in round-2
Diffstat (limited to 'core/evm.go')
-rw-r--r-- | core/evm.go | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/core/evm.go b/core/evm.go index 5e8cf9063..80b0eaa7a 100644 --- a/core/evm.go +++ b/core/evm.go @@ -18,11 +18,10 @@ package core import ( "math/big" - "reflect" - "sync" "github.com/dexon-foundation/dexon/common" "github.com/dexon-foundation/dexon/consensus" + "github.com/dexon-foundation/dexon/core/state" "github.com/dexon-foundation/dexon/core/types" "github.com/dexon-foundation/dexon/core/vm" ) @@ -36,8 +35,14 @@ type ChainContext interface { // GetHeader returns the hash corresponding to their hash. GetHeader(common.Hash, uint64) *types.Header - // GetRoundHeightMap returns the mapping between round and height. - GetRoundHeightMap() sync.Map + // StateAt returns the statedb given a root hash. + StateAt(common.Hash) (*state.StateDB, error) + + // GetHeaderByNumber returns the header given a block number. + GetHeaderByNumber(number uint64) *types.Header + + // GetRoundHeight returns the mapping between round and height. + GetRoundHeight(uint64) (uint64, bool) } // NewEVMContext creates a new context for use in the EVM. @@ -50,24 +55,29 @@ func NewEVMContext(msg Message, header *types.Header, chain ChainContext, author beneficiary = *author } - var roundHeight sync.Map - if !reflect.ValueOf(chain).IsNil() { - roundHeight = chain.GetRoundHeightMap() + return vm.Context{ + CanTransfer: CanTransfer, + Transfer: Transfer, + GetHash: GetHashFn(header, chain), + StateAtNumber: StateAtNumberFn(chain), + GetRoundHeight: chain.GetRoundHeight, + Origin: msg.From(), + Coinbase: beneficiary, + BlockNumber: new(big.Int).Set(header.Number), + Time: new(big.Int).SetUint64(header.Time), + Randomness: header.Randomness, + Difficulty: new(big.Int).Set(header.Difficulty), + GasLimit: header.GasLimit, + GasPrice: new(big.Int).Set(msg.GasPrice()), } +} - return vm.Context{ - CanTransfer: CanTransfer, - Transfer: Transfer, - GetHash: GetHashFn(header, chain), - Origin: msg.From(), - Coinbase: beneficiary, - BlockNumber: new(big.Int).Set(header.Number), - Time: new(big.Int).SetUint64(header.Time), - Randomness: header.Randomness, - Difficulty: new(big.Int).Set(header.Difficulty), - RoundHeight: roundHeight, - GasLimit: header.GasLimit, - GasPrice: new(big.Int).Set(msg.GasPrice()), +// StateAtNumberFn returns a StateAtNumberFunc which allows the retrieval of +// statedb at a given block height. +func StateAtNumberFn(chain ChainContext) func(n uint64) (*state.StateDB, error) { + return func(n uint64) (*state.StateDB, error) { + header := chain.GetHeaderByNumber(n) + return chain.StateAt(header.Root) } } |