Skip to content

Commit

Permalink
Merge pull request #1661 from eqlabs/chris/rm-extra-p2p-txn-fields
Browse files Browse the repository at this point in the history
remove extra p2p txn fields
  • Loading branch information
CHr15F0x authored Jan 4, 2024
2 parents 43d4db7 + 4ccc8d8 commit 320b55a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 53 deletions.
34 changes: 32 additions & 2 deletions crates/gateway-types/src/reply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ pub mod transaction {
}
}

#[derive(Clone, Debug, Serialize, PartialEq, Eq, Dummy)]
#[derive(Clone, Debug, Serialize, PartialEq, Eq)]
#[serde(tag = "version")]
pub enum DeclareTransaction {
#[serde(rename = "0x0")]
Expand Down Expand Up @@ -1161,6 +1161,22 @@ pub mod transaction {
}
}

impl<T> Dummy<T> for DeclareTransaction {
fn dummy_with_rng<R: rand::Rng + ?Sized>(_: &T, rng: &mut R) -> Self {
match rng.gen_range(0..=3) {
0 => {
let mut v0: DeclareTransactionV0V1 = Faker.fake_with_rng(rng);
v0.nonce = TransactionNonce::ZERO;
Self::V0(v0)
}
1 => Self::V1(Faker.fake_with_rng(rng)),
2 => Self::V2(Faker.fake_with_rng(rng)),
3 => Self::V3(Faker.fake_with_rng(rng)),
_ => unreachable!(),
}
}
}

