Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: artificially resetting the proposer priority #2

Merged
merged 17 commits into from
Aug 13, 2024
4 changes: 4 additions & 0 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,10 @@ func (cs *State) enterNewRound(height int64, round int32) {
validators.IncrementProposerPriority(cmtmath.SafeSubInt32(round, cs.Round))
}

if (round > 0 && round%types.PriorityResetRoundInterval == 0) ||
height%types.PriorityResetHeightInterval == 0 {
validators.ResetPriorities()
}
// Setup new round
// we don't fire newStep for this step,
// but we fire an event, so update the round step first
Expand Down
3 changes: 1 addition & 2 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"net"
"net/http"
_ "net/http/pprof" //nolint: gosec
"os"
"time"

Expand Down Expand Up @@ -38,8 +39,6 @@ import (
"github.com/cometbft/cometbft/types"
cmttime "github.com/cometbft/cometbft/types/time"
"github.com/cometbft/cometbft/version"

_ "net/http/pprof" //nolint: gosec
)

// Node is the highest level interface to a full CometBFT node.
Expand Down
5 changes: 5 additions & 0 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ func (blockExec *BlockExecutor) applyBlock(state State, blockID types.BlockID, b
blockExec.metrics.ConsensusParamUpdates.Add(1)
}

if (block.Height%types.PriorityResetHeightInterval == 0) ||
(block.LastCommit.Round >= types.PriorityResetRoundInterval) {
state.NextValidators.ResetPriorities()
}

// Update the state with the block and responses.
state, err = updateState(state, blockID, &block.Header, abciResponse, validatorUpdates)
if err != nil {
Expand Down
10 changes: 4 additions & 6 deletions state/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,13 +621,11 @@ func (store dbStore) saveValidatorsInfo(height, lastHeightChanged int64, valSet
}
// Only persist validator set if it was updated or checkpoint height (see
// valSetCheckpointInterval) is reached.
if height == lastHeightChanged || height%valSetCheckpointInterval == 0 {
pv, err := valSet.ToProto()
if err != nil {
return err
}
valInfo.ValidatorSet = pv
pv, err := valSet.ToProto()
if err != nil {
return err
}
valInfo.ValidatorSet = pv

bz, err := valInfo.Marshal()
if err != nil {
Expand Down
10 changes: 10 additions & 0 deletions types/priority_reset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package types

var (
// PriorityResetHeightInterval determines the interval at which the validator priority is reset.
// If set to 100, the priority is reset every 100 blocks (e.g., at heights 100, 200, 300, ...).
// When the chain reaches a height that is a multiple of this value, the validator priority is reset.
PriorityResetHeightInterval int64 = 100
// PriorityResetRoundInterval defines the interval at which the validator priority is reset.
PriorityResetRoundInterval int32 = 20
)
6 changes: 6 additions & 0 deletions types/validator_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,12 @@ func (vals *ValidatorSet) Iterate(fn func(index int, val *Validator) bool) {
}
}

func (vals *ValidatorSet) ResetPriorities() {
for _, val := range vals.Validators {
val.ProposerPriority = 0
}
}

// Checks changes against duplicates, splits the changes in updates and
// removals, sorts them by address.
//
Expand Down
Loading