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

feat(rpc): make ExecutionResources compatible with json-rpc v08 spec #2316

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions crates/common/src/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub struct ExecutionResources {
pub n_memory_holes: u64,
pub data_availability: L1Gas,
pub total_gas_consumed: L1Gas,
pub l2_gas: L2Gas,
}

#[derive(Clone, Debug, Default, PartialEq, Eq, Dummy)]
Expand All @@ -52,6 +53,10 @@ pub struct L1Gas {
pub l1_data_gas: u128,
}

#[derive(Clone, Debug, Default, PartialEq, Eq, Dummy, serde::Serialize)]
#[serde(transparent)]
pub struct L2Gas(pub u128);

#[derive(Clone, Debug, Default, PartialEq, Eq)]
pub struct BuiltinCounters {
pub output: u64,
Expand Down Expand Up @@ -103,6 +108,7 @@ impl<T> Dummy<T> for ExecutionResources {
data_availability: Faker.fake_with_rng(rng),
// TODO fix this after total_gas_consumed is added to p2p messages
total_gas_consumed: Default::default(),
l2_gas: Default::default(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/gateway-types/src/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ pub mod transaction {
n_memory_holes: value.n_memory_holes,
data_availability: value.data_availability.unwrap_or_default().into(),
total_gas_consumed: value.total_gas_consumed.unwrap_or_default().into(),
// TODO: Fix this when we have a way to get L2 gas from the gateway
l2_gas: Default::default(),
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions crates/p2p/src/client/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,8 @@ impl TryFrom<(p2p_proto::receipt::Receipt, TransactionIndex)> for crate::client:
)?
.0,
},
// TODO: Fix this when we have a way to get L2 gas from the gateway
l2_gas: Default::default(),
},
l2_to_l1_messages: common
.messages_sent
Expand Down
27 changes: 27 additions & 0 deletions crates/pathfinder/src/sync/checkpoint/fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use pathfinder_common::receipt::{
ExecutionResources,
ExecutionStatus,
L1Gas,
L2Gas,
L2ToL1Message,
Receipt,
};
Expand Down Expand Up @@ -137,6 +138,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -189,6 +191,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -242,6 +245,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![
L2ToL1Message {
Expand Down Expand Up @@ -305,6 +309,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -361,6 +366,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -420,6 +426,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -474,6 +481,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![
L2ToL1Message {
Expand Down Expand Up @@ -537,6 +545,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -589,6 +598,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -641,6 +651,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -695,6 +706,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -747,6 +759,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -801,6 +814,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![
L2ToL1Message {
Expand Down Expand Up @@ -864,6 +878,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -920,6 +935,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -974,6 +990,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -1028,6 +1045,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -1082,6 +1100,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -1251,6 +1270,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -1303,6 +1323,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -1357,6 +1378,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -1416,6 +1438,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -1470,6 +1493,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![
L2ToL1Message {
Expand Down Expand Up @@ -1532,6 +1556,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![
L2ToL1Message {
Expand Down Expand Up @@ -1597,6 +1622,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down Expand Up @@ -1651,6 +1677,7 @@ pub fn blocks() -> [Block; 2] {
l1_gas: 0,
l1_data_gas: 0,
},
l2_gas: L2Gas(0),
},
l2_to_l1_messages: vec![],
execution_status: Succeeded,
Expand Down
16 changes: 11 additions & 5 deletions crates/rpc/src/dto/receipt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,17 @@ impl SerializeForVersion for ExecutionResources<'_> {

let mut serializer = serializer.serialize_struct()?;

serializer.flatten(&ComputationResources(self.0))?;
serializer.serialize_field(
"data_availability",
&DataAvailability(&self.0.data_availability),
)?;
if serializer.version < RpcVersion::V08 {
serializer.flatten(&ComputationResources(self.0))?;
serializer.serialize_field(
"data_availability",
&DataAvailability(&self.0.data_availability),
)?;
} else {
serializer.serialize_field("l1_gas", &self.0.data_availability.l1_gas)?;
serializer.serialize_field("l1_data_gas", &self.0.data_availability.l1_data_gas)?;
serializer.serialize_field("l2_gas", &self.0.l2_gas)?;
}

serializer.end()
}
Expand Down
1 change: 1 addition & 0 deletions crates/storage/src/connection/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,7 @@ pub(crate) mod dto {
},
_ => Default::default(),
},
l2_gas: Default::default(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/storage/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ pub(crate) fn create_transactions_and_receipts(
l1_gas: i as u128 + 333,
l1_data_gas: i as u128 + 666,
},
l2_gas: Default::default(),
},
transaction_hash: tx.hash,
transaction_index: TransactionIndex::new_or_panic(i as u64 + 2311),
Expand Down