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

chore(blockifier): remove dupl tip() and resource_bounds() in AccountTx #2101

Merged
Merged
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
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
Loading