Skip to content

Commit 73b7de6

Browse files
committed
[squashed] Cache participating indices for Altair epoch processing #2416
Squashed commit of the following: commit 40b4ac3 Author: Paul Hauner <[email protected]> Date: Thu Jul 15 10:10:07 2021 +1000 Move ValidatorsStatuses into base commit d4fb7fe Author: Paul Hauner <[email protected]> Date: Thu Jul 15 09:59:44 2021 +1000 Unify participation metrics commit b9d8e07 Author: Paul Hauner <[email protected]> Date: Mon Jul 12 19:04:22 2021 +1000 Log error when exposing metrics fails commit 4533190 Author: Paul Hauner <[email protected]> Date: Mon Jul 12 18:45:54 2021 +1000 Adjust error handling commit f7e3f4a Author: Paul Hauner <[email protected]> Date: Mon Jul 12 18:39:36 2021 +1000 Add `Error` enum commit b48e02a Author: Paul Hauner <[email protected]> Date: Mon Jul 12 18:31:31 2021 +1000 Tidy, fix error handling commit 1bdcb9e Author: Paul Hauner <[email protected]> Date: Mon Jul 12 18:12:31 2021 +1000 Tidy, change "active" to "active unslashed" commit dbbff17 Author: Paul Hauner <[email protected]> Date: Mon Jul 12 16:58:33 2021 +1000 Tidy commit 751abe5 Author: Paul Hauner <[email protected]> Date: Mon Jul 12 11:29:14 2021 +1000 Avoid creating logs for offline vals commit 8644b05 Author: Paul Hauner <[email protected]> Date: Fri Jun 25 14:01:22 2021 +1000 Refactor validator inclusion endpoint commit de7ad33 Author: Paul Hauner <[email protected]> Date: Fri Jun 25 12:16:38 2021 +1000 Remove old balance getter in ef_tests commit 3fe9797 Author: Paul Hauner <[email protected]> Date: Fri Jun 25 12:11:19 2021 +1000 Remove flag error type FIXME commit e9ec4ba Author: realbigsean <[email protected]> Date: Thu Jun 17 17:15:54 2021 -0400 Couple more `unstable` merge fixes commit 10c793b Author: Paul Hauner <[email protected]> Date: Fri Jun 25 11:56:04 2021 +1000 Tidy, remove unused function, fix init length commit 96efe87 Author: Paul Hauner <[email protected]> Date: Fri Jun 25 11:41:40 2021 +1000 Tidy, add comments commit 9f08360 Author: Paul Hauner <[email protected]> Date: Fri Jun 25 11:03:36 2021 +1000 Working single-loop refactor commit 1f85249 Author: Paul Hauner <[email protected]> Date: Fri Jun 25 10:54:02 2021 +1000 Partial one-loop refactor commit 81b6768 Author: Paul Hauner <[email protected]> Date: Fri Jun 25 10:27:28 2021 +1000 Fix eligible indices commit 3b01744 Author: Paul Hauner <[email protected]> Date: Fri Jun 25 10:08:28 2021 +1000 Used cached indices commit 5584854 Author: Paul Hauner <[email protected]> Date: Fri Jun 25 09:37:56 2021 +1000 Fix active indices commit 3a38047 Author: Paul Hauner <[email protected]> Date: Fri Jun 25 09:23:22 2021 +1000 Fix balances issue commit 957bcad Author: Paul Hauner <[email protected]> Date: Thu Jun 24 16:40:45 2021 +1000 Fix EF test compile errors commit a8b0a7c Author: Paul Hauner <[email protected]> Date: Thu Jun 24 16:40:32 2021 +1000 Remove junk file commit 99292c2 Author: Paul Hauner <[email protected]> Date: Thu Jun 24 15:49:45 2021 +1000 Add eligible indices commit c6840bc Author: Paul Hauner <[email protected]> Date: Thu Jun 24 15:23:09 2021 +1000 Swap back to ParticipationCache commit ab687f3 Author: Paul Hauner <[email protected]> Date: Thu Jun 24 13:14:53 2021 +1000 Bring balances into ParticipationCache commit b6d634c Author: Paul Hauner <[email protected]> Date: Thu Jun 24 11:57:54 2021 +1000 Add EpochCache commit c5658f0 Author: Paul Hauner <[email protected]> Date: Thu Jun 24 11:45:44 2021 +1000 Tidy, remove metric commit 22fbf3e Author: Paul Hauner <[email protected]> Date: Wed Jun 23 16:45:28 2021 +1000 Remove unslashed indices function commit 6f87cd5 Author: Paul Hauner <[email protected]> Date: Wed Jun 23 15:42:12 2021 +1000 Update EpochProcessingSummary commit 1bb1c8f Author: Paul Hauner <[email protected]> Date: Wed Jun 23 15:07:06 2021 +1000 Add initial participation cache
1 parent 3ec3742 commit 73b7de6

