From 105af0b71bb5cf841126ec5260d954b052d8bafa Mon Sep 17 00:00:00 2001 From: Krzysztof Lis Date: Tue, 20 Feb 2024 13:09:00 +0100 Subject: [PATCH 1/4] feat(p2p_proto): update protos and dtos --- crates/p2p/src/client/types.rs | 108 +++++++++++++++++- crates/p2p_proto/proto/common.proto | 12 +- crates/p2p_proto/proto/header.proto | 38 +++--- crates/p2p_proto/proto/receipt.proto | 8 +- crates/p2p_proto/src/common.rs | 46 +++++++- crates/p2p_proto/src/header.rs | 17 ++- crates/p2p_proto/src/receipt.rs | 2 + .../pathfinder/src/p2p_network/client/conv.rs | 2 +- .../src/p2p_network/sync_handlers.rs | 6 +- .../src/p2p_network/sync_handlers/conv.rs | 5 +- crates/storage/src/connection/transaction.rs | 10 +- 11 files changed, 219 insertions(+), 35 deletions(-) diff --git a/crates/p2p/src/client/types.rs b/crates/p2p/src/client/types.rs index c300ed171e..b045025ae4 100644 --- a/crates/p2p/src/client/types.rs +++ b/crates/p2p/src/client/types.rs @@ -2,6 +2,9 @@ //! //! Also includes some "bridging" types which should eventually be removed use pathfinder_common::event::Event; +use pathfinder_common::receipt::{ + BuiltinCounters, ExecutionDataAvailability, ExecutionResources, ExecutionStatus, L2ToL1Message, +}; use pathfinder_common::transaction::{ DataAvailabilityMode, DeclareTransactionV0V1, DeclareTransactionV2, DeclareTransactionV3, DeployAccountTransactionV0V1, DeployAccountTransactionV3, DeployTransaction, @@ -11,10 +14,12 @@ use pathfinder_common::transaction::{ use pathfinder_common::{ AccountDeploymentDataElem, BlockCommitmentSignature, BlockCommitmentSignatureElem, BlockHash, BlockNumber, BlockTimestamp, CallParam, CasmHash, ClassHash, ConstructorParam, ContractAddress, - ContractAddressSalt, EntryPoint, EventCommitment, EventData, EventKey, Fee, GasPrice, - PaymasterDataElem, SequencerAddress, StarknetVersion, StateCommitment, Tip, - TransactionCommitment, TransactionNonce, TransactionSignatureElem, TransactionVersion, + ContractAddressSalt, EntryPoint, EthereumAddress, EventCommitment, EventData, EventKey, Fee, + GasPrice, L2ToL1MessagePayloadElem, PaymasterDataElem, SequencerAddress, StarknetVersion, + StateCommitment, Tip, TransactionCommitment, TransactionHash, TransactionNonce, + TransactionSignatureElem, TransactionVersion, }; +use pathfinder_crypto::Felt; /// We don't want to introduce circular dependencies between crates /// and we need to work around for the orphan rule - implement conversion fns for types ourside our crate. @@ -63,7 +68,7 @@ impl TryFrom for SignedBlockHeader { .ok_or(anyhow::anyhow!("block number > i64::MAX"))?, timestamp: BlockTimestamp::new(dto.time) .ok_or(anyhow::anyhow!("block timestamp > i64::MAX"))?, - eth_l1_gas_price: dto.gas_price.into(), + eth_l1_gas_price: todo!(), sequencer_address: SequencerAddress(dto.sequencer_address.0), starknet_version: dto.protocol_version.into(), event_commitment: EventCommitment(dto.events.root.0), @@ -106,6 +111,101 @@ impl } } +/// Represents a simplified [`pathfinder_common::receipt::Receipt`] (events and transaction index excluded). +#[derive(Clone, Default, Debug, PartialEq)] +pub struct Receipt { + pub actual_fee: Option, + pub execution_resources: Option, + pub l2_to_l1_messages: Vec, + pub execution_status: ExecutionStatus, + pub transaction_hash: TransactionHash, +} + +impl From for Receipt { + fn from(x: pathfinder_common::receipt::Receipt) -> Self { + Self { + transaction_hash: x.transaction_hash, + actual_fee: x.actual_fee, + execution_resources: x.execution_resources, + l2_to_l1_messages: x.l2_to_l1_messages, + execution_status: x.execution_status, + } + } +} + +impl TryFrom for Receipt { + type Error = anyhow::Error; + + fn try_from(proto: p2p_proto::receipt::Receipt) -> anyhow::Result + where + Self: Sized, + { + use p2p_proto::receipt::Receipt::{Declare, Deploy, DeployAccount, Invoke, L1Handler}; + use p2p_proto::receipt::{ + DeclareTransactionReceipt, DeployAccountTransactionReceipt, DeployTransactionReceipt, + InvokeTransactionReceipt, L1HandlerTransactionReceipt, + }; + match proto { + Invoke(InvokeTransactionReceipt { common }) + | Declare(DeclareTransactionReceipt { common }) + | L1Handler(L1HandlerTransactionReceipt { common, .. }) + | Deploy(DeployTransactionReceipt { common, .. }) + | DeployAccount(DeployAccountTransactionReceipt { common, .. }) => { + let data_availability = (common.execution_resources.l1_gas != Felt::ZERO + || common.execution_resources.l1_data_gas != Felt::ZERO) + .then_some(ExecutionDataAvailability { + l1_gas: GasPrice::from(common.execution_resources.l1_gas).0, + l1_data_gas: GasPrice::from(common.execution_resources.l1_data_gas).0, + }); + Ok(Self { + transaction_hash: TransactionHash(common.transaction_hash.0), + actual_fee: Some(Fee(common.actual_fee)), + execution_resources: Some(ExecutionResources { + builtin_instance_counter: BuiltinCounters { + output_builtin: common.execution_resources.builtins.output.into(), + pedersen_builtin: common.execution_resources.builtins.pedersen.into(), + range_check_builtin: common + .execution_resources + .builtins + .range_check + .into(), + ecdsa_builtin: common.execution_resources.builtins.ecdsa.into(), + bitwise_builtin: common.execution_resources.builtins.bitwise.into(), + ec_op_builtin: common.execution_resources.builtins.ec_op.into(), + keccak_builtin: common.execution_resources.builtins.keccak.into(), + poseidon_builtin: common.execution_resources.builtins.poseidon.into(), + segment_arena_builtin: 0, + }, + n_steps: common.execution_resources.steps.into(), + n_memory_holes: common.execution_resources.memory_holes.into(), + data_availability, + }), + l2_to_l1_messages: common + .messages_sent + .into_iter() + .map(|x| L2ToL1Message { + from_address: ContractAddress(x.from_address), + payload: x + .payload + .into_iter() + .map(L2ToL1MessagePayloadElem) + .collect(), + to_address: EthereumAddress(x.to_address.0), + }) + .collect(), + execution_status: if common.revert_reason.is_empty() { + ExecutionStatus::Succeeded + } else { + ExecutionStatus::Reverted { + reason: common.revert_reason, + } + }, + }) + } + } + } +} + /// Deployed contract address has not been computed for deploy account transactions. #[derive(Clone, Debug, PartialEq, Eq)] pub enum RawTransactionVariant { diff --git a/crates/p2p_proto/proto/common.proto b/crates/p2p_proto/proto/common.proto index e40def4879..8e20c11f89 100644 --- a/crates/p2p_proto/proto/common.proto +++ b/crates/p2p_proto/proto/common.proto @@ -22,13 +22,18 @@ message PeerID { bytes id = 1; } +message Uint128 { + uint64 low = 1; + uint64 high = 2; +} + message ConsensusSignature { Felt252 r = 1; Felt252 s = 2; } message Merkle { - uint32 n_leaves = 1; // needed to know the height, so as to how many nodes to expect in a proof. + uint64 n_leaves = 1; // needed to know the height, so as to how many nodes to expect in a proof. // and also when receiving all leaves, how many to expect Hash root = 2; } @@ -43,6 +48,11 @@ message BlockID { Hash header = 2; } +enum L1DataAvailabilityMode { + Calldata = 0; + Blob = 1; +} + message Iteration { enum Direction { Forward = 0; diff --git a/crates/p2p_proto/proto/header.proto b/crates/p2p_proto/proto/header.proto index be6c21fb67..246965aa7b 100644 --- a/crates/p2p_proto/proto/header.proto +++ b/crates/p2p_proto/proto/header.proto @@ -7,26 +7,30 @@ package starknet.header; // Note: commitments may change to be for the previous blocks like comet/tendermint // hash of block header sent to L1 message SignedBlockHeader { - starknet.common.Hash block_hash = 1; // For the structure of the block hash, see https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/header/#block_hash - starknet.common.Hash parent_hash = 2; - uint64 number = 3; - uint64 time = 4; // Encoded in Unix time. - starknet.common.Address sequencer_address = 5; - starknet.common.Hash state_diff_commitment = 6; // The state diff commitment returned by the Starknet Feeder Gateway. + starknet.common.Hash block_hash = 1; // For the structure of the block hash, see https://docs.starknet.io/documentation/architecture_and_concepts/Network_Architecture/header/#block_hash + starknet.common.Hash parent_hash = 2; + uint64 number = 3; + uint64 time = 4; // Encoded in Unix time. + starknet.common.Address sequencer_address = 5; + starknet.common.Hash state_diff_commitment = 6; // The state diff commitment returned by the Starknet Feeder Gateway. // For more info, see https://community.starknet.io/t/introducing-p2p-authentication-and-mismatch-resolution-in-v0-12-2/97993 - starknet.common.Patricia state = 7; // hash of contract and class patricia tries. Same as in L1. Later more trees will be included + starknet.common.Patricia state = 7; // hash of contract and class patricia tries. Same as in L1. Later more trees will be included // The following merkles can be built on the fly while sequencing/validating txs. - starknet.common.Merkle transactions = 8; // By order of execution. TBD: required? the client can execute (powerful machine) and match state diff - starknet.common.Merkle events = 9; // By order of issuance. TBD: in receipts? - starknet.common.Merkle receipts = 10; // By order of issuance. - string protocol_version = 11; // Starknet version - starknet.common.Felt252 gas_price = 12; - uint64 num_storage_diffs = 13; - uint64 num_nonce_updates = 14; - uint64 num_declared_classes = 15; // Includes both Cairo 0 and Cairo 1. - uint64 num_deployed_contracts = 16; // This includes the replaced classes too. + starknet.common.Merkle transactions = 8; // By order of execution. TBD: required? the client can execute (powerful machine) and match state diff + starknet.common.Merkle events = 9; // By order of issuance. TBD: in receipts? + starknet.common.Merkle receipts = 10; // By order of issuance. + string protocol_version = 11; // Starknet version + starknet.common.Uint128 gas_price_fri = 12; + starknet.common.Uint128 gas_price_wei = 13; + starknet.common.Uint128 data_gas_price_fri = 14; + starknet.common.Uint128 data_gas_price_wei = 15; + starknet.common.L1DataAvailabilityMode l1_data_availability_mode = 16; + uint64 num_storage_diffs = 17; + uint64 num_nonce_updates = 18; + uint64 num_declared_classes = 19; // Includes both Cairo 0 and Cairo 1. + uint64 num_deployed_contracts = 20; // This includes the replaced classes too. // for now, we assume a small consensus, so this fits in 1M. Else, these will be repeated and extracted from this message. - repeated starknet.common.ConsensusSignature signatures = 17; // + repeated starknet.common.ConsensusSignature signatures = 21; // can be more explicit here about the signature structure as this is not part of account abstraction } diff --git a/crates/p2p_proto/proto/receipt.proto b/crates/p2p_proto/proto/receipt.proto index bf8d6f412a..c53287f099 100644 --- a/crates/p2p_proto/proto/receipt.proto +++ b/crates/p2p_proto/proto/receipt.proto @@ -26,9 +26,11 @@ message Receipt { uint32 output = 8; } - BuiltinCounter builtins = 1; - uint32 steps = 2; - uint32 memory_holes = 3; + BuiltinCounter builtins = 1; + uint32 steps = 2; + uint32 memory_holes = 3; + starknet.common.Felt252 l1_gas = 4; + starknet.common.Felt252 l1_data_gas = 5; } message Common { diff --git a/crates/p2p_proto/src/common.rs b/crates/p2p_proto/src/common.rs index b37f79d173..bcd5156ed0 100644 --- a/crates/p2p_proto/src/common.rs +++ b/crates/p2p_proto/src/common.rs @@ -27,7 +27,7 @@ pub struct ConsensusSignature { #[derive(Debug, Copy, Clone, PartialEq, Eq, ToProtobuf, TryFromProtobuf, Dummy, Default)] #[protobuf(name = "crate::proto::common::Merkle")] pub struct Merkle { - pub n_leaves: u32, + pub n_leaves: u64, pub root: Hash, } @@ -48,6 +48,12 @@ pub struct BlockId { pub hash: Hash, } +#[derive(Debug, Copy, Clone, PartialEq, Eq, Dummy)] +pub enum L1DataAvailabilityMode { + Calldata, + Blob, +} + #[derive(Debug, Copy, Clone, PartialEq, Eq, ToProtobuf, TryFromProtobuf, Dummy)] #[protobuf(name = "crate::proto::common::Iteration")] pub struct Iteration { @@ -154,6 +160,26 @@ impl Display for BlockId { } } +impl ToProtobuf for L1DataAvailabilityMode { + fn to_protobuf(self) -> i32 { + use proto::common::L1DataAvailabilityMode::{Blob, Calldata}; + match self { + L1DataAvailabilityMode::Calldata => Calldata as i32, + L1DataAvailabilityMode::Blob => Blob as i32, + } + } +} + +impl TryFromProtobuf for L1DataAvailabilityMode { + fn try_from_protobuf(input: i32, _: &'static str) -> Result { + use proto::common::L1DataAvailabilityMode::{Blob, Calldata}; + Ok(match TryFrom::try_from(input)? { + Calldata => L1DataAvailabilityMode::Calldata, + Blob => L1DataAvailabilityMode::Blob, + }) + } +} + impl ToProtobuf for PeerId { fn to_protobuf(self) -> proto::common::PeerId { proto::common::PeerId { @@ -177,6 +203,24 @@ impl TryFromProtobuf for PeerId { } } +impl ToProtobuf for u128 { + fn to_protobuf(self) -> proto::common::Uint128 { + proto::common::Uint128 { + low: (self & 0xFFFF_FFFF_FFFF_FFFF) as u64, + high: (self >> 64) as u64, + } + } +} + +impl TryFromProtobuf for u128 { + fn try_from_protobuf( + input: proto::common::Uint128, + _: &'static str, + ) -> Result { + Ok((input.high as u128) << 64 | input.low as u128) + } +} + impl From for BlockNumberOrHash { fn from(x: u64) -> Self { Self::Number(x) diff --git a/crates/p2p_proto/src/header.rs b/crates/p2p_proto/src/header.rs index 515268a4bc..59f7c4b9f0 100644 --- a/crates/p2p_proto/src/header.rs +++ b/crates/p2p_proto/src/header.rs @@ -1,7 +1,8 @@ -use crate::common::{Address, BlockId, ConsensusSignature, Hash, Iteration, Merkle, Patricia}; +use crate::common::{ + Address, BlockId, ConsensusSignature, Hash, Iteration, L1DataAvailabilityMode, Merkle, Patricia, +}; use crate::{proto, proto_field, ToProtobuf, TryFromProtobuf}; use fake::{Dummy, Fake, Faker}; -use pathfinder_crypto::Felt; use std::time::SystemTime; #[derive(Debug, Clone, PartialEq, Eq, ToProtobuf, TryFromProtobuf)] @@ -18,7 +19,11 @@ pub struct SignedBlockHeader { pub events: Merkle, pub receipts: Merkle, pub protocol_version: String, - pub gas_price: Felt, + pub gas_price_fri: u128, + pub gas_price_wei: u128, + pub data_gas_price_fri: u128, + pub data_gas_price_wei: u128, + pub l1_data_availability_mode: L1DataAvailabilityMode, pub num_storage_diffs: u64, pub num_nonce_updates: u64, pub num_declared_classes: u64, @@ -62,7 +67,11 @@ impl Dummy for SignedBlockHeader { events: Faker.fake_with_rng(rng), receipts: Faker.fake_with_rng(rng), protocol_version: Faker.fake_with_rng(rng), - gas_price: Faker.fake_with_rng(rng), + gas_price_fri: Faker.fake_with_rng(rng), + gas_price_wei: Faker.fake_with_rng(rng), + data_gas_price_fri: Faker.fake_with_rng(rng), + data_gas_price_wei: Faker.fake_with_rng(rng), + l1_data_availability_mode: Faker.fake_with_rng(rng), num_storage_diffs: Faker.fake_with_rng(rng), num_nonce_updates: Faker.fake_with_rng(rng), num_declared_classes: Faker.fake_with_rng(rng), diff --git a/crates/p2p_proto/src/receipt.rs b/crates/p2p_proto/src/receipt.rs index f1c5f98704..946cb6c70f 100644 --- a/crates/p2p_proto/src/receipt.rs +++ b/crates/p2p_proto/src/receipt.rs @@ -23,6 +23,8 @@ pub struct ExecutionResources { pub builtins: execution_resources::BuiltinCounter, pub steps: u32, pub memory_holes: u32, + pub l1_gas: Felt, + pub l1_data_gas: Felt, } pub mod execution_resources { diff --git a/crates/pathfinder/src/p2p_network/client/conv.rs b/crates/pathfinder/src/p2p_network/client/conv.rs index 8f45447929..606b5a58a7 100644 --- a/crates/pathfinder/src/p2p_network/client/conv.rs +++ b/crates/pathfinder/src/p2p_network/client/conv.rs @@ -64,7 +64,7 @@ impl TryFrom for SignedBlockHeader { .ok_or(anyhow::anyhow!("block number > i64::MAX"))?, timestamp: BlockTimestamp::new(dto.time) .ok_or(anyhow::anyhow!("block timestamp > i64::MAX"))?, - eth_l1_gas_price: dto.gas_price.into(), + eth_l1_gas_price: todo!(), sequencer_address: SequencerAddress(dto.sequencer_address.0), starknet_version: dto.protocol_version.into(), event_commitment: EventCommitment(dto.events.root.0), diff --git a/crates/pathfinder/src/p2p_network/sync_handlers.rs b/crates/pathfinder/src/p2p_network/sync_handlers.rs index c7900b8f16..77b382d8b5 100644 --- a/crates/pathfinder/src/p2p_network/sync_handlers.rs +++ b/crates/pathfinder/src/p2p_network/sync_handlers.rs @@ -170,11 +170,15 @@ fn get_header( root: Hash(Felt::ZERO), // TODO }, protocol_version: header.starknet_version.take_inner(), - gas_price: Felt::from_u128(header.eth_l1_gas_price.0), + gas_price_fri: todo!(), + gas_price_wei: todo!(), + data_gas_price_fri: todo!(), + data_gas_price_wei: todo!(), num_storage_diffs: 0, // TODO num_nonce_updates: 0, // TODO num_declared_classes: 0, // TODO num_deployed_contracts: 0, // TODO + l1_data_availability_mode: todo!(), signatures: vec![ConsensusSignature { r: signature.r.0, s: signature.s.0, diff --git a/crates/pathfinder/src/p2p_network/sync_handlers/conv.rs b/crates/pathfinder/src/p2p_network/sync_handlers/conv.rs index 0fa19945c6..0833160365 100644 --- a/crates/pathfinder/src/p2p_network/sync_handlers/conv.rs +++ b/crates/pathfinder/src/p2p_network/sync_handlers/conv.rs @@ -202,7 +202,8 @@ impl ToDto for (CommonTransaction, CommonReceipt) { }) .collect(), execution_resources: { - let e = self.1.execution_resources.clone().unwrap_or_default(); + let e = self.1.execution_resources.unwrap_or_default(); + let da = e.data_availability.unwrap_or_default(); // Assumption: the values are small enough to fit into u32 ExecutionResources { builtins: BuiltinCounter { @@ -241,6 +242,8 @@ impl ToDto for (CommonTransaction, CommonReceipt) { }, steps: e.n_steps.try_into().unwrap(), memory_holes: e.n_memory_holes.try_into().unwrap(), + l1_gas: da.l1_gas.into(), + l1_data_gas: da.l1_data_gas.into(), } }, revert_reason, diff --git a/crates/storage/src/connection/transaction.rs b/crates/storage/src/connection/transaction.rs index dc73f655b5..6f8c0447ef 100644 --- a/crates/storage/src/connection/transaction.rs +++ b/crates/storage/src/connection/transaction.rs @@ -422,12 +422,18 @@ pub(crate) mod dto { impl Dummy for ExecutionResources { fn dummy_with_rng(_: &T, rng: &mut R) -> Self { + let (l1_gas, l1_data_gas) = if rng.gen() { + (Some(rng.next_u32() as u128), Some(rng.next_u32() as u128)) + } else { + (None, None) + }; + Self { builtin_instance_counter: Faker.fake_with_rng(rng), n_steps: rng.next_u32() as u64, n_memory_holes: rng.next_u32() as u64, - l1_gas: Some(rng.next_u32() as u128), - l1_data_gas: Some(rng.next_u32() as u128), + l1_gas, + l1_data_gas, } } } From e5b36cdb7fdb536b3f4f43790dca931fec3cb5e1 Mon Sep 17 00:00:00 2001 From: Krzysztof Lis Date: Tue, 20 Feb 2024 15:55:44 +0100 Subject: [PATCH 2/4] feat(pathfinder): update sync_handlers --- crates/p2p/src/client/types.rs | 33 +++- .../pathfinder/src/p2p_network/client/conv.rs | 180 +----------------- .../src/p2p_network/sync_handlers.rs | 20 +- .../src/p2p_network/sync_handlers/tests.rs | 92 ++++----- 4 files changed, 91 insertions(+), 234 deletions(-) diff --git a/crates/p2p/src/client/types.rs b/crates/p2p/src/client/types.rs index b045025ae4..0187db6ff0 100644 --- a/crates/p2p/src/client/types.rs +++ b/crates/p2p/src/client/types.rs @@ -15,9 +15,9 @@ use pathfinder_common::{ AccountDeploymentDataElem, BlockCommitmentSignature, BlockCommitmentSignatureElem, BlockHash, BlockNumber, BlockTimestamp, CallParam, CasmHash, ClassHash, ConstructorParam, ContractAddress, ContractAddressSalt, EntryPoint, EthereumAddress, EventCommitment, EventData, EventKey, Fee, - GasPrice, L2ToL1MessagePayloadElem, PaymasterDataElem, SequencerAddress, StarknetVersion, - StateCommitment, Tip, TransactionCommitment, TransactionHash, TransactionNonce, - TransactionSignatureElem, TransactionVersion, + GasPrice, L1DataAvailabilityMode, L2ToL1MessagePayloadElem, PaymasterDataElem, + SequencerAddress, StarknetVersion, StateCommitment, Tip, TransactionCommitment, + TransactionHash, TransactionNonce, TransactionSignatureElem, TransactionVersion, }; use pathfinder_crypto::Felt; @@ -37,6 +37,9 @@ pub struct SignedBlockHeader { pub number: BlockNumber, pub timestamp: BlockTimestamp, pub eth_l1_gas_price: GasPrice, + pub strk_l1_gas_price: GasPrice, + pub eth_l1_data_gas_price: GasPrice, + pub strk_l1_data_gas_price: GasPrice, pub sequencer_address: SequencerAddress, pub starknet_version: StarknetVersion, pub event_commitment: EventCommitment, @@ -44,6 +47,7 @@ pub struct SignedBlockHeader { pub transaction_commitment: TransactionCommitment, pub transaction_count: usize, pub event_count: usize, + pub l1_da_mode: L1DataAvailabilityMode, pub signature: BlockCommitmentSignature, } @@ -68,7 +72,10 @@ impl TryFrom for SignedBlockHeader { .ok_or(anyhow::anyhow!("block number > i64::MAX"))?, timestamp: BlockTimestamp::new(dto.time) .ok_or(anyhow::anyhow!("block timestamp > i64::MAX"))?, - eth_l1_gas_price: todo!(), + eth_l1_gas_price: GasPrice(dto.gas_price_wei), + strk_l1_gas_price: GasPrice(dto.gas_price_fri), + eth_l1_data_gas_price: GasPrice(dto.data_gas_price_wei), + strk_l1_data_gas_price: GasPrice(dto.data_gas_price_fri), sequencer_address: SequencerAddress(dto.sequencer_address.0), starknet_version: dto.protocol_version.into(), event_commitment: EventCommitment(dto.events.root.0), @@ -76,6 +83,7 @@ impl TryFrom for SignedBlockHeader { transaction_commitment: TransactionCommitment(dto.transactions.root.0), transaction_count: dto.transactions.n_leaves.try_into()?, event_count: dto.events.n_leaves.try_into()?, + l1_da_mode: TryFromDto::try_from_dto(dto.l1_data_availability_mode)?, signature, }) } @@ -99,6 +107,9 @@ impl number: header.number, timestamp: header.timestamp, eth_l1_gas_price: header.eth_l1_gas_price, + strk_l1_gas_price: header.strk_l1_gas_price, + eth_l1_data_gas_price: header.eth_l1_data_gas_price, + strk_l1_data_gas_price: header.strk_l1_data_gas_price, sequencer_address: header.sequencer_address, starknet_version: header.starknet_version, event_commitment: header.event_commitment, @@ -106,6 +117,7 @@ impl transaction_commitment: header.transaction_commitment, transaction_count: header.transaction_count, event_count: header.event_count, + l1_da_mode: header.l1_da_mode, signature, } } @@ -573,3 +585,16 @@ impl TryFromDto for DataAvailabilityMode { } } } + +impl TryFromDto for L1DataAvailabilityMode { + fn try_from_dto(dto: p2p_proto::common::L1DataAvailabilityMode) -> anyhow::Result + where + Self: Sized, + { + use p2p_proto::common::L1DataAvailabilityMode::{Blob, Calldata}; + Ok(match dto { + Calldata => Self::Calldata, + Blob => Self::Blob, + }) + } +} diff --git a/crates/pathfinder/src/p2p_network/client/conv.rs b/crates/pathfinder/src/p2p_network/client/conv.rs index 606b5a58a7..e5686cedb6 100644 --- a/crates/pathfinder/src/p2p_network/client/conv.rs +++ b/crates/pathfinder/src/p2p_network/client/conv.rs @@ -1,21 +1,9 @@ use std::borrow::Cow; -use anyhow::{Context, Ok}; +use anyhow::Context; use cairo_lang_starknet_classes::casm_contract_class::CasmContractClass; -use p2p_proto::{ - class::{Cairo0Class, Cairo1Class}, - receipt::{ - DeclareTransactionReceipt, DeployAccountTransactionReceipt, DeployTransactionReceipt, - InvokeTransactionReceipt, L1HandlerTransactionReceipt, - }, -}; -use pathfinder_common::{ - receipt::{BuiltinCounters, ExecutionResources, ExecutionStatus, L2ToL1Message}, - BlockCommitmentSignature, BlockCommitmentSignatureElem, BlockHash, BlockNumber, BlockTimestamp, - ByteCodeOffset, CasmHash, ClassHash, ContractAddress, EntryPoint, EthereumAddress, - EventCommitment, Fee, GasPrice, L2ToL1MessagePayloadElem, SequencerAddress, SierraHash, - StarknetVersion, StateCommitment, TransactionCommitment, TransactionHash, -}; +use p2p_proto::class::{Cairo0Class, Cairo1Class}; +use pathfinder_common::{ByteCodeOffset, CasmHash, ClassHash, EntryPoint, SierraHash}; use pathfinder_crypto::Felt; use serde::Deserialize; use serde_json::value::RawValue; @@ -25,168 +13,6 @@ use starknet_gateway_types::{ request::contract::{SelectorAndFunctionIndex, SelectorAndOffset}, }; -/// Represents a simplified [`pathfinder_common::SignedBlockHeader`], ie. excluding class commitment and storage commitment. -#[derive(Debug, Clone, PartialEq, Eq)] -pub struct SignedBlockHeader { - pub hash: BlockHash, - pub parent_hash: BlockHash, - pub number: BlockNumber, - pub timestamp: BlockTimestamp, - pub eth_l1_gas_price: GasPrice, - pub sequencer_address: SequencerAddress, - pub starknet_version: StarknetVersion, - pub event_commitment: EventCommitment, - pub state_commitment: StateCommitment, - pub transaction_commitment: TransactionCommitment, - pub transaction_count: usize, - pub event_count: usize, - pub signature: BlockCommitmentSignature, -} - -impl TryFrom for SignedBlockHeader { - type Error = anyhow::Error; - - fn try_from(dto: p2p_proto::header::SignedBlockHeader) -> Result { - anyhow::ensure!(dto.signatures.len() == 1, "expected exactly one signature"); - let signature = dto - .signatures - .into_iter() - .map(|sig| BlockCommitmentSignature { - r: BlockCommitmentSignatureElem(sig.r), - s: BlockCommitmentSignatureElem(sig.s), - }) - .next() - .expect("exactly one element"); - Ok(SignedBlockHeader { - hash: BlockHash(dto.block_hash.0), - parent_hash: BlockHash(dto.parent_hash.0), - number: BlockNumber::new(dto.number) - .ok_or(anyhow::anyhow!("block number > i64::MAX"))?, - timestamp: BlockTimestamp::new(dto.time) - .ok_or(anyhow::anyhow!("block timestamp > i64::MAX"))?, - eth_l1_gas_price: todo!(), - sequencer_address: SequencerAddress(dto.sequencer_address.0), - starknet_version: dto.protocol_version.into(), - event_commitment: EventCommitment(dto.events.root.0), - state_commitment: StateCommitment(dto.state.root.0), - transaction_commitment: TransactionCommitment(dto.transactions.root.0), - transaction_count: dto.transactions.n_leaves.try_into()?, - event_count: dto.events.n_leaves.try_into()?, - signature, - }) - } -} - -impl - From<( - pathfinder_common::BlockHeader, - pathfinder_common::BlockCommitmentSignature, - )> for SignedBlockHeader -{ - fn from( - (header, signature): ( - pathfinder_common::BlockHeader, - pathfinder_common::BlockCommitmentSignature, - ), - ) -> Self { - Self { - hash: header.hash, - parent_hash: header.parent_hash, - number: header.number, - timestamp: header.timestamp, - eth_l1_gas_price: header.eth_l1_gas_price, - sequencer_address: header.sequencer_address, - starknet_version: header.starknet_version, - event_commitment: header.event_commitment, - state_commitment: header.state_commitment, - transaction_commitment: header.transaction_commitment, - transaction_count: header.transaction_count, - event_count: header.event_count, - signature, - } - } -} - -/// Represents a simplified [`pathfinder_common::receipt::Receipt`] (events and transaction index excluded). -#[derive(Clone, Default, Debug, PartialEq)] -pub struct Receipt { - pub actual_fee: Option, - pub execution_resources: Option, - pub l2_to_l1_messages: Vec, - pub execution_status: ExecutionStatus, - pub transaction_hash: TransactionHash, -} - -impl From for Receipt { - fn from(x: pathfinder_common::receipt::Receipt) -> Self { - Self { - transaction_hash: x.transaction_hash, - actual_fee: x.actual_fee, - execution_resources: x.execution_resources, - l2_to_l1_messages: x.l2_to_l1_messages, - execution_status: x.execution_status, - } - } -} - -impl TryFrom for Receipt { - type Error = anyhow::Error; - - fn try_from(proto: p2p_proto::receipt::Receipt) -> anyhow::Result - where - Self: Sized, - { - use p2p_proto::receipt::Receipt::{Declare, Deploy, DeployAccount, Invoke, L1Handler}; - - match proto { - Invoke(InvokeTransactionReceipt { common }) - | Declare(DeclareTransactionReceipt { common }) - | L1Handler(L1HandlerTransactionReceipt { common, .. }) - | Deploy(DeployTransactionReceipt { common, .. }) - | DeployAccount(DeployAccountTransactionReceipt { common, .. }) => Ok(Self { - transaction_hash: TransactionHash(common.transaction_hash.0), - actual_fee: Some(Fee(common.actual_fee)), - execution_resources: Some(ExecutionResources { - builtin_instance_counter: BuiltinCounters { - output_builtin: common.execution_resources.builtins.output.into(), - pedersen_builtin: common.execution_resources.builtins.pedersen.into(), - range_check_builtin: common.execution_resources.builtins.range_check.into(), - ecdsa_builtin: common.execution_resources.builtins.ecdsa.into(), - bitwise_builtin: common.execution_resources.builtins.bitwise.into(), - ec_op_builtin: common.execution_resources.builtins.ec_op.into(), - keccak_builtin: common.execution_resources.builtins.keccak.into(), - poseidon_builtin: common.execution_resources.builtins.poseidon.into(), - segment_arena_builtin: 0, - }, - n_steps: common.execution_resources.steps.into(), - n_memory_holes: common.execution_resources.memory_holes.into(), - data_availability: None, - }), - l2_to_l1_messages: common - .messages_sent - .into_iter() - .map(|x| L2ToL1Message { - from_address: ContractAddress(x.from_address), - payload: x - .payload - .into_iter() - .map(L2ToL1MessagePayloadElem) - .collect(), - to_address: EthereumAddress(x.to_address.0), - }) - .collect(), - execution_status: if common.revert_reason.is_empty() { - ExecutionStatus::Succeeded - } else { - ExecutionStatus::Reverted { - reason: common.revert_reason, - } - }, - }), - } - } -} - pub fn cairo_hash_and_def_from_dto(c0: Cairo0Class) -> anyhow::Result<(ClassHash, Vec)> { let from_dto = |x: Vec| { x.into_iter() diff --git a/crates/pathfinder/src/p2p_network/sync_handlers.rs b/crates/pathfinder/src/p2p_network/sync_handlers.rs index 77b382d8b5..5335bcc310 100644 --- a/crates/pathfinder/src/p2p_network/sync_handlers.rs +++ b/crates/pathfinder/src/p2p_network/sync_handlers.rs @@ -3,8 +3,8 @@ use futures::channel::mpsc; use futures::SinkExt; use p2p_proto::class::{Class, ClassesRequest, ClassesResponse}; use p2p_proto::common::{ - Address, BlockNumberOrHash, ConsensusSignature, Direction, Hash, Iteration, Merkle, Patricia, - Step, + Address, BlockNumberOrHash, ConsensusSignature, Direction, Hash, Iteration, + L1DataAvailabilityMode, Merkle, Patricia, Step, }; use p2p_proto::event::{EventsRequest, EventsResponse}; use p2p_proto::header::{BlockHeadersRequest, BlockHeadersResponse, SignedBlockHeader}; @@ -170,15 +170,21 @@ fn get_header( root: Hash(Felt::ZERO), // TODO }, protocol_version: header.starknet_version.take_inner(), - gas_price_fri: todo!(), - gas_price_wei: todo!(), - data_gas_price_fri: todo!(), - data_gas_price_wei: todo!(), + gas_price_wei: header.eth_l1_gas_price.0, + gas_price_fri: header.strk_l1_gas_price.0, + data_gas_price_wei: header.eth_l1_data_gas_price.0, + data_gas_price_fri: header.strk_l1_data_gas_price.0, num_storage_diffs: 0, // TODO num_nonce_updates: 0, // TODO num_declared_classes: 0, // TODO num_deployed_contracts: 0, // TODO - l1_data_availability_mode: todo!(), + l1_data_availability_mode: { + use pathfinder_common::L1DataAvailabilityMode::{Blob, Calldata}; + match header.l1_da_mode { + Calldata => L1DataAvailabilityMode::Calldata, + Blob => L1DataAvailabilityMode::Blob, + } + }, signatures: vec![ConsensusSignature { r: signature.r.0, s: signature.s.0, diff --git a/crates/pathfinder/src/p2p_network/sync_handlers/tests.rs b/crates/pathfinder/src/p2p_network/sync_handlers/tests.rs index 5567adb77f..592177e6ba 100644 --- a/crates/pathfinder/src/p2p_network/sync_handlers/tests.rs +++ b/crates/pathfinder/src/p2p_network/sync_handlers/tests.rs @@ -95,17 +95,18 @@ mod boundary_conditions { /// Property tests, grouped to be immediately visible when executed mod prop { - use crate::p2p_network::client::conv::{ - cairo_def_from_dto, sierra_defs_from_dto, SignedBlockHeader as P2PSignedBlockHeader, - }; + use crate::p2p_network::client::conv::{cairo_def_from_dto, sierra_defs_from_dto}; use crate::p2p_network::sync_handlers; use futures::channel::mpsc; use futures::StreamExt; - use p2p::client::types::{RawTransactionVariant, TryFromDto}; + use p2p::client::types::{ + RawTransactionVariant, Receipt, SignedBlockHeader as P2PSignedBlockHeader, TryFromDto, + }; use p2p_proto::class::{Class, ClassesRequest, ClassesResponse}; use p2p_proto::common::{BlockNumberOrHash, Iteration}; use p2p_proto::event::{EventsRequest, EventsResponse}; use p2p_proto::header::{BlockHeadersRequest, BlockHeadersResponse}; + use p2p_proto::receipt::{ReceiptsRequest, ReceiptsResponse}; use p2p_proto::state::{ ContractDiff, ContractStoredValue, StateDiffsRequest, StateDiffsResponse, }; @@ -393,48 +394,47 @@ mod prop { } } - // FIXME: commented out until data_availability gets added to P2P receipt protobuf - // proptest! { - // #[test] - // fn get_receipts((num_blocks, seed, start_block, limit, step, direction) in strategy::composite()) { - // // Fake storage with a given number of blocks - // let (storage, in_db) = fixtures::storage_with_seed(seed, num_blocks); - // // Compute the overlapping set between the db and the request - // // These are the receipts that we expect to be read from the db - // // Grouped by block number - // let expected = overlapping::get(in_db, start_block, limit, step, num_blocks, direction).into_iter() - // .map(|(h, _, tr, _, _, _)| - // ( - // // Block number - // h.number, - // // List of receipts - // tr.into_iter().map(|(_, r)| P2PReceipt::from(r)).collect::>() - // ) - // ).collect::>(); - // // Run the handler - // let request = ReceiptsRequest { iteration: Iteration { start: BlockNumberOrHash::Number(start_block), limit, step, direction, } }; - // let mut responses = Runtime::new().unwrap().block_on(async { - // let (tx, rx) = mpsc::channel(0); - // let getter_fut = sync_handlers::get_receipts(storage, request, tx); - // let (_, responses) = tokio::join!(getter_fut, rx.collect::>()); - // responses - // }); - - // // Make sure the last reply is Fin - // assert_eq!(responses.pop().unwrap(), ReceiptsResponse::Fin); - - // // Check the rest - // let mut actual = responses.into_iter().map(|response| match response { - // ReceiptsResponse::Receipt(receipt) => P2PReceipt::try_from(receipt).unwrap(), - // _ => panic!("unexpected response"), - // }).collect::>(); - - // for expected_for_block in expected { - // let actual_for_block = actual.drain(..expected_for_block.1.len()).collect::>(); - // prop_assert_eq_sorted!(expected_for_block.1, actual_for_block, "block number: {}", expected_for_block.0); - // } - // } - // } + proptest! { + #[test] + fn get_receipts((num_blocks, seed, start_block, limit, step, direction) in strategy::composite()) { + // Fake storage with a given number of blocks + let (storage, in_db) = fixtures::storage_with_seed(seed, num_blocks); + // Compute the overlapping set between the db and the request + // These are the receipts that we expect to be read from the db + // Grouped by block number + let expected = overlapping::get(in_db, start_block, limit, step, num_blocks, direction).into_iter() + .map(|(h, _, tr, _, _, _)| + ( + // Block number + h.number, + // List of receipts + tr.into_iter().map(|(_, r)| Receipt::from(r)).collect::>() + ) + ).collect::>(); + // Run the handler + let request = ReceiptsRequest { iteration: Iteration { start: BlockNumberOrHash::Number(start_block), limit, step, direction, } }; + let mut responses = Runtime::new().unwrap().block_on(async { + let (tx, rx) = mpsc::channel(0); + let getter_fut = sync_handlers::get_receipts(storage, request, tx); + let (_, responses) = tokio::join!(getter_fut, rx.collect::>()); + responses + }); + + // Make sure the last reply is Fin + assert_eq!(responses.pop().unwrap(), ReceiptsResponse::Fin); + + // Check the rest + let mut actual = responses.into_iter().map(|response| match response { + ReceiptsResponse::Receipt(receipt) => Receipt::try_from(receipt).unwrap(), + _ => panic!("unexpected response"), + }).collect::>(); + + for expected_for_block in expected { + let actual_for_block = actual.drain(..expected_for_block.1.len()).collect::>(); + prop_assert_eq_sorted!(expected_for_block.1, actual_for_block, "block number: {}", expected_for_block.0); + } + } + } proptest! { #[test] From 751183e6ac9367fd407c33b21d29bd42df27511e Mon Sep 17 00:00:00 2001 From: Krzysztof Lis Date: Tue, 20 Feb 2024 16:11:03 +0100 Subject: [PATCH 3/4] chore(p2p_network): move type conversion into one module --- .../src/p2p_network/sync_handlers.rs | 91 ++----------------- .../src/p2p_network/sync_handlers/conv.rs | 88 +++++++++++++++++- 2 files changed, 91 insertions(+), 88 deletions(-) diff --git a/crates/pathfinder/src/p2p_network/sync_handlers.rs b/crates/pathfinder/src/p2p_network/sync_handlers.rs index 5335bcc310..5ba5d3f3e2 100644 --- a/crates/pathfinder/src/p2p_network/sync_handlers.rs +++ b/crates/pathfinder/src/p2p_network/sync_handlers.rs @@ -3,8 +3,8 @@ use futures::channel::mpsc; use futures::SinkExt; use p2p_proto::class::{Class, ClassesRequest, ClassesResponse}; use p2p_proto::common::{ - Address, BlockNumberOrHash, ConsensusSignature, Direction, Hash, Iteration, - L1DataAvailabilityMode, Merkle, Patricia, Step, + Address, BlockNumberOrHash, ConsensusSignature, Direction, Hash, Iteration, Merkle, Patricia, + Step, }; use p2p_proto::event::{EventsRequest, EventsResponse}; use p2p_proto::header::{BlockHeadersRequest, BlockHeadersResponse, SignedBlockHeader}; @@ -23,6 +23,8 @@ mod tests; use conv::ToDto; +use self::conv::{cairo_def_into_dto, sierra_def_into_dto}; + #[cfg(not(test))] const MAX_BLOCKS_COUNT: u64 = 100; @@ -178,13 +180,7 @@ fn get_header( num_nonce_updates: 0, // TODO num_declared_classes: 0, // TODO num_deployed_contracts: 0, // TODO - l1_data_availability_mode: { - use pathfinder_common::L1DataAvailabilityMode::{Blob, Calldata}; - match header.l1_da_mode { - Calldata => L1DataAvailabilityMode::Calldata, - Blob => L1DataAvailabilityMode::Blob, - } - }, + l1_data_availability_mode: header.l1_da_mode.to_dto(), signatures: vec![ConsensusSignature { r: signature.r.0, s: signature.s.0, @@ -241,7 +237,7 @@ fn get_classes_for_block( let cairo_class = serde_json::from_slice::>(&definition)?; Class::Cairo0 { - class: def_into_dto::cairo(cairo_class), + class: cairo_def_into_dto(cairo_class), domain: 0, // TODO class_hash: Hash(class_hash.0), } @@ -250,7 +246,7 @@ fn get_classes_for_block( let sierra_class = serde_json::from_slice::>(&sierra)?; Class::Cairo1 { - class: def_into_dto::sierra(sierra_class, casm), + class: sierra_def_into_dto(sierra_class, casm), domain: 0, // TODO class_hash: Hash(class_hash.0), } @@ -494,76 +490,3 @@ fn get_next_block_number( .and_then(BlockNumber::new), } } - -mod def_into_dto { - use p2p_proto::class::{ - Cairo0Class, Cairo1Class, Cairo1EntryPoints, EntryPoint, SierraEntryPoint, - }; - use starknet_gateway_types::request::contract::{SelectorAndFunctionIndex, SelectorAndOffset}; - - pub fn sierra(sierra: super::class_definition::Sierra<'_>, compiled: Vec) -> Cairo1Class { - let into_dto = |x: SelectorAndFunctionIndex| SierraEntryPoint { - selector: x.selector.0, - index: x.function_idx, - }; - - let entry_points = Cairo1EntryPoints { - externals: sierra - .entry_points_by_type - .external - .into_iter() - .map(into_dto) - .collect(), - l1_handlers: sierra - .entry_points_by_type - .l1_handler - .into_iter() - .map(into_dto) - .collect(), - constructors: sierra - .entry_points_by_type - .constructor - .into_iter() - .map(into_dto) - .collect(), - }; - - Cairo1Class { - abi: sierra.abi.as_bytes().to_owned(), - program: sierra.sierra_program, - entry_points, - compiled, // TODO not sure if encoding in storage and dto is the same - contract_class_version: sierra.contract_class_version.into(), - } - } - - pub fn cairo(cairo: super::class_definition::Cairo<'_>) -> Cairo0Class { - let into_dto = |x: SelectorAndOffset| EntryPoint { - selector: x.selector.0, - offset: x.offset.0, - }; - - Cairo0Class { - abi: cairo.abi.get().as_bytes().to_owned(), - externals: cairo - .entry_points_by_type - .external - .into_iter() - .map(into_dto) - .collect(), - l1_handlers: cairo - .entry_points_by_type - .l1_handler - .into_iter() - .map(into_dto) - .collect(), - constructors: cairo - .entry_points_by_type - .constructor - .into_iter() - .map(into_dto) - .collect(), - program: cairo.program.get().as_bytes().to_owned(), - } - } -} diff --git a/crates/pathfinder/src/p2p_network/sync_handlers/conv.rs b/crates/pathfinder/src/p2p_network/sync_handlers/conv.rs index 0833160365..7568dcb4cd 100644 --- a/crates/pathfinder/src/p2p_network/sync_handlers/conv.rs +++ b/crates/pathfinder/src/p2p_network/sync_handlers/conv.rs @@ -1,4 +1,5 @@ //! Workaround for the orphan rule - implement conversion fns for types ourside our crate. +use p2p_proto::class::{Cairo0Class, Cairo1Class, Cairo1EntryPoints, EntryPoint, SierraEntryPoint}; use p2p_proto::common::{Address, Hash}; use p2p_proto::receipt::EthereumAddress; use p2p_proto::receipt::{ @@ -7,12 +8,15 @@ use p2p_proto::receipt::{ InvokeTransactionReceipt, L1HandlerTransactionReceipt, MessageToL1, ReceiptCommon, }; use p2p_proto::transaction::{AccountSignature, ResourceBounds}; -use pathfinder_common::receipt::Receipt as CommonReceipt; +use pathfinder_common::receipt::Receipt; use pathfinder_common::transaction::DataAvailabilityMode; -use pathfinder_common::transaction::Transaction as CommonTransaction; use pathfinder_common::{event::Event, transaction::ResourceBound, transaction::Transaction}; -use pathfinder_common::{AccountDeploymentDataElem, PaymasterDataElem, TransactionHash}; +use pathfinder_common::{ + AccountDeploymentDataElem, L1DataAvailabilityMode, PaymasterDataElem, TransactionHash, +}; use pathfinder_crypto::Felt; +use starknet_gateway_types::class_definition::{Cairo, Sierra}; +use starknet_gateway_types::request::contract::{SelectorAndFunctionIndex, SelectorAndOffset}; /// Convert pathfinder common (ie. core) type to a p2p dto type pub trait ToDto { @@ -184,7 +188,7 @@ impl ToDto for Transaction { } } -impl ToDto for (CommonTransaction, CommonReceipt) { +impl ToDto for (Transaction, Receipt) { fn to_dto(self) -> p2p_proto::receipt::Receipt { use p2p_proto::receipt::Receipt::{Declare, Deploy, DeployAccount, Invoke, L1Handler}; let revert_reason = self.1.revert_reason().unwrap_or_default(); @@ -310,3 +314,79 @@ impl ToDto for DataAvailabilityMode { } } } + +impl ToDto for L1DataAvailabilityMode { + fn to_dto(self) -> p2p_proto::common::L1DataAvailabilityMode { + use p2p_proto::common::L1DataAvailabilityMode::{Blob, Calldata}; + match self { + L1DataAvailabilityMode::Calldata => Calldata, + L1DataAvailabilityMode::Blob => Blob, + } + } +} + +pub fn sierra_def_into_dto(sierra: Sierra<'_>, compiled: Vec) -> Cairo1Class { + let into_dto = |x: SelectorAndFunctionIndex| SierraEntryPoint { + selector: x.selector.0, + index: x.function_idx, + }; + + let entry_points = Cairo1EntryPoints { + externals: sierra + .entry_points_by_type + .external + .into_iter() + .map(into_dto) + .collect(), + l1_handlers: sierra + .entry_points_by_type + .l1_handler + .into_iter() + .map(into_dto) + .collect(), + constructors: sierra + .entry_points_by_type + .constructor + .into_iter() + .map(into_dto) + .collect(), + }; + + Cairo1Class { + abi: sierra.abi.as_bytes().to_owned(), + program: sierra.sierra_program, + entry_points, + compiled, // TODO not sure if encoding in storage and dto is the same + contract_class_version: sierra.contract_class_version.into(), + } +} + +pub fn cairo_def_into_dto(cairo: Cairo<'_>) -> Cairo0Class { + let into_dto = |x: SelectorAndOffset| EntryPoint { + selector: x.selector.0, + offset: x.offset.0, + }; + + Cairo0Class { + abi: cairo.abi.get().as_bytes().to_owned(), + externals: cairo + .entry_points_by_type + .external + .into_iter() + .map(into_dto) + .collect(), + l1_handlers: cairo + .entry_points_by_type + .l1_handler + .into_iter() + .map(into_dto) + .collect(), + constructors: cairo + .entry_points_by_type + .constructor + .into_iter() + .map(into_dto) + .collect(), + program: cairo.program.get().as_bytes().to_owned(), + } +} From dc31aa513b2208d6328ba87eb7d165d39894522b Mon Sep 17 00:00:00 2001 From: Krzysztof Lis Date: Tue, 20 Feb 2024 18:07:42 +0100 Subject: [PATCH 4/4] chore: clippy --- crates/p2p_proto/src/lib.rs | 1 + crates/p2p_proto/src/receipt.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/crates/p2p_proto/src/lib.rs b/crates/p2p_proto/src/lib.rs index d989ece45f..e3b951959d 100644 --- a/crates/p2p_proto/src/lib.rs +++ b/crates/p2p_proto/src/lib.rs @@ -14,6 +14,7 @@ pub mod proto { pub mod header { include!(concat!(env!("OUT_DIR"), "/starknet.header.rs")); } + #[allow(clippy::large_enum_variant)] pub mod receipt { include!(concat!(env!("OUT_DIR"), "/starknet.receipt.rs")); } diff --git a/crates/p2p_proto/src/receipt.rs b/crates/p2p_proto/src/receipt.rs index 946cb6c70f..c2205d5789 100644 --- a/crates/p2p_proto/src/receipt.rs +++ b/crates/p2p_proto/src/receipt.rs @@ -103,6 +103,7 @@ pub struct ReceiptsRequest { pub iteration: Iteration, } +#[allow(clippy::large_enum_variant)] #[derive(Debug, Default, Clone, PartialEq, Eq, Dummy)] pub enum ReceiptsResponse { Receipt(Receipt),