From f1f0e7d0b962c802124b2ed9123d3e9bd9cd9644 Mon Sep 17 00:00:00 2001 From: Wei-Ning Huang Date: Fri, 16 Nov 2018 17:26:50 +0800 Subject: core: fix light node synchronization issue (#30) InsertChain() need to record the correct roundHeight mapping in order to process snapshotRoundHeight() governance method correctly. --- core/blockchain.go | 1 + core/vm/evm.go | 3 +++ core/vm/governance.go | 20 +++++++++++--------- core/vm/interpreter.go | 3 +++ dex/backend.go | 1 + dex/handler.go | 4 ++++ 6 files changed, 23 insertions(+), 9 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index 344a032a1..f8d9bca9e 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1379,6 +1379,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, [] "txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles()), "root", block.Root()) events = append(events, ChainSideEvent{block}) + panic("fork found") } blockInsertTimer.UpdateSince(start) stats.processed++ 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 diff --git a/dex/backend.go b/dex/backend.go index 740b8cd6f..07646fd76 100644 --- a/dex/backend.go +++ b/dex/backend.go @@ -131,6 +131,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Dexon, error) { EnablePreimageRecording: config.EnablePreimageRecording, EWASMInterpreter: config.EWASMInterpreter, EVMInterpreter: config.EVMInterpreter, + IsBlockProposer: config.BlockProposerEnabled, } cacheConfig = &core.CacheConfig{Disabled: config.NoPruning, TrieCleanLimit: config.TrieCleanCache, TrieDirtyLimit: config.TrieDirtyCache, TrieTimeLimit: config.TrieTimeout} ) diff --git a/dex/handler.go b/dex/handler.go index 7bc9c297d..21322e4e0 100644 --- a/dex/handler.go +++ b/dex/handler.go @@ -1079,6 +1079,10 @@ func (pm *ProtocolManager) peerSetLoop() { pm.BroadcastBlock(event.Block, true) // First propagate block to peers pm.BroadcastBlock(event.Block, false) // Only then announce to the rest + if !pm.isBlockProposer { + break + } + newRound := pm.gov.LenCRS() - 1 log.Trace("new round", "round", newRound) if newRound == round { -- cgit v1.2.3