Skip to content

Commit

Permalink
chore(blockifier): remove duplicacy tip() and resource_bounds() in Ac…
Browse files Browse the repository at this point in the history
…countTransaction
  • Loading branch information
avivg-starkware committed Nov 27, 2024
1 parent cc87eaf commit eb22856
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 44 deletions.
12 changes: 10 additions & 2 deletions crates/blockifier/src/transaction/account_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,14 @@ pub struct AccountTransaction {
only_query: bool,
}
// TODO(AvivG): create additional macro that returns a reference.
macro_rules! implement_tx_getter_calls {
($(($field:ident, $field_type:ty)),*) => {
$(pub fn $field(&self) -> $field_type {
self.tx.$field()
})*
};
}

macro_rules! implement_account_tx_inner_getters {
($(($field:ident, $field_type:ty)),*) => {
$(pub fn $field(&self) -> $field_type {
Expand Down Expand Up @@ -142,11 +150,11 @@ impl HasRelatedFeeType for AccountTransaction {
}

impl AccountTransaction {
implement_tx_getter_calls!((resource_bounds, ValidResourceBounds), (tip, Tip));

implement_account_tx_inner_getters!(
(signature, TransactionSignature),
(nonce, Nonce),
(resource_bounds, ValidResourceBounds),
(tip, Tip),
(nonce_data_availability_mode, DataAvailabilityMode),
(fee_data_availability_mode, DataAvailabilityMode),
(paymaster_data, PaymasterData)
Expand Down
51 changes: 14 additions & 37 deletions crates/starknet_api/src/executable_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ macro_rules! implement_getter_calls {
};
}

macro_rules! implement_account_tx_inner_getters {
($(($field:ident, $field_type:ty)),*) => {
$(pub fn $field(&self) -> $field_type {
match self {
AccountTransaction::Declare(tx) => tx.tx.$field().clone(),
AccountTransaction::DeployAccount(tx) => tx.tx.$field().clone(),
AccountTransaction::Invoke(tx) => tx.tx.$field().clone(),
}
})*
};
}

/// Represents a paid Starknet transaction.
#[derive(Clone, Debug, Deserialize, Eq, PartialEq, Serialize)]
pub enum AccountTransaction {
Expand All @@ -48,6 +60,8 @@ pub enum AccountTransaction {
}

impl AccountTransaction {
implement_account_tx_inner_getters!((resource_bounds, ValidResourceBounds), (tip, Tip));

pub fn contract_address(&self) -> ContractAddress {
match self {
AccountTransaction::Declare(tx_data) => tx_data.tx.sender_address(),
Expand Down Expand Up @@ -75,43 +89,6 @@ impl AccountTransaction {
AccountTransaction::Invoke(tx_data) => tx_data.tx_hash,
}
}

// TODO(Mohammad): add a getter macro.
pub fn tip(&self) -> Option<Tip> {
match self {
AccountTransaction::Declare(declare_tx) => match &declare_tx.tx {
crate::transaction::DeclareTransaction::V3(tx_v3) => Some(tx_v3.tip),
_ => None,
},
AccountTransaction::DeployAccount(deploy_account_tx) => match &deploy_account_tx.tx {
crate::transaction::DeployAccountTransaction::V3(tx_v3) => Some(tx_v3.tip),
_ => None,
},
AccountTransaction::Invoke(invoke_tx) => match &invoke_tx.tx {
crate::transaction::InvokeTransaction::V3(tx_v3) => Some(tx_v3.tip),
_ => None,
},
}
}

pub fn resource_bounds(&self) -> Option<&ValidResourceBounds> {
match self {
AccountTransaction::Declare(declare_tx) => match &declare_tx.tx {
crate::transaction::DeclareTransaction::V3(tx_v3) => Some(&tx_v3.resource_bounds),
_ => None,
},
AccountTransaction::DeployAccount(deploy_account_tx) => match &deploy_account_tx.tx {
crate::transaction::DeployAccountTransaction::V3(tx_v3) => {
Some(&tx_v3.resource_bounds)
}
_ => None,
},
AccountTransaction::Invoke(invoke_tx) => match &invoke_tx.tx {
crate::transaction::InvokeTransaction::V3(tx_v3) => Some(&tx_v3.resource_bounds),
_ => None,
},
}
}
}

// TODO: add a converter for Declare transactions as well.
Expand Down
7 changes: 2 additions & 5 deletions crates/starknet_mempool/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,11 @@ impl Mempool {

// TODO(Elin): move to a shared location with other next-gen node crates.
fn tip(tx: &AccountTransaction) -> Tip {
tx.tip().expect("Expected a valid tip value.")
tx.tip()
}

fn max_l2_gas_price(tx: &AccountTransaction) -> GasPrice {
tx.resource_bounds()
.expect("Expected a valid resource bounds value.")
.get_l2_bounds()
.max_price_per_unit
tx.resource_bounds().get_l2_bounds().max_price_per_unit
}

/// Provides a lightweight representation of a transaction for mempool usage (e.g., excluding
Expand Down

0 comments on commit eb22856

Please sign in to comment.