Browse Source

blockchain/v2: respect fast_sync option (#4772)

Not thoroughly tested, but seems to work. Will do further testing as this is integrated with state sync.

Fixes #4688.
pull/4774/head
Erik Grinaker 5 years ago
committed by GitHub
parent
commit
8108ac9d17
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 6 deletions
  1. +1
    -0
      CHANGELOG_PENDING.md
  2. +9
    -5
      blockchain/v2/reactor.go
  3. +1
    -1
      blockchain/v2/reactor_test.go

+ 1
- 0
CHANGELOG_PENDING.md View File

@ -45,4 +45,5 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi
### BUG FIXES: ### BUG FIXES:
- [blockchain/v2] [\#4761](https://github.com/tendermint/tendermint/pull/4761) Fix excessive CPU usage caused by spinning on closed channels (@erikgrinaker) - [blockchain/v2] [\#4761](https://github.com/tendermint/tendermint/pull/4761) Fix excessive CPU usage caused by spinning on closed channels (@erikgrinaker)
- [blockchain/v2] Respect `fast_sync` option (@erikgrinaker)
- [light] [\#4741](https://github.com/tendermint/tendermint/pull/4741) Correctly return `ErrSignedHeaderNotFound` and `ErrValidatorSetNotFound` on corresponding RPC errors (@erikgrinaker) - [light] [\#4741](https://github.com/tendermint/tendermint/pull/4741) Correctly return `ErrSignedHeaderNotFound` and `ErrValidatorSetNotFound` on corresponding RPC errors (@erikgrinaker)

+ 9
- 5
blockchain/v2/reactor.go View File

@ -129,6 +129,7 @@ type blockStore interface {
type BlockchainReactor struct { type BlockchainReactor struct {
p2p.BaseReactor p2p.BaseReactor
fastSync bool // if true, enable fast sync on start
events chan Event // XXX: Rename eventsFromPeers events chan Event // XXX: Rename eventsFromPeers
scheduler *Routine scheduler *Routine
processor *Routine processor *Routine
@ -156,7 +157,7 @@ type blockApplier interface {
// XXX: unify naming in this package around tmState // XXX: unify naming in this package around tmState
// XXX: V1 stores a copy of state as initialState, which is never mutated. Is that nessesary? // XXX: V1 stores a copy of state as initialState, which is never mutated. Is that nessesary?
func newReactor(state state.State, store blockStore, reporter behaviour.Reporter, func newReactor(state state.State, store blockStore, reporter behaviour.Reporter,
blockApplier blockApplier, bufferSize int) *BlockchainReactor {
blockApplier blockApplier, bufferSize int, fastSync bool) *BlockchainReactor {
scheduler := newScheduler(state.LastBlockHeight, time.Now()) scheduler := newScheduler(state.LastBlockHeight, time.Now())
pContext := newProcessorContext(store, blockApplier, state) pContext := newProcessorContext(store, blockApplier, state)
// TODO: Fix naming to just newProcesssor // TODO: Fix naming to just newProcesssor
@ -170,6 +171,7 @@ func newReactor(state state.State, store blockStore, reporter behaviour.Reporter
store: store, store: store,
reporter: reporter, reporter: reporter,
logger: log.NewNopLogger(), logger: log.NewNopLogger(),
fastSync: fastSync,
} }
} }
@ -180,7 +182,7 @@ func NewBlockchainReactor(
store blockStore, store blockStore,
fastSync bool) *BlockchainReactor { fastSync bool) *BlockchainReactor {
reporter := behaviour.NewMockReporter() reporter := behaviour.NewMockReporter()
return newReactor(state, store, reporter, blockApplier, 1000)
return newReactor(state, store, reporter, blockApplier, 1000, fastSync)
} }
// SetSwitch implements Reactor interface. // SetSwitch implements Reactor interface.
@ -224,9 +226,11 @@ func (r *BlockchainReactor) SetLogger(logger log.Logger) {
// Start implements cmn.Service interface // Start implements cmn.Service interface
func (r *BlockchainReactor) Start() error { func (r *BlockchainReactor) Start() error {
r.reporter = behaviour.NewSwitchReporter(r.BaseReactor.Switch) r.reporter = behaviour.NewSwitchReporter(r.BaseReactor.Switch)
go r.scheduler.start()
go r.processor.start()
go r.demux()
if r.fastSync {
go r.scheduler.start()
go r.processor.start()
go r.demux()
}
return nil return nil
} }


+ 1
- 1
blockchain/v2/reactor_test.go View File

@ -156,7 +156,7 @@ func newTestReactor(p testReactorParams) *BlockchainReactor {
sm.SaveState(db, state) sm.SaveState(db, state)
} }
r := newReactor(state, store, reporter, appl, p.bufferSize)
r := newReactor(state, store, reporter, appl, p.bufferSize, true)
logger := log.TestingLogger() logger := log.TestingLogger()
r.SetLogger(logger.With("module", "blockchain")) r.SetLogger(logger.With("module", "blockchain"))


Loading…
Cancel
Save