From c89bd8af34a3fe7648b15ccfaab725aa5b6dd637 Mon Sep 17 00:00:00 2001 From: Krisztian Kovacs Date: Fri, 15 Nov 2024 15:14:29 +0100 Subject: [PATCH] feat(rpc/v08): add `l1_data_gas` to v3 transaction resource bounds This is a partial implementation: since we don't _really_ use these new values other than passing those on to the Starknet gateway when submitting new transactions the new field is not added to the `ResourceBounds` type in the common crate. We'll have to do that once these values need to be stored in storage and used in the P2P protocol when adding proper support for Starknet 0.13.4. Closes: #2379 --- crates/gateway-types/src/reply.rs | 10 ++++++++++ .../rpc/fixtures/0.6.0/broadcasted_transactions.json | 4 ++++ crates/rpc/src/method/add_declare_transaction.rs | 1 + .../rpc/src/method/add_deploy_account_transaction.rs | 1 + crates/rpc/src/method/add_invoke_transaction.rs | 1 + crates/rpc/src/v02/types.rs | 9 +++++++++ crates/rpc/src/v06/method/add_declare_transaction.rs | 1 + .../src/v06/method/add_deploy_account_transaction.rs | 1 + crates/rpc/src/v06/method/add_invoke_transaction.rs | 1 + crates/rpc/src/v06/method/simulate_transactions.rs | 1 + 10 files changed, 30 insertions(+) diff --git a/crates/gateway-types/src/reply.rs b/crates/gateway-types/src/reply.rs index 9fe4ca0abb..c860224cae 100644 --- a/crates/gateway-types/src/reply.rs +++ b/crates/gateway-types/src/reply.rs @@ -800,6 +800,14 @@ pub mod transaction { pub l1_gas: ResourceBound, #[serde(rename = "L2_GAS")] pub l2_gas: ResourceBound, + // Introduced in Starknet v0.13.4. This has to be optional because not sending it to the + // gateway is not equivalent to sending an explicit zero bound. + #[serde( + default, + skip_serializing_if = "Option::is_none", + rename = "L1_DATA_GAS" + )] + pub l1_data_gas: Option, } impl From for pathfinder_common::transaction::ResourceBounds { @@ -816,6 +824,8 @@ pub mod transaction { Self { l1_gas: value.l1_gas.into(), l2_gas: value.l2_gas.into(), + // TODO: add this when adding support for Starknet 0.13.4 + l1_data_gas: None, } } } diff --git a/crates/rpc/fixtures/0.6.0/broadcasted_transactions.json b/crates/rpc/fixtures/0.6.0/broadcasted_transactions.json index 5d2fb9c6c5..05cc637856 100644 --- a/crates/rpc/fixtures/0.6.0/broadcasted_transactions.json +++ b/crates/rpc/fixtures/0.6.0/broadcasted_transactions.json @@ -183,6 +183,10 @@ ], "nonce": "0x8", "resource_bounds": { + "l1_data_gas": { + "max_amount": "0x3333", + "max_price_per_unit": "0x4444" + }, "l1_gas": { "max_amount": "0x1111", "max_price_per_unit": "0x2222" diff --git a/crates/rpc/src/method/add_declare_transaction.rs b/crates/rpc/src/method/add_declare_transaction.rs index dc1d66b1fe..5bdd0a765c 100644 --- a/crates/rpc/src/method/add_declare_transaction.rs +++ b/crates/rpc/src/method/add_declare_transaction.rs @@ -743,6 +743,7 @@ mod tests { max_amount: ResourceAmount(0), max_price_per_unit: ResourcePricePerUnit(0), }, + l1_data_gas: None, }, tip: Tip(0), paymaster_data: vec![], diff --git a/crates/rpc/src/method/add_deploy_account_transaction.rs b/crates/rpc/src/method/add_deploy_account_transaction.rs index c796f521e8..a0a7786aca 100644 --- a/crates/rpc/src/method/add_deploy_account_transaction.rs +++ b/crates/rpc/src/method/add_deploy_account_transaction.rs @@ -389,6 +389,7 @@ mod tests { max_amount: ResourceAmount(0), max_price_per_unit: ResourcePricePerUnit(0), }, + l1_data_gas: None, }, tip: Tip(0), paymaster_data: vec![], diff --git a/crates/rpc/src/method/add_invoke_transaction.rs b/crates/rpc/src/method/add_invoke_transaction.rs index ff88d4c216..cb6e8c234a 100644 --- a/crates/rpc/src/method/add_invoke_transaction.rs +++ b/crates/rpc/src/method/add_invoke_transaction.rs @@ -424,6 +424,7 @@ mod tests { max_amount: ResourceAmount(0), max_price_per_unit: ResourcePricePerUnit(0), }, + l1_data_gas: None, }, tip: Tip(0), paymaster_data: vec![], diff --git a/crates/rpc/src/v02/types.rs b/crates/rpc/src/v02/types.rs index ef3eecab3d..0a47fba535 100644 --- a/crates/rpc/src/v02/types.rs +++ b/crates/rpc/src/v02/types.rs @@ -13,6 +13,8 @@ pub mod syncing; pub struct ResourceBounds { pub l1_gas: ResourceBound, pub l2_gas: ResourceBound, + #[serde(skip_serializing_if = "Option::is_none")] + pub l1_data_gas: Option, } impl crate::dto::DeserializeForVersion for ResourceBounds { @@ -21,6 +23,7 @@ impl crate::dto::DeserializeForVersion for ResourceBounds { Ok(Self { l1_gas: value.deserialize("l1_gas")?, l2_gas: value.deserialize("l2_gas")?, + l1_data_gas: value.deserialize_optional("l1_data_gas")?, }) }) } @@ -907,6 +910,7 @@ pub mod request { max_amount: ResourceAmount(0), max_price_per_unit: ResourcePricePerUnit(0), }, + l1_data_gas: None, }, tip: Tip(0x1234), paymaster_data: vec![ @@ -976,6 +980,7 @@ pub mod request { max_amount: ResourceAmount(0), max_price_per_unit: ResourcePricePerUnit(0), }, + l1_data_gas: None, }, tip: Tip(0x1234), paymaster_data: vec![ @@ -1006,6 +1011,10 @@ pub mod request { max_amount: ResourceAmount(0), max_price_per_unit: ResourcePricePerUnit(0), }, + l1_data_gas: Some(ResourceBound { + max_amount: ResourceAmount(0x3333), + max_price_per_unit: ResourcePricePerUnit(0x4444), + }), }, tip: Tip(0x1234), paymaster_data: vec![ diff --git a/crates/rpc/src/v06/method/add_declare_transaction.rs b/crates/rpc/src/v06/method/add_declare_transaction.rs index f0bb56e85f..7874ee9e66 100644 --- a/crates/rpc/src/v06/method/add_declare_transaction.rs +++ b/crates/rpc/src/v06/method/add_declare_transaction.rs @@ -709,6 +709,7 @@ mod tests { max_amount: ResourceAmount(0), max_price_per_unit: ResourcePricePerUnit(0), }, + l1_data_gas: None, }, tip: Tip(0), paymaster_data: vec![], diff --git a/crates/rpc/src/v06/method/add_deploy_account_transaction.rs b/crates/rpc/src/v06/method/add_deploy_account_transaction.rs index 6fddc81ff1..206f51baa4 100644 --- a/crates/rpc/src/v06/method/add_deploy_account_transaction.rs +++ b/crates/rpc/src/v06/method/add_deploy_account_transaction.rs @@ -357,6 +357,7 @@ mod tests { max_amount: ResourceAmount(0), max_price_per_unit: ResourcePricePerUnit(0), }, + l1_data_gas: None, }, tip: Tip(0), paymaster_data: vec![], diff --git a/crates/rpc/src/v06/method/add_invoke_transaction.rs b/crates/rpc/src/v06/method/add_invoke_transaction.rs index a6f0984c10..ae0b6e7def 100644 --- a/crates/rpc/src/v06/method/add_invoke_transaction.rs +++ b/crates/rpc/src/v06/method/add_invoke_transaction.rs @@ -395,6 +395,7 @@ mod tests { max_amount: ResourceAmount(0), max_price_per_unit: ResourcePricePerUnit(0), }, + l1_data_gas: None, }, tip: Tip(0), paymaster_data: vec![], diff --git a/crates/rpc/src/v06/method/simulate_transactions.rs b/crates/rpc/src/v06/method/simulate_transactions.rs index 75357db6bc..8c5963f53b 100644 --- a/crates/rpc/src/v06/method/simulate_transactions.rs +++ b/crates/rpc/src/v06/method/simulate_transactions.rs @@ -1225,6 +1225,7 @@ pub(crate) mod tests { max_amount: ResourceAmount(10000), max_price_per_unit: ResourcePricePerUnit(100000000), }, + l1_data_gas: None, }, tip: Tip(0), paymaster_data: vec![],