From bb67fe0356ca94db12c3f9c8010204acb95a0cd9 Mon Sep 17 00:00:00 2001 From: Ethan Buchman Date: Wed, 27 May 2015 22:06:33 -0400 Subject: [PATCH] dont run consensus state unless fast sync is off --- blockchain/reactor.go | 12 +++++------- config/tendermint_test/config.go | 4 ++-- consensus/reactor.go | 23 ++++++++++++----------- node/node.go | 7 +------ 4 files changed, 20 insertions(+), 26 deletions(-) diff --git a/blockchain/reactor.go b/blockchain/reactor.go index 793183375..e48da66f9 100644 --- a/blockchain/reactor.go +++ b/blockchain/reactor.go @@ -10,7 +10,6 @@ import ( "github.com/tendermint/tendermint/binary" . "github.com/tendermint/tendermint/common" - dbm "github.com/tendermint/tendermint/db" "github.com/tendermint/tendermint/events" "github.com/tendermint/tendermint/p2p" sm "github.com/tendermint/tendermint/state" @@ -33,8 +32,9 @@ const ( ) type consensusReactor interface { - SetSyncing(bool) - ResetToState(*sm.State) + // for when we switch from blockchain reactor and fast sync to + // the consensus machine + SwitchToConsensus(*sm.State) } // BlockchainReactor handles long-term catchup syncing. @@ -211,11 +211,9 @@ FOR_LOOP: if maxPending && allUnassigned && enoughPeers { log.Info("Time to switch to consensus reactor!", "height", bcR.pool.height) bcR.pool.Stop() - stateDB := dbm.GetDB("state") - state := sm.LoadState(stateDB) - bcR.sw.Reactor("CONSENSUS").(consensusReactor).ResetToState(state) - bcR.sw.Reactor("CONSENSUS").(consensusReactor).SetSyncing(false) + conR := bcR.sw.Reactor("CONSENSUS").(consensusReactor) + conR.SwitchToConsensus(bcR.state) break FOR_LOOP } diff --git a/config/tendermint_test/config.go b/config/tendermint_test/config.go index 51149ea2c..7f78a3c2c 100644 --- a/config/tendermint_test/config.go +++ b/config/tendermint_test/config.go @@ -71,7 +71,7 @@ func GetConfig(rootDir string) cfg.Config { mapConfig.SetDefault("genesis_file", rootDir+"/genesis.json") mapConfig.SetDefault("moniker", "anonymous") 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("priv_validator_file", rootDir+"/priv_validator.json") mapConfig.SetDefault("db_backend", "memdb") @@ -94,7 +94,7 @@ network = "tendermint_test" moniker = "__MONIKER__" node_laddr = "0.0.0.0:36656" seeds = "" -fast_sync = true +fast_sync = false db_backend = "memdb" log_level = "debug" rpc_laddr = "0.0.0.0:36657" diff --git a/consensus/reactor.go b/consensus/reactor.go index 1bd0edba5..2cddd51ae 100644 --- a/consensus/reactor.go +++ b/consensus/reactor.go @@ -42,16 +42,17 @@ type ConsensusReactor struct { conS *ConsensusState // if fast sync is running we don't really do anything - syncing bool + sync bool evsw events.Fireable } -func NewConsensusReactor(consensusState *ConsensusState, blockStore *bc.BlockStore) *ConsensusReactor { +func NewConsensusReactor(consensusState *ConsensusState, blockStore *bc.BlockStore, sync bool) *ConsensusReactor { conR := &ConsensusReactor{ blockStore: blockStore, quit: make(chan struct{}), conS: consensusState, + sync: sync, } return conR } @@ -61,7 +62,9 @@ func (conR *ConsensusReactor) Start(sw *p2p.Switch) { if atomic.CompareAndSwapUint32(&conR.running, 0, 1) { log.Info("Starting ConsensusReactor") conR.sw = sw - conR.conS.Start() + if !conR.sync { + conR.conS.Start() + } go conR.broadcastNewRoundStepRoutine() } } @@ -129,7 +132,7 @@ func (conR *ConsensusReactor) RemovePeer(peer *p2p.Peer, reason interface{}) { // Implements Reactor func (conR *ConsensusReactor) Receive(chId byte, peer *p2p.Peer, msgBytes []byte) { - if conR.syncing || !conR.IsRunning() { + if conR.sync || !conR.IsRunning() { 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. func (conR *ConsensusReactor) SetPrivValidator(priv *sm.PrivValidator) { conR.conS.SetPrivValidator(priv) } -// Reset to some state. -func (conR *ConsensusReactor) ResetToState(state *sm.State) { +// Switch from the fast sync to the consensus: +// 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.newStepCh <- conR.conS.getRoundState() + conR.sync = false + conR.conS.Start() } // implements events.Eventable diff --git a/node/node.go b/node/node.go index 35a165c41..ed0816a08 100644 --- a/node/node.go +++ b/node/node.go @@ -87,16 +87,11 @@ func NewNode() *Node { // Get ConsensusReactor consensusState := consensus.NewConsensusState(state, blockStore, mempoolReactor) - consensusReactor := consensus.NewConsensusReactor(consensusState, blockStore) + consensusReactor := consensus.NewConsensusReactor(consensusState, blockStore, config.GetBool("fast_sync")) if privValidator != nil { 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.AddReactor("PEX", pexReactor) sw.AddReactor("MEMPOOL", mempoolReactor)