Skip to content

Commit 287e07e

Browse files
chore: remove duplicate metrics
1 parent e5206a6 commit 287e07e

13 files changed

Lines changed: 79 additions & 52 deletions

File tree

finalizer/benches/consensus_state_write.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use alloy_primitives::Address;
22
use commonware_cryptography::{Signer, bls12381, ed25519};
3-
use commonware_runtime::buffer::PoolRef;
3+
use commonware_runtime::buffer::paged::CacheRef;
44
use commonware_runtime::{Runner as _, tokio::Runner};
55
use commonware_storage::translator::EightCap;
66
use commonware_utils::{NZU64, NZUsize};
@@ -90,7 +90,7 @@ fn main() {
9090
log_codec_config: (),
9191
log_items_per_section: NZU64!(4),
9292
translator: EightCap,
93-
buffer_pool: PoolRef::new(std::num::NonZero::new(77u16).unwrap(), NZUsize!(9)),
93+
page_cache: CacheRef::new(std::num::NonZero::new(77u16).unwrap(), NZUsize!(9)),
9494
};
9595

9696
let mut db = FinalizerState::<_, MinPk>::new(context, config).await;

finalizer/src/actor.rs

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ pub struct Finalizer<
8989
cancellation_token: CancellationToken,
9090
_signer_marker: PhantomData<S>,
9191
_variant_marker: PhantomData<V>,
92+
#[cfg(debug_assertions)]
93+
height_gauge: Gauge,
94+
#[cfg(debug_assertions)]
95+
consensus_state_stored_gauge: Gauge,
9296
}
9397

9498
impl<
@@ -143,6 +147,24 @@ impl<
143147
cfg.initial_state
144148
};
145149

150+
// Register debug gauges before moving context into ContextCell
151+
#[cfg(debug_assertions)]
152+
let height_gauge = {
153+
let gauge: Gauge = Gauge::default();
154+
context.register("height", "chain height", gauge.clone());
155+
gauge
156+
};
157+
#[cfg(debug_assertions)]
158+
let consensus_state_stored_gauge = {
159+
let gauge: Gauge = Gauge::default();
160+
context.register(
161+
"consensus_state_stored",
162+
"consensus state stored",
163+
gauge.clone(),
164+
);
165+
gauge
166+
};
167+
146168
(
147169
Self {
148170
context: ContextCell::new(context),
@@ -166,6 +188,10 @@ impl<
166188
cancellation_token: cfg.cancellation_token,
167189
_signer_marker: PhantomData,
168190
_variant_marker: PhantomData,
191+
#[cfg(debug_assertions)]
192+
height_gauge,
193+
#[cfg(debug_assertions)]
194+
consensus_state_stored_gauge,
169195
},
170196
state,
171197
FinalizerMailbox::new(tx),
@@ -353,6 +379,9 @@ impl<
353379
.await;
354380
}
355381

382+
#[cfg(debug_assertions)]
383+
self.height_gauge.set(height as i64);
384+
356385
self.canonical_state.forkchoice.safe_block_hash =
357386
self.canonical_state.forkchoice.head_block_hash;
358387
self.canonical_state.forkchoice.finalized_block_hash =
@@ -510,6 +539,8 @@ impl<
510539
histogram!("finalizer_db_consensus_state_write_micros")
511540
.record(consensus_state_duration);
512541
}
542+
#[cfg(debug_assertions)]
543+
self.consensus_state_stored_gauge.set(new_height as i64);
513544

514545
// This will commit all changes to the state db
515546
#[cfg(feature = "prom")]
@@ -559,14 +590,6 @@ impl<
559590
}))
560591
.await;
561592
epoch_change = true;
562-
563-
#[cfg(debug_assertions)]
564-
{
565-
let gauge: Gauge = Gauge::default();
566-
gauge.set(new_height as i64);
567-
self.context
568-
.register("consensus_state_stored", "chain height", gauge);
569-
}
570593
}
571594

