Skip to content

Commit 62b8910

Browse files
Bo Wuareshand
authored andcommitted
sync virtual genesis id between consensus and execution
1 parent e990929 commit 62b8910

File tree

15 files changed

+102
-40
lines changed

15 files changed

+102
-40
lines changed

config/src/config/consensus_config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ impl Default for ConsensusConfig {
363363
max_pending_rounds_in_commit_vote_cache: 100,
364364
optimistic_sig_verification: true,
365365
enable_round_timeout_msg: true,
366-
enable_pipeline: false,
366+
enable_pipeline: true,
367367
}
368368
}
369369
}

consensus/consensus-types/src/pipelined_block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl PipelinedBlock {
580580
.await
581581
.map(|(compute_result, execution_time, _)| (compute_result, execution_time))
582582
.map_err(|e| ExecutorError::InternalError {
583-
error: e.to_string()
583+
error: e.to_string(),
584584
})
585585
}
586586

consensus/src/consensus_observer/observer/consensus_observer.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,16 +1077,17 @@ impl ConsensusObserver {
10771077
.start_epoch(
10781078
sk,
10791079
epoch_state.clone(),
1080-
dummy_signer.clone(),
1080+
dummy_signer,
10811081
payload_manager,
10821082
&consensus_config,
10831083
&execution_config,
10841084
&randomness_config,
1085-
None,
1086-
None,
1085+
None, // rand_config
1086+
None, // fast_rand_config
10871087
rand_msg_rx,
1088-
0,
1089-
self.pipeline_enabled(),
1088+
0, // highest_committed_round
1089+
self.observer_epoch_state.pipeline_enabled(),
1090+
None, // Consensus observer doesn't use virtual genesis
10901091
)
10911092
.await;
10921093
if self.pipeline_enabled() {

consensus/src/epoch_manager.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,13 @@ impl<P: OnChainConfigProvider> EpochManager<P> {
844844

845845
let safety_rules_container = Arc::new(Mutex::new(safety_rules));
846846

847+
// Extract virtual genesis block ID if consensus created one
848+
let virtual_genesis_block_id = if recovery_data.commit_root_block().is_genesis_block() {
849+
Some(recovery_data.commit_root_block().id())
850+
} else {
851+
None
852+
};
853+
847854
self.execution_client
848855
.start_epoch(
849856
consensus_key.clone(),
@@ -858,6 +865,7 @@ impl<P: OnChainConfigProvider> EpochManager<P> {
858865
rand_msg_rx,
859866
recovery_data.commit_root_block().round(),
860867
self.config.enable_pipeline,
868+
virtual_genesis_block_id,
861869
)
862870
.await;
863871
let consensus_sk = consensus_key;
@@ -1422,6 +1430,7 @@ impl<P: OnChainConfigProvider> EpochManager<P> {
14221430
rand_msg_rx,
14231431
highest_committed_round,
14241432
self.config.enable_pipeline,
1433+
None, // DAG doesn't use virtual genesis
14251434
)
14261435
.await;
14271436

@@ -1479,7 +1488,7 @@ impl<P: OnChainConfigProvider> EpochManager<P> {
14791488
//TODO(l1-migration) turn on quorum store
14801489
fn enable_quorum_store(&mut self, onchain_config: &OnChainConsensusConfig) -> bool {
14811490
fail_point!("consensus::start_new_epoch::disable_qs", |_| false);
1482-
onchain_config.quorum_store_enabled() && false
1491+
onchain_config.quorum_store_enabled()
14831492
}
14841493

14851494
async fn process_message(

consensus/src/persistent_liveness_storage.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ impl LedgerRecoveryData {
110110
// We start from the block that storage's latest ledger info, if storage has end-epoch
111111
// LedgerInfo, we generate the virtual genesis block
112112
let ends_epoch = self.storage_ledger.ledger_info().ends_epoch();
113+
//TODO(l1-migration): when blocks is empty and we have to create virtual genesis from storage to start consensus.
114+
// This is only required for migration when we only have a single validator network
113115
let blocks_empty = blocks.is_empty();
114116
let (latest_commit_id, latest_ledger_info_sig) = if ends_epoch || blocks_empty {
115117
let genesis =
@@ -211,6 +213,7 @@ impl LedgerRecoveryData {
211213
// We start from the block that storage's latest ledger info, if storage has end-epoch
212214
// LedgerInfo, we generate the virtual genesis block
213215
let ends_epoch = self.storage_ledger.ledger_info().ends_epoch();
216+
// TODO(l1-migration): This is for single validator network boostrap. We created virtual genesis to start the consensus
214217
let blocks_empty = blocks.is_empty();
215218
let (root_id, latest_ledger_info_sig) = if ends_epoch || blocks_empty {
216219
let genesis =

consensus/src/pipeline/execution_client.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub trait TExecutionClient: Send + Sync {
7272
rand_msg_rx: aptos_channel::Receiver<AccountAddress, IncomingRandGenRequest>,
7373
highest_committed_round: Round,
7474
new_pipeline_enabled: bool,
75+
virtual_genesis_block_id: Option<aptos_crypto::HashValue>,
7576
);
7677

7778
/// This is needed for some DAG tests. Clean this up as a TODO.
@@ -325,8 +326,9 @@ impl TExecutionClient for ExecutionProxyClient {
325326
rand_msg_rx: aptos_channel::Receiver<AccountAddress, IncomingRandGenRequest>,
326327
highest_committed_round: Round,
327328
new_pipeline_enabled: bool,
329+
virtual_genesis_block_id: Option<aptos_crypto::HashValue>,
328330
) {
329-
let maybe_rand_msg_tx = self.spawn_decoupled_execution(
331+
self.spawn_decoupled_execution(
330332
maybe_consensus_key,
331333
commit_signer_provider,
332334
epoch_state.clone(),
@@ -357,9 +359,8 @@ impl TExecutionClient for ExecutionProxyClient {
357359
transaction_deduper,
358360
randomness_enabled,
359361
onchain_consensus_config.order_vote_enabled(),
362+
virtual_genesis_block_id,
360363
);
361-
362-
maybe_rand_msg_tx
363364
}
364365

365366
fn get_execution_channel(&self) -> Option<UnboundedSender<OrderedBlocks>> {
@@ -546,6 +547,7 @@ impl TExecutionClient for DummyExecutionClient {
546547
_rand_msg_rx: aptos_channel::Receiver<AccountAddress, IncomingRandGenRequest>,
547548
_highest_committed_round: Round,
548549
_new_pipeline_enabled: bool,
550+
_virtual_genesis_block_id: Option<aptos_crypto::HashValue>,
549551
) {
550552
}
551553

consensus/src/state_computer.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,17 @@ impl StateComputer for ExecutionProxy {
492492
transaction_deduper: Arc<dyn TransactionDeduper>,
493493
randomness_enabled: bool,
494494
order_vote_enabled: bool,
495+
virtual_genesis_block_id: Option<HashValue>,
495496
) {
497+
// Reset the executor with the virtual genesis block ID if provided
498+
if let Some(virtual_genesis_id) = virtual_genesis_block_id {
499+
self.executor
500+
.reset_with_virtual_genesis(Some(virtual_genesis_id))
501+
.expect("Failed to reset executor with virtual genesis");
502+
} else {
503+
self.executor.reset().expect("Failed to reset executor");
504+
}
505+
496506
*self.state.write() = Some(MutableState {
497507
validators: epoch_state
498508
.verifier
@@ -668,6 +678,7 @@ async fn test_commit_sync_race() {
668678
create_transaction_deduper(TransactionDeduperType::NoDedup),
669679
false,
670680
false,
681+
None,
671682
);
672683
executor
673684
.commit(vec![], generate_li(1, 1), callback.clone())

consensus/src/state_computer_tests.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ async fn should_see_and_notify_validator_txns() {
195195
Arc::new(NoOpDeduper {}),
196196
false,
197197
false,
198+
None,
198199
);
199200

200201
// Ensure the dummy executor has received the txns.

consensus/src/state_replication.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ pub trait StateComputer: Send + Sync {
7373
transaction_deduper: Arc<dyn TransactionDeduper>,
7474
randomness_enabled: bool,
7575
order_vote_enabled: bool,
76+
virtual_genesis_block_id: Option<aptos_crypto::HashValue>,
7677
);
7778

7879
// Reconfigure to clear epoch state at end of epoch.

consensus/src/test_utils/mock_execution_client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ impl TExecutionClient for MockExecutionClient {
107107
_rand_msg_rx: aptos_channel::Receiver<AccountAddress, IncomingRandGenRequest>,
108108
_highest_committed_round: Round,
109109
_new_pipeline_enabled: bool,
110+
_virtual_genesis_block_id: Option<aptos_crypto::HashValue>,
110111
) {
111112
}
112113

0 commit comments

Comments
 (0)