diff options
author | Wei-Ning Huang <w@dexon.org> | 2018-11-16 17:26:50 +0800 |
---|---|---|
committer | Wei-Ning Huang <w@dexon.org> | 2019-03-12 12:19:09 +0800 |
commit | c2d461f4c5cefde85173365175d2de8bf234b4aa (patch) | |
tree | cd7a3cc61f6befa7359d18f2e6b024452b3c267d /core/vm | |
parent | dcdb39cb09464422b1ab13a0b92f95e5378431b6 (diff) | |
download | dexon-c2d461f4c5cefde85173365175d2de8bf234b4aa.tar dexon-c2d461f4c5cefde85173365175d2de8bf234b4aa.tar.gz dexon-c2d461f4c5cefde85173365175d2de8bf234b4aa.tar.bz2 dexon-c2d461f4c5cefde85173365175d2de8bf234b4aa.tar.lz dexon-c2d461f4c5cefde85173365175d2de8bf234b4aa.tar.xz dexon-c2d461f4c5cefde85173365175d2de8bf234b4aa.tar.zst dexon-c2d461f4c5cefde85173365175d2de8bf234b4aa.zip |
core: fix light node synchronization issue (#30)
InsertChain() need to record the correct roundHeight mapping in order to
process snapshotRoundHeight() governance method correctly.
Diffstat (limited to 'core/vm')
-rw-r--r-- | core/vm/evm.go | 3 | ||||
-rw-r--r-- | core/vm/governance.go | 20 | ||||
-rw-r--r-- | core/vm/interpreter.go | 3 |
3 files changed, 17 insertions, 9 deletions
diff --git a/core/vm/evm.go b/core/vm/evm.go index 865ab0d5b..64f71e530 100644 --- a/core/vm/evm.go +++ b/core/vm/evm.go @@ -479,3 +479,6 @@ func (evm *EVM) Create2(caller ContractRef, code []byte, gas uint64, endowment * // ChainConfig returns the environment's chain configuration func (evm *EVM) ChainConfig() *params.ChainConfig { return evm.chainConfig } + +// IsBlockProposer returns whether or not we are a block proposer. +func (evm *EVM) IsBlockProposer() bool { return evm.vmConfig.IsBlockProposer } diff --git a/core/vm/governance.go b/core/vm/governance.go index b38733e1a..f406294d2 100644 --- a/core/vm/governance.go +++ b/core/vm/governance.go @@ -1767,16 +1767,18 @@ func (g *GovernanceContract) transferOwnership(newOwner common.Address) ([]byte, } func (g *GovernanceContract) snapshotRound(round, height *big.Int) ([]byte, error) { - // Validate if this mapping is correct. - realHeight, ok := g.evm.Context.GetRoundHeight(round.Uint64()) - if !ok { - g.penalize() - return nil, errExecutionReverted - } + // Validate if this mapping is correct. Only block proposer need to verify this. + if g.evm.IsBlockProposer() { + realHeight, ok := g.evm.Context.GetRoundHeight(round.Uint64()) + if !ok { + g.penalize() + return nil, errExecutionReverted + } - if height.Cmp(new(big.Int).SetUint64(realHeight)) != 0 { - g.penalize() - return nil, errExecutionReverted + if height.Cmp(new(big.Int).SetUint64(realHeight)) != 0 { + g.penalize() + return nil, errExecutionReverted + } } // Only allow updating the next round. diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index b5e35f1a4..ffe5ff626 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -46,6 +46,9 @@ type Config struct { EWASMInterpreter string // Type of the EVM interpreter EVMInterpreter string + + // Whether or not we are a block proposer. + IsBlockProposer bool } // Interpreter is used to run Ethereum based contracts and will utilise the |