26 files changed

+1066
-346
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ cargo-fmt:
9595
check-benches:
9696
cargo check --workspace --benches
9797

98-
# Typechecks consensus code *without* allowing deprecated legacy arithmetic
98+
# Typechecks consensus code *without* allowing deprecated legacy arithmetic or metrics.
9999
check-consensus:
100100
cargo check --manifest-path=consensus/state_processing/Cargo.toml --no-default-features
101101

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,11 @@ use slot_clock::SlotClock;
5858
use ssz::Encode;
5959
use state_processing::{
6060
block_signature_verifier::{BlockSignatureVerifier, Error as BlockSignatureVerifierError},
61-
per_block_processing,
62-
per_epoch_processing::EpochProcessingSummary,
63-
per_slot_processing,
61+
per_block_processing, per_slot_processing,
6462
state_advance::partial_state_advance,
6563
BlockProcessingError, BlockSignatureStrategy, SlotProcessingError,
6664
};
6765
use std::borrow::Cow;
68-
use std::convert::TryFrom;
6966
use std::fs;
7067
use std::io::Write;
7168
use store::{Error as DBError, HotColdDB, HotStateSummary, KeyValueStore, StoreOp};
@@ -972,12 +969,19 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> {
972969
};
973970

974971
if let Some(summary) = per_slot_processing(&mut state, Some(state_root), &chain.spec)? {
975-
summaries.push(summary)
972+
// Expose Prometheus metrics.
973+
if let Err(e) = summary.observe_metrics() {
974+
error!(
975+
chain.log,
976+
"Failed to observe epoch summary metrics";
977+
"src" => "block_verification",
978+
"error" => ?e
979+
);
980+
}
981+
summaries.push(summary);
976982
}
977983
}
978984

979-
expose_participation_metrics(&summaries);
980-
981985
// If the block is sufficiently recent, notify the validator monitor.
982986
if let Some(slot) = chain.slot_clock.now() {
983987
let epoch = slot.epoch(T::EthSpec::slots_per_epoch());
@@ -991,7 +995,15 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> {
991995
// performing `per_slot_processing`.
992996
for (i, summary) in summaries.iter().enumerate() {
993997
let epoch = state.current_epoch() - Epoch::from(summaries.len() - i);
994-
validator_monitor.process_validator_statuses(epoch, &summary.statuses);
998+
if let Err(e) =
999+
validator_monitor.process_validator_statuses(epoch, &summary, &chain.spec)
1000+
{
1001+
error!(
1002+
chain.log,
1003+
"Failed to process validator statuses";
1004+
"error" => ?e
1005+
);
1006+
}
9951007
}
9961008
}
9971009
}
@@ -1442,45 +1454,6 @@ fn verify_header_signature<T: BeaconChainTypes>(
14421454
}
14431455
}
14441456

