diff --git a/consensus/common_test.go b/consensus/common_test.go index 7f55fc29f..3e05d2564 100644 --- a/consensus/common_test.go +++ b/consensus/common_test.go @@ -317,7 +317,8 @@ func fixedConsensusState() *ConsensusState { privValidatorFile := config.GetString("priv_validator_file") privValidator := types.LoadOrGenPrivValidator(privValidatorFile) privValidator.Reset() - return newConsensusState(state, privValidator, counter.NewCounterApplication(true)) + cs := newConsensusState(state, privValidator, counter.NewCounterApplication(true)) + return cs } func newConsensusState(state *sm.State, pv *types.PrivValidator, app tmsp.Application) *ConsensusState { diff --git a/consensus/replay.go b/consensus/replay.go index c729fca27..19c117eac 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -78,12 +78,7 @@ func (cs *ConsensusState) readReplayMessage(msgBytes []byte, newStepCh chan inte // replay only those messages since the last block. // timeoutRoutine should run concurrently to read off tickChan func (cs *ConsensusState) catchupReplay(height int) error { - if cs.wal == nil { - log.Warn("consensus msg log is nil") - return nil - } - if !cs.wal.exists { - // new wal, nothing to catchup on + if !cs.wal.Exists() { return nil } @@ -254,8 +249,9 @@ func (pb *playback) replayReset(count int, newStepCh chan interface{}) error { } func (cs *ConsensusState) startForReplay() { + // don't want to start full cs cs.BaseService.OnStart() - go cs.receiveRoutine(0) + // since we replay tocks we just ignore ticks go func() { for { diff --git a/consensus/replay_test.go b/consensus/replay_test.go index 56d8e684b..a9376d0e4 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -99,16 +99,11 @@ func waitForBlock(newBlockCh chan interface{}) { } func runReplayTest(t *testing.T, cs *ConsensusState, fileName string, newBlockCh chan interface{}) { - // open wal and run catchup messages - openWAL(t, cs, fileName) - go cs.timeoutRoutine() - if err := cs.catchupReplay(cs.Height); err != nil { - panic(Fmt("Error on catchup replay %v", err)) - } - go cs.receiveRoutine(0) + cs.config.Set("cswal", fileName) + cs.Start() // wait to make a new block waitForBlock(newBlockCh) - cs.QuitService.OnStop() + cs.Stop() } func setupReplayTest(nLines int, crashAfter bool) (*ConsensusState, chan interface{}, string, string) { @@ -127,10 +122,8 @@ func setupReplayTest(nLines int, crashAfter bool) (*ConsensusState, chan interfa fileName := writeWAL(strings.Join(split[:nLines], "\n") + "\n") cs := fixedConsensusState() - cs.QuitService.OnStart() - // we've already precommitted on the first block - // without replay catchup we would be halted here forever + // set the last step according to when we crashed vs the wal cs.privValidator.LastHeight = 1 // first block cs.privValidator.LastStep = mapPrivValStep[lineStep] @@ -141,16 +134,6 @@ func setupReplayTest(nLines int, crashAfter bool) (*ConsensusState, chan interfa return cs, newBlockCh, lastMsg, fileName } -func openWAL(t *testing.T, cs *ConsensusState, file string) { - // open the wal - wal, err := NewWAL(file, config.GetBool("cswal_light")) - if err != nil { - panic(err) - } - wal.exists = true - cs.wal = wal -} - //----------------------------------------------- // Test the log at every iteration, and set the privVal last step // as if the log was written after signing, before the crash diff --git a/consensus/wal.go b/consensus/wal.go index 5b4747a6f..fb5b80568 100644 --- a/consensus/wal.go +++ b/consensus/wal.go @@ -60,6 +60,14 @@ func NewWAL(file string, light bool) (*WAL, error) { }, nil } +func (wal *WAL) Exists() bool { + if wal == nil { + log.Warn("consensus msg log is nil") + return false + } + return wal.exists +} + // called in newStep and for each pass in receiveRoutine func (wal *WAL) Save(clm ConsensusLogMessageInterface) { if wal != nil {