Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
//! - `compute_fee_actual`: the base fee for this block, calculated as the median of the most recent
//! `fee_proposal` values across `window_size` blocks.
//! - `compute_fee_target`: the fee we'd *like* for this block, derived from the STRK/USD oracle
//! quote and a fixed USD-cost target.
//! quote and a configurable USD-cost target.
//! - `compute_fee_proposal`: the target, clamped within a fixed multiplicative margin of
//! `fee_actual` (so a proposer cannot move the fee too far per round).
//!
Expand Down Expand Up @@ -44,10 +44,6 @@ const FRI_DECIMALS_SCALE: u128 = 10u128.pow(18);
/// Denominator for parts-per-thousand calculations in fee_proposal bounds.
pub(crate) const PPT_DENOMINATOR: u128 = 1000;

/// Target USD cost per L2 gas unit in atto-USD ($3e-9 = 3_000_000_000 atto-USD).
// TODO(AndrewL): consider moving this to a dynamic config.
pub(crate) const TARGET_ATTO_USD_PER_L2_GAS: u128 = 3_000_000_000;

/// Compute fee_actual for `height` as the median of the `fee_proposal` values
/// recorded for heights `[height - window_size, height - 1]`.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::collections::BTreeMap;

use apollo_consensus_orchestrator_config::config::DEFAULT_SNIP35_TARGET_ATTO_USD_PER_L2_GAS;
use apollo_versioned_constants::VersionedConstants;
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha8Rng;
Expand All @@ -13,7 +14,6 @@ use crate::dynamic_gas_price::{
compute_fee_target,
FeeProposalInfo,
PPT_DENOMINATOR,
TARGET_ATTO_USD_PER_L2_GAS,
};

