Skip to content

Commit 8d2400d

Browse files
apollo_consensus_orchestrator: rename snip35 module to dynamic_gas_price, scrub SNIP-35 comments
1 parent 0acd722 commit 8d2400d

26 files changed

Lines changed: 89 additions & 89 deletions

File tree

crates/apollo_consensus_manager/src/consensus_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl ConsensusManager {
170170
consensus_context
171171
.initialize_fee_proposals_window(current_height.height)
172172
.await
173-
.expect("Failed to bootstrap SNIP-35 fee_proposals window");
173+
.expect("Failed to bootstrap fee_proposals window");
174174
let run_consensus_args = self.create_run_consensus_args(current_height.height);
175175

176176
let network_task =

crates/apollo_consensus_orchestrator/src/build_proposal.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ use tokio_util::sync::CancellationToken;
3939
use tokio_util::task::AbortOnDropHandle;
4040
use tracing::{debug, info, trace, warn};
4141

42+
use crate::dynamic_gas_price::proposal_commitment_from;
4243
use crate::fee_market::calculate_next_l2_gas_price_for_fin;
4344
use crate::sequencer_consensus_context::{BuiltProposals, SequencerConsensusContextDeps};
44-
use crate::snip35::proposal_commitment_from;
4545
use crate::utils::{
4646
convert_to_sn_api_block_info,
4747
get_l1_prices_in_fri_and_wei,
@@ -77,9 +77,9 @@ pub(crate) struct ProposalBuildArguments {
7777
pub override_l2_gas_price_fri: Option<u128>,
7878
pub min_l2_gas_price_per_height: Vec<PricePerHeight>,
7979
pub compare_retrospective_block_hash: bool,
80-
/// SNIP-35: proposer's fee_proposal for this block.
80+
/// Proposer's fee_proposal for this block.
8181
pub fee_proposal: GasPrice,
82-
/// SNIP-35: current fee_actual from the sliding window.
82+
/// Current fee_actual from the sliding window.
8383
pub fee_actual: Option<GasPrice>,
8484
}
8585

crates/apollo_consensus_orchestrator/src/build_proposal_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use starknet_api::execution_resources::GasAmount;
1818
use tokio_util::task::AbortOnDropHandle;
1919

2020
use crate::build_proposal::{build_proposal, BuildProposalError};
21-
use crate::snip35::proposal_commitment_from;
21+
use crate::dynamic_gas_price::proposal_commitment_from;
2222
use crate::test_utils::{create_proposal_build_arguments, INTERNAL_TX_BATCH, PARTIAL_BLOCK_HASH};
2323

2424
#[tokio::test]

crates/apollo_consensus_orchestrator/src/cende/central_objects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ use starknet_api::transaction::TransactionHash;
4949
use starknet_types_core::felt::Felt;
5050

5151
use super::{CendeAmbassadorError, CendeAmbassadorResult};
52+
use crate::dynamic_gas_price::FeeProposalInfo;
5253
use crate::fee_market::FeeMarketInfo;
53-
use crate::snip35::FeeProposalInfo;
5454

5555
/// Central objects are required in order to continue processing the block by the centralized
5656
/// Python pipline. These objects are written to the Aerospike database and are used by python

crates/apollo_consensus_orchestrator/src/cende/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ use tokio::task::{self, JoinHandle};
4545
use tracing::{info, warn, Instrument};
4646
use url::Url;
4747

48+
use crate::dynamic_gas_price::FeeProposalInfo;
4849
use crate::fee_market::FeeMarketInfo;
4950
use crate::metrics::{
5051
record_write_failure,
@@ -54,7 +55,6 @@ use crate::metrics::{
5455
CENDE_WRITE_BLOB_SUCCESS,
5556
CENDE_WRITE_PREV_HEIGHT_BLOB_LATENCY,
5657
};
57-
use crate::snip35::FeeProposalInfo;
5858

5959
#[derive(thiserror::Error, Debug)]
6060
pub enum CendeAmbassadorError {

crates/apollo_consensus_orchestrator/src/snip35/mod.rs renamed to crates/apollo_consensus_orchestrator/src/dynamic_gas_price/mod.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//! SNIP-35 dynamic L2 gas pricing primitives.
1+
//! Dynamic L2 gas pricing primitives.
22
//!
33
//! Spec: <https://community.starknet.io/t/snip-35-automatically-adjust-base-fee-to-strk-price/116168>
44
//!
@@ -26,33 +26,33 @@ use tracing::warn;
2626
#[cfg(test)]
2727
mod test;
2828

29-
/// SNIP-35 proposer-stated fee value for a block, as it travels in the cende blob to the
29+
/// Proposer-stated fee value for a block, as it travels in the cende blob to the
3030
/// centralized recorder. Mirrors the `FeeProposalInfo` Marshmallow dataclass on the centralized
3131
/// (Python) side; the wire JSON shape must agree across the language boundary.
3232
#[cfg_attr(any(feature = "testing", test), derive(serde::Deserialize, PartialEq))]
3333
#[derive(Debug, Default, Serialize)]
3434
pub struct FeeProposalInfo {
35-
/// `None` for pre-V0_14_3 blocks (no value stated by the proposer); `Some(...)` for SNIP-35
36-
/// era blocks. The centralized side persists this independently of `FeeMarketInfo` so
35+
/// `None` for pre-V0_14_3 blocks (no value stated by the proposer); `Some(...)` for V0_14_3+
36+
/// blocks. The centralized side persists this independently of `FeeMarketInfo` so
3737
/// existing fee market storage blobs are untouched.
3838
pub fee_proposal_fri: Option<GasPrice>,
3939
}
4040

4141
/// Scale factor for 18-decimal fixed-point conversion (1 STRK = 10^18 FRI).
4242
const FRI_DECIMALS_SCALE: u128 = 10u128.pow(18);
4343

44-
/// Denominator for parts-per-thousand calculations in SNIP-35 fee_proposal bounds.
44+
/// Denominator for parts-per-thousand calculations in fee_proposal bounds.
4545
pub(crate) const PPT_DENOMINATOR: u128 = 1000;
4646

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

5151
/// Compute fee_actual for `height` as the median of the `fee_proposal` values
52-
/// recorded for heights `[height - window_size, height - 1]` (SNIP-35).
52+
/// recorded for heights `[height - window_size, height - 1]`.
5353
///
5454
/// Returns `None` (after logging a warning) when any of those heights is missing from
55-
/// `fee_proposals_window` or recorded as `None` (e.g., pre-SNIP-35 blocks). The `None`
55+
/// `fee_proposals_window` or recorded as `None` (e.g., pre-V0_14_3 blocks). The `None`
5656
/// case triggers the `l2_gas_price` fallback in both proposer and validator paths.
5757
///
5858
/// Median rule for even `window_size`: average of the two middle values rounded down;
@@ -95,7 +95,7 @@ pub fn compute_fee_actual(
9595
Some(median)
9696
}
9797

98-
/// Compute the fee target from STRK/USD price and a USD cost target (SNIP-35).
98+
/// Compute the fee target from STRK/USD price and a USD cost target.
9999
///
100100
/// `target_atto_usd_per_l2_gas` is in atto-USD (atto = 10⁻¹⁸; so a value of
101101
/// `3_000_000_000` means 3·10⁻⁹ USD = 3 nanodollars per L2 gas unit).
@@ -116,7 +116,7 @@ pub fn compute_fee_target(
116116
Some(GasPrice(u128::try_from(floor).unwrap_or(u128::MAX)))
117117
}
118118

119-
/// Compute the fee_proposal an honest proposer should publish (SNIP-35).
119+
/// Compute the fee_proposal an honest proposer should publish.
120120
/// - If oracle failed (`fee_target` is `None`): freeze at `fee_actual`.
121121
/// - Otherwise: clamp `fee_target` into the geometric bounds returned by `fee_proposal_bounds`.
122122
pub fn compute_fee_proposal(
@@ -131,7 +131,7 @@ pub fn compute_fee_proposal(
131131
GasPrice(fee_target.0.clamp(lower, upper))
132132
}
133133

134-
/// Geometric bounds for SNIP-35 fee_proposal: returns `(lower, upper)` where
134+
/// Geometric bounds for fee_proposal: returns `(lower, upper)` where
135135
/// - `upper = fee_actual * (1 + margin)` (multiplicative widening), and
136136
/// - `lower = fee_actual / (1 + margin)` (the reciprocal — multiplicative narrowing),
137137
///
@@ -154,7 +154,7 @@ pub(crate) fn fee_proposal_bounds(fee_actual: GasPrice, margin_ppt: u128) -> (u1
154154
(lower, upper)
155155
}
156156

157-
/// SNIP-35: bind `fee_proposal_fri` to the proposal commitment hash.
157+
/// Bind `fee_proposal_fri` to the proposal commitment hash.
158158
///
159159
/// Pre-V0_14_3 blocks have `fee_proposal = None` and the commitment is just `partial.0`,
160160
/// preserving on-chain behavior. From V0_14_3 onward, the commitment is

crates/apollo_consensus_orchestrator/src/snip35/test.rs renamed to crates/apollo_consensus_orchestrator/src/dynamic_gas_price/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rstest::rstest;
77
use starknet_api::block::{BlockNumber, GasPrice};
88
use starknet_api::versioned_constants_logic::VersionedConstantsTrait;
99

10-
use crate::snip35::{
10+
use crate::dynamic_gas_price::{
1111
compute_fee_actual,
1212
compute_fee_proposal,
1313
compute_fee_target,
@@ -79,7 +79,7 @@ fn test_compute_fee_actual_random_window() {
7979
window_from((0u64..10).filter(|h| *h != 5).map(|h| (h, Some(GasPrice(100))))),
8080
BlockNumber(10),
8181
)]
82-
// Heights [0, 9] needed; height 7 is recorded as None (pre-SNIP-35 block).
82+
// Heights [0, 9] needed; height 7 is recorded as None (pre-V0_14_3 block).
8383
#[case::none_entry(
8484
window_from((0u64..10).map(|h| (h, (h != 7).then_some(GasPrice(100))))),
8585
BlockNumber(10),
@@ -192,7 +192,7 @@ fn test_compute_fee_actual_lone_adversary_cannot_skew_median() {
192192
}
193193

194194
/// The validator's accept predicate. Must stay in sync with
195-
/// `validate_proposal::is_proposal_init_valid` SNIP-35 bounds check.
195+
/// `validate_proposal::is_proposal_init_valid` fee_proposal bounds check.
196196
fn validator_accepts(fee_actual: GasPrice, fee_proposal: GasPrice, margin_ppt: u128) -> bool {
197197
let lower = fee_actual.0.saturating_mul(PPT_DENOMINATOR) / (PPT_DENOMINATOR + margin_ppt);
198198
let upper = fee_actual.0.saturating_mul(PPT_DENOMINATOR + margin_ppt) / PPT_DENOMINATOR;

crates/apollo_consensus_orchestrator/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ pub mod cende;
1818
/// Fee market logic.
1919
pub mod fee_market;
2020

21-
/// SNIP-35 dynamic L2 gas pricing (consensus-level fee mechanism).
22-
pub mod snip35;
21+
/// Dynamic L2 gas pricing (consensus-level fee mechanism).
22+
pub mod dynamic_gas_price;
2323

2424
#[allow(missing_docs)]
2525
pub mod metrics;

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,14 @@ use crate::cende::{
8484
InternalTransactionWithReceipt,
8585
N_BLOCK_HASHES_BACK_IN_BLOB,
8686
};
87+
use crate::dynamic_gas_price::{
88+
compute_fee_actual,
89+
compute_fee_proposal,
90+
compute_fee_target,
91+
proposal_commitment_from,
92+
FeeProposalInfo,
93+
TARGET_ATTO_USD_PER_L2_GAS,
94+
};
8795
use crate::fee_market::{
8896
calculate_next_l2_gas_price_for_fin,
8997
get_min_gas_price_for_height,
@@ -98,14 +106,6 @@ use crate::metrics::{
98106
SNIP35_FEE_PROPOSAL,
99107
SNIP35_FEE_TARGET,
100108
};
101-
use crate::snip35::{
102-
compute_fee_actual,
103-
compute_fee_proposal,
104-
compute_fee_target,
105-
proposal_commitment_from,
106-
FeeProposalInfo,
107-
TARGET_ATTO_USD_PER_L2_GAS,
108-
};
109109
use crate::utils::{
110110
convert_to_sn_api_block_info,
111111
make_gas_price_params,
@@ -251,7 +251,7 @@ pub struct SequencerConsensusContext {
251251
l2_gas_price: GasPrice,
252252
l1_da_mode: L1DataAvailabilityMode,
253253
previous_proposal_init: Option<PreviousProposalInitInfo>,
254-
/// SNIP-35 fee_proposals window. `None` = pre-V0_14_3.
254+
/// fee_proposals window. `None` = pre-V0_14_3.
255255
fee_proposals_window: BTreeMap<BlockNumber, Option<GasPrice>>,
256256
}
257257

@@ -438,10 +438,10 @@ impl SequencerConsensusContext {
438438
)
439439
}
440440

441-
/// SNIP-35 fee_proposal: clamp the oracle's `fee_target` to a margin around `fee_actual`.
442-
/// When `fee_actual` is `None` (window incomplete), freeze at `l2_gas_price`; the validator
443-
/// derives the same fallback so both sides agree.
444-
async fn compute_snip35_fee_proposal(
441+
/// Compute the proposer's fee_proposal: clamp the oracle's `fee_target` to a margin around
442+
/// `fee_actual`. When `fee_actual` is `None` (window incomplete), freeze at `l2_gas_price`; the
443+
/// validator derives the same fallback so both sides agree.
444+
async fn compute_proposer_fee_proposal(
445445
&self,
446446
fee_actual: Option<GasPrice>,
447447
timestamp: u64,
@@ -579,18 +579,18 @@ impl SequencerConsensusContext {
579579
l2_gas_consumed: l2_gas_used,
580580
next_l2_gas_price: self.l2_gas_price,
581581
},
582-
// SNIP-35: forward the proposer's stated fee_proposal_fri (from ProposalInit)
582+
// Forward the proposer's stated fee_proposal_fri (from ProposalInit)
583583
// to the centralized cende pipeline. The centralized side persists this in
584584
// its own storage namespace, separate from FeeMarketInfo. Pre-V0_14_3 blocks
585585
// have `init.fee_proposal_fri == None`.
586586
fee_proposal_info: FeeProposalInfo { fee_proposal_fri: init.fee_proposal_fri },
587587
compiled_class_hashes_for_migration: central_objects
588588
.compiled_class_hashes_for_migration,
589589
proposal_commitment: commitment,
590-
// TODO(SNIP-35): plumb the parent block's `fee_proposal_fri` here once
590+
// TODO(AndrewL): plumb the parent block's `fee_proposal_fri` here once
591591
// `central_objects.parent_proposal_commitment` carries it (or read from
592592
// BlockHeaderWithoutHash storage). Today we pass `None`, which means
593-
// pre-V0_14_3 commitments — correct for non-SNIP-35 deployments only.
593+
// pre-V0_14_3 commitments — correct for pre-V0_14_3 deployments only.
594594
parent_proposal_commitment: central_objects
595595
.parent_proposal_commitment
596596
.map(|c| proposal_commitment_from(c.partial_block_hash, None)),
@@ -723,7 +723,7 @@ impl ConsensusContext for SequencerConsensusContext {
723723
VersionedConstants::latest_constants().fee_proposal_window_size,
724724
);
725725
let fee_proposal =
726-
self.compute_snip35_fee_proposal(fee_actual, self.deps.clock.unix_now()).await;
726+
self.compute_proposer_fee_proposal(fee_actual, self.deps.clock.unix_now()).await;
727727
let round = build_param.round;
728728
let args = ProposalBuildArguments {
729729
deps: self.deps.clone(),

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context_test.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@ use starknet_api::state::ThinStateDiff;
6363
use starknet_api::versioned_constants_logic::VersionedConstantsTrait;
6464

6565
use crate::cende::{MockCendeContext, N_BLOCK_HASHES_BACK_IN_BLOB};
66+
use crate::dynamic_gas_price::proposal_commitment_from;
6667
use crate::metrics::CONSENSUS_L2_GAS_PRICE;
6768
use crate::sequencer_consensus_context::{
6869
SequencerConsensusContext,
6970
SequencerConsensusContextDeps,
7071
};
71-
use crate::snip35::proposal_commitment_from;
7272
use crate::test_utils::{
7373
create_test_and_network_deps,
7474
proposal_init,
@@ -90,12 +90,12 @@ fn expected_l2_gas_info_for_build_proposal_defaults() -> L2GasInfo {
9090
l2_gas_used: GasAmount(0),
9191
}
9292
}
93-
use crate::snip35::compute_fee_actual;
93+
use crate::dynamic_gas_price::compute_fee_actual;
9494
use crate::utils::{apply_fee_transformations, make_gas_price_params};
9595

9696
static TEST_PROPOSAL_COMMITMENT: LazyLock<ProposalCommitment> = LazyLock::new(|| {
9797
// Default test setup: empty fee_proposals_window → `compute_fee_actual` returns `None` →
98-
// `compute_snip35_fee_proposal` falls back to `self.l2_gas_price` (default
98+
// `compute_proposer_fee_proposal` falls back to `self.l2_gas_price` (default
9999
// `min_gas_price` = 8 gwei = 8_000_000_000 FRI). The orchestrator chains this value into
100100
// the proposal commitment via `proposal_commitment_from`. The `proposal_init` test helper
101101
// produces an init with `fee_proposal_fri = Some(8 gwei)` to match what the proposer emits.
@@ -1582,7 +1582,7 @@ fn test_prune_fee_proposals_window(
15821582
#[case::all_some(BlockNumber(100), window_of(90..100))]
15831583
// v0.14.2 era: every block recorded with `fee_proposal_fri = None`.
15841584
#[case::all_none(BlockNumber(100), (90u64..100).map(|h| (BlockNumber(h), None)).collect())]
1585-
// Transition: heights < 95 are pre-SNIP-35 (None), heights >= 95 are SNIP-35 (Some).
1585+
// Transition: heights < 95 are pre-V0_14_3 (None), heights >= 95 are V0_14_3+ (Some).
15861586
#[case::mixed_transition(
15871587
BlockNumber(100),
15881588
(90u64..100)
@@ -1660,7 +1660,7 @@ enum OracleBehavior {
16601660
GasPrice(9_980_039_920)
16611661
)]
16621662
#[tokio::test]
1663-
async fn test_compute_snip35_fee_proposal(
1663+
async fn test_compute_proposer_fee_proposal(
16641664
#[case] fee_actual: Option<GasPrice>,
16651665
#[case] oracle_behavior: OracleBehavior,
16661666
#[case] l2_gas_price: GasPrice,
@@ -1685,12 +1685,12 @@ async fn test_compute_snip35_fee_proposal(
16851685

16861686
let mut context = deps.build_context();
16871687
context.l2_gas_price = l2_gas_price;
1688-
let proposal = context.compute_snip35_fee_proposal(fee_actual, 0).await;
1688+
let proposal = context.compute_proposer_fee_proposal(fee_actual, 0).await;
16891689
assert_eq!(proposal, expected_fee_proposal);
16901690
}
16911691

16921692
#[tokio::test]
1693-
async fn test_compute_snip35_fee_proposal_converges_to_oracle_target() {
1693+
async fn test_compute_proposer_fee_proposal_converges_to_oracle_target() {
16941694
// (strk_usd_rate, fee_target, n_blocks_until_convergence_with_buffer).
16951695
// 75 gwei bootstrap -> 100 gwei target at +33% reaches by block ~795.
16961696
// 100 gwei -> 60 gwei at -40% reaches by block ~1410.
@@ -1725,7 +1725,7 @@ async fn test_compute_snip35_fee_proposal_converges_to_oracle_target() {
17251725
let h = BlockNumber(height);
17261726
let fee_actual = compute_fee_actual(&context.fee_proposals_window, h, window_size)
17271727
.expect("window stays complete across the loop");
1728-
let proposal = context.compute_snip35_fee_proposal(Some(fee_actual), 0).await;
1728+
let proposal = context.compute_proposer_fee_proposal(Some(fee_actual), 0).await;
17291729
context.record_fee_proposal(h, Some(proposal));
17301730
height += 1;
17311731
}

0 commit comments

Comments
 (0)