Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

refactor(protocol/protocol): switch to nested structs#3058

Merged
einar-oplabs merged 1 commit intomainfrom
einar/unify-variants
Jan 14, 2026
Merged

refactor(protocol/protocol): switch to nested structs#3058
einar-oplabs merged 1 commit intomainfrom
einar/unify-variants

Conversation

@einar-oplabs
Copy link
Collaborator

@einar-oplabs einar-oplabs commented Nov 19, 2025

The L1BlockInfo___ structs contains overlapping fields. This branch factors out the non-deprecated fields e.g. L1BlockInfoBedrockBase and embeds this as a field in L1BlockInfoBedrock:

pub struct L1BlockInfoBedrock {
    #[serde(flatten)]
    base: L1BlockInfoBedrockBase,
    /// The fee overhead for L1 data. Deprecated in ecotone.
    pub l1_fee_overhead: U256,
    /// The fee scalar for L1 data. Deprecated in ecotone.
    pub l1_fee_scalar: U256,
}

The purpose is reuse (think OOP inheritance) instead of repetition. As a side-effect this increases encapsulation.

It establishes a partial order and a chain of fully embedded structs:

L1BlockInfoBedrockBase < L1BlockInfoEcotoneBase < L1BlockInfoIsthmus < L1BlockInfoJovian

Further

L1BlockInfoBedrockBase < L1BlockInfoBedrock

and

L1BlockInfoEcotoneBase < L1BlockInfoEcotone

This is deemed necessary to get around deprecated fields in L1BlockInfoBedrock and L1BlockInfoEcotone.

To hide the implementation details, constructors have been added and destructuring is discouraged.

There is no single way to do this in Rust, but this is one way. A similar way is used op-alloy.

@codecov
Copy link

codecov bot commented Nov 19, 2025

Codecov Report

❌ Patch coverage is 97.05449% with 20 lines in your changes missing coverage. Please review.
✅ Project coverage is 76.7%. Comparing base (6a3e71c) to head (0c3d49e).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
crates/protocol/protocol/src/info/variant.rs 91.3% 15 Missing ⚠️
crates/protocol/protocol/src/info/jovian.rs 95.1% 3 Missing ⚠️
crates/protocol/protocol/src/utils.rs 85.7% 2 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (6a3e71c) and HEAD (0c3d49e). Click for more details.

HEAD has 19 uploads less than BASE
Flag BASE (6a3e71c) HEAD (0c3d49e)
proof 7 0
e2e 11 0
unit 2 1

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@emhane emhane left a comment

Choose a reason for hiding this comment

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

nice, i like this approach. we do this in op-alloy to for payload attributes and sidecars

@einar-oplabs einar-oplabs changed the title Unify L1BlockInfo structs refactor(protocol/protocol): switch to nested structs Nov 20, 2025
@einar-oplabs einar-oplabs marked this pull request as ready for review November 20, 2025 19:05
@einar-oplabs einar-oplabs force-pushed the einar/unify-variants branch 3 times, most recently from a09174a to 95a4eeb Compare November 20, 2025 20:43
Copy link
Member

@theochap theochap left a comment

Choose a reason for hiding this comment

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

Approving to unblock. Feel free to go ahead and merge if my comment's not relevant

Copy link
Collaborator

@op-will op-will left a comment

Choose a reason for hiding this comment

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

👍

@wiz-b4c72f16a4
Copy link

wiz-b4c72f16a4 bot commented Dec 4, 2025

Wiz Scan Summary

Scanner Findings
Vulnerability Finding Vulnerabilities 4 Low
Data Finding Sensitive Data -
Secret Finding Secrets -
IaC Misconfiguration IaC Misconfigurations -
SAST Finding SAST Findings -
Software Supply Chain Finding Software Supply Chain Findings -
Total 4 Low

View scan details in Wiz

To detect these findings earlier in the dev lifecycle, try using Wiz Code VS Code Extension.

@github-actions
Copy link
Contributor

This pull request has been automatically marked as stale because it has been inactive for 3 weeks.
It will be closed in 1 week if no further activity occurs.
If you believe this PR should remain open, please add the M-prevent-stale label or leave a comment.

@github-actions github-actions bot added M-stale and removed M-stale labels Dec 30, 2025
@einar-oplabs einar-oplabs force-pushed the einar/unify-variants branch 4 times, most recently from 488276e to 69f81df Compare January 14, 2026 22:29
@einar-oplabs einar-oplabs added this pull request to the merge queue Jan 14, 2026
Merged via the queue into main with commit 3c02e71 Jan 14, 2026
31 of 32 checks passed
@einar-oplabs einar-oplabs deleted the einar/unify-variants branch January 14, 2026 23:38
theochap pushed a commit to ethereum-optimism/optimism that referenced this pull request Jan 15, 2026
The `L1BlockInfo___` structs contains overlapping fields. This branch
factors out the non-deprecated fields e.g. `L1BlockInfoBedrockBase` and
embeds this as a field in `L1BlockInfoBedrock`:

```
pub struct L1BlockInfoBedrock {
    #[serde(flatten)]
    base: L1BlockInfoBedrockBase,
    /// The fee overhead for L1 data. Deprecated in ecotone.
    pub l1_fee_overhead: U256,
    /// The fee scalar for L1 data. Deprecated in ecotone.
    pub l1_fee_scalar: U256,
}
```
The purpose is reuse (think OOP inheritance) instead of repetition. As a
side-effect this increases encapsulation.

It establishes a partial order and a chain of fully embedded structs:

L1BlockInfoBedrockBase < L1BlockInfoEcotoneBase < L1BlockInfoIsthmus <
L1BlockInfoJovian

Further

    L1BlockInfoBedrockBase < L1BlockInfoBedrock

and

    L1BlockInfoEcotoneBase < L1BlockInfoEcotone


This is deemed necessary to get around deprecated fields in
`L1BlockInfoBedrock` and `L1BlockInfoEcotone`.


To hide the implementation details, constructors have been added and
destructuring is discouraged.

There is no single way to do this in Rust, but this is one way. A
similar way is used
[`op-alloy`](https://github.com/alloy-rs/op-alloy/blob/main/crates/rpc-types/src/transaction.rs).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants