Skip to content

feat(l1): add engine_getBlobsV3 rpc method#5648

Merged
MegaRedHand merged 7 commits intolambdaclass:mainfrom
lakshya-sky:feat/add-getblobs-v3
Dec 18, 2025
Merged

feat(l1): add engine_getBlobsV3 rpc method#5648
MegaRedHand merged 7 commits intolambdaclass:mainfrom
lakshya-sky:feat/add-getblobs-v3

Conversation

@lakshya-sky
Copy link
Contributor

Motivation

Adds new rpc method almost identical to engine_getBlobsV2 expect the new method allows partial data as opposed to all or nothing.

Description

  • create & share a new function for both `engine_getBlobsV{2,3} as they are identical.

Closes #5634

@lakshya-sky lakshya-sky marked this pull request as ready for review December 15, 2025 22:12
@lakshya-sky lakshya-sky requested a review from a team as a code owner December 15, 2025 22:12
Copilot AI review requested due to automatic review settings December 15, 2025 22:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for the engine_getBlobsV3 RPC method, which allows partial blob data to be returned, unlike engine_getBlobsV2 which returns all blobs or nothing. The implementation refactors common logic between V2 and V3 into a shared helper function.

Key Changes:

  • Introduced new BlobsV3Request struct and RPC handler
  • Refactored blob retrieval logic into shared get_blobs_and_proof_v2 function
  • Added engine_getBlobsV3 to capabilities and routing

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
crates/networking/rpc/rpc.rs Added BlobsV3Request import and routing for engine_getBlobsV3 method
crates/networking/rpc/engine/mod.rs Updated capabilities array to include engine_getBlobsV3
crates/networking/rpc/engine/blobs.rs Introduced BlobsV3Request handler and refactored shared blob retrieval logic into get_blobs_and_proof_v2 function

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@MegaRedHand
Copy link
Collaborator

Thanks for your contribution! Left some comments, but should be good to merge once those are addressed

Copy link
Collaborator

@MegaRedHand MegaRedHand 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 +173 to +197
for blobs_bundle in context.blockchain.mempool.get_blobs_bundle_pool()? {
// Go over all blobs bundles from the blobs bundle pool.
let blobs_in_bundle = blobs_bundle.blobs;
let commitments_in_bundle = blobs_bundle.commitments;
let proofs_in_bundle = blobs_bundle.proofs;

// Go over all the commitments in each blobs bundle to calculate the blobs versioned hash.
for (commitment, (blob, proofs)) in commitments_in_bundle.iter().zip(
blobs_in_bundle
.iter()
.zip(proofs_in_bundle.chunks(CELLS_PER_EXT_BLOB)),
) {
let current_versioned_hash = kzg_commitment_to_versioned_hash(commitment);
if let Some(index) = blob_versioned_hashes
.iter()
.position(|&hash| hash == current_versioned_hash)
{
// If the versioned hash is one of the requested we save its corresponding blob and proof in the returned vector. We store them in the same position as the versioned hash was received.
res[index] = Some(BlobAndProofV2 {
blob: *blob,
proofs: proofs.to_vec(),
});
}
}
if res.iter().any(|blob| blob.is_none()) {
return Ok(Value::Null);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This looks like a lot of work to do for a single RPC call. We should probably, at the very least, hash once when we accept the blob tx to the mempool and keep that hash, rather than hash all of them each time someone calls this endpoint. Looks like a DoS vector to me.

NOTE: this is not necessarily the place to fix it, being already there, it just got it to my attention.
@MegaRedHand should we open an issue for this?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's. I think we should also add a get_blobs(versioned_hashes) method for fetching the blobs with those versioned hashes only.

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 will raise a PR with the a new method once the issue is up. Could you assign it to me when you create the issue @MegaRedHand. Thanks!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment on lines +186 to 195
if let Some(index) = blob_versioned_hashes
.iter()
.position(|&hash| hash == current_versioned_hash)
{
// If the versioned hash is one of the requested we save its corresponding blob and proof in the returned vector. We store them in the same position as the versioned hash was received.
res[index] = Some(BlobAndProofV2 {
blob: *blob,
proofs: proofs.to_vec(),
});
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This search also looks rather worrisome in terms of performance. We iterate all blobs, hash them, then iterate all hashes in the request each time. I suggest we just build a hashmap mapping hash to desired position (pseudo-code):

let mut res = vec![None; blob_versioned_hashes.len()];
let versioned_hashes_to_pos = HashMap::from_iter(blob_versioned_hashes.iter().enumerate().map(|(i, h)| (*h, i)));
for blob in blobs_pool {
    let hash = blob.hopefully_precomputed_sha2();
    let Some(pos) = versioned_hashes_to_pos.get(&hash) else {
         continue;
    };
    res[pos] = build_the_thing(blob);
}

Extra points for keeping a mapping of versioned hash to blob as well.

Again, not to handle now, just pointing out the issues in the original code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should also be addressed by #5679

@MegaRedHand MegaRedHand added this pull request to the merge queue Dec 18, 2025
Merged via the queue into lambdaclass:main with commit 2f60e7e Dec 18, 2025
49 checks passed
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.

Implement engine_getBlobsV3

3 participants