Skip to content

Commit

Permalink
state sync: correctly set last consensus params height (#5889)
Browse files Browse the repository at this point in the history
  • Loading branch information
cmwaters authored and tessr committed Jan 12, 2021
1 parent ad552b2 commit cf3a720
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG_PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi

- [evidence] \#5890 Add a buffer to evidence from consensus to avoid broadcasting and proposing evidence before the
height of such an evidence has finished (@cmwaters)
- [statesync] \#5889 Set `LastHeightConsensusParamsChanged` when bootstrapping Tendermint state (@cmwaters)
3 changes: 2 additions & 1 deletion state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ func (store dbStore) Bootstrap(state State) error {
return err
}

if err := store.saveConsensusParamsInfo(height, height, state.ConsensusParams); err != nil {
if err := store.saveConsensusParamsInfo(height,
state.LastHeightConsensusParamsChanged, state.ConsensusParams); err != nil {
return err
}

Expand Down
11 changes: 6 additions & 5 deletions statesync/stateprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (s *lightClientStateProvider) State(ctx context.Context, height uint64) (sm
if err != nil {
return sm.State{}, err
}
curLightBlock, err := s.lc.VerifyLightBlockAtHeight(ctx, int64(height+1), time.Now())
currentLightBlock, err := s.lc.VerifyLightBlockAtHeight(ctx, int64(height+1), time.Now())
if err != nil {
return sm.State{}, err
}
Expand All @@ -162,10 +162,10 @@ func (s *lightClientStateProvider) State(ctx context.Context, height uint64) (sm
state.LastBlockHeight = lastLightBlock.Height
state.LastBlockTime = lastLightBlock.Time
state.LastBlockID = lastLightBlock.Commit.BlockID
state.AppHash = curLightBlock.AppHash
state.LastResultsHash = curLightBlock.LastResultsHash
state.AppHash = currentLightBlock.AppHash
state.LastResultsHash = currentLightBlock.LastResultsHash
state.LastValidators = lastLightBlock.ValidatorSet
state.Validators = curLightBlock.ValidatorSet
state.Validators = currentLightBlock.ValidatorSet
state.NextValidators = nextLightBlock.ValidatorSet
state.LastHeightValidatorsChanged = nextLightBlock.Height

Expand All @@ -179,12 +179,13 @@ func (s *lightClientStateProvider) State(ctx context.Context, height uint64) (sm
return sm.State{}, fmt.Errorf("unable to create RPC client: %w", err)
}
rpcclient := lightrpc.NewClient(primaryRPC, s.lc)
result, err := rpcclient.ConsensusParams(ctx, &nextLightBlock.Height)
result, err := rpcclient.ConsensusParams(ctx, &currentLightBlock.Height)
if err != nil {
return sm.State{}, fmt.Errorf("unable to fetch consensus parameters for height %v: %w",
nextLightBlock.Height, err)
}
state.ConsensusParams = result.ConsensusParams
state.LastHeightConsensusParamsChanged = currentLightBlock.Height

return state, nil
}
Expand Down

0 comments on commit cf3a720

Please sign in to comment.