Skip to content

Commit d7b6b01

Browse files
committed
feat: add prometheus monitoring for signer agreement state conflicts, #5918
1 parent a0e3b9b commit d7b6b01

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

stacks-signer/src/monitoring/mod.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ SignerAgreementStateChangeReason {
3535
ProtocolUpgrade("protocol_upgrade"),
3636
});
3737

38+
define_named_enum!(
39+
/// Represent different conflict types on signer agreement protocol
40+
SignerAgreementStateConflict {
41+
/// Waiting for burn block propagation to be aligned with the signer set
42+
BurnBlockDelay("burn_block_delay"),
43+
/// Waiting for stacks block propagation to be aligned with the signer set
44+
StacksBlockDelay("stacks_block_delay"),
45+
/// Not allowing reorg to a new miner
46+
ReorgDisallowed("reorg_disallowed"),
47+
});
48+
3849
/// Actions for updating metrics
3950
#[cfg(feature = "monitoring_prom")]
4051
pub mod actions {
@@ -44,7 +55,7 @@ pub mod actions {
4455

4556
use crate::config::GlobalConfig;
4657
use crate::monitoring::prometheus::*;
47-
use crate::monitoring::SignerAgreementStateChangeReason;
58+
use crate::monitoring::{SignerAgreementStateChangeReason, SignerAgreementStateConflict};
4859
use crate::v0::signer_state::LocalStateMachine;
4960

5061
/// Update stacks tip height gauge
@@ -134,6 +145,14 @@ pub mod actions {
134145
.inc();
135146
}
136147

148+
/// Increment signer agreement state conflict counter
149+
pub fn increment_signer_agreement_state_conflict(conflict: SignerAgreementStateConflict) {
150+
let label_value = conflict.get_name();
151+
SIGNER_AGREEMENT_STATE_CONFLICTS
152+
.with_label_values(&[&label_value])
153+
.inc();
154+
}
155+
137156
/// Start serving monitoring metrics.
138157
/// This will only serve the metrics if the `monitoring_prom` feature is enabled.
139158
pub fn start_serving_monitoring_metrics(config: GlobalConfig) -> Result<(), String> {
@@ -157,7 +176,7 @@ pub mod actions {
157176
use blockstack_lib::chainstate::nakamoto::NakamotoBlock;
158177
use stacks_common::info;
159178

160-
use crate::monitoring::SignerAgreementStateChangeReason;
179+
use crate::monitoring::{SignerAgreementStateChangeReason, SignerAgreementStateConflict};
161180
use crate::v0::signer_state::LocalStateMachine;
162181
use crate::GlobalConfig;
163182

@@ -212,6 +231,9 @@ pub mod actions {
212231
) {
213232
}
214233

234+
/// Increment signer agreement state conflict counter
235+
pub fn increment_signer_agreement_state_conflict(_conflict: SignerAgreementStateConflict) {}
236+
215237
/// Start serving monitoring metrics.
216238
/// This will only serve the metrics if the `monitoring_prom` feature is enabled.
217239
pub fn start_serving_monitoring_metrics(config: GlobalConfig) -> Result<(), String> {

stacks-signer/src/monitoring/prometheus.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@ lazy_static! {
8585
&["reason"]
8686
).unwrap();
8787

88+
pub static ref SIGNER_AGREEMENT_STATE_CONFLICTS: IntCounterVec = register_int_counter_vec!(
89+
"stacks_signer_agreement_state_conflicts",
90+
"The number of state machine conflicts in signer agreement protocol. `conflict` can be one of: 'burn_block_delay', 'stacks_block_delay', 'reorg_disallowed'",
91+
&["conflict"]
92+
).unwrap();
93+
8894
pub static ref SIGNER_LOCAL_STATE_MACHINE: Mutex<Option<LocalStateMachine>> = Mutex::new(None);
8995
}
9096

stacks-signer/src/v0/signer_state.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ impl GlobalStateEvaluator {
177177
} = local_update.content;
178178
let (global_burn_view, _) = self.determine_global_burn_view(local_address, local_update)?;
179179
if current_burn_block != global_burn_view {
180+
crate::monitoring::actions::increment_signer_agreement_state_conflict(
181+
crate::monitoring::SignerAgreementStateConflict::BurnBlockDelay,
182+
);
180183
return None;
181184
}
182185
let mut current_miners = HashMap::new();
@@ -210,6 +213,9 @@ impl GlobalStateEvaluator {
210213
}
211214
}
212215
}
216+
crate::monitoring::actions::increment_signer_agreement_state_conflict(
217+
crate::monitoring::SignerAgreementStateConflict::ReorgDisallowed,
218+
);
213219
None
214220
}
215221

0 commit comments

Comments
 (0)