Skip to content

feat: added get_blob_by_hash #10987

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Soubhik-10
Copy link
Contributor

closes #10978

@Soubhik-10 Soubhik-10 marked this pull request as ready for review July 11, 2025 14:34
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

great, now we just need to make this a bit nicer

Comment on lines 1352 to 1355
pub async fn anvil_get_blob_by_tx_hash(
&self,
hash: B256,
) -> Result<Option<alloy_consensus::TxEip4844WithSidecar>> {
Copy link
Member

Choose a reason for hiding this comment

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

for this we should be able to reuse this logic:

let (info, block) = {
let storage = self.blockchain.storage.read();
let MinedTransaction { info, block_hash, .. } =
storage.transactions.get(&hash)?.clone();
let block = storage.blocks.get(&block_hash).cloned()?;
(info, block)
};

we should add a helper fn for this to Backend as well

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 just used the entire fn..not sure..can you please check te new one?

@Soubhik-10 Soubhik-10 requested a review from mattsse July 12, 2025 10:31
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

cool, a few more suggestions

Comment on lines +2935 to +2941
if let Some(sidecar) = typed_tx.sidecar() {
for blob in sidecar.sidecar.clone() {
let versioned_hash = B256::from(blob.to_kzg_versioned_hash());
if versioned_hash == hash {
return Ok(Some(sidecar.clone()));
}
}
Copy link
Member

Choose a reason for hiding this comment

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

we can simplify this a bit with:

https://github.com/alloy-rs/alloy/blob/d9ec782cc1e3a7850f44f72884aea8f6b9b11ca8/crates/eips/src/eip4844/sidecar.rs#L289-L289

because we want to avoid cloning all sidecars for this since this is a bit expensive

we also want a new helper blob_by_versioned_hash on the sidecar types in alloy, do you want to upstream this?

Comment on lines +1330 to +1331
/// Handler for RPC call: `anvil_getBlobByTransactionHash`
pub fn anvil_get_blob_by_tx_hash(
Copy link
Member

Choose a reason for hiding this comment

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

should be getBlobs

Comment on lines +2922 to +2927
let tx = self.mined_transaction_by_hash(hash).unwrap();
let typed_tx = TypedTransaction::try_from(tx).unwrap();
if let Some(sidecar) = typed_tx.sidecar() {
return Ok(Some(sidecar.clone()));
}
Ok(None)
Copy link
Member

Choose a reason for hiding this comment

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

this can fail, so we should handle this gracefully and only return the blobs Vec here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

feat(anvil): expose api to query blobs on anvil
2 participants