From 89fac8995ab9e9b89c3d9df93c16fc935cb95ae6 Mon Sep 17 00:00:00 2001 From: Jitendra Bhurat Date: Thu, 28 May 2020 16:15:34 -0400 Subject: [PATCH] Legacy ibft should be used if qibftBlock is not defined in genesis --- consensus/istanbul/backend/backend.go | 12 +++++++----- consensus/istanbul/core/handler.go | 5 +++-- eth/backend.go | 4 ---- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/consensus/istanbul/backend/backend.go b/consensus/istanbul/backend/backend.go index aeccf7951..e5769fb48 100644 --- a/consensus/istanbul/backend/backend.go +++ b/consensus/istanbul/backend/backend.go @@ -327,13 +327,15 @@ func (sb *backend) Close() error { // IsQIBFTConsensus returns whether qbft consensus should be used func (sb *backend) IsQIBFTConsensus() bool { - if sb.qibftConsensusEnabled { - return true - } - // If it is a new network then by default use qibft consensus - if sb.config.QibftBlock == nil || sb.config.QibftBlock.Uint64() == 0 { + // If qibftBlock is not defined in genesis, then use legacy ibft + if sb.config.QibftBlock == nil { + return false + } + + if sb.qibftConsensusEnabled || sb.config.QibftBlock.Uint64() == 0{ return true } + if sb.chain != nil && sb.chain.CurrentHeader().Number.Cmp(sb.config.QibftBlock) >= 0 { return true } diff --git a/consensus/istanbul/core/handler.go b/consensus/istanbul/core/handler.go index 299824cd4..9fa030aa5 100644 --- a/consensus/istanbul/core/handler.go +++ b/consensus/istanbul/core/handler.go @@ -39,8 +39,9 @@ func (c *core) Stop() error { c.stopTimer() c.unsubscribeEvents() - // Make sure the handler goroutine exits - c.handlerWg.Wait() + // Not waiting for handlerWg to stop, as it was blocking legacy IBFT consensus to stop + // and new events will be handled by qibft consensus + // c.handlerWg.Wait() return nil } diff --git a/eth/backend.go b/eth/backend.go index 57f36943c..47858d797 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -283,11 +283,7 @@ func CreateConsensusEngine(ctx *node.ServiceContext, chainConfig *params.ChainCo config.Istanbul.ProposerPolicy = istanbul.ProposerPolicy(chainConfig.Istanbul.ProposerPolicy) config.Istanbul.Ceil2Nby3Block = chainConfig.Istanbul.Ceil2Nby3Block config.Istanbul.AllowedFutureBlockTime = config.AllowedFutureBlockTime - config.Istanbul.QibftBlock = chainConfig.Istanbul.QibftBlock - if chainConfig.Istanbul.QibftBlock == nil { - config.Istanbul.QibftBlock = big.NewInt(0) - } return istanbulBackend.New(&config.Istanbul, ctx.NodeKey(), db) }