diff options
author | Wei-Ning Huang <aitjcize@gmail.com> | 2018-11-14 10:57:53 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | 9919263fe225d6bbd0183fba578a84ecbac8aae6 (patch) | |
tree | eba3fb16d35cb9db8769619ba5984fc4a9bfbfa6 /core/evm.go | |
parent | 9d1efe14607683825c69cce8f690e0f327c6a7b0 (diff) | |
download | dexon-9919263fe225d6bbd0183fba578a84ecbac8aae6.tar dexon-9919263fe225d6bbd0183fba578a84ecbac8aae6.tar.gz dexon-9919263fe225d6bbd0183fba578a84ecbac8aae6.tar.bz2 dexon-9919263fe225d6bbd0183fba578a84ecbac8aae6.tar.lz dexon-9919263fe225d6bbd0183fba578a84ecbac8aae6.tar.xz dexon-9919263fe225d6bbd0183fba578a84ecbac8aae6.tar.zst dexon-9919263fe225d6bbd0183fba578a84ecbac8aae6.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 bae09c514..87185abb8 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).Set(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).Set(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) } } |