Skip to content

Commit

Permalink
feat: update next_block_base_fee for BSC
Browse files Browse the repository at this point in the history
  • Loading branch information
yutianwu committed Oct 21, 2024
1 parent aa058f5 commit a80ca2d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
1 change: 1 addition & 0 deletions crates/consensus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ serde_json.workspace = true
tokio = { workspace = true, features = ["macros"] }

[features]
bsc = []
default = ["std"]
std = ["alloy-eips/std", "c-kzg?/std"]
k256 = ["alloy-primitives/k256", "alloy-eips/k256"]
Expand Down
24 changes: 18 additions & 6 deletions crates/consensus/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ pub const EMPTY_OMMER_ROOT_HASH: B256 =
pub const EMPTY_ROOT_HASH: B256 =
b256!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421");

/// Initial base fee as defined in [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)
#[cfg(not(feature = "bsc"))]
pub(crate) const EIP1559_INITIAL_BASE_FEE: u64 = 1_000_000_000;

/// Initial base fee of bsc
#[cfg(feature = "bsc")]
pub(crate) const EIP1559_INITIAL_BASE_FEE: u64 = 0;

/// Ethereum Block header
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
Expand Down Expand Up @@ -221,12 +229,16 @@ impl Header {
///
/// Returns a `None` if no base fee is set, no EIP-1559 support
pub fn next_block_base_fee(&self, base_fee_params: BaseFeeParams) -> Option<u64> {
Some(calc_next_block_base_fee(
self.gas_used,
self.gas_limit,
self.base_fee_per_gas?,
base_fee_params,
))
if cfg!(feature = "bsc") {
Some(EIP1559_INITIAL_BASE_FEE)
} else {
Some(calc_next_block_base_fee(
self.gas_used,
self.gas_limit,
self.base_fee_per_gas?,
base_fee_params,
))
}
}

/// Calculate excess blob gas for the next block according to the EIP-4844
Expand Down

0 comments on commit a80ca2d

Please sign in to comment.