Skip to content

Commit 752c20b

Browse files
LeanSerratomip01
andauthored
fix(l1,l2): eth client send blobs when calling eth_estimateGas (#3540)
**Motivation** When calling eth_estimateGas to estimate the gas for the L2 commitment the call was reverting because the blob was not included in the call **Description** - Add a function to add the blobs to a GenericTransaction - Add the field "blobs" to the request if the blobs field is not empty --------- Co-authored-by: Tomás Paradelo <[email protected]>
1 parent e141e10 commit 752c20b

File tree

1 file changed

+33
-3
lines changed
  • crates/networking/rpc/clients/eth

1 file changed

+33
-3
lines changed

crates/networking/rpc/clients/eth/mod.rs

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ impl EthClient {
155155
for url in self.urls.iter() {
156156
response = self.send_request_to_url(url, &request).await;
157157
if response.is_ok() {
158-
return response;
158+
// Some RPC servers don't implement all the endpoints or don't implement them completely/correctly
159+
// so if the server returns Ok(RpcResponse::Error) we retry with the others
160+
if let Ok(RpcResponse::Success(ref _a)) = response {
161+
return response;
162+
}
159163
}
160164
}
161165
response
@@ -436,6 +440,20 @@ impl EthClient {
436440
);
437441
}
438442

443+
if !transaction.blobs.is_empty() {
444+
let blobs_str: Vec<_> = transaction
445+
.blobs
446+
.into_iter()
447+
.map(|blob| format!("0x{}", hex::encode(blob)))
448+
.collect();
449+
450+
data.as_object_mut()
451+
.ok_or_else(|| {
452+
EthClientError::Custom("Failed to mutate data in estimate_gas".to_owned())
453+
})?
454+
.insert("blobs".to_owned(), json!(blobs_str));
455+
}
456+
439457
// Add the nonce just if present, otherwise the RPC will use the latest nonce
440458
if let Some(nonce) = transaction.nonce {
441459
if let Value::Object(ref mut map) = data {
@@ -843,7 +861,9 @@ impl EthClient {
843861
) -> Result<(), EthClientError> {
844862
let mut transaction = match wrapped_tx {
845863
WrappedTransaction::EIP4844(wrapped_eip4844_transaction) => {
846-
GenericTransaction::from(wrapped_eip4844_transaction.clone().tx)
864+
let mut tx = GenericTransaction::from(wrapped_eip4844_transaction.clone().tx);
865+
add_blobs_to_generic_tx(&mut tx, &wrapped_eip4844_transaction.blobs_bundle);
866+
tx
847867
}
848868
WrappedTransaction::EIP1559(eip1559_transaction) => {
849869
GenericTransaction::from(eip1559_transaction.clone())
@@ -877,7 +897,9 @@ impl EthClient {
877897
) -> Result<u64, EthClientError> {
878898
let mut transaction = match wrapped_tx {
879899
WrappedTransaction::EIP4844(wrapped_eip4844_transaction) => {
880-
GenericTransaction::from(wrapped_eip4844_transaction.clone().tx)
900+
let mut tx = GenericTransaction::from(wrapped_eip4844_transaction.clone().tx);
901+
add_blobs_to_generic_tx(&mut tx, &wrapped_eip4844_transaction.blobs_bundle);
902+
tx
881903
}
882904
WrappedTransaction::EIP1559(eip1559_transaction) => {
883905
GenericTransaction::from(eip1559_transaction.clone())
@@ -1423,6 +1445,14 @@ pub fn get_address_from_secret_key(secret_key: &SecretKey) -> Result<Address, Et
14231445
Ok(Address::from(address_bytes))
14241446
}
14251447

1448+
pub fn add_blobs_to_generic_tx(tx: &mut GenericTransaction, bundle: &BlobsBundle) {
1449+
tx.blobs = bundle
1450+
.blobs
1451+
.iter()
1452+
.map(|blob| Bytes::copy_from_slice(blob))
1453+
.collect()
1454+
}
1455+
14261456
#[derive(Serialize, Deserialize, Debug)]
14271457
#[serde(rename_all = "camelCase")]
14281458
pub struct GetTransactionByHashTransaction {

0 commit comments

Comments
 (0)