Skip to content

Deterministic Round Timeout - #1120

Merged
liorrutenberg merged 15 commits into
stagefrom
deterministic-round-timeout
Sep 7, 2023
Merged

Deterministic Round Timeout#1120
liorrutenberg merged 15 commits into
stagefrom
deterministic-round-timeout

Conversation

@olegshmuelov

@olegshmuelov olegshmuelov commented Aug 27, 2023

Copy link
Copy Markdown
Contributor

This PR brings significant updates to the roundtimer package, focusing on improving the round timeout logic and introducing new features for better synchronization and configurability.

Key Changes:

  1. Refactored RoundTimeout Function:

    • The timeout logic is now deterministic and role-specific. It calculates the timeout based on the role of the instance (Attester, Aggregator, Proposer, etc.), current round and the duty height(slot) time.
      To ensure synchronized timeouts across instances, the timeout is now calculated based on the duty start time, which is derived from the slot height
    • For roles like Attester and Sync Committee, the timeout is a fraction of the slot duration.
    • For the Proposer role, quick or slow timeouts are applied based on the round number (non-deterministic).
  2. Configurable Timeout Options:

    • The TimeoutOptions struct has been introduced to make the quick and slow timeout thresholds and durations configurable.
    • The BeaconNetwork interface has been added to abstract the logic for getting slot start times and slot durations. This makes the package more modular and easier to test.

TODOs Addressed:

  1. Update SIP for Deterministic Round Timeout:

    • The logic has been updated to synchronize timeouts across all instances based on the duty start time.
  2. Decide if to Make the Proposer Timeout Deterministic:

    • This is still under consideration and may be addressed in future updates.

SIP Reference:

For more details, see the related SIP at SIP-22.

@olegshmuelov olegshmuelov changed the title implementation Deterministic Round Timeout Aug 27, 2023
@olegshmuelov
olegshmuelov marked this pull request as ready for review August 28, 2023 15:16
@y0sher

y0sher commented Aug 28, 2023

Copy link
Copy Markdown
Contributor

This PR looks good. The only thing I'm missing is a tests that test this functionality.

@olegshmuelov olegshmuelov self-assigned this Aug 29, 2023
Comment thread protocol/v2/qbft/roundtimer/timer.go Outdated
)

type RoundTimeoutFunc func(specqbft.Round) time.Duration
type TimeAtSlotFunc func(slot phase0.Slot) int64

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its a bit confusing that we're using slot and height here. lets stick to either height or slot.

y0sher
y0sher previously approved these changes Aug 29, 2023

@y0sher y0sher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! I have one comment on naming. this is diverted from spec as we discussed. lets get review from @moshe-blox and @lior-blox and then add it to the spec alignment script as an exception.

Comment thread operator/validator/controller.go Outdated
Storage: options.Storage.Get(role),
Network: options.Network,
Timer: roundtimer.New(ctx, nil),
Timer: roundtimer.New(ctx, role, options.BeaconNetwork.EstimatedTimeAtSlot, nil),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Timer: roundtimer.New(ctx, role, options.BeaconNetwork.EstimatedTimeAtSlot, nil),
Timer: roundtimer.New(ctx, role, func(height specbft.Height) { return options.BeaconNetwork.EstimatedTimeAtSlot(phase.Slot(height)), nil),

y0sher
y0sher previously approved these changes Aug 30, 2023

@y0sher y0sher left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, again lets make sure we're ok with the spec divergence @moshe-blox @lior-blox

Comment thread protocol/v2/qbft/roundtimer/timer.go Outdated
func RoundTimeout(timeAtSlotF TimeAtSlotFunc, role spectypes.BeaconRole, height specqbft.Height, round specqbft.Round) time.Duration {
if round == specqbft.FirstRound && (role == spectypes.BNRoleAttester || role == spectypes.BNRoleSyncCommittee) {
dutyStartTime := time.Unix(timeAtSlotF(phase0.Slot(height)), 0)
return time.Until(dutyStartTime.Add(firstRoundTimeout))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if we started the duty very late into the slot (for example second 7) and this is in the past? we would need to start consensus at round 2, no? do we need a test for it?

i.metrics.StartStage()

i.config.GetTimer().TimeoutForRound(specqbft.FirstRound)
i.config.GetTimer().TimeoutForRound(height, specqbft.FirstRound)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think might have to to start not always at FirstRound but at a func that returns current round according to current time, otherwise if you start duty at second 7 you will start at wrong round

however, would that be a spec change? @lior-blox @GalRogozinski

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@GalRogozinski

GalRogozinski commented Sep 4, 2023

Copy link
Copy Markdown
Contributor

@lior-blox @alonmuroch @y0sher

Besides the SIP maybe this should also go inside the spec code imo
To my understanding it is testable

@liorrutenberg
liorrutenberg merged commit 013b88b into stage Sep 7, 2023
@liorrutenberg
liorrutenberg deleted the deterministic-round-timeout branch September 7, 2023 11:16
@GalRogozinski

Copy link
Copy Markdown
Contributor

First TODO is here
ssvlabs/SIPs#37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants