Skip to content

Commit e467c22

Browse files
committed
apollo_consensus_orchestrator: split consensus config into static and dynamic configs
1 parent 626cbb9 commit e467c22

File tree

17 files changed

+362
-277
lines changed

17 files changed

+362
-277
lines changed

config/papyrus/default_config.json

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -239,67 +239,67 @@
239239
"privacy": "TemporaryValue",
240240
"value": true
241241
},
242-
"context.block_timestamp_window_seconds": {
242+
"context.static_config.block_timestamp_window_seconds": {
243243
"description": "Maximum allowed deviation (seconds) of a proposed block's timestamp from the current time.",
244244
"privacy": "Public",
245245
"value": 1
246246
},
247-
"context.build_proposal_margin_millis": {
247+
"context.static_config.build_proposal_margin_millis": {
248248
"description": "Safety margin (in ms) to make sure that the batcher completes building the proposal with enough time for the Fin to be checked by validators.",
249249
"privacy": "Public",
250250
"value": 1000
251251
},
252-
"context.build_proposal_time_ratio_for_retrospective_block_hash": {
252+
"context.static_config.build_proposal_time_ratio_for_retrospective_block_hash": {
253253
"description": "The fraction (0.0 - 1.0) of the total build time allocated to waiting for the retrospective block hash to be available. The remaining time is used to build the proposal.",
254254
"privacy": "Public",
255255
"value": 0.7
256256
},
257-
"context.builder_address": {
257+
"context.static_config.builder_address": {
258258
"description": "The address of the contract that builds the block.",
259259
"privacy": "Public",
260260
"value": "0x0"
261261
},
262-
"context.chain_id": {
262+
"context.static_config.chain_id": {
263263
"description": "The chain id of the Starknet chain.",
264264
"pointer_target": "chain_id",
265265
"privacy": "Public"
266266
},
267-
"context.l1_da_mode": {
267+
"context.dynamic_config.l1_da_mode": {
268268
"description": "The data availability mode, true: Blob, false: Calldata.",
269269
"privacy": "Public",
270270
"value": true
271271
},
272-
"context.l1_data_gas_price_multiplier_ppt": {
272+
"context.dynamic_config.l1_data_gas_price_multiplier_ppt": {
273273
"description": "Part per thousand of multiplicative factor to apply to the data gas price, to enable fine-tuning of the price charged to end users.",
274274
"privacy": "Public",
275275
"value": 135
276276
},
277-
"context.l1_gas_tip_wei": {
277+
"context.dynamic_config.l1_gas_tip_wei": {
278278
"description": "This additional gas is added to the L1 gas price.",
279279
"privacy": "Public",
280280
"value": 1000000000
281281
},
282-
"context.max_l1_data_gas_price_wei": {
282+
"context.dynamic_config.max_l1_data_gas_price_wei": {
283283
"description": "The maximum L1 data gas price in wei.",
284284
"privacy": "Public",
285285
"value": 1000000000000000000
286286
},
287-
"context.max_l1_gas_price_wei": {
287+
"context.dynamic_config.max_l1_gas_price_wei": {
288288
"description": "The maximum L1 gas price in wei.",
289289
"privacy": "Public",
290290
"value": 200000000000
291291
},
292-
"context.min_l1_data_gas_price_wei": {
292+
"context.dynamic_config.min_l1_data_gas_price_wei": {
293293
"description": "The minimum L1 data gas price in wei.",
294294
"privacy": "Public",
295295
"value": 1
296296
},
297-
"context.min_l1_gas_price_wei": {
297+
"context.dynamic_config.min_l1_gas_price_wei": {
298298
"description": "The minimum L1 gas price in wei.",
299299
"privacy": "Public",
300300
"value": 1000000000
301301
},
302-
"context.num_validators": {
302+
"context.static_config.num_validators": {
303303
"description": "The number of validators.",
304304
"privacy": "Public",
305305
"value": 1
@@ -314,57 +314,57 @@
314314
"privacy": "TemporaryValue",
315315
"value": true
316316
},
317-
"context.override_l1_data_gas_price_wei": {
317+
"context.dynamic_config.override_l1_data_gas_price_wei": {
318318
"description": "Replace the L1 data gas price (wei) with this value.",
319319
"privacy": "Public",
320320
"value": 0
321321
},
322-
"context.override_l1_data_gas_price_wei.#is_none": {
322+
"context.dynamic_config.override_l1_data_gas_price_wei.#is_none": {
323323
"description": "Flag for an optional field.",
324324
"privacy": "TemporaryValue",
325325
"value": true
326326
},
327-
"context.override_l1_gas_price_wei": {
327+
"context.dynamic_config.override_l1_gas_price_wei": {
328328
"description": "Replace the L1 gas price (wei) with this value.",
329329
"privacy": "Public",
330330
"value": 0
331331
},
332-
"context.override_l1_gas_price_wei.#is_none": {
332+
"context.dynamic_config.override_l1_gas_price_wei.#is_none": {
333333
"description": "Flag for an optional field.",
334334
"privacy": "TemporaryValue",
335335
"value": true
336336
},
337-
"context.override_l2_gas_price_fri": {
337+
"context.dynamic_config.override_l2_gas_price_fri": {
338338
"description": "Replace the L2 gas price (fri) with this value.",
339339
"privacy": "Public",
340340
"value": 0
341341
},
342-
"context.override_l2_gas_price_fri.#is_none": {
342+
"context.dynamic_config.override_l2_gas_price_fri.#is_none": {
343343
"description": "Flag for an optional field.",
344344
"privacy": "TemporaryValue",
345345
"value": true
346346
},
347-
"context.proposal_buffer_size": {
347+
"context.static_config.proposal_buffer_size": {
348348
"description": "The buffer size for streaming outbound proposals.",
349349
"privacy": "Public",
350350
"value": 100
351351
},
352-
"context.retrospective_block_hash_retry_interval_millis": {
352+
"context.static_config.retrospective_block_hash_retry_interval_millis": {
353353
"description": "The interval between retrospective block hash retries.",
354354
"privacy": "Public",
355355
"value": 500
356356
},
357-
"context.validate_proposal_margin_millis": {
357+
"context.static_config.validate_proposal_margin_millis": {
358358
"description": "Safety margin (in ms) to make sure that consensus determines when to timeout validating a proposal.",
359359
"privacy": "Public",
360360
"value": 10000
361361
},
362-
"context.validator_ids": {
362+
"context.static_config.validator_ids": {
363363
"description": "Optional explicit set of validator IDs (comma separated).",
364364
"privacy": "Public",
365365
"value": ""
366366
},
367-
"context.validator_ids.#is_none": {
367+
"context.static_config.validator_ids.#is_none": {
368368
"description": "Flag for an optional field.",
369369
"privacy": "TemporaryValue",
370370
"value": true

crates/apollo_consensus_manager/src/consensus_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ impl ConsensusManager {
270270
SequencerConsensusContextDeps {
271271
transaction_converter: Arc::new(TransactionConverter::new(
272272
Arc::clone(&self.class_manager_client),
273-
self.config.context_config.chain_id.clone(),
273+
self.config.context_config.static_config.chain_id.clone(),
274274
)),
275275
state_sync_client: Arc::clone(&self.state_sync_client),
276276
batcher: Arc::clone(&self.batcher_client),

crates/apollo_consensus_orchestrator/src/build_proposal_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn create_proposal_build_arguments() -> (TestProposalBuildArguments, mpsc::Recei
101101
let stream_sender = StreamSender { proposal_sender };
102102
let context_config = ContextConfig::default();
103103

104-
let gas_price_params = make_gas_price_params(&context_config);
104+
let gas_price_params = make_gas_price_params(&context_config.dynamic_config);
105105
let valid_proposals = Arc::new(Mutex::new(BuiltProposals::new()));
106106
let proposal_id = ProposalId(1);
107107
let cende_write_success = AbortOnDropHandle::new(tokio::spawn(async { true }));

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context.rs

Lines changed: 37 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ enum ReproposeError {
198198
impl SequencerConsensusContext {
199199
pub fn new(config: ContextConfig, deps: SequencerConsensusContextDeps) -> Self {
200200
register_metrics();
201-
let num_validators = config.num_validators;
202-
let l1_da_mode = if config.l1_da_mode {
201+
let num_validators = config.static_config.num_validators;
202+
let l1_da_mode = if config.static_config.l1_da_mode {
203203
L1DataAvailabilityMode::Blob
204204
} else {
205205
L1DataAvailabilityMode::Calldata
206206
};
207-
let validators = if let Some(ids) = config.validator_ids.clone() {
207+
let validators = if let Some(ids) = config.static_config.validator_ids.clone() {
208208
ids.into_iter().collect()
209209
} else {
210210
(0..num_validators).map(|i| ValidatorId::from(DEFAULT_VALIDATOR_ID + i)).collect()
@@ -227,7 +227,8 @@ impl SequencerConsensusContext {
227227
}
228228

229229
async fn start_stream(&mut self, stream_id: HeightAndRound) -> StreamSender {
230-
let (proposal_sender, proposal_receiver) = mpsc::channel(self.config.proposal_buffer_size);
230+
let (proposal_sender, proposal_receiver) =
231+
mpsc::channel(self.config.static_config.proposal_buffer_size);
231232
self.deps
232233
.outbound_proposal_sender
233234
.send((stream_id, proposal_receiver))
@@ -318,7 +319,7 @@ impl SequencerConsensusContext {
318319

319320
fn update_l2_gas_price(&mut self, l2_gas_used: GasAmount) {
320321
let gas_target = VersionedConstants::latest_constants().gas_target;
321-
if let Some(override_value) = self.config.override_l2_gas_price_fri {
322+
if let Some(override_value) = self.config.dynamic_config.override_l2_gas_price_fri {
322323
info!(
323324
"L2 gas price ({}) is not updated, remains on override value of {override_value} \
324325
fri",
@@ -476,30 +477,32 @@ impl ConsensusContext for SequencerConsensusContext {
476477
let (fin_sender, fin_receiver) = oneshot::channel();
477478
let proposal_id = ProposalId(self.proposal_id);
478479
self.proposal_id += 1;
479-
assert!(timeout > self.config.build_proposal_margin_millis);
480+
assert!(timeout > self.config.static_config.build_proposal_margin_millis);
480481
let stream_id = HeightAndRound(proposal_init.height.0, proposal_init.round);
481482
let stream_sender = self.start_stream(stream_id).await;
482483

483484
info!(?proposal_init, ?timeout, %proposal_id, "Start building proposal");
484485
let cancel_token = CancellationToken::new();
485486
let cancel_token_clone = cancel_token.clone();
486-
let gas_price_params = make_gas_price_params(&self.config);
487+
let gas_price_params = make_gas_price_params(&self.config.dynamic_config);
487488
let mut l2_gas_price = self.l2_gas_price;
488-
if let Some(override_value) = self.config.override_l2_gas_price_fri {
489+
if let Some(override_value) = self.config.dynamic_config.override_l2_gas_price_fri {
489490
info!("Overriding L2 gas price to {override_value} fri");
490491
l2_gas_price = GasPrice(override_value);
491492
}
492493

493494
// The following calculations will panic on overflow/negative result.
494-
let total_build_proposal_time = timeout - self.config.build_proposal_margin_millis;
495+
let total_build_proposal_time =
496+
timeout - self.config.static_config.build_proposal_margin_millis;
495497
let time_now = self.deps.clock.now();
496498
let batcher_deadline = time_now + total_build_proposal_time;
497499
let retrospective_block_hash_deadline = time_now
498-
+ total_build_proposal_time
499-
.mul_f32(self.config.build_proposal_time_ratio_for_retrospective_block_hash);
500+
+ total_build_proposal_time.mul_f32(
501+
self.config.static_config.build_proposal_time_ratio_for_retrospective_block_hash,
502+
);
500503

501504
let use_state_sync_block_timestamp =
502-
self.config.deployment_mode.use_state_sync_block_timestamp();
505+
self.config.static_config.deployment_mode.use_state_sync_block_timestamp();
503506

504507
let args = ProposalBuildArguments {
505508
deps: self.deps.clone(),
@@ -512,13 +515,14 @@ impl ConsensusContext for SequencerConsensusContext {
512515
proposal_id,
513516
cende_write_success,
514517
l2_gas_price,
515-
builder_address: self.config.builder_address,
518+
builder_address: self.config.static_config.builder_address,
516519
cancel_token,
517520
previous_block_info: self.previous_block_info.clone(),
518521
proposal_round: self.current_round,
519522
retrospective_block_hash_deadline,
520523
retrospective_block_hash_retry_interval_millis: self
521524
.config
525+
.static_config
522526
.retrospective_block_hash_retry_interval_millis,
523527
use_state_sync_block_timestamp,
524528
};
@@ -580,11 +584,15 @@ impl ConsensusContext for SequencerConsensusContext {
580584
std::cmp::Ordering::Equal => {
581585
let block_info_validation = BlockInfoValidation {
582586
height: proposal_init.height,
583-
block_timestamp_window_seconds: self.config.block_timestamp_window_seconds,
587+
block_timestamp_window_seconds: self
588+
.config
589+
.static_config
590+
.block_timestamp_window_seconds,
584591
previous_block_info: self.previous_block_info.clone(),
585592
l1_da_mode: self.l1_da_mode,
586593
l2_gas_price_fri: self
587594
.config
595+
.dynamic_config
588596
.override_l2_gas_price_fri
589597
.map(GasPrice)
590598
.unwrap_or(self.l2_gas_price),
@@ -593,7 +601,7 @@ impl ConsensusContext for SequencerConsensusContext {
593601
block_info_validation,
594602
proposal_init.proposer,
595603
timeout,
596-
self.config.validate_proposal_margin_millis,
604+
self.config.static_config.validate_proposal_margin_millis,
597605
content_receiver,
598606
fin_sender,
599607
)
@@ -726,15 +734,15 @@ impl ConsensusContext for SequencerConsensusContext {
726734
let now: u64 = self.deps.clock.unix_now();
727735
if !(block_number == height
728736
&& timestamp.0 >= last_block_timestamp
729-
&& timestamp.0 <= now + self.config.block_timestamp_window_seconds)
737+
&& timestamp.0 <= now + self.config.static_config.block_timestamp_window_seconds)
730738
{
731739
warn!(
732740
"Invalid block info: expected block number {}, got {}, expected timestamp range \
733741
[{}, {}], got {}",
734742
height,
735743
block_number,
736744
last_block_timestamp,
737-
now + self.config.block_timestamp_window_seconds,
745+
now + self.config.static_config.block_timestamp_window_seconds,
738746
timestamp.0,
739747
);
740748
return false;
@@ -809,16 +817,24 @@ impl ConsensusContext for SequencerConsensusContext {
809817
};
810818
let block_info_validation = BlockInfoValidation {
811819
height,
812-
block_timestamp_window_seconds: self.config.block_timestamp_window_seconds,
820+
block_timestamp_window_seconds: self
821+
.config
822+
.static_config
823+
.block_timestamp_window_seconds,
813824
previous_block_info: self.previous_block_info.clone(),
814825
l1_da_mode: self.l1_da_mode,
815-
l2_gas_price_fri: self.l2_gas_price,
826+
l2_gas_price_fri: self
827+
.config
828+
.dynamic_config
829+
.override_l2_gas_price_fri
830+
.map(GasPrice)
831+
.unwrap_or(self.l2_gas_price),
816832
};
817833
self.validate_current_round_proposal(
818834
block_info_validation,
819835
validator,
820836
timeout,
821-
self.config.validate_proposal_margin_millis,
837+
self.config.static_config.validate_proposal_margin_millis,
822838
content,
823839
fin_sender,
824840
)
@@ -843,7 +859,7 @@ impl SequencerConsensusContext {
843859

844860
let cancel_token = CancellationToken::new();
845861
let cancel_token_clone = cancel_token.clone();
846-
let gas_price_params = make_gas_price_params(&self.config);
862+
let gas_price_params = make_gas_price_params(&self.config.dynamic_config);
847863
let args = ProposalValidateArguments {
848864
deps: self.deps.clone(),
849865
block_info_validation,

0 commit comments

Comments
 (0)