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

fix(l1): receipts invalid size libmdbx #2065

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

MarcosNicolau
Copy link
Contributor

@MarcosNicolau MarcosNicolau commented Feb 24, 2025

Motivation
Syncing holesky.

Description
While syncing on Holesky, we encountered blocks that exceeded the maximum allowed entry size in libmdbx. Increasing the page size was not a viable solution, as even the maximum allowable size in libmdbx wasn't enough for some blocks.

To address this, we implemented an IndexedChunk trait that splits oversized data into smaller chunks, ensuring each piece stays within the maximum value size limit. Since libmdbx is structured as a B+ tree map, we had to ensure correct order of chunks. We achieved this by appending a byte representing the chunk index, this way we preserve the correct sequence of chunks during retrieval.

Moving forward, we should consider whether other tables might also exceed this size limit. If so, we can extend this trait.

Closes None

@MarcosNicolau MarcosNicolau requested a review from a team as a code owner February 24, 2025 20:28
Copy link

github-actions bot commented Feb 24, 2025

| File                                                               | Lines | Diff |
+--------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/storage/rlp.rs              | 96    | +8   |
+--------------------------------------------------------------------+-------+------+
| /home/runner/work/ethrex/ethrex/crates/storage/store_db/libmdbx.rs | 1078  | +188 |
+--------------------------------------------------------------------+-------+------+

Total lines added: +196
Total lines removed: 0
Total lines changed: 196

Copy link
Collaborator

@mpaulucci mpaulucci left a comment

Choose a reason for hiding this comment

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

great work!

Comment on lines 520 to 527
while let Some(receipt) = IndexedChunk::read_from_db(&mut cursor, key)? {
receipts.push(receipt);
receipt_index += 1;
key = (*block_hash, receipt_index).into();
}

Ok(receipts.into_iter().map(|receipt| receipt.to()).collect())
Ok(receipts)
}
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 there might be a risk of infinite looping here. If your block uses 256 chunks then after chunk with index 255 the addition overflows, and you'll ask for chunk with index 0 of the same hash, and thus start the whole cycle again forever.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should store the size somewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I considered that as well. The size is defined as a u8, meaning we can have up to 256 chunks. However, if each value is 2022 bytes, we'd need to store around 517,632 bytes (~0.5 MB) to reach this limit. Tbh, I am not sure about the log size in ethereum and whether a receipt can take that amount of space.

For now, as we discussed offline, we'll keep it as is and address any limitations if they arise. I'll also update the code to explicitly reflect this limit and leave a clear warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Solved in 18b2941.

Copy link
Contributor

@avilagaston9 avilagaston9 left a comment

Choose a reason for hiding this comment

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

Works for me in the server! Let's wait for @Oppen's approval anyways

@MarcosNicolau MarcosNicolau requested a review from Oppen February 27, 2025 21:05
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