Skip to content

Commit 5413aef

Browse files
committed
add comments
1 parent c175336 commit 5413aef

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

crates/ingress-rpc/src/validation.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ use op_revm::{OpSpecId, l1block::L1BlockInfo};
1010
use reth_optimism_evm::extract_l1_info_from_tx;
1111
use reth_rpc_eth_types::{EthApiError, RpcInvalidTransactionError};
1212

13+
/// Account info for a given address
1314
pub struct AccountInfo {
1415
pub balance: U256,
1516
pub nonce: u64,
1617
pub code_hash: B256,
1718
}
1819

20+
/// Interface for fetching account info for a given address
1921
#[async_trait]
2022
pub trait AccountInfoLookup: Send + Sync {
2123
async fn fetch_account_info(&self, address: Address) -> Result<AccountInfo>;
2224
}
2325

26+
/// Implementation of the `AccountInfoLookup` trait for the `RootProvider`
2427
#[async_trait]
2528
impl AccountInfoLookup for RootProvider<Optimism> {
2629
async fn fetch_account_info(&self, address: Address) -> Result<AccountInfo> {
@@ -33,11 +36,13 @@ impl AccountInfoLookup for RootProvider<Optimism> {
3336
}
3437
}
3538

39+
/// Interface for fetching L1 block info for a given block number
3640
#[async_trait]
3741
pub trait L1BlockInfoLookup: Send + Sync {
3842
async fn fetch_l1_block_info(&self) -> Result<L1BlockInfo>;
3943
}
4044

45+
/// Implementation of the `L1BlockInfoLookup` trait for the `RootProvider`
4146
#[async_trait]
4247
impl L1BlockInfoLookup for RootProvider<Optimism> {
4348
async fn fetch_l1_block_info(&self) -> Result<L1BlockInfo> {
@@ -62,6 +67,13 @@ impl L1BlockInfoLookup for RootProvider<Optimism> {
6267
}
6368
}
6469

70+
/// Helper function to validate a transaction. A valid transaction must satisfy the following criteria:
71+
/// - If the transaction is not EIP-4844
72+
/// - If the transaction is not a cross chain tx
73+
/// - If the transaction is a 7702 tx, then the account is a 7702 account
74+
/// - If the transaction's nonce is the latest
75+
/// - If the transaction's execution cost is less than the account's balance
76+
/// - If the transaction's L1 gas cost is less than the account's balance
6577
pub async fn validate_tx<T: Transaction>(
6678
account: AccountInfo,
6779
txn: &Recovered<T>,

0 commit comments

Comments
 (0)