mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-15 06:11:20 +00:00
dont run consensus state unless fast sync is off
This commit is contained in:
@ -10,7 +10,6 @@ import (
|
|||||||
|
|
||||||
"github.com/tendermint/tendermint/binary"
|
"github.com/tendermint/tendermint/binary"
|
||||||
. "github.com/tendermint/tendermint/common"
|
. "github.com/tendermint/tendermint/common"
|
||||||
dbm "github.com/tendermint/tendermint/db"
|
|
||||||
"github.com/tendermint/tendermint/events"
|
"github.com/tendermint/tendermint/events"
|
||||||
"github.com/tendermint/tendermint/p2p"
|
"github.com/tendermint/tendermint/p2p"
|
||||||
sm "github.com/tendermint/tendermint/state"
|
sm "github.com/tendermint/tendermint/state"
|
||||||
@ -33,8 +32,9 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type consensusReactor interface {
|
type consensusReactor interface {
|
||||||
SetSyncing(bool)
|
// for when we switch from blockchain reactor and fast sync to
|
||||||
ResetToState(*sm.State)
|
// the consensus machine
|
||||||
|
SwitchToConsensus(*sm.State)
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlockchainReactor handles long-term catchup syncing.
|
// BlockchainReactor handles long-term catchup syncing.
|
||||||
@ -211,11 +211,9 @@ FOR_LOOP:
|
|||||||
if maxPending && allUnassigned && enoughPeers {
|
if maxPending && allUnassigned && enoughPeers {
|
||||||
log.Info("Time to switch to consensus reactor!", "height", bcR.pool.height)
|
log.Info("Time to switch to consensus reactor!", "height", bcR.pool.height)
|
||||||
bcR.pool.Stop()
|
bcR.pool.Stop()
|
||||||
stateDB := dbm.GetDB("state")
|
|
||||||
state := sm.LoadState(stateDB)
|
|
||||||
|
|
||||||
bcR.sw.Reactor("CONSENSUS").(consensusReactor).ResetToState(state)
|
conR := bcR.sw.Reactor("CONSENSUS").(consensusReactor)
|
||||||
bcR.sw.Reactor("CONSENSUS").(consensusReactor).SetSyncing(false)
|
conR.SwitchToConsensus(bcR.state)
|
||||||
|
|
||||||
break FOR_LOOP
|
break FOR_LOOP
|
||||||
}
|
}
|
||||||
|
@ -71,7 +71,7 @@ func GetConfig(rootDir string) cfg.Config {
|
|||||||
mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json")
|
mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json")
|
||||||
mapConfig.SetDefault("moniker", "anonymous")
|
mapConfig.SetDefault("moniker", "anonymous")
|
||||||
mapConfig.SetDefault("node_laddr", "0.0.0.0:36656")
|
mapConfig.SetDefault("node_laddr", "0.0.0.0:36656")
|
||||||
mapConfig.SetDefault("fast_sync", true)
|
mapConfig.SetDefault("fast_sync", false)
|
||||||
mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json")
|
mapConfig.SetDefault("addrbook_file", rootDir+"/addrbook.json")
|
||||||
mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json")
|
mapConfig.SetDefault("priv_validator_file", rootDir+"/priv_validator.json")
|
||||||
mapConfig.SetDefault("db_backend", "memdb")
|
mapConfig.SetDefault("db_backend", "memdb")
|
||||||
@ -94,7 +94,7 @@ network = "tendermint_test"
|
|||||||
moniker = "__MONIKER__"
|
moniker = "__MONIKER__"
|
||||||
node_laddr = "0.0.0.0:36656"
|
node_laddr = "0.0.0.0:36656"
|
||||||
seeds = ""
|
seeds = ""
|
||||||
fast_sync = true
|
fast_sync = false
|
||||||
db_backend = "memdb"
|
db_backend = "memdb"
|
||||||
log_level = "debug"
|
log_level = "debug"
|
||||||
rpc_laddr = "0.0.0.0:36657"
|
rpc_laddr = "0.0.0.0:36657"
|
||||||
|
@ -42,16 +42,17 @@ type ConsensusReactor struct {
|
|||||||
conS *ConsensusState
|
conS *ConsensusState
|
||||||
|
|
||||||
// if fast sync is running we don't really do anything
|
// if fast sync is running we don't really do anything
|
||||||
syncing bool
|
sync bool
|
||||||
|
|
||||||
evsw events.Fireable
|
evsw events.Fireable
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConsensusReactor(consensusState *ConsensusState, blockStore *bc.BlockStore) *ConsensusReactor {
|
func NewConsensusReactor(consensusState *ConsensusState, blockStore *bc.BlockStore, sync bool) *ConsensusReactor {
|
||||||
conR := &ConsensusReactor{
|
conR := &ConsensusReactor{
|
||||||
blockStore: blockStore,
|
blockStore: blockStore,
|
||||||
quit: make(chan struct{}),
|
quit: make(chan struct{}),
|
||||||
conS: consensusState,
|
conS: consensusState,
|
||||||
|
sync: sync,
|
||||||
}
|
}
|
||||||
return conR
|
return conR
|
||||||
}
|
}
|
||||||
@ -61,7 +62,9 @@ func (conR *ConsensusReactor) Start(sw *p2p.Switch) {
|
|||||||
if atomic.CompareAndSwapUint32(&conR.running, 0, 1) {
|
if atomic.CompareAndSwapUint32(&conR.running, 0, 1) {
|
||||||
log.Info("Starting ConsensusReactor")
|
log.Info("Starting ConsensusReactor")
|
||||||
conR.sw = sw
|
conR.sw = sw
|
||||||
conR.conS.Start()
|
if !conR.sync {
|
||||||
|
conR.conS.Start()
|
||||||
|
}
|
||||||
go conR.broadcastNewRoundStepRoutine()
|
go conR.broadcastNewRoundStepRoutine()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -129,7 +132,7 @@ func (conR *ConsensusReactor) RemovePeer(peer *p2p.Peer, reason interface{}) {
|
|||||||
|
|
||||||
// Implements Reactor
|
// Implements Reactor
|
||||||
func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte) {
|
func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte) {
|
||||||
if conR.syncing || !conR.IsRunning() {
|
if conR.sync || !conR.IsRunning() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,20 +238,18 @@ func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sets whether or not we're using the blockchain reactor for syncing
|
|
||||||
func (conR *ConsensusReactor) SetSyncing(syncing bool) {
|
|
||||||
conR.syncing = syncing
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sets our private validator account for signing votes.
|
// Sets our private validator account for signing votes.
|
||||||
func (conR *ConsensusReactor) SetPrivValidator(priv *sm.PrivValidator) {
|
func (conR *ConsensusReactor) SetPrivValidator(priv *sm.PrivValidator) {
|
||||||
conR.conS.SetPrivValidator(priv)
|
conR.conS.SetPrivValidator(priv)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reset to some state.
|
// Switch from the fast sync to the consensus:
|
||||||
func (conR *ConsensusReactor) ResetToState(state *sm.State) {
|
// reset the state, turn off fast sync, start the consensus-state-machine
|
||||||
|
func (conR *ConsensusReactor) SwitchToConsensus(state *sm.State) {
|
||||||
conR.conS.updateToState(state, false)
|
conR.conS.updateToState(state, false)
|
||||||
conR.conS.newStepCh <- conR.conS.getRoundState()
|
conR.conS.newStepCh <- conR.conS.getRoundState()
|
||||||
|
conR.sync = false
|
||||||
|
conR.conS.Start()
|
||||||
}
|
}
|
||||||
|
|
||||||
// implements events.Eventable
|
// implements events.Eventable
|
||||||
|
@ -87,16 +87,11 @@ func NewNode() *Node {
|
|||||||
|
|
||||||
// Get ConsensusReactor
|
// Get ConsensusReactor
|
||||||
consensusState := consensus.NewConsensusState(state, blockStore, mempoolReactor)
|
consensusState := consensus.NewConsensusState(state, blockStore, mempoolReactor)
|
||||||
consensusReactor := consensus.NewConsensusReactor(consensusState, blockStore)
|
consensusReactor := consensus.NewConsensusReactor(consensusState, blockStore, config.GetBool("fast_sync"))
|
||||||
if privValidator != nil {
|
if privValidator != nil {
|
||||||
consensusReactor.SetPrivValidator(privValidator)
|
consensusReactor.SetPrivValidator(privValidator)
|
||||||
}
|
}
|
||||||
|
|
||||||
// so the consensus reactor won't do anything until we're synced
|
|
||||||
if config.GetBool("fast_sync") {
|
|
||||||
consensusReactor.SetSyncing(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
sw := p2p.NewSwitch()
|
sw := p2p.NewSwitch()
|
||||||
sw.AddReactor("PEX", pexReactor)
|
sw.AddReactor("PEX", pexReactor)
|
||||||
sw.AddReactor("MEMPOOL", mempoolReactor)
|
sw.AddReactor("MEMPOOL", mempoolReactor)
|
||||||
|
Reference in New Issue
Block a user