Skip to content

Commit b68b8f9

Browse files
sirandreww-starkwareShahakShama
authored andcommitted
apollo_consensus_orchestrator: wire SNIP-35 fee_proposal into cende blob
1 parent b49ef3d commit b68b8f9

8 files changed

Lines changed: 73 additions & 1 deletion

File tree

crates/apollo_consensus_orchestrator/resources/central_blob.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@
9393
"l2_gas_consumed": 150000,
9494
"next_l2_gas_price": "0x186a0"
9595
},
96+
"fee_proposal_info": {
97+
"fee_proposal_fri": "0x186a0"
98+
},
9699
"transactions": [
97100
{
98101
"tx": {

crates/apollo_consensus_orchestrator/resources/central_blob_empty_or_none_fields.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
"l2_gas_consumed": 150000,
5555
"next_l2_gas_price": "0x186a0"
5656
},
57+
"fee_proposal_info": {
58+
"fee_proposal_fri": "0x186a0"
59+
},
5760
"transactions": [],
5861
"execution_infos": [],
5962
"contract_classes": [],

crates/apollo_consensus_orchestrator/src/cende/central_objects.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ use starknet_types_core::felt::Felt;
5050

5151
use super::{CendeAmbassadorError, CendeAmbassadorResult};
5252
use crate::fee_market::FeeMarketInfo;
53+
use crate::snip35::FeeProposalInfo;
5354

5455
/// Central objects are required in order to continue processing the block by the centralized
5556
/// Python pipline. These objects are written to the Aerospike database and are used by python
@@ -86,6 +87,7 @@ impl From<BouncerWeights> for CentralBouncerWeights {
8687
}
8788
}
8889
pub(crate) type CentralFeeMarketInfo = FeeMarketInfo;
90+
pub(crate) type CentralFeeProposalInfo = FeeProposalInfo;
8991
pub(crate) type CentralCompressedStateDiff = CentralStateDiff;
9092
pub(crate) type CentralSierraContractClassEntry = (ClassHash, CentralSierraContractClass);
9193
pub(crate) type CentralCasmContractClassEntry = (CompiledClassHash, CentralCasmContractClass);

crates/apollo_consensus_orchestrator/src/cende/central_objects_test.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ use super::{
139139
CentralDeclareTransaction,
140140
CentralDeployAccountTransaction,
141141
CentralFeeMarketInfo,
142+
CentralFeeProposalInfo,
142143
CentralInvokeTransaction,
143144
CentralSierraContractClass,
144145
CentralStateDiff,
@@ -417,6 +418,10 @@ fn central_fee_market_info() -> CentralFeeMarketInfo {
417418
CentralFeeMarketInfo { l2_gas_consumed: GasAmount(150000), next_l2_gas_price: GasPrice(100000) }
418419
}
419420

421+
fn central_fee_proposal_info() -> CentralFeeProposalInfo {
422+
CentralFeeProposalInfo { fee_proposal_fri: Some(GasPrice(100000)) }
423+
}
424+
420425
fn entry_point(idx: usize, selector: u8) -> EntryPoint {
421426
EntryPoint { function_idx: FunctionIndex(idx), selector: EntryPointSelector(felt!(selector)) }
422427
}
@@ -745,6 +750,7 @@ fn central_blob() -> AerospikeBlob {
745750
transactions_with_execution_infos,
746751
bouncer_weights: test_bouncer_weights(),
747752
fee_market_info: central_fee_market_info(),
753+
fee_proposal_info: central_fee_proposal_info(),
748754
casm_hash_computation_data_sierra_gas: central_casm_hash_computation_data(),
749755
casm_hash_computation_data_proving_gas: central_casm_hash_computation_data(),
750756
compiled_class_hashes_for_migration: central_compiled_class_hashes_for_migration(),
@@ -776,6 +782,7 @@ fn central_blob_with_empty_or_none_fields() -> AerospikeBlob {
776782
transactions_with_execution_infos: vec![],
777783
bouncer_weights: test_bouncer_weights(),
778784
fee_market_info: central_fee_market_info(),
785+
fee_proposal_info: central_fee_proposal_info(),
779786
casm_hash_computation_data_sierra_gas: central_casm_hash_computation_data(),
780787
casm_hash_computation_data_proving_gas: central_casm_hash_computation_data(),
781788
compiled_class_hashes_for_migration: vec![],

crates/apollo_consensus_orchestrator/src/cende/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ use central_objects::{
2323
CentralCompiledClassHashesForMigration,
2424
CentralCompressedStateDiff,
2525
CentralFeeMarketInfo,
26+
CentralFeeProposalInfo,
2627
CentralSierraContractClassEntry,
2728
CentralStateDiff,
2829
CentralTransactionWritten,
@@ -53,6 +54,7 @@ use crate::metrics::{
5354
CENDE_WRITE_BLOB_SUCCESS,
5455
CENDE_WRITE_PREV_HEIGHT_BLOB_LATENCY,
5556
};
57+
use crate::snip35::FeeProposalInfo;
5658

5759
#[derive(thiserror::Error, Debug)]
5860
pub enum CendeAmbassadorError {
@@ -80,6 +82,7 @@ pub struct AerospikeBlob {
8082
compressed_state_diff: Option<CentralCompressedStateDiff>,
8183
bouncer_weights: CentralBouncerWeights,
8284
fee_market_info: CentralFeeMarketInfo,
85+
fee_proposal_info: CentralFeeProposalInfo,
8386
transactions: Vec<CentralTransactionWritten>,
8487
execution_infos: Vec<CentralTransactionExecutionInfo>,
8588
contract_classes: Vec<CentralSierraContractClassEntry>,
@@ -362,6 +365,7 @@ pub struct BlobParameters {
362365
pub compressed_state_diff: Option<CommitmentStateDiff>,
363366
pub bouncer_weights: BouncerWeights,
364367
pub fee_market_info: FeeMarketInfo,
368+
pub fee_proposal_info: FeeProposalInfo,
365369
pub transactions_with_execution_infos: Vec<InternalTransactionWithReceipt>,
366370
pub casm_hash_computation_data_sierra_gas: CasmHashComputationData,
367371
pub casm_hash_computation_data_proving_gas: CasmHashComputationData,
@@ -412,6 +416,7 @@ impl AerospikeBlob {
412416
compressed_state_diff,
413417
bouncer_weights: blob_parameters.bouncer_weights.into(),
414418
fee_market_info: blob_parameters.fee_market_info,
419+
fee_proposal_info: blob_parameters.fee_proposal_info,
415420
transactions: central_transactions,
416421
execution_infos,
417422
contract_classes,

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ use crate::snip35::{
103103
compute_fee_actual,
104104
compute_fee_proposal,
105105
compute_fee_target,
106+
FeeProposalInfo,
106107
FEE_PROPOSAL_MARGIN_PPT,
107108
FEE_PROPOSAL_WINDOW_SIZE,
108109
TARGET_ATTO_USD_PER_L2_GAS,
@@ -582,6 +583,11 @@ impl SequencerConsensusContext {
582583
l2_gas_consumed: l2_gas_used,
583584
next_l2_gas_price: self.l2_gas_price,
584585
},
586+
// SNIP-35: forward the proposer's stated fee_proposal_fri (from ProposalInit)
587+
// to the centralized cende pipeline. The centralized side persists this in
588+
// its own storage namespace, separate from FeeMarketInfo. Pre-V0_14_3 blocks
589+
// have `init.fee_proposal_fri == None`.
590+
fee_proposal_info: FeeProposalInfo { fee_proposal_fri: init.fee_proposal_fri },
585591
compiled_class_hashes_for_migration: central_objects
586592
.compiled_class_hashes_for_migration,
587593
proposal_commitment: commitment,

crates/apollo_consensus_orchestrator/src/snip35/mod.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,25 @@
1515
use std::collections::BTreeMap;
1616

1717
use ethnum::U256;
18+
use serde::Serialize;
1819
use starknet_api::block::{BlockNumber, GasPrice};
1920
use tracing::warn;
2021

2122
#[cfg(test)]
2223
mod test;
2324

25+
/// SNIP-35 proposer-stated fee value for a block, as it travels in the cende blob to the
26+
/// centralized recorder. Mirrors the `FeeProposalInfo` Marshmallow dataclass on the centralized
27+
/// (Python) side; the wire JSON shape must agree across the language boundary.
28+
#[cfg_attr(any(feature = "testing", test), derive(serde::Deserialize, PartialEq))]
29+
#[derive(Debug, Default, Serialize)]
30+
pub struct FeeProposalInfo {
31+
/// `None` for pre-V0_14_3 blocks (no value stated by the proposer); `Some(...)` for SNIP-35
32+
/// era blocks. The centralized side persists this independently of `FeeMarketInfo` so
33+
/// existing fee market storage blobs are untouched.
34+
pub fee_proposal_fri: Option<GasPrice>,
35+
}
36+
2437
/// Scale factor for 18-decimal fixed-point conversion (1 STRK = 10^18 FRI).
2538
const FRI_DECIMALS_SCALE: u128 = 10u128.pow(18);
2639

crates/apollo_consensus_orchestrator/src/snip35/test.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,40 @@ use std::collections::BTreeMap;
33
use rstest::rstest;
44
use starknet_api::block::{BlockNumber, GasPrice};
55

6-
use crate::snip35::{compute_fee_actual, compute_fee_proposal, compute_fee_target};
6+
use crate::snip35::{
7+
compute_fee_actual,
8+
compute_fee_proposal,
9+
compute_fee_target,
10+
FeeProposalInfo,
11+
};
12+
13+
#[test]
14+
fn fee_proposal_info_serializes_field_by_name() {
15+
// The cende blob's wire shape must agree with the Python `FeeProposalInfo` Marshmallow
16+
// dataclass — same field name (`fee_proposal_fri`), same JSON shape. If a refactor here
17+
// accidentally renames or restructures the field, the centralized recorder would silently
18+
// fail to load the Marshmallow schema on the new blob shape.
19+
let info = FeeProposalInfo { fee_proposal_fri: Some(GasPrice(0x1dcd65000)) };
20+
let json = serde_json::to_value(&info).unwrap();
21+
assert_eq!(json["fee_proposal_fri"], serde_json::Value::String("0x1dcd65000".to_string()));
22+
23+
let info_none = FeeProposalInfo { fee_proposal_fri: None };
24+
let json_none = serde_json::to_value(&info_none).unwrap();
25+
assert_eq!(json_none["fee_proposal_fri"], serde_json::Value::Null);
26+
}
27+
28+
#[test]
29+
fn fee_proposal_info_round_trips_through_serde_json() {
30+
let original = FeeProposalInfo { fee_proposal_fri: Some(GasPrice(0xDEAD_BEEF)) };
31+
let bytes = serde_json::to_vec(&original).unwrap();
32+
let reparsed: FeeProposalInfo = serde_json::from_slice(&bytes).unwrap();
33+
assert_eq!(reparsed, original);
34+
35+
let original_none = FeeProposalInfo { fee_proposal_fri: None };
36+
let bytes_none = serde_json::to_vec(&original_none).unwrap();
37+
let reparsed_none: FeeProposalInfo = serde_json::from_slice(&bytes_none).unwrap();
38+
assert_eq!(reparsed_none, original_none);
39+
}
740

841
const FRI_DECIMALS_SCALE: u128 = 10u128.pow(18);
942

0 commit comments

Comments
 (0)