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

consensus: make Header gas limit u64 #1333

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ semver = "1.0"
thiserror = "1.0"
thiserror-no-std = "2.0.2"
url = "2.5"
derive_more = { version = "1.0.0", default-features = false }
derive_more = { version = "1.0.0", default-features = false, features = ["full"] }
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
http = "1.1.0"

## serde
Expand Down
20 changes: 16 additions & 4 deletions crates/consensus/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ pub struct Header {
pub number: BlockNumber,
/// A scalar value equal to the current limit of gas expenditure per block; formally Hl.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas_limit: u128,
pub gas_limit: u64,
/// A scalar value equal to the total gas used in transactions in this block; formally Hg.
#[cfg_attr(feature = "serde", serde(with = "alloy_serde::quantity"))]
pub gas_used: u128,
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -484,7 +484,7 @@ impl Decodable for Header {
logs_bloom: Decodable::decode(buf)?,
difficulty: Decodable::decode(buf)?,
number: u64::decode(buf)?,
gas_limit: u128::decode(buf)?,
gas_limit: u64::decode(buf)?,
gas_used: u128::decode(buf)?,
timestamp: Decodable::decode(buf)?,
extra_data: Decodable::decode(buf)?,
Expand Down Expand Up @@ -671,7 +671,7 @@ pub trait BlockHeader {
fn number(&self) -> BlockNumber;

/// Retrieves the gas limit of the block
fn gas_limit(&self) -> u128;
fn gas_limit(&self) -> u64;

/// Retrieves the gas used by the block
fn gas_used(&self) -> u128;
Expand Down Expand Up @@ -745,7 +745,7 @@ impl BlockHeader for Header {
self.number
}

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

Expand Down Expand Up @@ -808,5 +808,17 @@ mod tests {

let decoded: Header = serde_json::from_str(&json).unwrap();
assert_eq!(decoded, header);

// Create a vector to store the encoded RLP
let mut encoded_rlp = Vec::new();

// Encode the header data
decoded.encode(&mut encoded_rlp);

// Decode the RLP data
let decoded_rlp = Header::decode(&mut encoded_rlp.as_slice()).unwrap();

// Check that the decoded RLP data matches the original header data
assert_eq!(decoded_rlp, decoded);
tcoratger marked this conversation as resolved.
Show resolved Hide resolved
}
}
2 changes: 1 addition & 1 deletion crates/eips/src/eip1559/basefee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ impl BaseFeeParams {
///
/// See also [calc_next_block_base_fee]
#[inline]
pub fn next_block_base_fee(self, gas_used: u128, gas_limit: u128, base_fee: u128) -> u128 {
pub fn next_block_base_fee(self, gas_used: u128, gas_limit: u64, base_fee: u128) -> u128 {
calc_next_block_base_fee(gas_used, gas_limit, base_fee, self)
}
}
4 changes: 2 additions & 2 deletions crates/eips/src/eip1559/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ use crate::eip1559::BaseFeeParams;
/// For more information, refer to the [EIP-1559 spec](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md).
pub fn calc_next_block_base_fee(
gas_used: u128,
gas_limit: u128,
gas_limit: u64,
base_fee: u128,
base_fee_params: BaseFeeParams,
) -> u128 {
// Calculate the target gas by dividing the gas limit by the elasticity multiplier.
let gas_target = gas_limit / base_fee_params.elasticity_multiplier;
let gas_target = gas_limit as u128 / base_fee_params.elasticity_multiplier;

match gas_used.cmp(&gas_target) {
// If the gas used in the current block is equal to the gas target, the base fee remains the
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 @@ -153,7 +153,7 @@ pub trait HeaderResponse {
fn coinbase(&self) -> Address;

/// Gas limit of the block
fn gas_limit(&self) -> u128;
fn gas_limit(&self) -> u64;

/// Mix hash of the block
///
Expand Down Expand Up @@ -392,7 +392,7 @@ impl<T: HeaderResponse> HeaderResponse for WithOtherFields<T> {
self.inner.coinbase()
}

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

Expand Down
4 changes: 2 additions & 2 deletions crates/rpc-types-eth/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub struct Header {
pub number: u64,
/// Gas Limit
#[cfg_attr(feature = "serde", serde(default, with = "alloy_serde::quantity"))]
pub gas_limit: u128,
pub gas_limit: u64,
/// Gas Used
#[cfg_attr(feature = "serde", serde(default, with = "alloy_serde::quantity"))]
pub gas_used: u128,
Expand Down Expand Up @@ -259,7 +259,7 @@ impl HeaderResponse for Header {
self.miner
}

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

Expand Down
Loading