Skip to content

Commit 1fd82a4

Browse files
committed
apollo_consensus_orchestrator: split consensus config into static and dynamic configs
1 parent 5b2e0e9 commit 1fd82a4

File tree

10 files changed

+201
-116
lines changed

10 files changed

+201
-116
lines changed

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use apollo_class_manager_types::transaction_converter::{
1313
TransactionConverterError,
1414
};
1515
use apollo_consensus::types::{ProposalCommitment as ConsensusProposalCommitment, Round};
16-
use apollo_consensus_orchestrator_config::config::ContextConfig;
16+
use apollo_consensus_orchestrator_config::config::{ContextConfig, ContextDynamicConfig};
1717
use apollo_infra::component_client::ClientError;
1818
use apollo_protobuf::consensus::{ConsensusBlockInfo, ProposalInit, ProposalPart};
1919
use apollo_state_sync_types::communication::StateSyncClientError;
@@ -99,7 +99,7 @@ fn create_proposal_build_arguments() -> (TestProposalBuildArguments, mpsc::Recei
9999
let stream_sender = StreamSender { proposal_sender };
100100
let context_config = ContextConfig::default();
101101

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

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,13 +182,13 @@ pub struct SequencerConsensusContextDeps {
182182
impl SequencerConsensusContext {
183183
pub fn new(config: ContextConfig, deps: SequencerConsensusContextDeps) -> Self {
184184
register_metrics();
185-
let num_validators = config.num_validators;
186-
let l1_da_mode = if config.l1_da_mode {
185+
let num_validators = config.static_config.num_validators;
186+
let l1_da_mode = if config.static_config.l1_da_mode {
187187
L1DataAvailabilityMode::Blob
188188
} else {
189189
L1DataAvailabilityMode::Calldata
190190
};
191-
let validators = if let Some(ids) = config.validator_ids.clone() {
191+
let validators = if let Some(ids) = config.static_config.validator_ids.clone() {
192192
ids.into_iter().collect()
193193
} else {
194194
(0..num_validators).map(|i| ValidatorId::from(DEFAULT_VALIDATOR_ID + i)).collect()
@@ -211,7 +211,8 @@ impl SequencerConsensusContext {
211211
}
212212

213213
async fn start_stream(&mut self, stream_id: HeightAndRound) -> StreamSender {
214-
let (proposal_sender, proposal_receiver) = mpsc::channel(self.config.proposal_buffer_size);
214+
let (proposal_sender, proposal_receiver) =
215+
mpsc::channel(self.config.static_config.proposal_buffer_size);
215216
self.deps
216217
.outbound_proposal_sender
217218
.send((stream_id, proposal_receiver))
@@ -279,27 +280,29 @@ impl ConsensusContext for SequencerConsensusContext {
279280
let (fin_sender, fin_receiver) = oneshot::channel();
280281
let proposal_id = ProposalId(self.proposal_id);
281282
self.proposal_id += 1;
282-
assert!(timeout > self.config.build_proposal_margin_millis);
283+
assert!(timeout > self.config.static_config.build_proposal_margin_millis);
283284
let stream_id = HeightAndRound(proposal_init.height.0, proposal_init.round);
284285
let stream_sender = self.start_stream(stream_id).await;
285286

286287
info!(?proposal_init, ?timeout, %proposal_id, "Start building proposal");
287288
let cancel_token = CancellationToken::new();
288289
let cancel_token_clone = cancel_token.clone();
289-
let gas_price_params = make_gas_price_params(&self.config);
290+
let gas_price_params = make_gas_price_params(&self.config.dynamic_config);
290291
let mut l2_gas_price = self.l2_gas_price;
291-
if let Some(override_value) = self.config.override_l2_gas_price_fri {
292+
if let Some(override_value) = self.config.dynamic_config.override_l2_gas_price_fri {
292293
info!("Overriding L2 gas price to {override_value} fri");
293294
l2_gas_price = GasPrice(override_value);
294295
}
295296

296297
// The following calculations will panic on overflow/negative result.
297-
let total_build_proposal_time = timeout - self.config.build_proposal_margin_millis;
298+
let total_build_proposal_time =
299+
timeout - self.config.static_config.build_proposal_margin_millis;
298300
let time_now = self.deps.clock.now();
299301
let batcher_deadline = time_now + total_build_proposal_time;
300302
let retrospective_block_hash_deadline = time_now
301-
+ total_build_proposal_time
302-
.mul_f32(self.config.build_proposal_time_ratio_for_retrospective_block_hash);
303+
+ total_build_proposal_time.mul_f32(
304+
self.config.static_config.build_proposal_time_ratio_for_retrospective_block_hash,
305+
);
303306

304307
let args = ProposalBuildArguments {
305308
deps: self.deps.clone(),
@@ -312,13 +315,14 @@ impl ConsensusContext for SequencerConsensusContext {
312315
proposal_id,
313316
cende_write_success,
314317
l2_gas_price,
315-
builder_address: self.config.builder_address,
318+
builder_address: self.config.static_config.builder_address,
316319
cancel_token,
317320
previous_block_info: self.previous_block_info.clone(),
318321
proposal_round: self.current_round,
319322
retrospective_block_hash_deadline,
320323
retrospective_block_hash_retry_interval_millis: self
321324
.config
325+
.static_config
322326
.retrospective_block_hash_retry_interval_millis,
323327
};
324328
let handle = tokio::spawn(
@@ -377,11 +381,15 @@ impl ConsensusContext for SequencerConsensusContext {
377381
std::cmp::Ordering::Equal => {
378382
let block_info_validation = BlockInfoValidation {
379383
height: proposal_init.height,
380-
block_timestamp_window_seconds: self.config.block_timestamp_window_seconds,
384+
block_timestamp_window_seconds: self
385+
.config
386+
.static_config
387+
.block_timestamp_window_seconds,
381388
previous_block_info: self.previous_block_info.clone(),
382389
l1_da_mode: self.l1_da_mode,
383390
l2_gas_price_fri: self
384391
.config
392+
.dynamic_config
385393
.override_l2_gas_price_fri
386394
.map(GasPrice)
387395
.unwrap_or(self.l2_gas_price),
@@ -390,7 +398,7 @@ impl ConsensusContext for SequencerConsensusContext {
390398
block_info_validation,
391399
proposal_init.proposer,
392400
timeout,
393-
self.config.validate_proposal_margin_millis,
401+
self.config.static_config.validate_proposal_margin_millis,
394402
content_receiver,
395403
fin_sender,
396404
)
@@ -542,7 +550,7 @@ impl ConsensusContext for SequencerConsensusContext {
542550
})?;
543551

544552
let gas_target = VersionedConstants::latest_constants().gas_target;
545-
if let Some(override_value) = self.config.override_l2_gas_price_fri {
553+
if let Some(override_value) = self.config.dynamic_config.override_l2_gas_price_fri {
546554
info!(
547555
"L2 gas price ({}) is not updated, remains on override value of {override_value} \
548556
fri",
@@ -666,15 +674,15 @@ impl ConsensusContext for SequencerConsensusContext {
666674
let now: u64 = self.deps.clock.unix_now();
667675
if !(block_number == height
668676
&& timestamp.0 >= last_block_timestamp
669-
&& timestamp.0 <= now + self.config.block_timestamp_window_seconds)
677+
&& timestamp.0 <= now + self.config.static_config.block_timestamp_window_seconds)
670678
{
671679
warn!(
672680
"Invalid block info: expected block number {}, got {}, expected timestamp range \
673681
[{}, {}], got {}",
674682
height,
675683
block_number,
676684
last_block_timestamp,
677-
now + self.config.block_timestamp_window_seconds,
685+
now + self.config.static_config.block_timestamp_window_seconds,
678686
timestamp.0,
679687
);
680688
return false;
@@ -737,16 +745,24 @@ impl ConsensusContext for SequencerConsensusContext {
737745
};
738746
let block_info_validation = BlockInfoValidation {
739747
height,
740-
block_timestamp_window_seconds: self.config.block_timestamp_window_seconds,
748+
block_timestamp_window_seconds: self
749+
.config
750+
.static_config
751+
.block_timestamp_window_seconds,
741752
previous_block_info: self.previous_block_info.clone(),
742753
l1_da_mode: self.l1_da_mode,
743-
l2_gas_price_fri: self.l2_gas_price,
754+
l2_gas_price_fri: self
755+
.config
756+
.dynamic_config
757+
.override_l2_gas_price_fri
758+
.map(GasPrice)
759+
.unwrap_or(self.l2_gas_price),
744760
};
745761
self.validate_current_round_proposal(
746762
block_info_validation,
747763
validator,
748764
timeout,
749-
self.config.validate_proposal_margin_millis,
765+
self.config.static_config.validate_proposal_margin_millis,
750766
content,
751767
fin_sender,
752768
)
@@ -770,7 +786,7 @@ impl SequencerConsensusContext {
770786

771787
let cancel_token = CancellationToken::new();
772788
let cancel_token_clone = cancel_token.clone();
773-
let gas_price_params = make_gas_price_params(&self.config);
789+
let gas_price_params = make_gas_price_params(&self.config.dynamic_config);
774790
let args = ProposalValidateArguments {
775791
deps: self.deps.clone(),
776792
block_info_validation,

crates/apollo_consensus_orchestrator/src/sequencer_consensus_context_test.rs

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use apollo_batcher_types::batcher_types::{CentralObjects, DecisionReachedRespons
55
use apollo_batcher_types::communication::BatcherClientError;
66
use apollo_batcher_types::errors::BatcherError;
77
use apollo_consensus::types::{ConsensusContext, Round};
8-
use apollo_consensus_orchestrator_config::config::ContextConfig;
8+
use apollo_consensus_orchestrator_config::config::{ContextConfig, ContextDynamicConfig};
99
use apollo_infra::component_client::ClientError;
1010
use apollo_l1_gas_price_types::errors::{
1111
EthToStrkOracleClientError,
@@ -80,7 +80,8 @@ async fn validate_proposal_success() {
8080
// Initialize the context for a specific height, starting with round 0.
8181
context.set_height_and_round(BlockNumber(0), 0).await;
8282

83-
let (mut content_sender, content_receiver) = mpsc::channel(context.config.proposal_buffer_size);
83+
let (mut content_sender, content_receiver) =
84+
mpsc::channel(context.config.static_config.proposal_buffer_size);
8485
content_sender.send(ProposalPart::BlockInfo(block_info(BlockNumber(0)))).await.unwrap();
8586
content_sender
8687
.send(ProposalPart::Transactions(TransactionBatch { transactions: TX_BATCH.to_vec() }))
@@ -116,7 +117,8 @@ async fn dont_send_block_info() {
116117
// Initialize the context for a specific height, starting with round 0.
117118
context.set_height_and_round(BlockNumber(0), 0).await;
118119

119-
let (mut content_sender, content_receiver) = mpsc::channel(context.config.proposal_buffer_size);
120+
let (mut content_sender, content_receiver) =
121+
mpsc::channel(context.config.static_config.proposal_buffer_size);
120122
let fin_receiver =
121123
context.validate_proposal(ProposalInit::default(), TIMEOUT, content_receiver).await;
122124
content_sender.close_channel();
@@ -143,7 +145,8 @@ async fn validate_then_repropose(#[case] execute_all_txs: bool) {
143145
context.set_height_and_round(BlockNumber(0), 0).await;
144146

145147
// Receive a valid proposal.
146-
let (mut content_sender, content_receiver) = mpsc::channel(context.config.proposal_buffer_size);
148+
let (mut content_sender, content_receiver) =
149+
mpsc::channel(context.config.static_config.proposal_buffer_size);
147150
let block_info = ProposalPart::BlockInfo(block_info(BlockNumber(0)));
148151
content_sender.send(block_info.clone()).await.unwrap();
149152
let transactions =
@@ -198,7 +201,8 @@ async fn proposals_from_different_rounds() {
198201
});
199202

200203
// The proposal from the past round is ignored.
201-
let (mut content_sender, content_receiver) = mpsc::channel(context.config.proposal_buffer_size);
204+
let (mut content_sender, content_receiver) =
205+
mpsc::channel(context.config.static_config.proposal_buffer_size);
202206
content_sender.send(ProposalPart::BlockInfo(block_info(BlockNumber(0)))).await.unwrap();
203207
content_sender.send(prop_part_txs.clone()).await.unwrap();
204208
content_sender.send(prop_part_executed_count.clone()).await.unwrap();
@@ -209,7 +213,8 @@ async fn proposals_from_different_rounds() {
209213
assert!(fin_receiver_past_round.await.is_err());
210214

211215
// The proposal from the current round should be validated.
212-
let (mut content_sender, content_receiver) = mpsc::channel(context.config.proposal_buffer_size);
216+
let (mut content_sender, content_receiver) =
217+
mpsc::channel(context.config.static_config.proposal_buffer_size);
213218
content_sender.send(ProposalPart::BlockInfo(block_info(BlockNumber(0)))).await.unwrap();
214219
content_sender.send(prop_part_txs.clone()).await.unwrap();
215220
content_sender.send(prop_part_executed_count.clone()).await.unwrap();
@@ -219,7 +224,8 @@ async fn proposals_from_different_rounds() {
219224
assert_eq!(fin_receiver_curr_round.await.unwrap().0, STATE_DIFF_COMMITMENT.0.0);
220225

221226
// The proposal from the future round should not be processed.
222-
let (mut content_sender, content_receiver) = mpsc::channel(context.config.proposal_buffer_size);
227+
let (mut content_sender, content_receiver) =
228+
mpsc::channel(context.config.static_config.proposal_buffer_size);
223229
content_sender.send(ProposalPart::BlockInfo(block_info(BlockNumber(0)))).await.unwrap();
224230
content_sender.send(prop_part_txs.clone()).await.unwrap();
225231
content_sender.send(prop_part_executed_count.clone()).await.unwrap();
@@ -247,12 +253,12 @@ async fn interrupt_active_proposal() {
247253
// Keep the sender open, as closing it or sending Fin would cause the validate to complete
248254
// without needing interrupt.
249255
let (mut _content_sender_0, content_receiver) =
250-
mpsc::channel(context.config.proposal_buffer_size);
256+
mpsc::channel(context.config.static_config.proposal_buffer_size);
251257
let fin_receiver_0 =
252258
context.validate_proposal(ProposalInit::default(), TIMEOUT, content_receiver).await;
253259

254260
let (mut content_sender_1, content_receiver) =
255-
mpsc::channel(context.config.proposal_buffer_size);
261+
mpsc::channel(context.config.static_config.proposal_buffer_size);
256262
content_sender_1.send(ProposalPart::BlockInfo(block_info(BlockNumber(0)))).await.unwrap();
257263
content_sender_1
258264
.send(ProposalPart::Transactions(TransactionBatch { transactions: TX_BATCH.to_vec() }))
@@ -482,7 +488,7 @@ async fn batcher_not_ready(#[case] proposer: bool) {
482488
assert_eq!(fin_receiver.await, Err(Canceled));
483489
} else {
484490
let (mut content_sender, content_receiver) =
485-
mpsc::channel(context.config.proposal_buffer_size);
491+
mpsc::channel(context.config.static_config.proposal_buffer_size);
486492
content_sender.send(ProposalPart::BlockInfo(block_info(BlockNumber(0)))).await.unwrap();
487493

488494
let fin_receiver =
@@ -547,7 +553,8 @@ async fn eth_to_fri_rate_out_of_range() {
547553
.return_const(Ok(()));
548554
let mut context = deps.build_context();
549555
context.set_height_and_round(BlockNumber(0), 0).await;
550-
let (mut content_sender, content_receiver) = mpsc::channel(context.config.proposal_buffer_size);
556+
let (mut content_sender, content_receiver) =
557+
mpsc::channel(context.config.static_config.proposal_buffer_size);
551558
// Send a block info with an eth_to_fri_rate that is outside the margin of error.
552559
let mut block_info = block_info(BlockNumber(0));
553560
block_info.eth_to_fri_rate *= 2;
@@ -567,7 +574,7 @@ async fn eth_to_fri_rate_out_of_range() {
567574
async fn gas_price_limits(#[case] maximum: bool) {
568575
let (mut deps, _network) = create_test_and_network_deps();
569576
deps.setup_deps_for_validate(BlockNumber(0), INTERNAL_TX_BATCH.len(), 1);
570-
let context_config = ContextConfig::default();
577+
let context_config = ContextDynamicConfig::default();
571578
let min_gas_price = context_config.min_l1_gas_price_wei;
572579
let min_data_price = context_config.min_l1_data_gas_price_wei;
573580
let max_gas_price = context_config.max_l1_gas_price_wei;
@@ -591,7 +598,8 @@ async fn gas_price_limits(#[case] maximum: bool) {
591598
let mut context = deps.build_context();
592599

593600
context.set_height_and_round(BlockNumber(0), 0).await;
594-
let (mut content_sender, content_receiver) = mpsc::channel(context.config.proposal_buffer_size);
601+
let (mut content_sender, content_receiver) =
602+
mpsc::channel(context.config.static_config.proposal_buffer_size);
595603

596604
let mut block_info = block_info(BlockNumber(0));
597605

@@ -730,7 +738,7 @@ async fn oracle_fails_on_startup(#[case] l1_oracle_failure: bool) {
730738
panic!("Expected ProposalPart::BlockInfo");
731739
};
732740

733-
let default_context_config = ContextConfig::default();
741+
let default_context_config = ContextDynamicConfig::default();
734742
assert_eq!(info.eth_to_fri_rate, DEFAULT_ETH_TO_FRI_RATE);
735743
// Despite the l1_gas_price_provider being set up not to fail, we still expect the default
736744
// values because eth_to_strk_rate_oracle_client failed.
@@ -827,7 +835,8 @@ async fn oracle_fails_on_second_block(#[case] l1_oracle_failure: bool) {
827835
// Initialize the context for a specific height, starting with round 0.
828836
context.set_height_and_round(BlockNumber(0), 0).await;
829837

830-
let (mut content_sender, content_receiver) = mpsc::channel(context.config.proposal_buffer_size);
838+
let (mut content_sender, content_receiver) =
839+
mpsc::channel(context.config.static_config.proposal_buffer_size);
831840
content_sender.send(ProposalPart::BlockInfo(block_info(BlockNumber(0)))).await.unwrap();
832841
content_sender
833842
.send(ProposalPart::Transactions(TransactionBatch { transactions: TX_BATCH.to_vec() }))
@@ -974,17 +983,20 @@ async fn override_prices_behavior(
974983
deps.cende_ambassador.expect_prepare_blob_for_next_height().return_once(|_| Ok(()));
975984

976985
let context_config = ContextConfig {
977-
override_l2_gas_price_fri,
978-
override_l1_gas_price_wei,
979-
override_l1_data_gas_price_wei,
980-
override_eth_to_fri_rate,
986+
dynamic_config: ContextDynamicConfig {
987+
override_l2_gas_price_fri,
988+
override_l1_gas_price_wei,
989+
override_l1_data_gas_price_wei,
990+
override_eth_to_fri_rate,
991+
..Default::default()
992+
},
981993
..Default::default()
982994
};
983995
let mut context = deps.build_context();
984996
context.config = context_config;
985997

986998
let min_gas_price = VersionedConstants::latest_constants().min_gas_price.0;
987-
let gas_price_params = make_gas_price_params(&context.config);
999+
let gas_price_params = make_gas_price_params(&context.config.dynamic_config);
9881000
let mut expected_l1_prices = PriceInfo {
9891001
base_fee_per_gas: GasPrice(TEMP_ETH_GAS_FEE_IN_WEI),
9901002
blob_fee: GasPrice(TEMP_ETH_BLOB_GAS_FEE_IN_WEI),

0 commit comments

Comments
 (0)