Skip to content

Commit

Permalink
consensus: make gas_limit u64 for transactions (#1382)
Browse files Browse the repository at this point in the history
Make gas_limit u64 for transactions
  • Loading branch information
tcoratger authored Sep 26, 2024
1 parent 8f7cf55 commit e01492a
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 42 deletions.
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct TxEip1559 {
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas_limit: u128,
pub gas_limit: u64,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
/// this transaction. This is paid up-front, before any
Expand Down Expand Up @@ -272,7 +272,7 @@ impl Transaction for TxEip1559 {
self.nonce
}

fn gas_limit(&self) -> u128 {
fn gas_limit(&self) -> u64 {
self.gas_limit
}

Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct TxEip2930 {
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas_limit: u128,
pub gas_limit: u64,
/// The 160-bit address of the message call’s recipient or, for a contract creation
/// transaction, ∅, used here to denote the only member of B0 ; formally Tt.
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "TxKind::is_create"))]
Expand Down Expand Up @@ -236,7 +236,7 @@ impl Transaction for TxEip2930 {
self.nonce
}

fn gas_limit(&self) -> u128 {
fn gas_limit(&self) -> u64 {
self.gas_limit
}

Expand Down
8 changes: 4 additions & 4 deletions crates/consensus/src/transaction/eip4844.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ impl Transaction for TxEip4844Variant {
}
}

fn gas_limit(&self) -> u128 {
fn gas_limit(&self) -> u64 {
match self {
Self::TxEip4844(tx) => tx.gas_limit,
Self::TxEip4844WithSidecar(tx) => tx.tx().gas_limit,
Expand Down Expand Up @@ -351,7 +351,7 @@ pub struct TxEip4844 {
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas_limit: u128,
pub gas_limit: u64,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
/// this transaction. This is paid up-front, before any
Expand Down Expand Up @@ -693,7 +693,7 @@ impl Transaction for TxEip4844 {
self.nonce
}

fn gas_limit(&self) -> u128 {
fn gas_limit(&self) -> u64 {
self.gas_limit
}

Expand Down Expand Up @@ -966,7 +966,7 @@ impl Transaction for TxEip4844WithSidecar {
self.tx.nonce()
}

fn gas_limit(&self) -> u128 {
fn gas_limit(&self) -> u64 {
self.tx.gas_limit()
}

Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/eip7702.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub struct TxEip7702 {
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas_limit: u128,
pub gas_limit: u64,
/// A scalar value equal to the maximum
/// amount of gas that should be used in executing
/// this transaction. This is paid up-front, before any
Expand Down Expand Up @@ -282,7 +282,7 @@ impl Transaction for TxEip7702 {
self.nonce
}

fn gas_limit(&self) -> u128 {
fn gas_limit(&self) -> u64 {
self.gas_limit
}

Expand Down
6 changes: 3 additions & 3 deletions crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ impl Transaction for TxEnvelope {
}
}

fn gas_limit(&self) -> u128 {
fn gas_limit(&self) -> u64 {
match self {
Self::Legacy(tx) => tx.tx().gas_limit(),
Self::Eip2930(tx) => tx.tx().gas_limit(),
Expand Down Expand Up @@ -918,7 +918,7 @@ mod tests {
chain_id: u64::MAX,
nonce: u64::MAX,
gas_price: u128::MAX,
gas_limit: u128::MAX,
gas_limit: u64::MAX,
to: Address::random().into(),
value: U256::MAX,
input: Bytes::new(),
Expand Down Expand Up @@ -976,7 +976,7 @@ mod tests {
let tx = TxEip7702 {
chain_id: u64::MAX,
nonce: u64::MAX,
gas_limit: u128::MAX,
gas_limit: u64::MAX,
max_fee_per_gas: u128::MAX,
max_priority_fee_per_gas: u128::MAX,
to: Address::random(),
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct TxLegacy {
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas_limit: u128,
pub gas_limit: u64,
/// The 160-bit address of the message call’s recipient or, for a contract creation
/// transaction, ∅, used here to denote the only member of B0 ; formally Tt.
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "TxKind::is_create"))]
Expand Down Expand Up @@ -214,7 +214,7 @@ impl Transaction for TxLegacy {
self.nonce
}

fn gas_limit(&self) -> u128 {
fn gas_limit(&self) -> u64 {
self.gas_limit
}

Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pub trait Transaction: any::Any + Send + Sync + 'static {
fn nonce(&self) -> u64;

/// Get `gas_limit`.
fn gas_limit(&self) -> u128;
fn gas_limit(&self) -> u64;

/// Get `gas_price`.
fn gas_price(&self) -> Option<u128>;
Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/transaction/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ impl Transaction for TypedTransaction {
}
}

fn gas_limit(&self) -> u128 {
fn gas_limit(&self) -> u64 {
match self {
Self::Legacy(tx) => tx.gas_limit(),
Self::Eip2930(tx) => tx.gas_limit(),
Expand Down
4 changes: 2 additions & 2 deletions crates/contract/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ impl<T: Transport + Clone, P: Provider<T, N>, D: CallDecoder, N: Network> CallBu
}

/// Sets the `gas` field in the transaction to the provided value
pub fn gas(mut self, gas: u128) -> Self {
pub fn gas(mut self, gas: u64) -> Self {
self.request.set_gas_limit(gas);
self
}
Expand Down Expand Up @@ -432,7 +432,7 @@ impl<T: Transport + Clone, P: Provider<T, N>, D: CallDecoder, N: Network> CallBu

/// Returns the estimated gas cost for the underlying transaction to be executed
/// If [`state overrides`](Self::state) are set, they will be applied to the gas estimation.
pub async fn estimate_gas(&self) -> Result<u128> {
pub async fn estimate_gas(&self) -> Result<u64> {
let mut estimate = self.provider.estimate_gas(&self.request);
if let Some(state) = &self.state {
estimate = estimate.overrides(state);
Expand Down
4 changes: 2 additions & 2 deletions crates/genesis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub struct Genesis {
pub extra_data: Bytes,
/// The genesis header gas limit.
#[serde(with = "alloy_serde::quantity")]
pub gas_limit: u128,
pub gas_limit: u64,
/// The genesis header difficulty.
pub difficulty: U256,
/// The genesis header mix hash.
Expand Down Expand Up @@ -144,7 +144,7 @@ impl Genesis {
}

/// Set the gas limit.
pub const fn with_gas_limit(mut self, gas_limit: u128) -> Self {
pub const fn with_gas_limit(mut self, gas_limit: u64) -> Self {
self.gas_limit = gas_limit;
self
}
Expand Down
4 changes: 2 additions & 2 deletions crates/network-primitives/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ pub trait TransactionResponse {
fn gas_price(&self) -> Option<u128>;

/// Gas limit
fn gas(&self) -> u128;
fn gas(&self) -> u64;

/// Max BaseFeePerGas the user is willing to pay
fn max_fee_per_gas(&self) -> Option<u128>;
Expand Down Expand Up @@ -235,7 +235,7 @@ impl<T: TransactionResponse> TransactionResponse for WithOtherFields<T> {
self.inner.gas_price()
}

fn gas(&self) -> u128 {
fn gas(&self) -> u64 {
self.inner.gas()
}

Expand Down
4 changes: 2 additions & 2 deletions crates/network/src/any/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ impl TransactionBuilder<AnyNetwork> for WithOtherFields<TransactionRequest> {
self.deref_mut().set_max_priority_fee_per_gas(max_priority_fee_per_gas);
}

fn gas_limit(&self) -> Option<u128> {
fn gas_limit(&self) -> Option<u64> {
self.deref().gas_limit()
}

fn set_gas_limit(&mut self, gas_limit: u128) {
fn set_gas_limit(&mut self, gas_limit: u64) {
self.deref_mut().set_gas_limit(gas_limit);
}

Expand Down
4 changes: 2 additions & 2 deletions crates/network/src/ethereum/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ impl TransactionBuilder<Ethereum> for TransactionRequest {
self.max_priority_fee_per_gas = Some(max_priority_fee_per_gas);
}

fn gas_limit(&self) -> Option<u128> {
fn gas_limit(&self) -> Option<u64> {
self.gas
}

fn set_gas_limit(&mut self, gas_limit: u128) {
fn set_gas_limit(&mut self, gas_limit: u64) {
self.gas = Some(gas_limit);
}

Expand Down
6 changes: 3 additions & 3 deletions crates/network/src/transaction/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ pub trait TransactionBuilder<N: Network>: Default + Sized + Send + Sync + 'stati
self
}
/// Get the gas limit for the transaction.
fn gas_limit(&self) -> Option<u128>;
fn gas_limit(&self) -> Option<u64>;

/// Set the gas limit for the transaction.
fn set_gas_limit(&mut self, gas_limit: u128);
fn set_gas_limit(&mut self, gas_limit: u64);

/// Builder-pattern method for setting the gas limit.
fn with_gas_limit(mut self, gas_limit: u128) -> Self {
fn with_gas_limit(mut self, gas_limit: u64) -> Self {
self.set_gas_limit(gas_limit);
self
}
Expand Down
4 changes: 2 additions & 2 deletions crates/provider/src/fillers/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use futures::FutureExt;
#[doc(hidden)]
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum GasFillable {
Legacy { gas_limit: u128, gas_price: u128 },
Eip1559 { gas_limit: u128, estimate: Eip1559Estimation },
Legacy { gas_limit: u64, gas_price: u128 },
Eip1559 { gas_limit: u64, estimate: Eip1559Estimation },
}

/// A [`TxFiller`] that populates gas related fields in transaction requests if
Expand Down
7 changes: 2 additions & 5 deletions crates/provider/src/provider/trait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,8 @@ pub trait Provider<T: Transport + Clone = BoxTransport, N: Network = Ethereum>:
/// # Note
///
/// Not all client implementations support state overrides for eth_estimateGas.
fn estimate_gas<'req>(
&self,
tx: &'req N::TransactionRequest,
) -> EthCall<'req, T, N, U128, u128> {
EthCall::gas_estimate(self.weak_client(), tx).map_resp(utils::convert_u128)
fn estimate_gas<'req>(&self, tx: &'req N::TransactionRequest) -> EthCall<'req, T, N, U64, u64> {
EthCall::gas_estimate(self.weak_client(), tx).map_resp(utils::convert_u64)
}

/// Estimates the EIP1559 `maxFeePerGas` and `maxPriorityFeePerGas` fields.
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc-types-eth/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct Transaction {
pub gas_price: Option<u128>,
/// Gas amount
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas: u128,
pub gas: u64,
/// Max BaseFeePerGas the user is willing to pay.
#[cfg_attr(
feature = "serde",
Expand Down Expand Up @@ -377,7 +377,7 @@ impl TransactionResponse for Transaction {
self.gas_price
}

fn gas(&self) -> u128 {
fn gas(&self) -> u64 {
self.gas
}

Expand Down
4 changes: 2 additions & 2 deletions crates/rpc-types-eth/src/transaction/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pub struct TransactionRequest {
with = "alloy_serde::quantity::opt"
)
)]
pub gas: Option<u128>,
pub gas: Option<u64>,
/// The value transferred in the transaction, in wei.
#[cfg_attr(feature = "serde", serde(default, skip_serializing_if = "Option::is_none"))]
pub value: Option<U256>,
Expand Down Expand Up @@ -149,7 +149,7 @@ impl TransactionRequest {
}

/// Sets the gas limit for the transaction.
pub const fn gas_limit(mut self, gas_limit: u128) -> Self {
pub const fn gas_limit(mut self, gas_limit: u64) -> Self {
self.gas = Some(gas_limit);
self
}
Expand Down
2 changes: 1 addition & 1 deletion crates/signer-trezor/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ impl TrezorSigner {
let gas_price = u128_to_trezor(gas_price);

let gas_limit = tx.gas_limit();
let gas_limit = u128_to_trezor(gas_limit);
let gas_limit = u64_to_trezor(gas_limit);

let to = match tx.to() {
TxKind::Call(to) => address_to_trezor(&to),
Expand Down

0 comments on commit e01492a

Please sign in to comment.