diff --git a/crates/sequencing/papyrus_consensus/src/manager.rs b/crates/sequencing/papyrus_consensus/src/manager.rs index c10e4581a7a..9154cf1db4e 100644 --- a/crates/sequencing/papyrus_consensus/src/manager.rs +++ b/crates/sequencing/papyrus_consensus/src/manager.rs @@ -9,12 +9,11 @@ use std::time::Duration; use futures::channel::{mpsc, oneshot}; use futures::{Stream, StreamExt}; -use papyrus_common::metrics as papyrus_metrics; use papyrus_network::network_manager::ReportSender; use papyrus_protobuf::consensus::{ConsensusMessage, Proposal}; use papyrus_protobuf::converters::ProtobufConversionError; use starknet_api::block::{BlockHash, BlockNumber}; -use tracing::{debug, info, instrument}; +use tracing::{debug, instrument}; use crate::single_height_consensus::SingleHeightConsensus; use crate::types::{ @@ -52,13 +51,7 @@ where let decision = manager .run_height(&mut context, current_height, validator_id, &mut network_receiver) .await?; - - info!( - "Finished consensus for height: {current_height}. Agreed on block with id: {:x}", - decision.block.id().0 - ); - debug!("Decision: {:?}", decision); - metrics::gauge!(papyrus_metrics::PAPYRUS_CONSENSUS_HEIGHT, current_height.0 as f64); + context.notify_decision(decision.block, decision.precommits).await?; current_height = current_height.unchecked_next(); } } diff --git a/crates/sequencing/papyrus_consensus/src/manager_test.rs b/crates/sequencing/papyrus_consensus/src/manager_test.rs index 119cee3f977..36daac0ab9c 100644 --- a/crates/sequencing/papyrus_consensus/src/manager_test.rs +++ b/crates/sequencing/papyrus_consensus/src/manager_test.rs @@ -71,6 +71,12 @@ mock! { content_receiver: mpsc::Receiver, fin_receiver: oneshot::Receiver, ) -> Result<(), ConsensusError>; + + async fn notify_decision( + &self, + block: TestBlock, + precommits: Vec, + ) -> Result<(), ConsensusError>; } } diff --git a/crates/sequencing/papyrus_consensus/src/papyrus_consensus_context.rs b/crates/sequencing/papyrus_consensus/src/papyrus_consensus_context.rs index a1372595125..54a843e176c 100644 --- a/crates/sequencing/papyrus_consensus/src/papyrus_consensus_context.rs +++ b/crates/sequencing/papyrus_consensus/src/papyrus_consensus_context.rs @@ -9,15 +9,16 @@ use async_trait::async_trait; use futures::channel::{mpsc, oneshot}; use futures::sink::SinkExt; use futures::StreamExt; +use papyrus_common::metrics::PAPYRUS_CONSENSUS_HEIGHT; use papyrus_network::network_manager::BroadcastSubscriberSender; -use papyrus_protobuf::consensus::{ConsensusMessage, Proposal}; +use papyrus_protobuf::consensus::{ConsensusMessage, Proposal, Vote}; use papyrus_storage::body::BodyStorageReader; use papyrus_storage::header::HeaderStorageReader; use papyrus_storage::{StorageError, StorageReader}; use starknet_api::block::{BlockHash, BlockNumber}; use starknet_api::core::ContractAddress; use starknet_api::transaction::Transaction; -use tracing::{debug, debug_span, Instrument}; +use tracing::{debug, debug_span, info, Instrument}; use crate::types::{ConsensusBlock, ConsensusContext, ConsensusError, ProposalInit, ValidatorId}; use crate::ProposalWrapper; @@ -225,6 +226,20 @@ impl ConsensusContext for PapyrusConsensusContext { ); Ok(()) } + + async fn notify_decision( + &self, + block: Self::Block, + precommits: Vec, + ) -> Result<(), ConsensusError> { + let height = precommits[0].height; + info!( + "Finished consensus for height: {height}. Agreed on block with id: {:x}", + block.id().0 + ); + metrics::gauge!(PAPYRUS_CONSENSUS_HEIGHT, height as f64); + Ok(()) + } } const SLEEP_BETWEEN_CHECK_FOR_BLOCK: Duration = Duration::from_secs(10); diff --git a/crates/sequencing/papyrus_consensus/src/test_utils.rs b/crates/sequencing/papyrus_consensus/src/test_utils.rs index 098dc262987..008247052d5 100644 --- a/crates/sequencing/papyrus_consensus/src/test_utils.rs +++ b/crates/sequencing/papyrus_consensus/src/test_utils.rs @@ -1,7 +1,7 @@ use async_trait::async_trait; use futures::channel::{mpsc, oneshot}; use mockall::mock; -use papyrus_protobuf::consensus::ConsensusMessage; +use papyrus_protobuf::consensus::{ConsensusMessage, Vote}; use starknet_api::block::{BlockHash, BlockNumber}; use crate::types::{ConsensusBlock, ConsensusContext, ConsensusError, ProposalInit, ValidatorId}; @@ -57,5 +57,11 @@ mock! { content_receiver: mpsc::Receiver, fin_receiver: oneshot::Receiver, ) -> Result<(), ConsensusError>; + + async fn notify_decision( + &self, + block: TestBlock, + precommits: Vec, + ) -> Result<(), ConsensusError>; } } diff --git a/crates/sequencing/papyrus_consensus/src/types.rs b/crates/sequencing/papyrus_consensus/src/types.rs index d213bc04afb..b685c551f31 100644 --- a/crates/sequencing/papyrus_consensus/src/types.rs +++ b/crates/sequencing/papyrus_consensus/src/types.rs @@ -135,6 +135,16 @@ pub trait ConsensusContext { content_receiver: mpsc::Receiver<::ProposalChunk>, fin_receiver: oneshot::Receiver, ) -> Result<(), ConsensusError>; + + /// Update the context that a decision has been reached for a given height. + /// - `block` identifies the decision. + /// - `precommits` - All precommits must be for the same `(block.id(), height, round)` and form + /// a quorum (>2/3 of the voting power) for this height. + async fn notify_decision( + &self, + block: Self::Block, + precommits: Vec, + ) -> Result<(), ConsensusError>; } #[derive(PartialEq)]