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

Deterministic Round Timeout #1120

Merged
merged 15 commits into from
Sep 7, 2023
Merged

Conversation

olegshmuelov
Copy link
Contributor

@olegshmuelov olegshmuelov commented Aug 27, 2023

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
Copy link
Contributor

y0sher commented Aug 28, 2023

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
)

type RoundTimeoutFunc func(specqbft.Round) time.Duration
type TimeAtSlotFunc func(slot phase0.Slot) int64
Copy link
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
Copy link
Contributor

@y0sher y0sher left a comment

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.

@@ -809,7 +809,7 @@ func SetupRunners(ctx context.Context, logger *zap.Logger, options validator.Opt
},
Storage: options.Storage.Get(role),
Network: options.Network,
Timer: roundtimer.New(ctx, nil),
Timer: roundtimer.New(ctx, role, options.BeaconNetwork.EstimatedTimeAtSlot, nil),
Copy link
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
Copy link
Contributor

@y0sher y0sher left a comment

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

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
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?

@@ -66,7 +66,7 @@ func (i *Instance) Start(logger *zap.Logger, value []byte, height specqbft.Heigh
i.State.Height = height
i.metrics.StartStage()

i.config.GetTimer().TimeoutForRound(specqbft.FirstRound)
i.config.GetTimer().TimeoutForRound(height, specqbft.FirstRound)
Copy link
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
Contributor

Choose a reason for hiding this comment

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

@GalRogozinski
Copy link
Contributor

GalRogozinski commented Sep 4, 2023

@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
5 checks passed
@liorrutenberg liorrutenberg deleted the deterministic-round-timeout branch September 7, 2023 11:16
@GalRogozinski
Copy link
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