Skip to content

Commit

Permalink
refactor(papyrus_protobuf): fix MempoolTransaction types (#3853)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlonLStarkWare authored Feb 2, 2025
1 parent 4398000 commit 6230a33
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 101 deletions.
91 changes: 1 addition & 90 deletions crates/papyrus_protobuf/src/converters/rpc_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,14 @@ mod rpc_transaction_test;
use prost::Message;
use starknet_api::rpc_transaction::{
RpcDeclareTransaction,
RpcDeclareTransactionV3,
RpcDeployAccountTransaction,
RpcDeployAccountTransactionV3,
RpcInvokeTransaction,
RpcInvokeTransactionV3,
RpcTransaction,
};
use starknet_api::transaction::fields::{AllResourceBounds, ValidResourceBounds};
use starknet_api::transaction::{
DeclareTransactionV3,
DeployAccountTransactionV3,
InvokeTransactionV3,
};
use starknet_api::transaction::{DeployAccountTransactionV3, InvokeTransactionV3};

use super::ProtobufConversionError;
use crate::auto_impl_into_and_try_from_vec_u8;
Expand Down Expand Up @@ -86,90 +81,6 @@ impl From<RpcTransaction> for protobuf::MempoolTransaction {
}
}

impl TryFrom<protobuf::mempool_transaction::DeclareV3> for RpcDeclareTransactionV3 {
type Error = ProtobufConversionError;
fn try_from(value: protobuf::mempool_transaction::DeclareV3) -> Result<Self, Self::Error> {
let declare_v3 = value.declare_v3.ok_or(ProtobufConversionError::MissingField {
field_description: "DeclareV3::declare_v3",
})?;
let contract_class = value
.contract_class
.ok_or(ProtobufConversionError::MissingField {
field_description: "DeclareV3::contract_class",
})?
.try_into()?;
let DeclareTransactionV3 {
sender_address,
compiled_class_hash,
signature,
nonce,
resource_bounds,
class_hash: _,
tip,
paymaster_data,
account_deployment_data,
nonce_data_availability_mode,
fee_data_availability_mode,
} = declare_v3.try_into()?;

let resource_bounds = match resource_bounds {
ValidResourceBounds::AllResources(resource_bounds) => resource_bounds,
ValidResourceBounds::L1Gas(resource_bounds) => AllResourceBounds {
l1_gas: resource_bounds,
l2_gas: Default::default(),
l1_data_gas: Default::default(),
},
};

Ok(Self {
sender_address,
compiled_class_hash,
signature,
nonce,
contract_class,
resource_bounds,
tip,
paymaster_data,
account_deployment_data,
nonce_data_availability_mode,
fee_data_availability_mode,
})
}
}

impl From<RpcDeclareTransactionV3> for protobuf::mempool_transaction::DeclareV3 {
fn from(value: RpcDeclareTransactionV3) -> Self {
let RpcDeclareTransactionV3 {
sender_address,
compiled_class_hash,
signature,
nonce,
contract_class,
resource_bounds,
tip,
paymaster_data,
account_deployment_data,
nonce_data_availability_mode,
fee_data_availability_mode,
} = value;
let declare_v3 = DeclareTransactionV3 {
resource_bounds: ValidResourceBounds::AllResources(resource_bounds),
tip,
signature,
nonce,
// TODO(Eitan): refactor the protobuf transaction to not have class_hash
class_hash: Default::default(),
compiled_class_hash,
sender_address,
nonce_data_availability_mode,
fee_data_availability_mode,
paymaster_data,
account_deployment_data,
};
Self { contract_class: Some(contract_class.into()), declare_v3: Some(declare_v3.into()) }
}
}

impl TryFrom<protobuf::transaction::DeployAccountV3> for RpcDeployAccountTransactionV3 {
type Error = ProtobufConversionError;
fn try_from(value: protobuf::transaction::DeployAccountV3) -> Result<Self, Self::Error> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,16 @@ import "p2p/proto/class.proto";
import "p2p/proto/common.proto";
import "p2p/proto/transaction.proto";
import "p2p/proto/sync/transaction.proto";
// TODO(alonl): remove this import (used only for the old Transaction struct as an intermediate step)
import "p2p/proto/consensus/consensus.proto";


option go_package = "github.com/starknet-io/starknet-p2pspecs/p2p/proto/mempool/transaction";

// Doesn't contain L1Handler, as those don't need to be propagated and can be downloaded from L1.
message MempoolTransaction {
message DeclareV3 {
// TODO(alonl): change declare_v3 type to TransactionInBlock.DeclareV3WithoutClass (defined in sync/transaction.proto)
Transaction.DeclareV3 declare_v3 = 1;
Cairo1Class contract_class = 2;
}

oneof txn {
DeclareV3 declare_v3 = 1;
Transaction.DeployAccountV3 deploy_account_v3 = 2;
Transaction.InvokeV3 invoke_v3 = 3;
DeclareV3WithClass declare_v3 = 1;
DeployAccountV3 deploy_account_v3 = 2;
InvokeV3 invoke_v3 = 3;
}
Hash transaction_hash = 4;
}

0 comments on commit 6230a33

Please sign in to comment.