diff options
author | Wei-Ning Huang <aitjcize@gmail.com> | 2018-11-14 10:57:53 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@byzantine-lab.io> | 2019-06-12 17:27:18 +0800 |
commit | 070647ec674c96582ebe93dadeefe017964c0488 (patch) | |
tree | cf14e337a1f306adc15ccafa4086f2745f8a4093 /core/evm.go | |
parent | cbb7cc20f824fd96279a0c14eb5d0a2187347955 (diff) | |
download | go-tangerine-070647ec674c96582ebe93dadeefe017964c0488.tar go-tangerine-070647ec674c96582ebe93dadeefe017964c0488.tar.gz go-tangerine-070647ec674c96582ebe93dadeefe017964c0488.tar.bz2 go-tangerine-070647ec674c96582ebe93dadeefe017964c0488.tar.lz go-tangerine-070647ec674c96582ebe93dadeefe017964c0488.tar.xz go-tangerine-070647ec674c96582ebe93dadeefe017964c0488.tar.zst go-tangerine-070647ec674c96582ebe93dadeefe017964c0488.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) } } |