Browse Source

dont run consensus state unless fast sync is off

pull/80/head
Ethan Buchman 10 years ago
committed by Jae Kwon
parent
commit
bb67fe0356
4 changed files with 20 additions and 26 deletions
  1. +5
    -7
      blockchain/reactor.go
  2. +2
    -2
      config/tendermint_test/config.go
  3. +12
    -11
      consensus/reactor.go
  4. +1
    -6
      node/node.go

+ 5
- 7
blockchain/reactor.go View File

@ -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
}


+ 2
- 2
config/tendermint_test/config.go View File

@ -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"


+ 12
- 11
consensus/reactor.go View File

@ -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


+ 1
- 6
node/node.go View File

@ -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)


Loading…
Cancel
Save