ceremonyclient/consensus/pacemaker/timeout/config.go
Cassandra Heart c797d482f9
v2.1.0.5 (#457)
* wip: conversion of hotstuff from flow into Q-oriented model

* bulk of tests

* remaining non-integration tests

* add integration test, adjust log interface, small tweaks

* further adjustments, restore full pacemaker shape

* add component lifecycle management+supervisor

* further refinements

* resolve timeout hanging

* mostly finalized state for consensus

* bulk of engine swap out

* lifecycle-ify most types

* wiring nearly complete, missing needed hooks for proposals

* plugged in, vetting message validation paths

* global consensus, plugged in and verified

* app shard now wired in too

* do not decode empty keys.yml (#456)

* remove obsolete engine.maxFrames config parameter (#454)

* default to Info log level unless debug is enabled (#453)

* respect config's  "logging" section params, remove obsolete single-file logging (#452)

* Trivial code cleanup aiming to reduce Go compiler warnings (#451)

* simplify range traversal

* simplify channel read for single select case

* delete rand.Seed() deprecated in Go 1.20 and no-op as of Go 1.24

* simplify range traversal

* simplify channel read for single select case

* remove redundant type from array

* simplify range traversal

* simplify channel read for single select case

* RC slate

* finalize 2.1.0.5

* Update comments in StrictMonotonicCounter

Fix comment formatting and clarify description.

---------

Co-authored-by: Black Swan <3999712+blacks1ne@users.noreply.github.com>
2025-11-11 05:00:17 -06:00

125 lines
4.8 KiB
Go

package timeout
import (
"time"
"source.quilibrium.com/quilibrium/monorepo/consensus/models"
)
// Config contains the configuration parameters for a Truncated Exponential
// Backoff, as implemented by the `timeout.Controller`
// - On timeout: increase timeout by multiplicative factor
// `TimeoutAdjustmentFactor`. This results in exponentially growing timeout
// duration on multiple subsequent timeouts.
// - On progress: decrease timeout by multiplicative factor
// `TimeoutAdjustmentFactor.
//
// Config is implemented such that it can be passed by value, while still
// supporting updates of `StateRateDelayMS` at runtime (all configs share the
// same memory holding `StateRateDelayMS`).
type Config struct {
// MinReplicaTimeout is the minimum the timeout can decrease to [MILLISECONDS]
MinReplicaTimeout float64
// MaxReplicaTimeout is the maximum value the timeout can increase to
// [MILLISECONDS]
MaxReplicaTimeout float64
// TimeoutAdjustmentFactor: MULTIPLICATIVE factor for increasing timeout when
// rank change was triggered by a TC (unhappy path) or decreasing the timeout
// on progress
TimeoutAdjustmentFactor float64
// HappyPathMaxRoundFailures is the number of rounds without progress where we
// still consider being on hot path of execution. After exceeding this value
// we will start increasing timeout values.
HappyPathMaxRoundFailures uint64
// MaxTimeoutStateRebroadcastInterval is the maximum value for timeout state
// rebroadcast interval [MILLISECONDS]
MaxTimeoutStateRebroadcastInterval float64
}
var DefaultConfig = NewDefaultConfig()
// NewDefaultConfig returns a default timeout configuration.
// We explicitly provide a method here, which demonstrates in-code how
// to compute standard values from some basic quantities.
func NewDefaultConfig() Config {
// minReplicaTimeout is the lower bound on the replica's timeout value, this
// is also the initial timeout with what replicas will start their execution.
// If HotStuff is running at full speed, 1200ms should be enough. However, we
// add some buffer. This value is for instant message delivery.
minReplicaTimeout := 3 * time.Second
maxReplicaTimeout := 1 * time.Minute
timeoutAdjustmentFactorFactor := 1.2
// after 6 successively failed rounds, the pacemaker leaves the hot path and
// starts increasing timeouts (recovery mode)
happyPathMaxRoundFailures := uint64(6)
maxRebroadcastInterval := 5 * time.Second
conf, err := NewConfig(
minReplicaTimeout,
maxReplicaTimeout,
timeoutAdjustmentFactorFactor,
happyPathMaxRoundFailures,
maxRebroadcastInterval,
)
if err != nil {
// we check in a unit test that this does not happen
panic("Default config is not compliant with timeout Config requirements")
}
return conf
}
// NewConfig creates a new TimoutConfig.
// - minReplicaTimeout: minimal timeout value for replica round [Milliseconds]
// Consistency requirement: must be non-negative
// - maxReplicaTimeout: maximal timeout value for replica round [Milliseconds]
// Consistency requirement: must be non-negative and cannot be smaller than
// minReplicaTimeout
// - timeoutAdjustmentFactor: multiplicative factor for adjusting timeout
// duration
// Consistency requirement: must be strictly larger than 1
// - happyPathMaxRoundFailures: number of successive failed rounds after which
// we will start increasing timeouts
// - stateRateDelay: a delay to delay the proposal broadcasting [Milliseconds]
// Consistency requirement: must be non-negative
//
// Returns `models.ConfigurationError` is any of the consistency requirements is
// violated.
func NewConfig(
minReplicaTimeout time.Duration,
maxReplicaTimeout time.Duration,
timeoutAdjustmentFactor float64,
happyPathMaxRoundFailures uint64,
maxRebroadcastInterval time.Duration,
) (Config, error) {
if minReplicaTimeout <= 0 {
return Config{}, models.NewConfigurationErrorf(
"minReplicaTimeout must be a positive number[milliseconds]",
)
}
if maxReplicaTimeout < minReplicaTimeout {
return Config{}, models.NewConfigurationErrorf(
"maxReplicaTimeout cannot be smaller than minReplicaTimeout",
)
}
if timeoutAdjustmentFactor <= 1 {
return Config{}, models.NewConfigurationErrorf(
"timeoutAdjustmentFactor must be strictly bigger than 1",
)
}
if maxRebroadcastInterval <= 0 {
return Config{}, models.NewConfigurationErrorf(
"maxRebroadcastInterval must be a positive number [milliseconds]",
)
}
tc := Config{
MinReplicaTimeout: float64(minReplicaTimeout.Milliseconds()),
MaxReplicaTimeout: float64(maxReplicaTimeout.Milliseconds()),
TimeoutAdjustmentFactor: timeoutAdjustmentFactor,
HappyPathMaxRoundFailures: happyPathMaxRoundFailures,
MaxTimeoutStateRebroadcastInterval: float64(maxRebroadcastInterval.Milliseconds()),
}
return tc, nil
}