mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-13 13:21:20 +00:00
fixes from review
This commit is contained in:
@ -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 {
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
@ -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 {
|
||||
|
Reference in New Issue
Block a user