572595
if epoch_change {
@@ -1134,12 +1157,6 @@ async fn execute_block<
11341157
);
11351158
}
11361159

1137-
#[cfg(debug_assertions)]
1138-
{
1139-
let gauge: Gauge = Gauge::default();
1140-
gauge.set(new_height as i64);
1141-
context.register("height", "chain height", gauge);
1142-
}
11431160
state.set_latest_height(new_height);
11441161
state.set_view(block.view());
11451162
state.head_digest = block.digest();

node/src/test_harness/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ pub fn run_until_height(
247247
// If ends with contiguous_height, ensure it is at least required_container
248248
if metric.ends_with("finalizer_height") {
249249
let value = value.parse::<u64>().unwrap();
250-
if value == stop_height {
250+
if value >= stop_height {
251251
nodes_finished.insert(metric.to_string());
252252
if nodes_finished.len() as u32 == n {
253253
success = true;

node/src/tests/checkpointing.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,24 @@ fn test_checkpoint_created() {
143143

144144
if metric.ends_with("consensus_state_stored") {
145145
let height = value.parse::<u64>().unwrap();
146-
assert_eq!(height, BLOCKS_PER_EPOCH - 1);
146+
// Height should be the last block of an epoch
147+
if height > 0 {
148+
assert_eq!((height + 1) % BLOCKS_PER_EPOCH, 0);
149+
}
147150
state_stored.insert(metric.to_string());
148151
}
149152

150153
if metric.ends_with("finalizer_height") {
151154
let height = value.parse::<u64>().unwrap();
152-
if height == stop_height {
155+
if height >= stop_height {
153156
height_reached.insert(metric.to_string());
154157
}
155158
}
156159

157160
if metric.ends_with("finalized_header_stored") {
158161
let height = value.parse::<u64>().unwrap();
159-
assert_eq!(height, BLOCKS_PER_EPOCH - 1);
162+
// Height should be the last block of an epoch
163+
assert_eq!((height + 1) % BLOCKS_PER_EPOCH, 0);
160164
header_stored.insert(metric.to_string());
161165
}
162166
if header_stored.len() as u32 >= n
@@ -333,7 +337,7 @@ fn test_previous_header_hash_matches() {
333337

334338
if metric.ends_with("finalizer_height") {
335339
let height = value.parse::<u64>().unwrap();
336-
if height == stop_height {
340+
if height >= stop_height {
337341
height_reached.insert(metric.to_string());
338342
}
339343
}
@@ -712,7 +716,7 @@ fn test_node_joins_later_with_checkpoint() {
712716

713717
if metric.ends_with("finalizer_height") {
714718
let value = value.parse::<u64>().unwrap();
715-
if value == stop_height {
719+
if value >= stop_height {
716720
nodes_finished.insert(metric.to_string());
717721
if nodes_finished.len() as u32 == n {
718722
success = true;
@@ -949,7 +953,7 @@ fn test_node_joins_later_with_checkpoint_not_in_genesis() {
949953

950954
if metric.ends_with("finalizer_height") {
951955
let value = value.parse::<u64>().unwrap();
952-
if value == stop_height {
956+
if value >= stop_height {
953957
nodes_finished.insert(metric.to_string());
954958
if nodes_finished.len() == n as usize {
955959
success = true;

node/src/tests/execution_requests/deposit_withdrawal_combined.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ fn test_deposit_and_withdrawal_request_single() {
165165

166166
if metric.ends_with("finalizer_height") {
167167
let height = value.parse::<u64>().unwrap();
168-
if height == stop_height {
168+
if height >= stop_height {
169169
height_reached.insert(metric.to_string());
170170
}
171171
}
@@ -394,7 +394,7 @@ fn test_deposit_and_withdrawal_request_multiple() {
394394

395395
if metric.ends_with("finalizer_height") {
396396
let height = value.parse::<u64>().unwrap();
397-
if height == stop_height {
397+
if height >= stop_height {
398398
height_reached.insert(metric.to_string());
399399
}
400400
}
@@ -623,7 +623,7 @@ fn test_deposit_blocked_by_pending_withdrawal() {
623623

624624
if metric.ends_with("finalizer_height") {
625625
let height = value.parse::<u64>().unwrap();
626-
if height == stop_height {
626+
if height >= stop_height {
627627
height_reached.insert(metric.to_string());
628628
}
629629
}
@@ -814,7 +814,7 @@ fn test_withdrawal_blocked_by_pending_deposit() {
814814

815815
if metric.ends_with("finalizer_height") {
816816
let height = value.parse::<u64>().unwrap();
817-
if height == stop_height {
817+
if height >= stop_height {
818818
height_reached.insert(metric.to_string());
819819
}
820820
}
@@ -1015,7 +1015,7 @@ fn test_deposit_and_withdrawal_same_block() {
10151015

10161016
if metric.ends_with("finalizer_height") {
10171017
let height = value.parse::<u64>().unwrap();
1018-
if height == stop_height {
1018+
if height >= stop_height {
10191019
height_reached.insert(metric.to_string());
10201020
}
10211021
}

node/src/tests/execution_requests/deposits.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ fn test_deposit_request_single() {
139139

140140
if metric.ends_with("finalizer_height") {
141141
let height = value.parse::<u64>().unwrap();
142-
if height == stop_height {
142+
if height >= stop_height {
143143
height_reached.insert(metric.to_string());
144144
}
145145
}
@@ -366,7 +366,7 @@ fn test_deposit_request_top_up() {
366366

367367
if metric.ends_with("finalizer_height") {
368368
let height = value.parse::<u64>().unwrap();
369-
if height == stop_height {
369+
if height >= stop_height {
370370
height_reached.insert(metric.to_string());
371371
}
372372
}
@@ -574,7 +574,7 @@ fn test_deposit_less_than_min_stake_rejected() {
574574

575575
if metric.ends_with("finalizer_height") {
576576
let height = value.parse::<u64>().unwrap();
577-
if height == stop_height {
577+
if height >= stop_height {
578578
height_reached.insert(metric.to_string());
579579
}
580580
}
@@ -768,7 +768,7 @@ fn test_deposit_greater_than_max_stake_rejected() {
768768

769769
if metric.ends_with("finalizer_height") {
770770
let height = value.parse::<u64>().unwrap();
771-
if height == stop_height {
771+
if height >= stop_height {
772772
height_reached.insert(metric.to_string());
773773
}
774774
}
@@ -947,7 +947,7 @@ fn test_deposit_request_invalid_node_signature() {
947947

948948
if metric.ends_with("finalizer_height") {
949949
let height = value.parse::<u64>().unwrap();
950-
if height == stop_height {
950+
if height >= stop_height {
951951
height_reached.insert(metric.to_string());
952952
}
953953
}
@@ -1140,7 +1140,7 @@ fn test_deposit_request_invalid_consensus_signature() {
11401140

11411141
if metric.ends_with("finalizer_height") {
11421142
let height = value.parse::<u64>().unwrap();
1143-
if height == stop_height {
1143+
if height >= stop_height {
11441144
height_reached.insert(metric.to_string());
11451145
}
11461146
}
@@ -1349,7 +1349,7 @@ fn test_duplicate_deposit_blocked() {
13491349

13501350
if metric.ends_with("finalizer_height") {
13511351
let height = value.parse::<u64>().unwrap();
1352-
if height == stop_height {
1352+
if height >= stop_height {
13531353
height_reached.insert(metric.to_string());
13541354
}
13551355
}

node/src/tests/execution_requests/protocol_params.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ fn test_protocol_param_max_stake() {
143143

144144
if metric.ends_with("finalizer_height") {
145145
let height = value.parse::<u64>().unwrap();
146-
if height == stop_height {
146+
if height >= stop_height {
147147
height_reached.insert(metric.to_string());
148148
}
149149
}
@@ -377,7 +377,7 @@ fn test_protocol_param_stake_update_committee() {
377377

378378
if metric.ends_with("finalizer_height") {
379379
let height = value.parse::<u64>().unwrap();
380-
if height == stop_height {
380+
if height >= stop_height {
381381
height_reached.insert(metric.to_string());
382382
}
383383
}

node/src/tests/execution_requests/validator_set.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ fn test_added_validators_at_epoch_boundary() {
154154

155155
if metric.ends_with("finalizer_height") {
156156
let height = value.parse::<u64>().unwrap();
157-
if height == stop_height {
157+
if height >= stop_height {
158158
height_reached.insert(metric.to_string());
159159
}
160160
}
@@ -376,7 +376,7 @@ fn test_removed_validators_at_epoch_boundary() {
376376

377377
if metric.ends_with("finalizer_height") {
378378
let height = value.parse::<u64>().unwrap();
379-
if height == stop_height {
379+
if height >= stop_height {
380380
height_reached.insert(metric.to_string());
381381
}
382382
}

node/src/tests/execution_requests/withdrawals.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ fn test_partial_withdrawal_balance_below_minimum_stake() {
168168

169169
if metric.ends_with("finalizer_height") {
170170
let height = value.parse::<u64>().unwrap();
171-
if height == stop_height {
171+
if height >= stop_height {
172172
height_reached.insert(metric.to_string());
173173
}
174174
}
@@ -369,7 +369,7 @@ fn test_duplicate_withdrawal_blocked() {
369369

370370
if metric.ends_with("finalizer_height") {
371371
let height = value.parse::<u64>().unwrap();
372-
if height == stop_height {
372+
if height >= stop_height {
373373
height_reached.insert(metric.to_string());
374374
}
375375
}
@@ -543,7 +543,7 @@ fn test_withdrawal_wrong_source_address_rejected() {
543543

544544
if metric.ends_with("finalizer_height") {
545545
let height = value.parse::<u64>().unwrap();
546-
if height == stop_height {
546+
if height >= stop_height {
547547
height_reached.insert(metric.to_string());
548548
}
549549
}
@@ -718,7 +718,7 @@ fn test_withdrawal_nonexistent_validator_ignored() {
718718

719719
if metric.ends_with("finalizer_height") {
720720
let height = value.parse::<u64>().unwrap();
721-
if height == stop_height {
721+
if height >= stop_height {
722722
height_reached.insert(metric.to_string());
723723
}
724724
}
@@ -911,7 +911,7 @@ fn test_withdrawal_during_onboarding_aborts() {
911911

912912
if metric.ends_with("finalizer_height") {
913913
let height = value.parse::<u64>().unwrap();
914-
if height == stop_height {
914+
if height >= stop_height {
915915
height_reached.insert(metric.to_string());
916916
}
917917
}
@@ -1125,7 +1125,7 @@ fn test_withdrawal_on_last_block_of_epoch_deferred() {
11251125

11261126
if metric.ends_with("finalizer_height") {
11271127
let height = value.parse::<u64>().unwrap();
1128-
if height == stop_height {
1128+
if height >= stop_height {
11291129
height_reached.insert(metric.to_string());
11301130
}
11311131
}

node/src/tests/syncer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ fn test_node_joins_later_no_checkpoint_in_genesis() {
203203

204204
if metric.ends_with("finalizer_height") {
205205
let value = value.parse::<u64>().unwrap();
206-
if value == stop_height {
206+
if value >= stop_height {
207207
nodes_finished.insert(metric.to_string());
208208
if nodes_finished.len() as u32 == n {
209209
success = true;
@@ -427,7 +427,7 @@ fn test_node_joins_later_no_checkpoint_not_in_genesis() {
427427

428428
if metric.ends_with("finalizer_height") {
429429
let value = value.parse::<u64>().unwrap();
430-
if value == stop_height {
430+
if value >= stop_height {
431431
nodes_finished.insert(metric.to_string());
432432
if nodes_finished.len() as u32 == n {
433433
success = true;

0 commit comments

Comments
 (0)