Skip to content

Commit

Permalink
chore: rename UpdateScores to UpdateHeightRound
Browse files Browse the repository at this point in the history
  • Loading branch information
lklimek committed Sep 18, 2024
1 parent ce65781 commit 6cff6fe
Show file tree
Hide file tree
Showing 11 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion internal/consensus/state_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ func (s *StateData) updateRoundStep(round int32, step cstypes.RoundStepType) {
s.Round = round
s.Step = step

if err := s.ProposerSelector.UpdateScores(s.Height, round); err != nil {
if err := s.ProposerSelector.UpdateHeightRound(s.Height, round); err != nil {
s.logger.Error("error updating proposer scores",
"height", s.Height, "round", round,
"err", err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ func (s *heightProposerSelector) proposerFromStore(height int64) error {
return nil
}

// UpdateScores updates the scores of the validators to the given height.
// UpdateHeightRound updates the scores of the validators to the given height.
// Here, we ignore the round, as we don't want to persist round info.
func (s *heightProposerSelector) UpdateScores(newHeight int64, round int32) error {
func (s *heightProposerSelector) UpdateHeightRound(newHeight int64, round int32) error {
s.mtx.Lock()
defer s.mtx.Unlock()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func TestProposerSelection3(t *testing.T) {
}

round := uint32(rand.Int31n(100))
require.NoError(t, vs.UpdateScores(int64(h), int32(round)))
require.NoError(t, vs.UpdateHeightRound(int64(h), int32(round)))
j++ // height proposer strategy only increment by 1 each height, regardless of the rounds
}
}
Expand Down Expand Up @@ -157,7 +157,7 @@ func TestHeightScoreH(t *testing.T) {
proposer := vs.MustGetProposer(h, 0)
pos := (h - genesisHeight) % int64(len(proTxHashes))
assert.Equal(t, proTxHashes[pos], proposer.ProTxHash, "height %d", h)
require.NoError(t, vs.UpdateScores(h, 0), "height %d", h)
require.NoError(t, vs.UpdateHeightRound(h, 0), "height %d", h)
}
}

Expand All @@ -173,7 +173,7 @@ func TestHeightScoreHR(t *testing.T) {
proposer := vs.MustGetProposer(h, r)
pos := (h - genesisHeight + int64(r)) % int64(len(proTxHashes))
require.Equal(t, proTxHashes[pos], proposer.ProTxHash, "height %d, round %d", h, r)
require.NoError(t, vs.UpdateScores(h, r), "height %d, round %d", h, r)
require.NoError(t, vs.UpdateHeightRound(h, r), "height %d, round %d", h, r)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ func (s *heightRoundProposerSelector) SetLogger(logger log.Logger) {
s.logger = logger
}

// UpdateScores updates the scores of the validators to the given height and round.
func (s *heightRoundProposerSelector) UpdateScores(newHeight int64, newRound int32) error {
// UpdateHeightRound updates the scores of the validators to the given height and round.
func (s *heightRoundProposerSelector) UpdateHeightRound(newHeight int64, newRound int32) error {
s.mtx.Lock()
defer s.mtx.Unlock()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func TestProposerSelectionHR(t *testing.T) {
}

round := uint32(rand.Int31n(100))
require.NoError(t, vs.UpdateScores(int64(h), int32(round)))
require.NoError(t, vs.UpdateHeightRound(int64(h), int32(round)))

// t.Logf("Height: %d, Round: %d, proposer index %d", h, round, proposerIndex)
// we expect proposer increase for each round, plus one for next height
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ type ProposerSelector interface {
// Use in tests
// See [GetProposer](#GetProposer) for details.
MustGetProposer(height int64, round int32) *types.Validator
// Update updates scores for the given height and round. It should be called at least once for each round.
// UpdateHeightRound updates proposer to match provided height and round. It should be called at least once for each round.
// - `height` is the height
// - `round` is the round
UpdateScores(height int64, round int32) error
UpdateHeightRound(height int64, round int32) error
// Returns pointer to underlying validator set; not thread-safe, and should be modified with caution
ValidatorSet() *types.ValidatorSet
// Create deep copy of the strategy and its underlying validator set
Expand Down
2 changes: 1 addition & 1 deletion internal/state/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ func makeRandomStateFromValidatorSet(
panic(err)
}
for h := lastHeightValidatorsChanged; h <= height; h++ {
if err := expectedVS.UpdateScores(h, 0); err != nil {
if err := expectedVS.UpdateHeightRound(h, 0); err != nil {
panic(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion internal/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ func valsetScoresNewHeight(t *testing.T, state *sm.State) *types.Validator {
log.NewTestingLogger(t))

require.NoError(t, err)
err = ps.UpdateScores(state.LastBlockHeight+1, 0)
err = ps.UpdateHeightRound(state.LastBlockHeight+1, 0)
require.NoError(t, err)

return ps.MustGetProposer(state.LastBlockHeight+1, 0)
Expand Down
4 changes: 2 additions & 2 deletions internal/state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -556,7 +556,7 @@ func (store dbStore) LoadValidators(height int64, bs selectproposer.BlockStore)
if err != nil {
return nil, fmt.Errorf("failed to create validator scoring strategy: %w", err)
}
if err := strategy.UpdateScores(meta.Header.Height, 0); err != nil {
if err := strategy.UpdateHeightRound(meta.Header.Height, 0); err != nil {
return nil, fmt.Errorf("failed to update validator scores at height %d, round 0: %w", meta.Header.Height, err)
}
return strategy.ValidatorSet(), nil
Expand All @@ -578,7 +578,7 @@ func (store dbStore) LoadValidators(height int64, bs selectproposer.BlockStore)
}

// now, advance to (height,0)
if err := strategy.UpdateScores(height, 0); err != nil {
if err := strategy.UpdateHeightRound(height, 0); err != nil {
return nil, fmt.Errorf("failed to update validator scores at height %d, round 0: %w", height, err)
}

Expand Down
6 changes: 3 additions & 3 deletions internal/state/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func TestStoreLoadValidators(t *testing.T) {
_, err = stateStore.LoadValidators(3, blockStore)
assert.Error(t, err, "no validator expected at this height")

err = expectedVS.UpdateScores(2, 0)
err = expectedVS.UpdateHeightRound(2, 0)
require.NoError(t, err)
assertProposer(t, expectedVS.ValidatorSet(), 2)

Expand Down Expand Up @@ -149,13 +149,13 @@ func TestStoreLoadValidators(t *testing.T) {
// ensure we have correct validator set loaded; at height h, we expcect `(h+1) % 3`
// (adding 1 as we start from initial height 1).
for h := int64(2); h <= valSetCheckpointInterval-1; h++ {
require.NoError(t, expectedVS.UpdateScores(h, 0))
require.NoError(t, expectedVS.UpdateHeightRound(h, 0))
}
expected := expectedVS.ValidatorSet()
assertProposer(t, expected, valSetCheckpointInterval-1)
require.NotEqual(t, expected, valsAtCheckpoint)

require.NoError(t, expectedVS.UpdateScores(valSetCheckpointInterval, 0))
require.NoError(t, expectedVS.UpdateHeightRound(valSetCheckpointInterval, 0))
expected = expectedVS.ValidatorSet()
assertProposer(t, expected, valSetCheckpointInterval)
require.Equal(t, expected, valsAtCheckpoint)
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/tests/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (s *validatorSchedule) Increment(heights int64) error {
}
}
}
if err := s.Set.UpdateScores(s.height, 0); err != nil {
if err := s.Set.UpdateHeightRound(s.height, 0); err != nil {
return err
}
}
Expand Down

0 comments on commit 6cff6fe

Please sign in to comment.