From c728a9694f2ab878368fc050686d0ec92215dc9b Mon Sep 17 00:00:00 2001 From: Jitendra Bhurat Date: Fri, 29 May 2020 15:14:25 -0400 Subject: [PATCH] Moving setting the consensus in the start instead of when getting a new backend --- consensus/istanbul/backend/backend.go | 8 ++------ consensus/istanbul/backend/engine.go | 8 ++++++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/consensus/istanbul/backend/backend.go b/consensus/istanbul/backend/backend.go index e5769fb48..11ecc5d48 100644 --- a/consensus/istanbul/backend/backend.go +++ b/consensus/istanbul/backend/backend.go @@ -62,11 +62,7 @@ func New(config *istanbul.Config, privateKey *ecdsa.PrivateKey, db ethdb.Databas recentMessages: recentMessages, knownMessages: knownMessages, } - if backend.IsQIBFTConsensus() { - backend.core = qibftCore.New(backend, backend.config) - } else { - backend.core = istanbulCore.New(backend, backend.config) - } + return backend } @@ -332,7 +328,7 @@ func (sb *backend) IsQIBFTConsensus() bool { return false } - if sb.qibftConsensusEnabled || sb.config.QibftBlock.Uint64() == 0{ + if sb.qibftConsensusEnabled || sb.config.QibftBlock.Uint64() == 0 { return true } diff --git a/consensus/istanbul/backend/engine.go b/consensus/istanbul/backend/engine.go index f33c5139f..be9ae43b3 100644 --- a/consensus/istanbul/backend/engine.go +++ b/consensus/istanbul/backend/engine.go @@ -29,6 +29,7 @@ import ( "github.com/ethereum/go-ethereum/consensus/istanbul" istanbulCore "github.com/ethereum/go-ethereum/consensus/istanbul/core" "github.com/ethereum/go-ethereum/consensus/istanbul/validator" + qibftCore "github.com/ethereum/go-ethereum/consensus/qibft/core" "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" @@ -530,6 +531,13 @@ func (sb *backend) Start(chain consensus.ChainReader, currentBlock func() *types sb.currentBlock = currentBlock sb.hasBadBlock = hasBadBlock + // Check if qibft Consensus needs to be used after chain is set + if sb.IsQIBFTConsensus() { + sb.core = qibftCore.New(sb, sb.config) + } else { + sb.core = istanbulCore.New(sb, sb.config) + } + if err := sb.core.Start(); err != nil { return err }