mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-14 22:01:20 +00:00
Fix #198; Do not fast-sync when lone validator
This commit is contained in:
@ -47,7 +47,7 @@ type BlockchainReactor struct {
|
|||||||
proxyAppConn proxy.AppConn // same as consensus.proxyAppConn
|
proxyAppConn proxy.AppConn // same as consensus.proxyAppConn
|
||||||
store *BlockStore
|
store *BlockStore
|
||||||
pool *BlockPool
|
pool *BlockPool
|
||||||
sync bool
|
fastSync bool
|
||||||
requestsCh chan BlockRequest
|
requestsCh chan BlockRequest
|
||||||
timeoutsCh chan string
|
timeoutsCh chan string
|
||||||
lastBlock *types.Block
|
lastBlock *types.Block
|
||||||
@ -55,7 +55,7 @@ type BlockchainReactor struct {
|
|||||||
evsw *events.EventSwitch
|
evsw *events.EventSwitch
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewBlockchainReactor(state *sm.State, proxyAppConn proxy.AppConn, store *BlockStore, sync bool) *BlockchainReactor {
|
func NewBlockchainReactor(state *sm.State, proxyAppConn proxy.AppConn, store *BlockStore, fastSync bool) *BlockchainReactor {
|
||||||
if state.LastBlockHeight == store.Height()-1 {
|
if state.LastBlockHeight == store.Height()-1 {
|
||||||
store.height -= 1 // XXX HACK, make this better
|
store.height -= 1 // XXX HACK, make this better
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ func NewBlockchainReactor(state *sm.State, proxyAppConn proxy.AppConn, store *Bl
|
|||||||
proxyAppConn: proxyAppConn,
|
proxyAppConn: proxyAppConn,
|
||||||
store: store,
|
store: store,
|
||||||
pool: pool,
|
pool: pool,
|
||||||
sync: sync,
|
fastSync: fastSync,
|
||||||
requestsCh: requestsCh,
|
requestsCh: requestsCh,
|
||||||
timeoutsCh: timeoutsCh,
|
timeoutsCh: timeoutsCh,
|
||||||
}
|
}
|
||||||
@ -84,7 +84,7 @@ func NewBlockchainReactor(state *sm.State, proxyAppConn proxy.AppConn, store *Bl
|
|||||||
|
|
||||||
func (bcR *BlockchainReactor) OnStart() error {
|
func (bcR *BlockchainReactor) OnStart() error {
|
||||||
bcR.BaseReactor.OnStart()
|
bcR.BaseReactor.OnStart()
|
||||||
if bcR.sync {
|
if bcR.fastSync {
|
||||||
_, err := bcR.pool.Start()
|
_, err := bcR.pool.Start()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
14
node/node.go
14
node/node.go
@ -73,8 +73,18 @@ func NewNode(privValidator *types.PrivValidator) *Node {
|
|||||||
Exit(Fmt("Failed to start switch: %v", err))
|
Exit(Fmt("Failed to start switch: %v", err))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decide whether to fast-sync or not
|
||||||
|
// We don't fast-sync when the only validator is us.
|
||||||
|
fastSync := config.GetBool("fast_sync")
|
||||||
|
if state.Validators.Size() == 1 {
|
||||||
|
addr, _ := state.Validators.GetByIndex(0)
|
||||||
|
if bytes.Equal(privValidator.Address, addr) {
|
||||||
|
fastSync = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Make BlockchainReactor
|
// Make BlockchainReactor
|
||||||
bcReactor := bc.NewBlockchainReactor(state.Copy(), proxyAppConnConsensus, blockStore, config.GetBool("fast_sync"))
|
bcReactor := bc.NewBlockchainReactor(state.Copy(), proxyAppConnConsensus, blockStore, fastSync)
|
||||||
|
|
||||||
// Make MempoolReactor
|
// Make MempoolReactor
|
||||||
mempool := mempl.NewMempool(proxyAppConnMempool)
|
mempool := mempl.NewMempool(proxyAppConnMempool)
|
||||||
@ -82,7 +92,7 @@ func NewNode(privValidator *types.PrivValidator) *Node {
|
|||||||
|
|
||||||
// Make ConsensusReactor
|
// Make ConsensusReactor
|
||||||
consensusState := consensus.NewConsensusState(state.Copy(), proxyAppConnConsensus, blockStore, mempool)
|
consensusState := consensus.NewConsensusState(state.Copy(), proxyAppConnConsensus, blockStore, mempool)
|
||||||
consensusReactor := consensus.NewConsensusReactor(consensusState, blockStore, config.GetBool("fast_sync"))
|
consensusReactor := consensus.NewConsensusReactor(consensusState, blockStore, fastSync)
|
||||||
if privValidator != nil {
|
if privValidator != nil {
|
||||||
consensusReactor.SetPrivValidator(privValidator)
|
consensusReactor.SetPrivValidator(privValidator)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user