Skip to content

Commit

Permalink
feat(consensus): redefine consensus height metric to working height
Browse files Browse the repository at this point in the history
This will be more useful than stating the most recent decision when we are stuck on block 0.
Also moved out of Context::decision due to sync
  • Loading branch information
matan-starkware committed Aug 13, 2024
1 parent 33df538 commit 8df6db1
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion crates/papyrus_common/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ pub const PAPYRUS_NUM_ACTIVE_OUTBOUND_SESSIONS: &str = "papyrus_num_active_outbo
/// Global variable set by the main config to enable collecting profiling metrics.
pub static COLLECT_PROFILING_METRICS: OnceLock<bool> = OnceLock::new();

/// The height most recently decided by consensus.
/// The height consensus is currently working on.
pub const PAPYRUS_CONSENSUS_HEIGHT: &str = "papyrus_consensus_height";
2 changes: 1 addition & 1 deletion crates/sequencing/papyrus_consensus/run_consensus.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_height(self):
port = self.monitoring_gateway_server_port
command = f"curl -s -X GET http://localhost:{port}/monitoring/metrics | grep -oP 'papyrus_consensus_height \\K\\d+'"
result = subprocess.run(command, shell=True, capture_output=True, text=True)
# returns the latest decided height, or None if node isn't ready or no height reached.
# returns the latest decided height, or None if consensus has not yet started.
return int(result.stdout) if result.stdout else None

def check_height(self):
Expand Down
3 changes: 3 additions & 0 deletions crates/sequencing/papyrus_consensus/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::time::Duration;

use futures::channel::{mpsc, oneshot};
use futures::{Stream, StreamExt};
use papyrus_common::metrics::PAPYRUS_CONSENSUS_HEIGHT;
use papyrus_network::network_manager::ReportSender;
use papyrus_protobuf::consensus::{ConsensusMessage, Proposal};
use papyrus_protobuf::converters::ProtobufConversionError;
Expand Down Expand Up @@ -50,6 +51,8 @@ where
let mut current_height = start_height;
let mut manager = MultiHeightManager::new();
loop {
metrics::gauge!(PAPYRUS_CONSENSUS_HEIGHT, current_height.0 as f64);

let run_height =
manager.run_height(&mut context, current_height, validator_id, &mut network_receiver);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ 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, Vote};
use papyrus_storage::body::BodyStorageReader;
Expand Down Expand Up @@ -237,7 +236,6 @@ impl ConsensusContext for PapyrusConsensusContext {
"Finished consensus for height: {height}. Agreed on block with id: {:x}",
block.id().0
);
metrics::gauge!(PAPYRUS_CONSENSUS_HEIGHT, height as f64);
Ok(())
}
}
Expand Down

0 comments on commit 8df6db1

Please sign in to comment.