Moving setting the consensus in the start instead of when getting a new backend

This commit is contained in:
Jitendra Bhurat 2020-05-29 15:14:25 -04:00
parent 89fac8995a
commit c728a9694f
2 changed files with 10 additions and 6 deletions

View File

@ -62,11 +62,7 @@ func New(config *istanbul.Config, privateKey *ecdsa.PrivateKey, db ethdb.Databas
recentMessages: recentMessages, recentMessages: recentMessages,
knownMessages: knownMessages, knownMessages: knownMessages,
} }
if backend.IsQIBFTConsensus() {
backend.core = qibftCore.New(backend, backend.config)
} else {
backend.core = istanbulCore.New(backend, backend.config)
}
return backend return backend
} }
@ -332,7 +328,7 @@ func (sb *backend) IsQIBFTConsensus() bool {
return false return false
} }
if sb.qibftConsensusEnabled || sb.config.QibftBlock.Uint64() == 0{ if sb.qibftConsensusEnabled || sb.config.QibftBlock.Uint64() == 0 {
return true return true
} }

View File

@ -29,6 +29,7 @@ import (
"github.com/ethereum/go-ethereum/consensus/istanbul" "github.com/ethereum/go-ethereum/consensus/istanbul"
istanbulCore "github.com/ethereum/go-ethereum/consensus/istanbul/core" istanbulCore "github.com/ethereum/go-ethereum/consensus/istanbul/core"
"github.com/ethereum/go-ethereum/consensus/istanbul/validator" "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/state"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
@ -530,6 +531,13 @@ func (sb *backend) Start(chain consensus.ChainReader, currentBlock func() *types
sb.currentBlock = currentBlock sb.currentBlock = currentBlock
sb.hasBadBlock = hasBadBlock 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 { if err := sb.core.Start(); err != nil {
return err return err
} }