Browse Source

fixes from review

pull/249/head
Ethan Buchman 8 years ago
parent
commit
3998bdbfc1
4 changed files with 17 additions and 29 deletions
  1. +2
    -1
      consensus/common_test.go
  2. +3
    -7
      consensus/replay.go
  3. +4
    -21
      consensus/replay_test.go
  4. +8
    -0
      consensus/wal.go

+ 2
- 1
consensus/common_test.go View File

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


+ 3
- 7
consensus/replay.go View File

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


+ 4
- 21
consensus/replay_test.go View File

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


+ 8
- 0
consensus/wal.go View File

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


Loading…
Cancel
Save