Skip to content

Commit

Permalink
feat(consensus): set active/obserever height based on batcher height
Browse files Browse the repository at this point in the history
  • Loading branch information
asmaastarkware committed Dec 17, 2024
1 parent 5217539 commit c591619
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/starknet_consensus_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ papyrus_consensus_orchestrator.workspace = true
papyrus_network.workspace = true
papyrus_protobuf.workspace = true
serde.workspace = true
starknet_api.workspace = true
starknet_batcher_types.workspace = true
starknet_sequencer_infra.workspace = true
starknet_state_sync_types.workspace = true
Expand Down
19 changes: 16 additions & 3 deletions crates/starknet_consensus_manager/src/consensus_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use papyrus_consensus_orchestrator::sequencer_consensus_context::SequencerConsen
use papyrus_network::gossipsub_impl::Topic;
use papyrus_network::network_manager::{BroadcastTopicChannels, NetworkManager};
use papyrus_protobuf::consensus::{ConsensusMessage, ProposalPart, StreamMessage};
use starknet_api::block::BlockNumber;
use starknet_batcher_types::communication::SharedBatcherClient;
use starknet_sequencer_infra::component_definitions::ComponentStarter;
use starknet_sequencer_infra::errors::ComponentError;
Expand Down Expand Up @@ -63,6 +64,19 @@ impl ConsensusManager {
let (outbound_internal_sender, inbound_internal_receiver, mut stream_handler_task_handle) =
StreamHandler::get_channels(inbound_network_receiver, outbound_network_sender);

let observer_height =
self.batcher_client.get_height().await.map(|h| h.height).map_err(|e| {
error!("Failed to get height from batcher: {:?}", e);
ConsensusError::InternalNetworkError(
"Failed to get height from batcher".to_string(),
)
})?;
let active_height = if self.config.consensus_config.start_height == observer_height {
observer_height
} else {
BlockNumber(observer_height.0 + 1)
};

let context = SequencerConsensusContext::new(
Arc::clone(&self.batcher_client),
outbound_internal_sender,
Expand All @@ -74,9 +88,8 @@ impl ConsensusManager {
let mut network_handle = tokio::task::spawn(network_manager.run());
let consensus_task = papyrus_consensus::run_consensus(
context,
self.config.consensus_config.start_height,
// TODO(Asmaa): replace with the correct value.
self.config.consensus_config.start_height,
active_height,
observer_height,
self.config.consensus_config.validator_id,
self.config.consensus_config.consensus_delay,
self.config.consensus_config.timeouts.clone(),
Expand Down

0 comments on commit c591619

Please sign in to comment.