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 @@ -93,6 +93,9 @@
"l2_gas_consumed": 150000,
"next_l2_gas_price": "0x186a0"
},
"fee_proposal_info": {
"fee_proposal_fri": "0x186a0"
},
"transactions": [
{
"tx": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
"l2_gas_consumed": 150000,
"next_l2_gas_price": "0x186a0"
},
"fee_proposal_info": {
"fee_proposal_fri": "0x186a0"
},
Comment thread
cursor[bot] marked this conversation as resolved.
"transactions": [],
"execution_infos": [],
"contract_classes": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ use starknet_types_core::felt::Felt;

use super::{CendeAmbassadorError, CendeAmbassadorResult};
use crate::fee_market::FeeMarketInfo;
use crate::snip35::FeeProposalInfo;

/// Central objects are required in order to continue processing the block by the centralized
/// Python pipline. These objects are written to the Aerospike database and are used by python
Expand Down Expand Up @@ -86,6 +87,7 @@ impl From<BouncerWeights> for CentralBouncerWeights {
}
}
pub(crate) type CentralFeeMarketInfo = FeeMarketInfo;
pub(crate) type CentralFeeProposalInfo = FeeProposalInfo;
pub(crate) type CentralCompressedStateDiff = CentralStateDiff;
pub(crate) type CentralSierraContractClassEntry = (ClassHash, CentralSierraContractClass);
pub(crate) type CentralCasmContractClassEntry = (CompiledClassHash, CentralCasmContractClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ use super::{
CentralDeclareTransaction,
CentralDeployAccountTransaction,
CentralFeeMarketInfo,
CentralFeeProposalInfo,
CentralInvokeTransaction,
CentralSierraContractClass,
CentralStateDiff,
Expand Down Expand Up @@ -417,6 +418,10 @@ fn central_fee_market_info() -> CentralFeeMarketInfo {
CentralFeeMarketInfo { l2_gas_consumed: GasAmount(150000), next_l2_gas_price: GasPrice(100000) }
}

fn central_fee_proposal_info() -> CentralFeeProposalInfo {
CentralFeeProposalInfo { fee_proposal_fri: Some(GasPrice(100000)) }
}

fn entry_point(idx: usize, selector: u8) -> EntryPoint {
EntryPoint { function_idx: FunctionIndex(idx), selector: EntryPointSelector(felt!(selector)) }
}
Expand Down Expand Up @@ -745,6 +750,7 @@ fn central_blob() -> AerospikeBlob {
transactions_with_execution_infos,
bouncer_weights: test_bouncer_weights(),
fee_market_info: central_fee_market_info(),
fee_proposal_info: central_fee_proposal_info(),
casm_hash_computation_data_sierra_gas: central_casm_hash_computation_data(),
casm_hash_computation_data_proving_gas: central_casm_hash_computation_data(),
compiled_class_hashes_for_migration: central_compiled_class_hashes_for_migration(),
Expand Down Expand Up @@ -776,6 +782,7 @@ fn central_blob_with_empty_or_none_fields() -> AerospikeBlob {
transactions_with_execution_infos: vec![],
bouncer_weights: test_bouncer_weights(),
fee_market_info: central_fee_market_info(),
fee_proposal_info: central_fee_proposal_info(),
casm_hash_computation_data_sierra_gas: central_casm_hash_computation_data(),
casm_hash_computation_data_proving_gas: central_casm_hash_computation_data(),
compiled_class_hashes_for_migration: vec![],
Expand Down
5 changes: 5 additions & 0 deletions crates/apollo_consensus_orchestrator/src/cende/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ use central_objects::{
CentralCompiledClassHashesForMigration,
CentralCompressedStateDiff,
CentralFeeMarketInfo,
CentralFeeProposalInfo,
CentralSierraContractClassEntry,
CentralStateDiff,
CentralTransactionWritten,
Expand Down Expand Up @@ -53,6 +54,7 @@ use crate::metrics::{
CENDE_WRITE_BLOB_SUCCESS,
CENDE_WRITE_PREV_HEIGHT_BLOB_LATENCY,
};
use crate::snip35::FeeProposalInfo;

#[derive(thiserror::Error, Debug)]
pub enum CendeAmbassadorError {
Expand Down Expand Up @@ -80,6 +82,7 @@ pub struct AerospikeBlob {
compressed_state_diff: Option<CentralCompressedStateDiff>,
bouncer_weights: CentralBouncerWeights,
fee_market_info: CentralFeeMarketInfo,
fee_proposal_info: CentralFeeProposalInfo,
transactions: Vec<CentralTransactionWritten>,
execution_infos: Vec<CentralTransactionExecutionInfo>,
contract_classes: Vec<CentralSierraContractClassEntry>,
Expand Down Expand Up @@ -362,6 +365,7 @@ pub struct BlobParameters {
pub compressed_state_diff: Option<CommitmentStateDiff>,
pub bouncer_weights: BouncerWeights,
pub fee_market_info: FeeMarketInfo,
pub fee_proposal_info: FeeProposalInfo,
pub transactions_with_execution_infos: Vec<InternalTransactionWithReceipt>,
pub casm_hash_computation_data_sierra_gas: CasmHashComputationData,
pub casm_hash_computation_data_proving_gas: CasmHashComputationData,
Expand Down Expand Up @@ -412,6 +416,7 @@ impl AerospikeBlob {
compressed_state_diff,
bouncer_weights: blob_parameters.bouncer_weights.into(),
fee_market_info: blob_parameters.fee_market_info,
fee_proposal_info: blob_parameters.fee_proposal_info,
transactions: central_transactions,
execution_infos,
contract_classes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ use crate::snip35::{
compute_fee_actual,
compute_fee_proposal,
compute_fee_target,
FeeProposalInfo,
FEE_PROPOSAL_MARGIN_PPT,
FEE_PROPOSAL_WINDOW_SIZE,
TARGET_ATTO_USD_PER_L2_GAS,
Expand Down Expand Up @@ -582,6 +583,11 @@ impl SequencerConsensusContext {
l2_gas_consumed: l2_gas_used,
next_l2_gas_price: self.l2_gas_price,
},
// SNIP-35: forward the proposer's stated fee_proposal_fri (from ProposalInit)
// to the centralized cende pipeline. The centralized side persists this in
// its own storage namespace, separate from FeeMarketInfo. Pre-V0_14_3 blocks
// have `init.fee_proposal_fri == None`.
fee_proposal_info: FeeProposalInfo { fee_proposal_fri: init.fee_proposal_fri },
compiled_class_hashes_for_migration: central_objects
.compiled_class_hashes_for_migration,
proposal_commitment: commitment,
Expand Down
13 changes: 13 additions & 0 deletions crates/apollo_consensus_orchestrator/src/snip35/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,25 @@
use std::collections::BTreeMap;

use ethnum::U256;
use serde::Serialize;
use starknet_api::block::{BlockNumber, GasPrice};
use tracing::warn;

#[cfg(test)]
mod test;

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

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

Expand Down
35 changes: 34 additions & 1 deletion crates/apollo_consensus_orchestrator/src/snip35/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,40 @@ use std::collections::BTreeMap;
use rstest::rstest;
use starknet_api::block::{BlockNumber, GasPrice};

use crate::snip35::{compute_fee_actual, compute_fee_proposal, compute_fee_target};
use crate::snip35::{
compute_fee_actual,
compute_fee_proposal,
compute_fee_target,
FeeProposalInfo,
};

#[test]
fn fee_proposal_info_serializes_field_by_name() {
// The cende blob's wire shape must agree with the Python `FeeProposalInfo` Marshmallow
// dataclass — same field name (`fee_proposal_fri`), same JSON shape. If a refactor here
// accidentally renames or restructures the field, the centralized recorder would silently
// fail to load the Marshmallow schema on the new blob shape.
let info = FeeProposalInfo { fee_proposal_fri: Some(GasPrice(0x1dcd65000)) };
let json = serde_json::to_value(&info).unwrap();
assert_eq!(json["fee_proposal_fri"], serde_json::Value::String("0x1dcd65000".to_string()));

let info_none = FeeProposalInfo { fee_proposal_fri: None };
let json_none = serde_json::to_value(&info_none).unwrap();
assert_eq!(json_none["fee_proposal_fri"], serde_json::Value::Null);
}

#[test]
fn fee_proposal_info_round_trips_through_serde_json() {
let original = FeeProposalInfo { fee_proposal_fri: Some(GasPrice(0xDEAD_BEEF)) };
let bytes = serde_json::to_vec(&original).unwrap();
let reparsed: FeeProposalInfo = serde_json::from_slice(&bytes).unwrap();
assert_eq!(reparsed, original);

let original_none = FeeProposalInfo { fee_proposal_fri: None };
let bytes_none = serde_json::to_vec(&original_none).unwrap();
let reparsed_none: FeeProposalInfo = serde_json::from_slice(&bytes_none).unwrap();
assert_eq!(reparsed_none, original_none);
}

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
15
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use apollo_consensus_orchestrator::cende::{
InternalTransactionWithReceipt,
};
use apollo_consensus_orchestrator::fee_market::FeeMarketInfo;
use apollo_consensus_orchestrator::snip35::FeeProposalInfo;
use apollo_infra_utils::compile_time_cargo_manifest_dir;
use blockifier::abi::constants::STORED_BLOCK_HASH_BUFFER;
use blockifier::blockifier::config::TransactionExecutorConfig;
Expand Down Expand Up @@ -236,6 +237,7 @@ impl From<BlockData> for BlobParameters {
transactions_with_execution_infos: transactions_with_receipts,
bouncer_weights: BouncerWeights::default(),
fee_market_info: FeeMarketInfo::default(),
fee_proposal_info: FeeProposalInfo::default(),
casm_hash_computation_data_sierra_gas: CasmHashComputationData::default(),
casm_hash_computation_data_proving_gas: CasmHashComputationData::default(),
compiled_class_hashes_for_migration: vec![],
Expand Down
Loading