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

op-node: Stall block creation when block finalization lags behind #216

Closed
wants to merge 4 commits into from

Conversation

palango
Copy link

@palango palango commented Aug 20, 2024

Builds on #209

  • Use finalized block for derivation pipeline as well
  • Use finalized block when loading runtime config
  • Stall block creation when block finalization lags behind

@palango palango changed the title Palango/stall when no finality op-node: Stall block creation when block finalization lags behind Aug 20, 2024
Comment on lines +224 to +245
var safeBlock eth.L1BlockRef
if cfg.Driver.SequencerUseFinalized {
fetchCtx, fetchCancel = context.WithTimeout(ctx, time.Second*10)
safeBlock, err = n.l1Source.L1BlockRefByLabel(fetchCtx, eth.Finalized)
fetchCancel()
if err != nil {
n.log.Error("failed to fetch finalized L1 block for runtime config loading", "err", err)
return eth.L1BlockRef{}, err
}
} else {
// Apply confirmation-distance
blNum := l1Head.Number
if blNum >= confDepth {
blNum -= confDepth
}
fetchCtx, fetchCancel = context.WithTimeout(ctx, time.Second*10)
safeBlock, err = n.l1Source.L1BlockRefByNumber(fetchCtx, blNum)
fetchCancel()
if err != nil {
n.log.Error("failed to fetch confirmed L1 block for runtime config loading", "err", err, "number", blNum)
return eth.L1BlockRef{}, err
}

Choose a reason for hiding this comment

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

Don't really know if it's going to make things clearer or even if it going to make the merges harder, but the cancel logic could be common for both

Suggested change
var safeBlock eth.L1BlockRef
if cfg.Driver.SequencerUseFinalized {
fetchCtx, fetchCancel = context.WithTimeout(ctx, time.Second*10)
safeBlock, err = n.l1Source.L1BlockRefByLabel(fetchCtx, eth.Finalized)
fetchCancel()
if err != nil {
n.log.Error("failed to fetch finalized L1 block for runtime config loading", "err", err)
return eth.L1BlockRef{}, err
}
} else {
// Apply confirmation-distance
blNum := l1Head.Number
if blNum >= confDepth {
blNum -= confDepth
}
fetchCtx, fetchCancel = context.WithTimeout(ctx, time.Second*10)
safeBlock, err = n.l1Source.L1BlockRefByNumber(fetchCtx, blNum)
fetchCancel()
if err != nil {
n.log.Error("failed to fetch confirmed L1 block for runtime config loading", "err", err, "number", blNum)
return eth.L1BlockRef{}, err
}
var safeBlock eth.L1BlockRef
fetchCtx, fetchCancel = context.WithTimeout(ctx, time.Second*10)
if cfg.Driver.SequencerUseFinalized {
safeBlock, err = n.l1Source.L1BlockRefByLabel(fetchCtx, eth.Finalized)
} else {
// Apply confirmation-distance
blNum := l1Head.Number
if blNum >= confDepth {
blNum -= confDepth
}
safeBlock, err = n.l1Source.L1BlockRefByNumber(fetchCtx, blNum)
}
fetchCancel()
if err != nil {
if cfg.Driver.SequencerUseFinalized {
n.log.Error("failed to fetch finalized L1 block for runtime config loading", "err", err)
} else {
n.log.Error("failed to fetch confirmed L1 block for runtime config loading", "err", err, "number", blNum)
}
return eth.L1BlockRef{}, err
}

Also if we change the log to something understandable by both like would be cleaner. But it's only a nit, and we are not gaining too much either, so it's up to you

// If this is set to true, the value of `SequencerConfDepth` is ignored.
SequencerUseFinalized bool `json:"sequencer_use_finalized"`

SequencerMaxFinalizedLag uint64 `json:"sequencer_max_finalized_lag"`

Choose a reason for hiding this comment

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

Maybe just a little comment on this. That is probably measured in blocks from the L2

op-node/rollup/driver/driver.go Show resolved Hide resolved
op-node/rollup/driver/finalized.go Show resolved Hide resolved
if cfg.Driver.SequencerUseFinalized {
fetchCtx, fetchCancel = context.WithTimeout(ctx, time.Second*10)
safeBlock, err = n.l1Source.L1BlockRefByLabel(fetchCtx, eth.Finalized)
fetchCancel()

Choose a reason for hiding this comment

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

is this correct? why are you directly calling the kill function? i think the pattern is something like: defer killCtx() or similar

Choose a reason for hiding this comment

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

ok, i see it's a copy-paste from above.. but still weird :P

"unsafe_l2", s.Engine.UnsafeL2Head(),
"safe_l2", s.Engine.SafeL2Head(),
)
sequencerCh = nil

Choose a reason for hiding this comment

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

not familiar enough to know that this transales to "pause the sequencer"...

things that pop into my head... is this for loop going to be called inmediately after or is it going to be called a after x seconds pass? I mean, was "do nothing/ skip" already an option in this for loop, and so we're just adding another trigger for that action, or is this the first trigger that wants to 'do nothing'?

Choose a reason for hiding this comment

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

I think it's the same exact scenario that they are handling below this one, to just avoid block creations

Copy link

github-actions bot commented Sep 7, 2024

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Sep 7, 2024
@github-actions github-actions bot closed this Sep 12, 2024
@jcortejoso jcortejoso reopened this Sep 16, 2024
@lvpeschke lvpeschke removed the Stale label Sep 16, 2024
@jcortejoso
Copy link
Member

Does this stall the L2 if l2_unsafe - l2_safe > sequencerWindowSize?

@palango
Copy link
Author

palango commented Sep 17, 2024

Does this stall the L2 if l2_unsafe - l2_safe > sequencerWindowSize?

No, it would stall if the number of blocks since the last finalized blocks reaches some threshold.

numBlocksSinceFinalization := s.l1State.L1Head().Number - s.l1State.L1Finalized().Number
if numBlocksSinceFinalization > s.driverConfig.SequencerMaxFinalizedLag {
    // stall chain

@jcortejoso
Copy link
Member

Does this stall the L2 if l2_unsafe - l2_safe > sequencerWindowSize?

No, it would stall if the number of blocks since the last finalized blocks reaches some threshold.

numBlocksSinceFinalization := s.l1State.L1Head().Number - s.l1State.L1Finalized().Number
if numBlocksSinceFinalization > s.driverConfig.SequencerMaxFinalizedLag {
    // stall chain

Cool, probably we want to set this config to something slightly lower to sequencerWindowSize (in terms of L2 blocks); right?

Copy link

github-actions bot commented Oct 2, 2024

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the Stale label Oct 2, 2024
@palango
Copy link
Author

palango commented Oct 2, 2024

Closing as this is outdated

@palango palango closed this Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants