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

Don't post a batch that would cause a reorg due to being outside (or near) the time bounds #2340

Merged
merged 6 commits into from
Jun 5, 2024

Conversation

ganeshvanahalli
Copy link
Contributor

@ganeshvanahalli ganeshvanahalli commented May 24, 2024

Resolves NIT-2524

@cla-bot cla-bot bot added the s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA. label May 24, 2024
@ganeshvanahalli ganeshvanahalli marked this pull request as ready for review May 24, 2024 22:49
if (config.ReorgResistanceMargin > 0 && config.ReorgResistanceMargin < config.MaxDelay) &&
(batchDuration >= config.MaxDelay-config.ReorgResistanceMargin) &&
(batchDuration <= config.MaxDelay || (batchDuration <= config.MaxDelay+config.ReorgResistanceMargin && !config.IgnoreReorgResistanceMargin)) {
disablePosting = true
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should log an error here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added it

@@ -156,6 +156,8 @@ type BatchPosterConfig struct {
L1BlockBoundBypass time.Duration `koanf:"l1-block-bound-bypass" reload:"hot"`
UseAccessLists bool `koanf:"use-access-lists" reload:"hot"`
GasEstimateBaseFeeMultipleBips arbmath.Bips `koanf:"gas-estimate-base-fee-multiple-bips"`
ReorgResistanceMargin time.Duration `koanf:"reorg-resistance-margin" reload:"hot"`
IgnoreReorgResistanceMargin bool `koanf:"ignore-reorg-resistance-margin" reload:"hot"`
Copy link
Member

Choose a reason for hiding this comment

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

Optional(Nit): Prefer using boolean flags with a positive phrasing. Maybe "EnableReorgResistanceMargin" or "EnforceReorgResistanceMargin". When you have a negative like "Ignore" or "Disable" it means that you have to mentally negate the meaning of the boolean which slightly deteriorates the readability of the code.

batchDuration := time.Since(firstMsgTime)
if (config.ReorgResistanceMargin > 0 && config.ReorgResistanceMargin < config.MaxDelay) &&
(batchDuration >= config.MaxDelay-config.ReorgResistanceMargin) &&
(batchDuration <= config.MaxDelay || (batchDuration <= config.MaxDelay+config.ReorgResistanceMargin && !config.IgnoreReorgResistanceMargin)) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm personally having trouble reasoning through this compound condition. For example, I wonder why we are only checking config.IgnoreReorgResistanceMargin in the last parenthetical || instead of in the other places where the value of the config.ReorgResistanceMargin is being checked. Like, why don't we only ignore the config.ReorgResistanceMargin when checking <= instead of for both <= and >=?

Maybe some test-cases would make it easier to see the truth table of when this clause should disable posting?

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree with @eljobe on this one.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that the if condition is quite complex, I'll try to split it into multiple stages for clarity.

When the batch's duration is between config.MaxDelay-config.ReorgResistanceMargin and config.MaxDelay we will definitely pause posting of batches.

And when its between config.MaxDelay and config.MaxDelay+config.ReorgResistanceMargin we provide an option to prioritize MaxDelay's purpose over ReorgResistanceMargin's.
IgnoreReorgResistanceMargin flag is used to achieve this.

forcePostBatch := config.MaxDelay <= 0 || time.Since(firstMsgTime) >= config.MaxDelay

I'll rename IgnoreReorgResistanceMargin flag to something like PrioritizeMaxDelayOverReorgResistance which captures its purpose clearly

@eljobe eljobe self-requested a review June 4, 2024 10:07
Copy link
Member

@eljobe eljobe left a comment

Choose a reason for hiding this comment

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

LGTM

@PlasmaPower PlasmaPower enabled auto-merge June 5, 2024 16:16
@PlasmaPower PlasmaPower merged commit 5b20961 into master Jun 5, 2024
11 checks passed
@PlasmaPower PlasmaPower deleted the delay-batchposting-avoidreorg branch June 5, 2024 17:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design-approved s Automatically added by the CLA bot if the creator of a PR is registered as having signed the CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants