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

Numeric type audit: network, consensus, provider, rpc-types #454

Merged
merged 13 commits into from
Apr 5, 2024
8 changes: 4 additions & 4 deletions crates/consensus/src/transaction/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub struct TxEip1559 {
/// this transaction. This is paid up-front, before any
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
pub gas_limit: u64,
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
pub gas_limit: u128,
/// 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 @@ -273,11 +273,11 @@ impl Transaction for TxEip1559 {
self.nonce
}

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

fn gas_price(&self) -> Option<U256> {
fn gas_price(&self) -> Option<u128> {
None
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/consensus/src/transaction/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub struct TxEip2930 {
/// this transaction. This is paid up-front, before any
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
pub gas_limit: u64,
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do any endpoints use decimal here? in other PRs we've avoided allowing decimal when nobody actually uses it

pub gas_limit: u128,
/// 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 @@ -237,12 +237,12 @@ impl Transaction for TxEip2930 {
self.nonce
}

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

fn gas_price(&self) -> Option<U256> {
Some(U256::from(self.gas_price))
fn gas_price(&self) -> Option<u128> {
Some(self.gas_price)
}
}

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

fn gas_limit(&self) -> u64 {
fn gas_limit(&self) -> u128 {
match self {
TxEip4844Variant::TxEip4844(tx) => tx.gas_limit,
TxEip4844Variant::TxEip4844WithSidecar(tx) => tx.tx().gas_limit,
}
}

fn gas_price(&self) -> Option<U256> {
fn gas_price(&self) -> Option<u128> {
None
}

Expand Down Expand Up @@ -333,8 +333,8 @@ pub struct TxEip4844 {
/// this transaction. This is paid up-front, before any
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
pub gas_limit: u64,
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
pub gas_limit: u128,
/// 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 @@ -716,11 +716,11 @@ impl Transaction for TxEip4844 {
self.nonce
}

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

fn gas_price(&self) -> Option<U256> {
fn gas_price(&self) -> Option<u128> {
None
}
}
Expand Down Expand Up @@ -931,11 +931,11 @@ impl Transaction for TxEip4844WithSidecar {
self.tx.chain_id()
}

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

fn gas_price(&self) -> Option<U256> {
fn gas_price(&self) -> Option<u128> {
self.tx.gas_price()
}

Expand Down
2 changes: 1 addition & 1 deletion crates/consensus/src/transaction/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ mod tests {
chain_id: u64::MAX,
nonce: u64::MAX,
gas_price: u128::MAX,
gas_limit: u64::MAX,
gas_limit: u128::MAX,
to: TxKind::Call(Address::random()),
value: U256::MAX,
input: Bytes::new(),
Expand Down
10 changes: 5 additions & 5 deletions crates/consensus/src/transaction/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ pub struct TxLegacy {
/// this transaction. This is paid up-front, before any
/// computation is done and may not be increased
/// later; formally Tg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u64_hex_or_decimal"))]
pub gas_limit: u64,
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::u128_hex_or_decimal"))]
pub gas_limit: u128,
/// 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 @@ -213,12 +213,12 @@ impl Transaction for TxLegacy {
self.nonce
}

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

fn gas_price(&self) -> Option<U256> {
Some(U256::from(self.gas_price))
fn gas_price(&self) -> Option<u128> {
Some(self.gas_price)
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,10 @@ pub trait Transaction: std::any::Any + Send + Sync + 'static {
fn nonce(&self) -> u64;

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

/// Get `gas_price`.
fn gas_price(&self) -> Option<U256>;
fn gas_price(&self) -> Option<u128>;
}

/// A signable transaction.
Expand Down
4 changes: 2 additions & 2 deletions crates/consensus/src/transaction/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl Transaction for TypedTransaction {
}
}

fn gas_limit(&self) -> u64 {
fn gas_limit(&self) -> u128 {
match self {
Self::Legacy(tx) => tx.gas_limit(),
Self::Eip2930(tx) => tx.gas_limit(),
Expand All @@ -105,7 +105,7 @@ impl Transaction for TypedTransaction {
}
}

fn gas_price(&self) -> Option<alloy_primitives::U256> {
fn gas_price(&self) -> Option<u128> {
match self {
Self::Legacy(tx) => tx.gas_price(),
Self::Eip2930(tx) => tx.gas_price(),
Expand Down
6 changes: 3 additions & 3 deletions crates/contract/src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,15 +286,15 @@ 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: U256) -> Self {
pub fn gas(mut self, gas: u128) -> Self {
self.request.set_gas_limit(gas);
self
}

/// Sets the `gas_price` field in the transaction to the provided value
/// If the internal transaction is an EIP-1559 one, then it sets both
/// `max_fee_per_gas` and `max_priority_fee_per_gas` to the same value
pub fn gas_price(mut self, gas_price: U256) -> Self {
pub fn gas_price(mut self, gas_price: u128) -> Self {
self.request.set_gas_price(gas_price);
self
}
Expand Down Expand Up @@ -342,7 +342,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
pub async fn estimate_gas(&self) -> Result<U256> {
pub async fn estimate_gas(&self) -> Result<u128> {
self.provider.estimate_gas(&self.request, self.block).await.map_err(Into::into)
}

Expand Down
21 changes: 10 additions & 11 deletions crates/network/src/any/builder.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ops::{Deref, DerefMut};

use alloy_consensus::BlobTransactionSidecar;
use alloy_primitives::U256;
use alloy_rpc_types::{TransactionRequest, WithOtherFields};

use crate::{
Expand Down Expand Up @@ -57,43 +56,43 @@ impl TransactionBuilder<AnyNetwork> for WithOtherFields<TransactionRequest> {
self.deref_mut().set_value(value)
}

fn gas_price(&self) -> Option<U256> {
fn gas_price(&self) -> Option<u128> {
self.deref().gas_price()
}

fn set_gas_price(&mut self, gas_price: U256) {
fn set_gas_price(&mut self, gas_price: u128) {
self.deref_mut().set_gas_price(gas_price);
}

fn max_fee_per_gas(&self) -> Option<U256> {
fn max_fee_per_gas(&self) -> Option<u128> {
self.deref().max_fee_per_gas()
}

fn set_max_fee_per_gas(&mut self, max_fee_per_gas: U256) {
fn set_max_fee_per_gas(&mut self, max_fee_per_gas: u128) {
self.deref_mut().set_max_fee_per_gas(max_fee_per_gas);
}

fn max_priority_fee_per_gas(&self) -> Option<U256> {
fn max_priority_fee_per_gas(&self) -> Option<u128> {
self.deref().max_priority_fee_per_gas()
}

fn set_max_priority_fee_per_gas(&mut self, max_priority_fee_per_gas: U256) {
fn set_max_priority_fee_per_gas(&mut self, max_priority_fee_per_gas: u128) {
self.deref_mut().set_max_priority_fee_per_gas(max_priority_fee_per_gas);
}

fn max_fee_per_blob_gas(&self) -> Option<U256> {
fn max_fee_per_blob_gas(&self) -> Option<u128> {
self.deref().max_fee_per_blob_gas()
}

fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: U256) {
fn set_max_fee_per_blob_gas(&mut self, max_fee_per_blob_gas: u128) {
self.deref_mut().set_max_fee_per_blob_gas(max_fee_per_blob_gas)
}

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

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

Expand Down
Loading
Loading