Skip to content

Commit

Permalink
Add quality duration multiplier (#805)
Browse files Browse the repository at this point in the history
* Add quality duration multiplier

Signed-off-by: Jakub Sztandera <[email protected]>

* Rename from QualityDurationMultiplier to QualityDeltaMultiplier

Signed-off-by: Jakub Sztandera <[email protected]>

---------

Signed-off-by: Jakub Sztandera <[email protected]>
  • Loading branch information
Kubuxu authored Dec 20, 2024
1 parent 67e2c06 commit 135bfe6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
11 changes: 9 additions & 2 deletions gpbft/gpbft.go
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ func (i *instance) beginQuality() error {
// Broadcast input value and wait to receive from others.
i.current.Phase = QUALITY_PHASE
i.participant.progression.NotifyProgress(i.current)
i.phaseTimeout = i.alarmAfterSynchrony()
i.phaseTimeout = i.alarmAfterSynchronyWithMulti(i.participant.qualityDeltaMulti)
i.resetRebroadcastParams()
i.broadcast(i.current.Round, QUALITY_PHASE, i.proposal, false, nil)
metrics.phaseCounter.Add(context.TODO(), 1, metric.WithAttributes(attrQualityPhase))
Expand Down Expand Up @@ -1006,7 +1006,14 @@ func (i *instance) rebroadcastQuietly(round uint64, phase Phase) {
// The delay duration increases with each round.
// Returns the absolute time at which the alarm will fire.
func (i *instance) alarmAfterSynchrony() time.Time {
delta := time.Duration(float64(i.participant.delta) *
return i.alarmAfterSynchronyWithMulti(1)
}

// Sets an alarm to be delivered after a synchrony delay including a multiplier on the duration.
// The delay duration increases with each round.
// Returns the absolute time at which the alarm will fire.
func (i *instance) alarmAfterSynchronyWithMulti(multi float64) time.Time {
delta := time.Duration(float64(i.participant.delta) * multi *
math.Pow(i.participant.deltaBackOffExponent, float64(i.current.Round)))
timeout := i.participant.host.Time().Add(2 * delta)
i.participant.host.SetAlarm(timeout)
Expand Down
13 changes: 13 additions & 0 deletions gpbft/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type options struct {
delta time.Duration
deltaBackOffExponent float64

qualityDeltaMulti float64

committeeLookback uint64
maxLookaheadRounds uint64
rebroadcastAfter func(int) time.Duration
Expand All @@ -38,6 +40,7 @@ func newOptions(o ...Option) (*options, error) {
opts := &options{
delta: defaultDelta,
deltaBackOffExponent: defaultDeltaBackOffExponent,
qualityDeltaMulti: 1.0,
committeeLookback: defaultCommitteeLookback,
rebroadcastAfter: defaultRebroadcastAfter,
maxCachedInstances: defaultMaxCachedInstances,
Expand Down Expand Up @@ -82,6 +85,16 @@ func WithDeltaBackOffExponent(e float64) Option {
}
}

func WithQualityDeltaMultiplier(m float64) Option {
return func(o *options) error {
if m < 0 {
return errors.New("quality duration multiplier cannot be less than zero")
}
o.qualityDeltaMulti = m
return nil
}
}

// WithTracer sets the Tracer for this gPBFT instance, which receives diagnostic
// logs about the state mutation. Defaults to no tracer if unspecified.
func WithTracer(t Tracer) Option {
Expand Down
13 changes: 10 additions & 3 deletions manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
DefaultGpbftConfig = GpbftConfig{
Delta: 6 * time.Second,
DeltaBackOffExponent: 2.0,
QualityDeltaMultiplier: 1.0,
MaxLookaheadRounds: 5,
ChainProposedLength: gpbft.ChainDefaultLen,
RebroadcastBackoffBase: 6 * time.Second,
Expand Down Expand Up @@ -98,9 +99,10 @@ func (c *CxConfig) Validate() error {
}

type GpbftConfig struct {
Delta time.Duration
DeltaBackOffExponent float64
MaxLookaheadRounds uint64
Delta time.Duration
DeltaBackOffExponent float64
QualityDeltaMultiplier float64
MaxLookaheadRounds uint64

ChainProposedLength int

Expand All @@ -118,6 +120,10 @@ func (g *GpbftConfig) Validate() error {
return fmt.Errorf("gpbft backoff exponent must be at least 1.0, was %f", g.DeltaBackOffExponent)
}

if g.QualityDeltaMultiplier < 0 {
return fmt.Errorf("gpbft quality duration multiplier is negative: %f", g.QualityDeltaMultiplier)
}

if g.ChainProposedLength < 1 {
return fmt.Errorf("gpbft proposed chain length cannot be less than 1")
}
Expand All @@ -142,6 +148,7 @@ func (g *GpbftConfig) ToOptions() []gpbft.Option {
return []gpbft.Option{
gpbft.WithDelta(g.Delta),
gpbft.WithDeltaBackOffExponent(g.DeltaBackOffExponent),
gpbft.WithQualityDeltaMultiplier(g.QualityDeltaMultiplier),
gpbft.WithMaxLookaheadRounds(g.MaxLookaheadRounds),
gpbft.WithRebroadcastBackoff(
DefaultGpbftConfig.RebroadcastBackoffExponent,
Expand Down
1 change: 1 addition & 0 deletions manifest/manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var base = manifest.Manifest{
Gpbft: manifest.GpbftConfig{
Delta: 10,
DeltaBackOffExponent: 1.2,
QualityDeltaMultiplier: 1.0,
MaxLookaheadRounds: 5,
ChainProposedLength: gpbft.ChainDefaultLen,
RebroadcastBackoffBase: 10,
Expand Down

0 comments on commit 135bfe6

Please sign in to comment.