Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(consensus): calculate base gas price #2999

Merged
merged 1 commit into from
Dec 29, 2024
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 @@ -9,7 +9,8 @@ mod test;
const GAS_PRICE_MAX_CHANGE_DENOMINATOR: u128 = 48;
const MIN_GAS_PRICE: u64 = 100000; // In fri.
// TODO(Mohammad): Check the exact value for maximum block size in StarkNet.
const MAX_BLOCK_SIZE: u64 = 4000000000; // In gas units. It's equivalent to 40M gas steps, with 100 gas units per step.
/// The maximum block size in gas units: 40M gas steps * 100 units/step.
pub const MAX_BLOCK_SIZE: u64 = 4000000000;

/// Calculate the base gas price for the next block according to EIP-1559.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ use starknet_api::executable_transaction::Transaction as ExecutableTransaction;
use starknet_api::transaction::{Transaction, TransactionHash};
use starknet_batcher_types::batcher_types::{
DecisionReachedInput,
DecisionReachedResponse,
GetProposalContent,
GetProposalContentInput,
ProposalId,
Expand All @@ -62,6 +63,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};

// TODO(Dan, Matan): Remove this once and replace with real gas prices.
const TEMPORARY_GAS_PRICES: GasPrices = GasPrices {
Expand Down Expand Up @@ -126,6 +128,9 @@ pub struct SequencerConsensusContext {
// Used to convert Transaction to ExecutableTransaction.
chain_id: ChainId,
cende_ambassador: Arc<dyn CendeContext>,
// The next block's l2 gas price, calculated based on EIP-1559, used for building and
// validating proposals.
l2_gas_price: u64,
}

impl SequencerConsensusContext {
Expand Down Expand Up @@ -155,6 +160,8 @@ impl SequencerConsensusContext {
queued_proposals: BTreeMap::new(),
chain_id,
cende_ambassador,
// TODO(Ayelet): Replace placeholder with real value.
l2_gas_price: MAX_BLOCK_SIZE / 2,
}
}
}
Expand Down Expand Up @@ -307,12 +314,11 @@ impl ConsensusContext for SequencerConsensusContext {
}
// TODO(dvir): return from the batcher's 'decision_reached' function the relevant data to
// build a blob.
let state_diff = self
let DecisionReachedResponse { state_diff, l2_gas_used } = self
.batcher
.decision_reached(DecisionReachedInput { proposal_id })
.await
.expect("Failed to get state diff.")
.state_diff;
.expect("Failed to get state diff.");
// TODO(dvir): pass here real `BlobParameters` info.
// TODO(dvir): when passing here the correct `BlobParameters`, also test that
// `prepare_blob_for_next_height` is called with the correct parameters.
Expand All @@ -331,6 +337,9 @@ impl ConsensusContext for SequencerConsensusContext {
.await
.expect("Failed to add new block.");

self.l2_gas_price =
calculate_next_base_gas_price(self.l2_gas_price, l2_gas_used.0, MAX_BLOCK_SIZE / 2);

Ok(())
}

Expand Down
Loading