Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Cache participating indices for Altair epoch processing #2416

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
1bb1c8f
Add initial participation cache
paulhauner Jun 23, 2021
6f87cd5
Update EpochProcessingSummary
paulhauner Jun 23, 2021
22fbf3e
Remove unslashed indices function
paulhauner Jun 23, 2021
c5658f0
Tidy, remove metric
paulhauner Jun 24, 2021
b6d634c
Add EpochCache
paulhauner Jun 24, 2021
ab687f3
Bring balances into ParticipationCache
paulhauner Jun 24, 2021
c6840bc
Swap back to ParticipationCache
paulhauner Jun 24, 2021
99292c2
Add eligible indices
paulhauner Jun 24, 2021
a8b0a7c
Remove junk file
paulhauner Jun 24, 2021
957bcad
Fix EF test compile errors
paulhauner Jun 24, 2021
3a38047
Fix balances issue
paulhauner Jun 24, 2021
5584854
Fix active indices
paulhauner Jun 24, 2021
3b01744
Used cached indices
paulhauner Jun 25, 2021
81b6768
Fix eligible indices
paulhauner Jun 25, 2021
1f85249
Partial one-loop refactor
paulhauner Jun 25, 2021
9f08360
Working single-loop refactor
paulhauner Jun 25, 2021
96efe87
Tidy, add comments
paulhauner Jun 25, 2021
10c793b
Tidy, remove unused function, fix init length
paulhauner Jun 25, 2021
e9ec4ba
Couple more `unstable` merge fixes
realbigsean Jun 17, 2021
3fe9797
Remove flag error type FIXME
paulhauner Jun 25, 2021
de7ad33
Remove old balance getter in ef_tests
paulhauner Jun 25, 2021
8644b05
Refactor validator inclusion endpoint
paulhauner Jun 25, 2021
751abe5
Avoid creating logs for offline vals
paulhauner Jul 12, 2021
dbbff17
Tidy
paulhauner Jul 12, 2021
1bdcb9e
Tidy, change "active" to "active unslashed"
paulhauner Jul 12, 2021
b48e02a
Tidy, fix error handling
paulhauner Jul 12, 2021
f7e3f4a
Add `Error` enum
paulhauner Jul 12, 2021
4533190
Adjust error handling
paulhauner Jul 12, 2021
b9d8e07
Log error when exposing metrics fails
paulhauner Jul 12, 2021
d4fb7fe
Unify participation metrics
paulhauner Jul 14, 2021
40b4ac3
Move ValidatorsStatuses into base
paulhauner Jul 15, 2021
20ddb5b
Partially adress first batch of review comments
paulhauner Jul 26, 2021
a2a5c1d
Remove shrink to fit
paulhauner Jul 26, 2021
3a55c01
Partially address second batch of comments
paulhauner Jul 26, 2021
0327a5f
Apply patch for is_eligible_validator
paulhauner Jul 27, 2021
23ff33b
Apply suggestions from code review
paulhauner Jul 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -971,12 +968,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 @@ -990,7 +994,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 @@ -1432,45 +1444,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_VOLUNTARY_EXITS: Result<IntGauge> =
try_create_int_gauge("beacon_op_pool_voluntary_exits_total", "Count of voluntary exits 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