const TEST_FEE_PROPOSAL_WINDOW_SIZE: u64 = 10;
Expand Down Expand Up @@ -228,7 +228,7 @@ fn test_honest_proposer_always_passes_validation_fuzzed() {
let fee_actual_value = rng.gen_range(1u128..1_000_000_000_000_000_000);
let strk_usd_rate = rng.gen_range(1u128..2 * 10u128.pow(18));
let fee_actual = GasPrice(fee_actual_value);
let target = compute_fee_target(TARGET_ATTO_USD_PER_L2_GAS, strk_usd_rate);
let target = compute_fee_target(DEFAULT_SNIP35_TARGET_ATTO_USD_PER_L2_GAS, strk_usd_rate);
let oracle_result = if rng.gen_bool(0.1) { None } else { target };
let proposal = compute_fee_proposal(oracle_result, fee_actual, margin_ppt);
assert!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ use crate::dynamic_gas_price::{
compute_fee_target,
proposal_commitment_from,
FeeProposalInfo,
TARGET_ATTO_USD_PER_L2_GAS,
};
use crate::fee_market::{
calculate_next_l2_gas_price_for_fin,
Expand Down Expand Up @@ -445,6 +444,7 @@ impl SequencerConsensusContext {
&self,
fee_actual: Option<GasPrice>,
timestamp: u64,
target_atto_usd_per_l2_gas: u128,
) -> GasPrice {
let Some(fee_actual) = fee_actual else {
warn!("fee_actual unavailable, freezing fee_proposal at l2_gas_price");
Expand All @@ -456,7 +456,7 @@ impl SequencerConsensusContext {
let fee_target = match self.deps.l1_gas_price_provider.get_strk_to_usd_rate(timestamp).await
{
Ok(rate) => {
let target = compute_fee_target(TARGET_ATTO_USD_PER_L2_GAS, rate);
let target = compute_fee_target(target_atto_usd_per_l2_gas, rate);
match target {
Some(t) => SNIP35_FEE_TARGET.set_lossy(t.0),
None => warn!("STRK/USD oracle returned zero rate, freezing fee_proposal"),
Expand Down Expand Up @@ -722,8 +722,13 @@ impl ConsensusContext for SequencerConsensusContext {
build_param.height,
VersionedConstants::latest_constants().fee_proposal_window_size,
);
let fee_proposal =
self.compute_proposer_fee_proposal(fee_actual, self.deps.clock.unix_now()).await;
let fee_proposal = self
.compute_proposer_fee_proposal(
fee_actual,
self.deps.clock.unix_now(),
self.config.dynamic_config.snip35_target_atto_usd_per_l2_gas,
)
.await;
let round = build_param.round;
let args = ProposalBuildArguments {
deps: self.deps.clone(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ const HEIGHT_1: BlockNumber = BlockNumber(1);
// Use heights < 10 to avoid triggering the height-10 block-hash mapping code path (not tested
// here). Use non-zero height because height 0 always skips the write without querying the recorder.
const HEIGHT_FOR_WRITE_TESTS: BlockNumber = BlockNumber(8);
const TARGET_ATTO_USD_PER_L2_GAS: u128 = 3_000_000_000;

const ROUND_0: Round = 0;
const ROUND_1: Round = 1;
Expand Down Expand Up @@ -1685,7 +1686,8 @@ async fn test_compute_proposer_fee_proposal(

let mut context = deps.build_context();
context.l2_gas_price = l2_gas_price;
let proposal = context.compute_proposer_fee_proposal(fee_actual, 0).await;
let proposal =
context.compute_proposer_fee_proposal(fee_actual, 0, TARGET_ATTO_USD_PER_L2_GAS).await;
assert_eq!(proposal, expected_fee_proposal);
}

Expand Down Expand Up @@ -1725,7 +1727,9 @@ async fn test_compute_proposer_fee_proposal_converges_to_oracle_target() {
let h = BlockNumber(height);
let fee_actual = compute_fee_actual(&context.fee_proposals_window, h, window_size)
.expect("window stays complete across the loop");
let proposal = context.compute_proposer_fee_proposal(Some(fee_actual), 0).await;
let proposal = context
.compute_proposer_fee_proposal(Some(fee_actual), 0, TARGET_ATTO_USD_PER_L2_GAS)
.await;
context.record_fee_proposal(h, Some(proposal));
height += 1;
}
Expand Down
14 changes: 14 additions & 0 deletions crates/apollo_consensus_orchestrator_config/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ impl SerializeConfig for CendeConfig {
const GWEI_FACTOR: u128 = u128::pow(10, 9);
const ETH_FACTOR: u128 = u128::pow(10, 18);

// Default SNIP-35 target USD cost per L2 gas unit: $0.88 per 1e9 L2 gas = 880_000_000 atto-USD.
pub const DEFAULT_SNIP35_TARGET_ATTO_USD_PER_L2_GAS: u128 = 880_000_000;

// This matches the min_gas_price in orchestrator_versioned_constants_0_14_1.json (0x1dcd65000).
const MIN_ALLOWED_GAS_PRICE: u128 = 8_000_000_000;

Expand Down Expand Up @@ -284,6 +287,9 @@ pub struct ContextDynamicConfig {
pub l1_data_gas_price_multiplier_ppt: u128,
/// This additional gas is added to the L1 gas price.
pub l1_gas_tip_wei: u128,
/// SNIP-35 target USD cost per L2 gas unit, in atto-USD ($0.88 per 1e9 L2 gas = 880_000_000
/// atto-USD).
pub snip35_target_atto_usd_per_l2_gas: u128,
/// If given, will override the L2 gas price.
pub override_l2_gas_price_fri: Option<u128>,
/// If given, will override the L1 gas price in FRI.
Expand Down Expand Up @@ -350,6 +356,13 @@ impl SerializeConfig for ContextDynamicConfig {
"This additional gas is added to the L1 gas price.",
ParamPrivacyInput::Public,
),
ser_param(
"snip35_target_atto_usd_per_l2_gas",
&self.snip35_target_atto_usd_per_l2_gas,
"SNIP-35 target USD cost per L2 gas unit, in atto-USD ($0.88 per 1e9 L2 gas = \
880_000_000 atto-USD).",
ParamPrivacyInput::Public,
),
ser_param(
"compare_retrospective_block_hash",
&self.compare_retrospective_block_hash,
Expand Down Expand Up @@ -413,6 +426,7 @@ impl Default for ContextDynamicConfig {
max_l1_data_gas_price_wei: ETH_FACTOR,
l1_data_gas_price_multiplier_ppt: 135,
l1_gas_tip_wei: GWEI_FACTOR,
snip35_target_atto_usd_per_l2_gas: DEFAULT_SNIP35_TARGET_ATTO_USD_PER_L2_GAS,
override_l2_gas_price_fri: None,
override_l1_gas_price_fri: None,
override_l1_data_gas_price_fri: None,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"consensus_manager_config.context_config.dynamic_config.max_l1_gas_price_wei": 1000000000000,
"consensus_manager_config.context_config.dynamic_config.min_l1_data_gas_price_wei": 1,
"consensus_manager_config.context_config.dynamic_config.min_l1_gas_price_wei": 1000000000,
"consensus_manager_config.context_config.dynamic_config.snip35_target_atto_usd_per_l2_gas": 880000000,
Comment thread
cursor[bot] marked this conversation as resolved.
"consensus_manager_config.context_config.static_config.proposal_buffer_size": 512,
"consensus_manager_config.context_config.static_config.retrospective_block_hash_retry_interval_millis": 500,
"consensus_manager_config.context_config.static_config.validate_proposal_margin_millis": 10000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"consensus_manager_config.context_config.dynamic_config.override_l1_gas_price_fri.#is_none": "$$$_CONSENSUS_MANAGER_CONFIG-CONTEXT_CONFIG-DYNAMIC_CONFIG-OVERRIDE_L1_GAS_PRICE_FRI-IS_NONE_$$$",
"consensus_manager_config.context_config.dynamic_config.override_l2_gas_price_fri": "$$$_CONSENSUS_MANAGER_CONFIG-CONTEXT_CONFIG-DYNAMIC_CONFIG-OVERRIDE_L2_GAS_PRICE_FRI_$$$",
"consensus_manager_config.context_config.dynamic_config.override_l2_gas_price_fri.#is_none": "$$$_CONSENSUS_MANAGER_CONFIG-CONTEXT_CONFIG-DYNAMIC_CONFIG-OVERRIDE_L2_GAS_PRICE_FRI-IS_NONE_$$$",
"consensus_manager_config.context_config.dynamic_config.snip35_target_atto_usd_per_l2_gas": 880000000,
"consensus_manager_config.context_config.static_config.block_timestamp_window_seconds": 1,
"consensus_manager_config.context_config.static_config.build_proposal_time_ratio_for_retrospective_block_hash": 0.7,
"consensus_manager_config.context_config.static_config.builder_address": "0x1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8",
Expand Down
5 changes: 5 additions & 0 deletions crates/apollo_node/resources/config_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2729,6 +2729,11 @@
"privacy": "TemporaryValue",
"value": true
},
"consensus_manager_config.context_config.dynamic_config.snip35_target_atto_usd_per_l2_gas": {
"description": "SNIP-35 target USD cost per L2 gas unit, in atto-USD ($0.88 per 1e9 L2 gas = 880_000_000 atto-USD).",
"privacy": "Public",
"value": 880000000
},
"consensus_manager_config.context_config.static_config.behavior_mode": {
"description": "Behavior mode: 'starknet' for production, 'echonet' for test/replay mode.",
"pointer_target": "behavior_mode",
Expand Down
Loading