Skip to content

feat(l1): drop unwraps storage - #3002

Merged
ilitteri merged 19 commits into
mainfrom
drop-unwraps-storage
Jun 4, 2025
Merged

ilitteri merged 19 commits into
mainfrom
drop-unwraps-storage

Conversation

@cdiielsi

@cdiielsi cdiielsi commented Jun 2, 2025 •

Copy link
Copy Markdown
Contributor

Motivation

Dissallow unwraps on l1.

Description

This pr drops unwraps on crate storage. Test's unwraps remain. Resolves partially #2879.

@github-actions

github-actions Bot commented Jun 2, 2025 •

Copy link
Copy Markdown

Lines of code report

Total lines added: 106
Total lines removed: 0
Total lines changed: 106

Detailed view
+---------------------------------------------+-------+------+
| File                                        | Lines | Diff |
+---------------------------------------------+-------+------+
| ethrex/crates/networking/p2p/snap.rs        | 918   | +12  |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/api.rs                | 270   | +4   |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/store.rs              | 1287  | +10  |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/in_memory.rs | 624   | +13  |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/libmdbx.rs   | 1406  | +37  |
+---------------------------------------------+-------+------+
| ethrex/crates/storage/store_db/redb.rs      | 1250  | +30  |
+---------------------------------------------+-------+------+

@cdiielsi
cdiielsi marked this pull request as ready for review June 2, 2025 20:43
@cdiielsi
cdiielsi requested a review from a team as a code owner June 2, 2025 20:43
Comment thread cmd/ef_tests/state/levm_ef_tests_report0.txt Outdated
Comment thread crates/networking/p2p/snap.rs

@ilitteri ilitteri left a comment •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I added comments in most of the functions that could be refactored using the transpose method, but the following are other functions where this could be done.

  • In crates/storage/store_db/libmdbx.rs:
    • set_canonical_block .
    • get_payload.
    • get_pending_block.
    • get_latest_valid_ancestor ;
  • In crates/storage/store_db/redb.rs:
    • get_block_hash_by_block_number .
    • get_block_header .
    • get_block_body_by_hash .
    • get_block_header_by_hash .
    • get_pending_block.
    • get_account_code .
    • get_receipt.
    • get_canonical_block_hash.
    • get_payload.
    • get_latest_valid_ancestor .

The same goes for the use of expect to help replace the use of unwraps. Using the motivation for removing the unwraps as context, it is the same to use expect in its place. I left some comments, but not in the following functions:

  • In crates/storage/store_db/libmdbx.rs:
    • add_transaction_locations.
    • read_account_snapshot.
  • In crates/storage/store_db/redb.rs:
    • get_transaction_location .
    • take_storage_heal_paths .
    • read_account_snapshot .

EDIT: Having read the issue, as we are allowing the use of expect for unrecoverable errors, let's add a comment saying so above the line of code that has an expect explaining in detail why the error is unrecoverable.

Comment thread crates/storage/store_db/in_memory.rs Outdated
Comment thread crates/storage/store_db/libmdbx.rs Outdated
Comment thread crates/storage/store_db/libmdbx.rs Outdated
Comment thread crates/storage/store_db/libmdbx.rs Outdated
Comment thread crates/storage/store_db/libmdbx.rs Outdated
Comment thread crates/storage/store_db/libmdbx.rs Outdated
Comment thread crates/storage/store_db/libmdbx.rs Outdated
Comment thread crates/storage/store_db/libmdbx.rs Outdated

@SDartayet SDartayet 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!

@fmoletta fmoletta 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.

The InMemory Store variant is mostly used for local testing. I think it is overkill to modify all these trait methods just to guard the rare lock error on the in memory variant. Maybe we should just use expect and let it crash.
This is just my opinion, I would like to know what the rest of the team thinks about this

@ilitteri

ilitteri commented Jun 4, 2025 •

Copy link
Copy Markdown
Collaborator

The InMemory Store variant is mostly used for local testing. I think it is overkill to modify all these trait methods just to guard the rare lock error on the in memory variant. Maybe we should just use expect and let it crash. This is just my opinion, I would like to know what the rest of the team thinks about this

I understand the appeal of using expect for simplicity in the StorageEngine implementation, as it avoids verbose error handling. However, this approach would make the in-memory Store non-compliant with the StorageEngine trait, which requires all methods to be safe and return a Result to handle errors gracefully. The inner method is central to the implementation and is called by most of all trait methods. Allowing it to panic via expect introduces inconsistency, as it undermines the trait’s guarantee of predictable error handling. While the previous use of unwrap had similar issues, we can improve by propagating errors properly with Result, ensuring the implementation aligns with the trait’s contract and maintains reliability.

@ilitteri
ilitteri added this pull request to the merge queue Jun 4, 2025
Merged via the queue into main with commit a59e11a Jun 4, 2025
@ilitteri
ilitteri deleted the drop-unwraps-storage branch June 4, 2025 22:14
pedrobergamini pushed a commit to pedrobergamini/ethrex that referenced this pull request Aug 24, 2025
**Motivation**

Dissallow unwraps on l1.

**Description**

This pr drops unwraps on crate storage. Test's unwraps remain. Resolves
partially lambdaclass#2879.
edg-l added a commit that referenced this pull request Jun 18, 2026
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.

4 participants