fixes from review

This commit is contained in:
Ethan Buchman
2016-08-17 23:08:43 -04:00
parent 1110c5d37d
commit 3998bdbfc1
4 changed files with 17 additions and 29 deletions

View File

@ -317,7 +317,8 @@ func fixedConsensusState() *ConsensusState {
privValidatorFile := config.GetString("priv_validator_file") privValidatorFile := config.GetString("priv_validator_file")
privValidator := types.LoadOrGenPrivValidator(privValidatorFile) privValidator := types.LoadOrGenPrivValidator(privValidatorFile)
privValidator.Reset() 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 { func newConsensusState(state *sm.State, pv *types.PrivValidator, app tmsp.Application) *ConsensusState {

View File

@ -78,12 +78,7 @@ func (cs *ConsensusState) readReplayMessage(msgBytes []byte, newStepCh chan inte
// replay only those messages since the last block. // replay only those messages since the last block.
// timeoutRoutine should run concurrently to read off tickChan // timeoutRoutine should run concurrently to read off tickChan
func (cs *ConsensusState) catchupReplay(height int) error { func (cs *ConsensusState) catchupReplay(height int) error {
if cs.wal == nil { if !cs.wal.Exists() {
log.Warn("consensus msg log is nil")
return nil
}
if !cs.wal.exists {
// new wal, nothing to catchup on
return nil return nil
} }
@ -254,8 +249,9 @@ func (pb *playback) replayReset(count int, newStepCh chan interface{}) error {
} }
func (cs *ConsensusState) startForReplay() { func (cs *ConsensusState) startForReplay() {
// don't want to start full cs
cs.BaseService.OnStart() cs.BaseService.OnStart()
go cs.receiveRoutine(0)
// since we replay tocks we just ignore ticks // since we replay tocks we just ignore ticks
go func() { go func() {
for { for {

View File

@ -99,16 +99,11 @@ func waitForBlock(newBlockCh chan interface{}) {
} }
func runReplayTest(t *testing.T, cs *ConsensusState, fileName string, newBlockCh chan interface{}) { func runReplayTest(t *testing.T, cs *ConsensusState, fileName string, newBlockCh chan interface{}) {
// open wal and run catchup messages cs.config.Set("cswal", fileName)
openWAL(t, cs, fileName) cs.Start()
go cs.timeoutRoutine()
if err := cs.catchupReplay(cs.Height); err != nil {
panic(Fmt("Error on catchup replay %v", err))
}
go cs.receiveRoutine(0)
// wait to make a new block // wait to make a new block
waitForBlock(newBlockCh) waitForBlock(newBlockCh)
cs.QuitService.OnStop() cs.Stop()
} }
func setupReplayTest(nLines int, crashAfter bool) (*ConsensusState, chan interface{}, string, string) { 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") fileName := writeWAL(strings.Join(split[:nLines], "\n") + "\n")
cs := fixedConsensusState() cs := fixedConsensusState()
cs.QuitService.OnStart()
// we've already precommitted on the first block // set the last step according to when we crashed vs the wal
// without replay catchup we would be halted here forever
cs.privValidator.LastHeight = 1 // first block cs.privValidator.LastHeight = 1 // first block
cs.privValidator.LastStep = mapPrivValStep[lineStep] cs.privValidator.LastStep = mapPrivValStep[lineStep]
@ -141,16 +134,6 @@ func setupReplayTest(nLines int, crashAfter bool) (*ConsensusState, chan interfa
return cs, newBlockCh, lastMsg, fileName 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 // Test the log at every iteration, and set the privVal last step
// as if the log was written after signing, before the crash // as if the log was written after signing, before the crash

View File

@ -60,6 +60,14 @@ func NewWAL(file string, light bool) (*WAL, error) {
}, nil }, 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 // called in newStep and for each pass in receiveRoutine
func (wal *WAL) Save(clm ConsensusLogMessageInterface) { func (wal *WAL) Save(clm ConsensusLogMessageInterface) {
if wal != nil { if wal != nil {