Compare commits

...

5 Commits

Author SHA1 Message Date
William Banfield
b4ef3050aa compare state equivalence instead of using bool flag 2022-05-19 12:17:45 -04:00
William Banfield
02230b7683 Merge branch 'master' into wb/fix-state-no-initialized 2022-05-19 10:31:25 -04:00
William Banfield
0f53f94a34 Update internal/consensus/reactor.go
Co-authored-by: M. J. Fromberger <fromberger@interchain.io>
2022-05-19 09:54:15 -04:00
William Banfield
01ab2e653b remove unused bool 2022-05-18 20:57:23 -04:00
William Banfield
bff21bafbf update state from store before use in reactor 2022-05-18 20:48:56 -04:00
2 changed files with 13 additions and 7 deletions

View File

@@ -216,6 +216,8 @@ func (r *Reactor) OnStart(ctx context.Context) error {
if err := r.state.Start(ctx); err != nil {
return err
}
} else if err := r.state.updateStateFromStore(); err != nil {
return err
}
go r.updateRoundStateRoutine(ctx)

View File

@@ -122,9 +122,8 @@ type State struct {
// store blocks and commits
blockStore sm.BlockStore
stateStore sm.Store
initialStatePopulated bool
skipBootstrapping bool
stateStore sm.Store
skipBootstrapping bool
// create and execute blocks
blockExec *sm.BlockExecutor
@@ -248,9 +247,6 @@ func NewState(
}
func (cs *State) updateStateFromStore() error {
if cs.initialStatePopulated {
return nil
}
state, err := cs.stateStore.Load()
if err != nil {
return fmt.Errorf("loading state: %w", err)
@@ -259,6 +255,15 @@ func (cs *State) updateStateFromStore() error {
return nil
}
eq, err := state.Equals(cs.state)
if err != nil {
return fmt.Errorf("comparing state: %w", err)
}
// if the new state is equivalent to the old state, we should not trigger a state update.
if eq {
return nil
}
// We have no votes, so reconstruct LastCommit from SeenCommit.
if state.LastBlockHeight > 0 {
cs.reconstructLastCommit(state)
@@ -266,7 +271,6 @@ func (cs *State) updateStateFromStore() error {
cs.updateToState(state)
cs.initialStatePopulated = true
return nil
}