1445-
fn expose_participation_metrics(summaries: &[EpochProcessingSummary]) {
1446-
if !cfg!(feature = "participation_metrics") {
1447-
return;
1448-
}
1449-
1450-
for summary in summaries {
1451-
let b = &summary.total_balances;
1452-
1453-
metrics::maybe_set_float_gauge(
1454-
&metrics::PARTICIPATION_PREV_EPOCH_ATTESTER,
1455-
participation_ratio(b.previous_epoch_attesters(), b.previous_epoch()),
1456-
);
1457-
1458-
metrics::maybe_set_float_gauge(
1459-
&metrics::PARTICIPATION_PREV_EPOCH_TARGET_ATTESTER,
1460-
participation_ratio(b.previous_epoch_target_attesters(), b.previous_epoch()),
1461-
);
1462-
1463-
metrics::maybe_set_float_gauge(
1464-
&metrics::PARTICIPATION_PREV_EPOCH_HEAD_ATTESTER,
1465-
participation_ratio(b.previous_epoch_head_attesters(), b.previous_epoch()),
1466-
);
1467-
}
1468-
}
1469-
1470-
fn participation_ratio(section: u64, total: u64) -> Option<f64> {
1471-
// Reduce the precision to help ensure we fit inside a u32.
1472-
const PRECISION: u64 = 100_000_000;
1473-
1474-
let section: f64 = u32::try_from(section / PRECISION).ok()?.into();
1475-
let total: f64 = u32::try_from(total / PRECISION).ok()?.into();
1476-
1477-
if total > 0_f64 {
1478-
Some(section / total)
1479-
} else {
1480-
None
1481-
}
1482-
}
1483-
14841457
fn write_state<T: EthSpec>(prefix: &str, state: &BeaconState<T>, log: &Logger) {
14851458
if WRITE_BLOCK_PROCESSING_SSZ {
14861459
let root = state.tree_hash_root();

beacon_node/beacon_chain/src/metrics.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -330,21 +330,6 @@ lazy_static! {
330330
pub static ref OP_POOL_NUM_SYNC_CONTRIBUTIONS: Result<IntGauge> =
331331
try_create_int_gauge("beacon_op_pool_sync_contributions_total", "Count of sync contributions in the op pool");
332332

333-
/*
334-
* Participation Metrics
335-
*/
336-
pub static ref PARTICIPATION_PREV_EPOCH_ATTESTER: Result<Gauge> = try_create_float_gauge(
337-
"beacon_participation_prev_epoch_attester",
338-
"Ratio of attesting balances to total balances"
339-
);
340-
pub static ref PARTICIPATION_PREV_EPOCH_TARGET_ATTESTER: Result<Gauge> = try_create_float_gauge(
341-
"beacon_participation_prev_epoch_target_attester",
342-
"Ratio of target-attesting balances to total balances"
343-
);
344-
pub static ref PARTICIPATION_PREV_EPOCH_HEAD_ATTESTER: Result<Gauge> = try_create_float_gauge(
345-
"beacon_participation_prev_epoch_head_attester",
346-
"Ratio of head-attesting balances to total balances"
347-
);
348333

349334
/*
350335
* Attestation Observation Metrics

beacon_node/beacon_chain/src/state_advance_timer.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,32 @@ fn advance_head<T: BeaconChainTypes>(
233233
if let Some(summary) = per_slot_processing(&mut state, state_root, &beacon_chain.spec)
234234
.map_err(BeaconChainError::from)?
235235
{
236+
// Expose Prometheus metrics.
237+
if let Err(e) = summary.observe_metrics() {
238+
error!(
239+
log,
240+
"Failed to observe epoch summary metrics";
241+
"src" => "state_advance_timer",
242+
"error" => ?e
243+
);
244+
}
245+
236246
// Only notify the validator monitor for recent blocks.
237247
if state.current_epoch() + VALIDATOR_MONITOR_HISTORIC_EPOCHS as u64
238248
>= current_slot.epoch(T::EthSpec::slots_per_epoch())
239249
{
240250
// Potentially create logs/metrics for locally monitored validators.
241-
beacon_chain
251+
if let Err(e) = beacon_chain
242252
.validator_monitor
243253
.read()
244-
.process_validator_statuses(state.current_epoch(), &summary.statuses);
254+
.process_validator_statuses(state.current_epoch(), &summary, &beacon_chain.spec)
255+
{
256+
error!(
257+
log,
258+
"Unable to process validator statuses";
259+
"error" => ?e
260+
);
261+
}
245262
}
246263
}
247264

0 commit comments

Comments
 (0)