Skip to content

Conversation

Copy link

Copilot AI commented Nov 9, 2025

Implements XLayer gas price controller with default mode that dynamically adjusts 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

Congestion Logic

// L2 gas price = max(base_fee + tip_cap, default, raw_gp)
let l2_price = max(base_fee + tip_cap, default_price);
let result = max(l2_price, raw_gp);

// If congested (pending >= threshold && block not empty), use result directly
// Otherwise, average with raw_gp to gradually decrease
if !is_congested {
    result = (raw_gp + result) / 2;
}

Configuration

--xlayer.gasprice.type default \
--xlayer.gasprice.default 100000000 \
--xlayer.gasprice.update-period 3s \
--xlayer.gasprice.congestion-threshold 100

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


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Add gas price controller in default mode feat(gasprice): Add gas price controller (default mode) Nov 9, 2025
Copilot AI requested a review from JimmyShi22 November 9, 2025 08:31
@JimmyShi22 JimmyShi22 closed this Nov 9, 2025
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.

2 participants