Skip to content
This repository has been archived by the owner on Nov 5, 2023. It is now read-only.

Commit

Permalink
chore: nits
Browse files Browse the repository at this point in the history
  • Loading branch information
merklefruit committed Nov 5, 2023
1 parent af6d37b commit 619ce45
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 40 deletions.
5 changes: 3 additions & 2 deletions bin/reth/src/node/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -831,8 +831,9 @@ impl<Ext: RethCliExt> NodeCommand<Ext> {
self.network.port + self.instance - 1,
)));

// Expose an http sequencer endpoint if configured and disables tx gossip.
// This prevents tx gossip from leaking into the network.
// When `sequencer_endpoint` is configured, the node will forward all transactions to a
// Sequencer node for execution and inclusion on L1, and disable its own txpool
// gossip to prevent other parties in the network from learning about them.
#[cfg(feature = "optimism")]
let cfg_builder = cfg_builder
.sequencer_endpoint(self.rollup.sequencer_http.clone())
Expand Down
72 changes: 41 additions & 31 deletions crates/primitives/src/chain/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,37 +242,6 @@ pub static DEV: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
.into()
});

/// BaseFeeParams contains the config parameters that control block base fee computation
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
pub struct BaseFeeParams {
/// The base_fee_max_change_denominator from EIP-1559
pub max_change_denominator: u64,
/// The elasticity multiplier from EIP-1559
pub elasticity_multiplier: u64,
}

impl BaseFeeParams {
/// Get the base fee parameters for Ethereum mainnet
pub const fn ethereum() -> BaseFeeParams {
BaseFeeParams {
max_change_denominator: EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR,
elasticity_multiplier: EIP1559_DEFAULT_ELASTICITY_MULTIPLIER,
}
}

/// Get the base fee parameters for optimism goerli
#[cfg(feature = "optimism")]
pub const fn optimism_goerli() -> BaseFeeParams {
BaseFeeParams { max_change_denominator: 50, elasticity_multiplier: 10 }
}

/// Get the base fee parameters for optimism mainnet
#[cfg(feature = "optimism")]
pub const fn optimism() -> BaseFeeParams {
BaseFeeParams { max_change_denominator: 50, elasticity_multiplier: 6 }
}
}

/// The Optimism Goerli spec
#[cfg(feature = "optimism")]
pub static OP_GOERLI: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
Expand Down Expand Up @@ -396,6 +365,47 @@ pub static BASE_MAINNET: Lazy<Arc<ChainSpec>> = Lazy::new(|| {
.into()
});

/// BaseFeeParams contains the config parameters that control block base fee computation
#[derive(Serialize, Deserialize, Debug, Copy, Clone, PartialEq, Eq)]
pub struct BaseFeeParams {
/// The base_fee_max_change_denominator from EIP-1559
pub max_change_denominator: u64,
/// The elasticity multiplier from EIP-1559
pub elasticity_multiplier: u64,
}

impl BaseFeeParams {
/// Get the base fee parameters for Ethereum mainnet
pub const fn ethereum() -> BaseFeeParams {
BaseFeeParams {
max_change_denominator: EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR,
elasticity_multiplier: EIP1559_DEFAULT_ELASTICITY_MULTIPLIER,
}
}

/// Get the base fee parameters for optimism goerli
#[cfg(feature = "optimism")]
pub const fn optimism_goerli() -> BaseFeeParams {
BaseFeeParams {
max_change_denominator:
crate::constants::OP_GOERLI_EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR,
elasticity_multiplier:
crate::constants::OP_GOERLI_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER,
}
}

/// Get the base fee parameters for optimism mainnet
#[cfg(feature = "optimism")]
pub const fn optimism() -> BaseFeeParams {
BaseFeeParams {
max_change_denominator:
crate::constants::OP_MAINNET_EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR,
elasticity_multiplier:
crate::constants::OP_MAINNET_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER,
}
}
}

/// An Ethereum chain specification.
///
/// A chain specification describes:
Expand Down
20 changes: 20 additions & 0 deletions crates/primitives/src/constants/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ pub const EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR: u64 = 8;
/// Elasticity multiplier as defined in [EIP-1559](https://eips.ethereum.org/EIPS/eip-1559)
pub const EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u64 = 2;

/// Base fee max change denominator for Optimism Mainnet as defined in the Optimism
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
#[cfg(feature = "optimism")]
pub const OP_MAINNET_EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR: u64 = 50;

/// Baes fee max change denominator for Optimism Mainnet as defined in the Optimism
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
#[cfg(feature = "optimism")]
pub const OP_MAINNET_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u64 = 6;

/// Base fee max change denominator for Optimism Goerli as defined in the Optimism
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
#[cfg(feature = "optimism")]
pub const OP_GOERLI_EIP1559_DEFAULT_BASE_FEE_MAX_CHANGE_DENOMINATOR: u64 = 50;

/// Baes fee max change denominator for Optimism Goerli as defined in the Optimism
/// [transaction costs](https://community.optimism.io/docs/developers/build/differences/#transaction-costs) doc.
#[cfg(feature = "optimism")]
pub const OP_GOERLI_EIP1559_DEFAULT_ELASTICITY_MULTIPLIER: u64 = 10;

/// Multiplier for converting gwei to wei.
pub const GWEI_TO_WEI: u64 = 1_000_000_000;

Expand Down
12 changes: 6 additions & 6 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,12 @@ impl Transaction {
}

/// Returns the source hash of the transaction, which uniquely identifies its source.
/// If the transaction is not a deposit transaction, this will always return `B256::zero()`.
/// If not a deposit transaction, this will always return `None`.
#[cfg(feature = "optimism")]
pub fn source_hash(&self) -> B256 {
pub fn source_hash(&self) -> Option<B256> {
match self {
Transaction::Deposit(TxDeposit { source_hash, .. }) => *source_hash,
_ => B256::ZERO,
Transaction::Deposit(TxDeposit { source_hash, .. }) => Some(*source_hash),
_ => None,
}
}

Expand Down Expand Up @@ -616,8 +616,8 @@ impl Compact for Transaction {
tx.to_compact(buf);
}
#[cfg(feature = "optimism")]
Transaction::Deposit(deposit) => {
deposit.to_compact(buf);
Transaction::Deposit(tx) => {
tx.to_compact(buf);
}
}
identifier
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/rpc-types-compat/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ fn fill(
// Optimism fields
#[cfg(feature = "optimism")]
optimism: reth_rpc_types::OptimismTransactionFields {
source_hash: signed_tx.is_deposit().then_some(signed_tx.source_hash()),
source_hash: signed_tx.source_hash(),
mint: signed_tx.mint().map(U128::from),
is_system_tx: signed_tx.is_deposit().then_some(signed_tx.is_system_transaction()),
},
Expand Down

0 comments on commit 619ce45

Please sign in to comment.