Skip to content

Conversation

@JimmyShi22
Copy link

@JimmyShi22 JimmyShi22 commented Nov 6, 2025

Implements XLayer gas price controller with default mode that control L2 gas prices based on network congestion while maintaining a configured minimum floor.

Architecture

Gas Price Controller (crates/xlayer/gasprice/)

  • DefaultGasPricer: Returns fixed configured price, no external data dependencies
  • XLayerScheduler: Periodic updates based on L2 congestion metrics (pending txs, block fullness)
  • GasPriceCache: Thread-safe price storage with raw/adjusted values

Node Integration (crates/optimism/node/)

  • Extracted XLayer initialization to node_xlayer.rs
  • Wires scheduler → EthAPI oracle + transaction validator
  • Spawns xlayer-gas-price-scheduler background task

RPC Layer (crates/optimism/rpc/, crates/rpc/rpc/)

  • Implemented XLayerFees trait on OpEthApi for pricer management
  • Separated XLayer-specific logic to mod_xlayer.rs
  • Added eth_minGasPrice RPC method
  • RPC node will proxy query to seqencer if --rollup.sequencer http://xxxxx is set.

Configuration

To enable, add these to op-reth startup params

  --gpo.default-suggested-fee 1 \
  --xlayer.gasprice.type default \
  --xlayer.gasprice.update-period 3s \
  --xlayer.gasprice.default 100000000 \

Future modes (follower, fixed) will calculate raw_gp from L1 prices; default mode uses configured value.

@JimmyShi22 JimmyShi22 force-pushed the jimmyshi/gasprice-controller branch 3 times, most recently from 724ab64 to 5e271ca Compare November 9, 2025 05:53
@JimmyShi22
Copy link
Author

@copilot please describe this PR

Copy link

Copilot AI commented Nov 9, 2025

@JimmyShi22 I've opened a new pull request, #24, to work on those changes. Once the pull request is ready, I'll request review from you.

@JimmyShi22 JimmyShi22 force-pushed the jimmyshi/gasprice-controller branch from dd84e5f to cd92f8f Compare November 10, 2025 03:03
@JimmyShi22 JimmyShi22 force-pushed the jimmyshi/gasprice-controller branch from bf58221 to a698831 Compare November 10, 2025 06:13

[[package]]
name = "ahash"
version = "0.7.8"
Copy link

Choose a reason for hiding this comment

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

There is already an ahash with version 0.8.12. Let's see if we can use that instead

reth-evm.workspace = true
reth-rpc-server-types.workspace = true
reth-tasks = { workspace = true, optional = true }
reth-tasks.workspace = true
Copy link

Choose a reason for hiding this comment

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

why need to change this?

/// Validate all X Layer configurations
pub fn validate(&self) -> Result<(), String> {
self.intercept.validate()
self.intercept.validate()?;
Copy link

Choose a reason for hiding this comment

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

why need to change this?

Copy link
Author

Choose a reason for hiding this comment

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

Done

Copy link
Author

Choose a reason for hiding this comment

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

add this function: self.gas_price.validate()

}
}

impl Default for XLayerGasPriceArgs {
Copy link

Choose a reason for hiding this comment

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

use derive(Default) instead

Copy link
Author

Choose a reason for hiding this comment

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

done


/// Default gas price for XLayer (in wei)
#[arg(long = "xlayer.gasprice.default")]
pub default: Option<U256>,
Copy link

Choose a reason for hiding this comment

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

Using default as a field name is a bit unusual.

Copy link
Author

Choose a reason for hiding this comment

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

done

pub use node::*;

mod node_xlayer;

Copy link

Choose a reason for hiding this comment

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

better to group the modules related to xlayer together.

Copy link
Author

Choose a reason for hiding this comment

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

done

// }
_ => {
tracing::error!("Invalid gas price type: {}", price_type);
panic!("Invalid gas price type: {}", price_type);
Copy link
Collaborator

@louisliu2048 louisliu2048 Nov 11, 2025

Choose a reason for hiding this comment

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

the node will crash if use panic.

Copy link
Author

Choose a reason for hiding this comment

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

done: default to default mode

@JimmyShi22 JimmyShi22 force-pushed the jimmyshi/gasprice-controller branch 2 times, most recently from fd67039 to 9105ea8 Compare November 11, 2025 07:18
@JimmyShi22 JimmyShi22 force-pushed the jimmyshi/gasprice-controller branch from 9105ea8 to b7b867a Compare November 11, 2025 07:20
Comment on lines +143 to +145
pub fn validator_arc(&self) -> &Arc<V> {
&self.validator
}

Choose a reason for hiding this comment

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

Just a thought.

// Implement this trait
impl<V> AsRef<Arc<V>> for TransactionValidationTaskExecutor<V> {
    fn as_ref(&self) -> &Arc<V> {
        &self.validator
    }
}

// Then instead of `self.validator().validator_arc().clone()`, do:
self.validator().as_ref().clone()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants