Skip to content

Commit

Permalink
[squashed] Cache participating indices for Altair epoch processing #2416
Browse files Browse the repository at this point in the history


Squashed commit of the following:

commit 40b4ac3
Author: Paul Hauner <paul@paulhauner.com>
Date:   Thu Jul 15 10:10:07 2021 +1000

    Move ValidatorsStatuses into base

commit d4fb7fe
Author: Paul Hauner <paul@paulhauner.com>
Date:   Thu Jul 15 09:59:44 2021 +1000

    Unify participation metrics

commit b9d8e07
Author: Paul Hauner <paul@paulhauner.com>
Date:   Mon Jul 12 19:04:22 2021 +1000

    Log error when exposing metrics fails

commit 4533190
Author: Paul Hauner <paul@paulhauner.com>
Date:   Mon Jul 12 18:45:54 2021 +1000

    Adjust error handling

commit f7e3f4a
Author: Paul Hauner <paul@paulhauner.com>
Date:   Mon Jul 12 18:39:36 2021 +1000

    Add `Error` enum

commit b48e02a
Author: Paul Hauner <paul@paulhauner.com>
Date:   Mon Jul 12 18:31:31 2021 +1000

    Tidy, fix error handling

commit 1bdcb9e
Author: Paul Hauner <paul@paulhauner.com>
Date:   Mon Jul 12 18:12:31 2021 +1000

    Tidy, change "active" to "active unslashed"

commit dbbff17
Author: Paul Hauner <paul@paulhauner.com>
Date:   Mon Jul 12 16:58:33 2021 +1000

    Tidy

commit 751abe5
Author: Paul Hauner <paul@paulhauner.com>
Date:   Mon Jul 12 11:29:14 2021 +1000

    Avoid creating logs for offline vals

commit 8644b05
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 14:01:22 2021 +1000

    Refactor validator inclusion endpoint

commit de7ad33
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 12:16:38 2021 +1000

    Remove old balance getter in ef_tests

commit 3fe9797
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 12:11:19 2021 +1000

    Remove flag error type FIXME

commit e9ec4ba
Author: realbigsean <seananderson33@gmail.com>
Date:   Thu Jun 17 17:15:54 2021 -0400

    Couple more `unstable` merge fixes

commit 10c793b
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 11:56:04 2021 +1000

    Tidy, remove unused function, fix init length

commit 96efe87
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 11:41:40 2021 +1000

    Tidy, add comments

commit 9f08360
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 11:03:36 2021 +1000

    Working single-loop refactor

commit 1f85249
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 10:54:02 2021 +1000

    Partial one-loop refactor

commit 81b6768
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 10:27:28 2021 +1000

    Fix eligible indices

commit 3b01744
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 10:08:28 2021 +1000

    Used cached indices

commit 5584854
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 09:37:56 2021 +1000

    Fix active indices

commit 3a38047
Author: Paul Hauner <paul@paulhauner.com>
Date:   Fri Jun 25 09:23:22 2021 +1000

    Fix balances issue

commit 957bcad
Author: Paul Hauner <paul@paulhauner.com>
Date:   Thu Jun 24 16:40:45 2021 +1000

    Fix EF test compile errors

commit a8b0a7c
Author: Paul Hauner <paul@paulhauner.com>
Date:   Thu Jun 24 16:40:32 2021 +1000

    Remove junk file

commit 99292c2
Author: Paul Hauner <paul@paulhauner.com>
Date:   Thu Jun 24 15:49:45 2021 +1000

    Add eligible indices

commit c6840bc
Author: Paul Hauner <paul@paulhauner.com>
Date:   Thu Jun 24 15:23:09 2021 +1000

    Swap back to ParticipationCache

commit ab687f3
Author: Paul Hauner <paul@paulhauner.com>
Date:   Thu Jun 24 13:14:53 2021 +1000

    Bring balances into ParticipationCache

commit b6d634c
Author: Paul Hauner <paul@paulhauner.com>
Date:   Thu Jun 24 11:57:54 2021 +1000

    Add EpochCache

commit c5658f0
Author: Paul Hauner <paul@paulhauner.com>
Date:   Thu Jun 24 11:45:44 2021 +1000

    Tidy, remove metric

commit 22fbf3e
Author: Paul Hauner <paul@paulhauner.com>
Date:   Wed Jun 23 16:45:28 2021 +1000

    Remove unslashed indices function

commit 6f87cd5
Author: Paul Hauner <paul@paulhauner.com>
Date:   Wed Jun 23 15:42:12 2021 +1000

    Update EpochProcessingSummary

commit 1bb1c8f
Author: Paul Hauner <paul@paulhauner.com>
Date:   Wed Jun 23 15:07:06 2021 +1000

    Add initial participation cache
  • Loading branch information
michaelsproul committed Jul 26, 2021
1 parent 9c13543 commit 32b8685
Show file tree
Hide file tree
Showing 26 changed files with 1,066 additions and 346 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ cargo-fmt:
check-benches:
cargo check --workspace --benches

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

Expand Down
67 changes: 20 additions & 47 deletions beacon_node/beacon_chain/src/block_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,11 @@ use slot_clock::SlotClock;
use ssz::Encode;
use state_processing::{
block_signature_verifier::{BlockSignatureVerifier, Error as BlockSignatureVerifierError},
per_block_processing,
per_epoch_processing::EpochProcessingSummary,
per_slot_processing,
per_block_processing, per_slot_processing,
state_advance::partial_state_advance,
BlockProcessingError, BlockSignatureStrategy, SlotProcessingError,
};
use std::borrow::Cow;
use std::convert::TryFrom;
use std::fs;
use std::io::Write;
use store::{Error as DBError, HotColdDB, HotStateSummary, KeyValueStore, StoreOp};
Expand Down Expand Up @@ -972,12 +969,19 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> {
};

if let Some(summary) = per_slot_processing(&mut state, Some(state_root), &chain.spec)? {
summaries.push(summary)
// Expose Prometheus metrics.
if let Err(e) = summary.observe_metrics() {
error!(
chain.log,
"Failed to observe epoch summary metrics";
"src" => "block_verification",
"error" => ?e
);
}
summaries.push(summary);
}
}

expose_participation_metrics(&summaries);

// If the block is sufficiently recent, notify the validator monitor.
if let Some(slot) = chain.slot_clock.now() {
let epoch = slot.epoch(T::EthSpec::slots_per_epoch());
Expand All @@ -991,7 +995,15 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> {
// performing `per_slot_processing`.
for (i, summary) in summaries.iter().enumerate() {
let epoch = state.current_epoch() - Epoch::from(summaries.len() - i);
validator_monitor.process_validator_statuses(epoch, &summary.statuses);
if let Err(e) =
validator_monitor.process_validator_statuses(epoch, &summary, &chain.spec)
{
error!(
chain.log,
"Failed to process validator statuses";
"error" => ?e
);
}
}
}
}
Expand Down Expand Up @@ -1442,45 +1454,6 @@ fn verify_header_signature<T: BeaconChainTypes>(
}
}

fn expose_participation_metrics(summaries: &[EpochProcessingSummary]) {
if !cfg!(feature = "participation_metrics") {
return;
}

for summary in summaries {
let b = &summary.total_balances;

metrics::maybe_set_float_gauge(
&metrics::PARTICIPATION_PREV_EPOCH_ATTESTER,
participation_ratio(b.previous_epoch_attesters(), b.previous_epoch()),
);

metrics::maybe_set_float_gauge(
&metrics::PARTICIPATION_PREV_EPOCH_TARGET_ATTESTER,
participation_ratio(b.previous_epoch_target_attesters(), b.previous_epoch()),
);

metrics::maybe_set_float_gauge(
&metrics::PARTICIPATION_PREV_EPOCH_HEAD_ATTESTER,
participation_ratio(b.previous_epoch_head_attesters(), b.previous_epoch()),
);
}
}

fn participation_ratio(section: u64, total: u64) -> Option<f64> {
// Reduce the precision to help ensure we fit inside a u32.
const PRECISION: u64 = 100_000_000;

let section: f64 = u32::try_from(section / PRECISION).ok()?.into();
let total: f64 = u32::try_from(total / PRECISION).ok()?.into();

if total > 0_f64 {
Some(section / total)
} else {
None
}
}

fn write_state<T: EthSpec>(prefix: &str, state: &BeaconState<T>, log: &Logger) {
if WRITE_BLOCK_PROCESSING_SSZ {
let root = state.tree_hash_root();
Expand Down
15 changes: 0 additions & 15 deletions beacon_node/beacon_chain/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,21 +330,6 @@ lazy_static! {
pub static ref OP_POOL_NUM_SYNC_CONTRIBUTIONS: Result<IntGauge> =
try_create_int_gauge("beacon_op_pool_sync_contributions_total", "Count of sync contributions in the op pool");

/*
* Participation Metrics
*/
pub static ref PARTICIPATION_PREV_EPOCH_ATTESTER: Result<Gauge> = try_create_float_gauge(
"beacon_participation_prev_epoch_attester",
"Ratio of attesting balances to total balances"
);
pub static ref PARTICIPATION_PREV_EPOCH_TARGET_ATTESTER: Result<Gauge> = try_create_float_gauge(
"beacon_participation_prev_epoch_target_attester",
"Ratio of target-attesting balances to total balances"
);
pub static ref PARTICIPATION_PREV_EPOCH_HEAD_ATTESTER: Result<Gauge> = try_create_float_gauge(
"beacon_participation_prev_epoch_head_attester",
"Ratio of head-attesting balances to total balances"
);

/*
* Attestation Observation Metrics
Expand Down
21 changes: 19 additions & 2 deletions beacon_node/beacon_chain/src/state_advance_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,15 +233,32 @@ fn advance_head<T: BeaconChainTypes>(
if let Some(summary) = per_slot_processing(&mut state, state_root, &beacon_chain.spec)
.map_err(BeaconChainError::from)?
{
// Expose Prometheus metrics.
if let Err(e) = summary.observe_metrics() {
error!(
log,
"Failed to observe epoch summary metrics";
"src" => "state_advance_timer",
"error" => ?e
);
}

// Only notify the validator monitor for recent blocks.
if state.current_epoch() + VALIDATOR_MONITOR_HISTORIC_EPOCHS as u64
>= current_slot.epoch(T::EthSpec::slots_per_epoch())
{
// Potentially create logs/metrics for locally monitored validators.
beacon_chain
if let Err(e) = beacon_chain
.validator_monitor
.read()
.process_validator_statuses(state.current_epoch(), &summary.statuses);
.process_validator_statuses(state.current_epoch(), &summary, &beacon_chain.spec)
{
error!(
log,
"Unable to process validator statuses";
"error" => ?e
);
}
}
}

Expand Down
Loading

0 comments on commit 32b8685

Please sign in to comment.