Skip to content

Commit

Permalink
feat(consensus): pass l2_gas_price in validate and build proposal (#3017
Browse files Browse the repository at this point in the history
)
  • Loading branch information
ayeletstarkware authored Jan 5, 2025
1 parent 030cba2 commit 71c1a30
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ mod test;
// and serves as a sensitivity parameter that limits the maximum rate of change of the gas price
// between consecutive blocks.
const GAS_PRICE_MAX_CHANGE_DENOMINATOR: u128 = 48;
const MIN_GAS_PRICE: u64 = 100000; // In fri.
/// The minimum gas price in fri.
pub const MIN_GAS_PRICE: u64 = 100000;
// TODO(Mohammad): Check the exact value for maximum block size in StarkNet.
/// The maximum block size in gas units: 40M gas steps * 100 units/step.
pub const MAX_BLOCK_SIZE: u64 = 4000000000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ use tokio_util::sync::CancellationToken;
use tracing::{debug, debug_span, info, instrument, trace, warn, Instrument};

use crate::cende::{BlobParameters, CendeContext};
use crate::fee_market::{calculate_next_base_gas_price, MAX_BLOCK_SIZE};
use crate::fee_market::{calculate_next_base_gas_price, MAX_BLOCK_SIZE, MIN_GAS_PRICE};

// TODO(Dan, Matan): Remove this once and replace with real gas prices.
const TEMPORARY_GAS_PRICES: GasPrices = GasPrices {
Expand Down Expand Up @@ -162,8 +162,18 @@ impl SequencerConsensusContext {
queued_proposals: BTreeMap::new(),
chain_id,
cende_ambassador,
// TODO(Ayelet): Replace placeholder with real value.
l2_gas_price: MAX_BLOCK_SIZE / 2,
l2_gas_price: MIN_GAS_PRICE,
}
}

fn gas_prices(&self) -> GasPrices {
GasPrices {
strk_gas_prices: GasPriceVector {
l2_gas_price: NonzeroGasPrice::new(self.l2_gas_price.into())
.expect("Failed to convert l2_gas_price to NonzeroGasPrice, should not be 0."),
..TEMPORARY_GAS_PRICES.strk_gas_prices
},
..TEMPORARY_GAS_PRICES
}
}
}
Expand Down Expand Up @@ -196,6 +206,7 @@ impl ConsensusContext for SequencerConsensusContext {
.send((stream_id, proposal_receiver))
.await
.expect("Failed to send proposal receiver");
let gas_prices = self.gas_prices();

let handle = tokio::spawn(
async move {
Expand All @@ -208,6 +219,7 @@ impl ConsensusContext for SequencerConsensusContext {
valid_proposals,
proposal_id,
cende_write_success,
gas_prices,
)
.await;
}
Expand Down Expand Up @@ -429,6 +441,7 @@ impl SequencerConsensusContext {
let chain_id = self.chain_id.clone();
let proposal_id = ProposalId(self.proposal_id);
self.proposal_id += 1;
let gas_prices = self.gas_prices();

let handle = tokio::spawn(async move {
validate_proposal(
Expand All @@ -442,6 +455,7 @@ impl SequencerConsensusContext {
content_receiver,
fin_sender,
cancel_token_clone,
gas_prices,
)
.await
});
Expand All @@ -467,8 +481,9 @@ async fn build_proposal(
valid_proposals: Arc<Mutex<HeightToIdToContent>>,
proposal_id: ProposalId,
cende_write_success: oneshot::Receiver<bool>,
gas_prices: GasPrices,
) {
initialize_build(proposal_id, &proposal_init, timeout, batcher.as_ref()).await;
initialize_build(proposal_id, &proposal_init, timeout, batcher.as_ref(), gas_prices).await;
debug!("Broadcasting proposal init: {proposal_init:?}");
proposal_sender
.send(ProposalPart::Init(proposal_init))
Expand Down Expand Up @@ -505,6 +520,7 @@ async fn initialize_build(
proposal_init: &ProposalInit,
timeout: Duration,
batcher: &dyn BatcherClient,
gas_prices: GasPrices,
) {
let batcher_timeout = chrono::Duration::from_std(timeout - BUILD_PROPOSAL_MARGIN)
.expect("Can't convert timeout to chrono::Duration");
Expand All @@ -521,7 +537,7 @@ async fn initialize_build(
// TODO(Dan, Matan): Fill block info.
block_info: BlockInfo {
block_number: proposal_init.height,
gas_prices: TEMPORARY_GAS_PRICES,
gas_prices,
block_timestamp: BlockTimestamp(
now.timestamp().try_into().expect("Failed to convert timestamp"),
),
Expand Down Expand Up @@ -626,8 +642,9 @@ async fn validate_proposal(
mut content_receiver: mpsc::Receiver<ProposalPart>,
fin_sender: oneshot::Sender<(ProposalContentId, ProposalFin)>,
cancel_token: CancellationToken,
gas_prices: GasPrices,
) {
initiate_validation(batcher, proposal_id, height, proposer, timeout).await;
initiate_validation(batcher, proposal_id, height, proposer, timeout, gas_prices).await;

let mut content = Vec::new();
let (built_block, received_fin) = loop {
Expand Down Expand Up @@ -681,6 +698,7 @@ async fn initiate_validation(
height: BlockNumber,
proposer: ValidatorId,
timeout: Duration,
gas_prices: GasPrices,
) {
// Initiate the validation.
let chrono_timeout =
Expand All @@ -697,7 +715,7 @@ async fn initiate_validation(
// TODO(Dan, Matan): Fill block info.
block_info: BlockInfo {
block_number: height,
gas_prices: TEMPORARY_GAS_PRICES,
gas_prices,
block_timestamp: BlockTimestamp(
now.timestamp().try_into().expect("Failed to convert timestamp"),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ async fn end_to_end_flow(mut tx_generator: MultiAccountTransactionGenerator) {
let heights_to_build = next_height.iter_up_to(LAST_HEIGHT.unchecked_next());
let expected_content_ids = [
Felt::from_hex_unchecked(
"0x58ad05a6987a675eda038663d8e7dcc8e1d91c9057dd57f16d9b3b9602fc840",
"0x665101f416fd5c4e91083fa9dcac1dba9a282f5211a1a2ad7695e95cb35d6b",
),
Felt::from_hex_unchecked(
"0x79b59c5036c9427b5194796ede67bdfffed1f311a77382d715174fcfcc33003",
"0x5c17ba5f9681bcc8ca5a9dee3fe3a9fd2da42e660a99c64aa1a95fa826a1b2",
),
Felt::from_hex_unchecked(
"0x36e1f3e0c71b77474494a5baa0a04a4e406626141eba2b2944e4b568f70ff48",
"0x5ec39365c6bbf631f3957f41d7b972f1c57e12544484b1db53458de03714b19",
),
];

Expand Down

0 comments on commit 71c1a30

Please sign in to comment.