/// A version 0 or 1 declare transaction.
#[serde_as]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Dummy)]
Expand Down Expand Up @@ -1463,7 +1479,7 @@ pub mod transaction {

/// Represents deserialized L2 invoke transaction v0 data.
#[serde_as]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Dummy)]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
#[serde(deny_unknown_fields)]
pub struct InvokeTransactionV0 {
#[serde_as(as = "Vec<CallParamAsDecimalStr>")]
Expand All @@ -1483,6 +1499,20 @@ pub mod transaction {
pub transaction_hash: TransactionHash,
}

impl<T> Dummy<T> for InvokeTransactionV0 {
fn dummy_with_rng<R: rand::Rng + ?Sized>(_: &T, rng: &mut R) -> Self {
Self {
calldata: Faker.fake_with_rng(rng),
sender_address: Faker.fake_with_rng(rng),
entry_point_selector: Faker.fake_with_rng(rng),
entry_point_type: None,
max_fee: Faker.fake_with_rng(rng),
signature: Faker.fake_with_rng(rng),
transaction_hash: Faker.fake_with_rng(rng),
}
}
}

/// Represents deserialized L2 invoke transaction v1 data.
#[serde_as]
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, Dummy)]
Expand Down
12 changes: 3 additions & 9 deletions crates/p2p/src/client/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use pathfinder_common::signature::BlockCommitmentSignature;
use pathfinder_common::state_update::SystemContractUpdate;
use pathfinder_common::transaction::{
DataAvailabilityMode, DeclareTransactionV0V1, DeclareTransactionV2, DeclareTransactionV3,
DeployAccountTransactionV0V1, DeployAccountTransactionV3, DeployTransaction, EntryPointType,
DeployAccountTransactionV0V1, DeployAccountTransactionV3, DeployTransaction,
InvokeTransactionV0, InvokeTransactionV1, InvokeTransactionV3, L1HandlerTransaction,
ResourceBound, ResourceBounds, TransactionVariant,
};
Expand Down Expand Up @@ -201,7 +201,7 @@ impl TryFromDto<p2p_proto::transaction::Transaction> for TransactionVariant {
DeclareV0(x) => TransactionVariant::DeclareV0(DeclareTransactionV0V1 {
class_hash: ClassHash(x.class_hash.0),
max_fee: Fee(x.max_fee),
nonce: TransactionNonce(x.nonce),
nonce: TransactionNonce::ZERO,
sender_address: ContractAddress(x.sender.0),
signature: x
.signature
Expand Down Expand Up @@ -305,13 +305,7 @@ impl TryFromDto<p2p_proto::transaction::Transaction> for TransactionVariant {
calldata: x.calldata.into_iter().map(CallParam).collect(),
sender_address: ContractAddress(x.address.0),
entry_point_selector: EntryPoint(x.entry_point_selector),
entry_point_type: x.entry_point_type.map(|x| {
use p2p_proto::transaction::EntryPointType::{External, L1Handler};
match x {
External => EntryPointType::External,
L1Handler => EntryPointType::L1Handler,
}
}),
entry_point_type: None,
max_fee: Fee(x.max_fee),
signature: x
.signature
Expand Down
11 changes: 0 additions & 11 deletions crates/p2p_proto/proto/transaction.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ message Transaction
starknet.common.Felt252 max_fee = 2;
AccountSignature signature = 3;
starknet.common.Hash class_hash = 4;
// FIXME added missing field
// example:
// https://alpha4.starknet.io/feeder_gateway/get_transaction?transactionHash=0x6d346ba207eb124355960c19c737698ad37a3c920a588b741e0130ff5bd4d6d
starknet.common.Felt252 nonce = 5;
}

message DeclareV1 {
Expand Down Expand Up @@ -104,13 +100,6 @@ message Transaction
starknet.common.Address address = 3;
starknet.common.Felt252 entry_point_selector = 4;
repeated starknet.common.Felt252 calldata = 5;
// FIXME added missing fields
optional EntryPointType entry_point_type = 6;
}

enum EntryPointType {
EXTERNAL = 0;
L1_HANDLER = 1;
}

message InvokeV1 {
Expand Down
23 changes: 0 additions & 23 deletions crates/p2p_proto/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub struct DeclareV0 {
pub max_fee: Felt,
pub signature: AccountSignature,
pub class_hash: Hash,
pub nonce: Felt,
}

#[derive(Debug, Clone, PartialEq, Eq, ToProtobuf, TryFromProtobuf, Dummy)]
Expand Down Expand Up @@ -119,9 +118,6 @@ pub struct InvokeV0 {
pub address: Address,
pub entry_point_selector: Felt,
pub calldata: Vec<Felt>,
// FIXME added missing field
#[optional]
pub entry_point_type: Option<EntryPointType>,
}

#[derive(Debug, Clone, PartialEq, Eq, Dummy)]
Expand Down Expand Up @@ -326,22 +322,3 @@ impl TryFromProtobuf<proto::transaction::transactions_response::Responses>
}
}
}

impl ToProtobuf<i32> for EntryPointType {
fn to_protobuf(self) -> i32 {
match self {
EntryPointType::External => 0,
EntryPointType::L1Handler => 1,
}
}
}

impl TryFromProtobuf<i32> for EntryPointType {
fn try_from_protobuf(input: i32, _: &'static str) -> Result<Self, std::io::Error> {
use proto::transaction::transaction::EntryPointType::{External, L1Handler};
Ok(match TryFrom::try_from(input)? {
External => Self::External,
L1Handler => Self::L1Handler,
})
}
}
8 changes: 0 additions & 8 deletions crates/pathfinder/src/p2p_network/sync_handlers/conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ impl ToProto<p2p_proto::transaction::Transaction> for Transaction {
parts: x.signature.into_iter().map(|s| s.0).collect(),
},
class_hash: Hash(x.class_hash.0),
nonce: x.nonce.0,
}),
DeclareV1(x) => proto::Transaction::DeclareV1(proto::DeclareV1 {
sender: Address(x.sender_address.0),
Expand Down Expand Up @@ -220,13 +219,6 @@ impl ToProto<p2p_proto::transaction::Transaction> for Transaction {
address: Address(x.sender_address.0),
entry_point_selector: x.entry_point_selector.0,
calldata: x.calldata.into_iter().map(|c| c.0).collect(),
entry_point_type: x.entry_point_type.map(|e| {
use pathfinder_common::transaction::EntryPointType::{External, L1Handler};
match e {
External => proto::EntryPointType::External,
L1Handler => proto::EntryPointType::L1Handler,
}
}),
}),
InvokeV1(x) => proto::Transaction::InvokeV1(proto::InvokeV1 {
sender: Address(x.sender_address.0),
Expand Down

0 comments on commit 320b55a

Please sign in to comment.