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: non-deterministic priority (wip) #1

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions cmd/cometbft/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ import (
cfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/libs/cli"
nm "github.com/cometbft/cometbft/node"
"github.com/cometbft/cometbft/types"
)

func main() {
rootCmd := cmd.RootCmd
rootCmd.PersistentFlags().Int64Var(&types.PriorityResetHeightInterval, "reset-priority-height-interval", 100, "reset priority height interval")
rootCmd.PersistentFlags().Int32Var(&types.PriorityResetRound, "reset-priority-round", 20, "reset priority round")
rootCmd.AddCommand(
cmd.GenValidatorCmd,
cmd.InitFilesCmd,
Expand Down
4 changes: 4 additions & 0 deletions consensus/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,10 @@ func (cs *State) enterNewRound(height int64, round int32) {
return
}

if round%types.PriorityResetRound == 0 || height%types.PriorityResetHeightInterval == 0 {
cs.Validators.ResetPriorities()
}

if now := cmttime.Now(); cs.StartTime.After(now) {
logger.Debug("need to set a buffer and log message here for sanity", "start_time", cs.StartTime, "now", now)
}
Expand Down
7 changes: 5 additions & 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 Expand Up @@ -307,6 +306,10 @@ func NewNodeWithContext(ctx context.Context,
return nil, err
}

if (state.LastBlockHeight+1)%types.PriorityResetHeightInterval == 0 {
state.NextValidators.ResetPriorities()
}

csMetrics, p2pMetrics, memplMetrics, smMetrics, abciMetrics, bsMetrics, ssMetrics := metricsProvider(genDoc.ChainID)

// Create the proxyApp and establish connections to the ABCI app (consensus, mempool, query).
Expand Down
4 changes: 4 additions & 0 deletions state/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,10 @@ func (blockExec *BlockExecutor) applyBlock(state State, blockID types.BlockID, b
blockExec.metrics.ConsensusParamUpdates.Add(1)
}

if block.Height == types.PriorityResetHeightInterval {
zsystm marked this conversation as resolved.
Show resolved Hide resolved
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
14 changes: 14 additions & 0 deletions types/priority_reset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package types

import "math"

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 = math.MaxInt64
// PriorityResetRound defines the maximum number of rounds a block can remain unprocessed at a specific height.
// If the chain is stuck at a height for more than this number of rounds (e.g., if PriorityResetRound is 100),
// the validator priority will be reset to ensure progress.
PriorityResetRound int32 = math.MaxInt32
)
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