Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
d31ea37
basic scaffold
v4lproik Oct 25, 2023
20c462c
remove unnecessary ?
v4lproik Oct 25, 2023
1bb4f4d
check if committee cache is init
v4lproik Oct 25, 2023
498911d
typed ValidatorMonitor with ethspecs + store attestations within
v4lproik Oct 26, 2023
df5c68a
nits
v4lproik Oct 26, 2023
03ccb26
process unaggregated attestation
v4lproik Oct 29, 2023
857bfdd
typo
v4lproik Oct 29, 2023
7e1f6d8
extract in func
v4lproik Oct 30, 2023
51fdf14
add tests
v4lproik Oct 31, 2023
5d97fb4
better naming
v4lproik Nov 8, 2023
7e45dbc
better naming 2
v4lproik Nov 8, 2023
702de94
less verbose
v4lproik Nov 8, 2023
f515ed9
use same naming as validator monitor
v4lproik Nov 8, 2023
fc9d26f
use attestation_simulator
v4lproik Nov 8, 2023
d3d2294
add metrics
v4lproik Nov 8, 2023
8d88571
remove cache
v4lproik Nov 8, 2023
6363c5d
refacto flag_indices process
v4lproik Nov 8, 2023
7267646
add lag
v4lproik Nov 8, 2023
8921e6b
remove copying state
v4lproik Nov 8, 2023
8e985dc
clean and lint
v4lproik Nov 9, 2023
1f4065d
extract metrics
v4lproik Nov 10, 2023
2241b42
nits
v4lproik Nov 10, 2023
95792ad
compare prom metrics in tests
v4lproik Nov 10, 2023
862c140
implement lag
v4lproik Nov 10, 2023
6cfd407
nits
v4lproik Nov 10, 2023
dc7356e
nits
v4lproik Nov 10, 2023
8593771
add attestation simulator service
v4lproik Nov 16, 2023
b19b14c
fmt
v4lproik Nov 16, 2023
00b439e
return beacon_chain as arc
v4lproik Nov 16, 2023
b16c4ad
nit: debug
v4lproik Dec 8, 2023
6cd5c07
sed s/unaggregated/unagg.//
v4lproik Dec 8, 2023
84a09fb
fmt
v4lproik Dec 8, 2023
ecf5b97
fmt
v4lproik Dec 8, 2023
ab8bdaa
nit: remove unused comments
v4lproik Dec 8, 2023
d030811
increase max unaggregated attestation hashmap to 64
v4lproik Dec 8, 2023
6d7a667
nit: sed s/clone/copied//
v4lproik Dec 8, 2023
4dccdd2
improve perf: remove unecessary hashmap copy
v4lproik Dec 8, 2023
1b376cc
fix flag indices comp
v4lproik Dec 8, 2023
72e175e
start service in client builder
v4lproik Dec 8, 2023
cd0fb62
remove //
v4lproik Dec 8, 2023
afb204a
cargo fmt
v4lproik Dec 8, 2023
0f66b32
lint
v4lproik Dec 8, 2023
cd1b468
cloned keys
v4lproik Dec 8, 2023
32e7910
fmt
v4lproik Dec 8, 2023
ff9b6b5
use Slot value instead of pointer
v4lproik Dec 12, 2023
997e023
Merge branch 'unstable' into 4880-testing
paulhauner Dec 13, 2023
c59635f
Update beacon_node/beacon_chain/src/attestation_simulator.rs
v4lproik Dec 13, 2023
fcbbd56
Merge commit '997e023efb05cb56316bf1c9166850ccdccaaf8a' into attestat…
v4lproik Dec 13, 2023
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
93 changes: 93 additions & 0 deletions beacon_node/beacon_chain/src/attestation_simulator.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
use crate::{BeaconChain, BeaconChainTypes};
use slog::{debug, error};
use slot_clock::SlotClock;
use std::sync::Arc;
use task_executor::TaskExecutor;
use tokio::time::sleep;
use types::Slot;

/// Spawns a routine which produces an unaggregated attestation at every slot.
///
/// This routine will run once per slot
pub fn start_attestation_simulator_service<T: BeaconChainTypes>(
executor: TaskExecutor,
chain: Arc<BeaconChain<T>>,
) {
executor.clone().spawn(
async move { attestation_simulator_service(executor, chain).await },
"attestation_simulator_service",
);
}

/// Loop indefinitely, calling `BeaconChain::produce_unaggregated_attestation` every 4s into each slot.
async fn attestation_simulator_service<T: BeaconChainTypes>(
executor: TaskExecutor,
chain: Arc<BeaconChain<T>>,
) {
let slot_duration = chain.slot_clock.slot_duration();
let additional_delay = slot_duration / 3;

loop {
match chain.slot_clock.duration_to_next_slot() {
Some(duration) => {
sleep(duration + additional_delay).await;

debug!(
chain.log,
"Simulating unagg. attestation production";
);

// Run the task in the executor
let inner_chain = chain.clone();
executor.spawn(
async move {
if let Ok(current_slot) = inner_chain.slot() {
produce_unaggregated_attestation(inner_chain, current_slot);
}
},
"attestation_simulator_service",
);
}
None => {
error!(chain.log, "Failed to read slot clock");
// If we can't read the slot clock, just wait another slot.
sleep(slot_duration).await;
}
};
}
}

pub fn produce_unaggregated_attestation<T: BeaconChainTypes>(
inner_chain: Arc<BeaconChain<T>>,
current_slot: Slot,
) {
// Since attestations for different committees are practically identical (apart from the committee index field)
// Committee 0 is guaranteed to exist. That means there's no need to load the committee.
let beacon_committee_index = 0;

// Store the unaggregated attestation in the validator monitor for later processing
match inner_chain.produce_unaggregated_attestation(current_slot, beacon_committee_index) {
Ok(unaggregated_attestation) => {
let data = &unaggregated_attestation.data;

debug!(
inner_chain.log,
"Produce unagg. attestation";
"attestation_source" => data.source.root.to_string(),
"attestation_target" => data.target.root.to_string(),
);

inner_chain
.validator_monitor
.write()
.set_unaggregated_attestation(unaggregated_attestation);
}
Err(e) => {
debug!(
inner_chain.log,
"Failed to simulate attestation";
"error" => ?e
);
}
}
}
8 changes: 5 additions & 3 deletions beacon_node/beacon_chain/src/beacon_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3621,9 +3621,11 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}

// Allow the validator monitor to learn about a new valid state.
self.validator_monitor
.write()
.process_valid_state(current_slot.epoch(T::EthSpec::slots_per_epoch()), state);
self.validator_monitor.write().process_valid_state(
current_slot.epoch(T::EthSpec::slots_per_epoch()),
state,
&self.spec,
);

let validator_monitor = self.validator_monitor.read();

Expand Down
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ where
validator_monitor.process_valid_state(
slot.epoch(TEthSpec::slots_per_epoch()),
&head_snapshot.beacon_state,
&self.spec,
);
}

Expand Down
1 change: 1 addition & 0 deletions beacon_node/beacon_chain/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub mod attestation_rewards;
pub mod attestation_simulator;
pub mod attestation_verification;
mod attester_cache;
pub mod beacon_block_reward;
Expand Down
56 changes: 56 additions & 0 deletions beacon_node/beacon_chain/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ use types::{BeaconState, Epoch, EthSpec, Hash256, Slot};
/// The maximum time to wait for the snapshot cache lock during a metrics scrape.
const SNAPSHOT_CACHE_TIMEOUT: Duration = Duration::from_millis(100);

// Attestation simulator metrics
pub const VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_HIT_TOTAL: &str =
"validator_monitor_attestation_simulator_head_attester_hit_total";
pub const VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_MISS_TOTAL: &str =
"validator_monitor_attestation_simulator_head_attester_miss_total";
pub const VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_HIT_TOTAL: &str =
"validator_monitor_attestation_simulator_target_attester_hit_total";
pub const VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_MISS_TOTAL: &str =
"validator_monitor_attestation_simulator_target_attester_miss_total";
pub const VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_HIT_TOTAL: &str =
"validator_monitor_attestation_simulator_source_attester_hit_total";
pub const VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_MISS_TOTAL: &str =
"validator_monitor_attestation_simulator_source_attester_miss_total";

lazy_static! {
/*
* Block Processing
Expand Down Expand Up @@ -1041,6 +1055,48 @@ lazy_static! {
"beacon_aggregated_attestation_subsets_total",
"Count of new aggregated attestations that are subsets of already known aggregates"
);
/*
* Attestation simulator metrics
*/
pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_HIT: Result<IntCounter> =
try_create_int_counter(
VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_HIT_TOTAL,
"Incremented if a validator is flagged as a previous slot head attester \
during per slot processing",
);
pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_MISS: Result<IntCounter> =
try_create_int_counter(
VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_HEAD_ATTESTER_MISS_TOTAL,
"Incremented if a validator is not flagged as a previous slot head attester \
during per slot processing",
);
pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_HIT: Result<IntCounter> =
try_create_int_counter(
VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_HIT_TOTAL,
"Incremented if a validator is flagged as a previous slot target attester \
during per slot processing",
);
pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_MISS: Result<IntCounter> =
try_create_int_counter(
VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_TARGET_ATTESTER_MISS_TOTAL,
"Incremented if a validator is not flagged as a previous slot target attester \
during per slot processing",
);
pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_HIT: Result<IntCounter> =
try_create_int_counter(
VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_HIT_TOTAL,
"Incremented if a validator is flagged as a previous slot source attester \
during per slot processing",
);
pub static ref VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_MISS: Result<IntCounter> =
try_create_int_counter(
VALIDATOR_MONITOR_ATTESTATION_SIMULATOR_SOURCE_ATTESTER_MISS_TOTAL,
"Incremented if a validator is not flagged as a previous slot source attester \
during per slot processing",
);
/*
* Missed block metrics
*/
pub static ref VALIDATOR_MONITOR_MISSED_BLOCKS_TOTAL: Result<IntCounterVec> = try_create_int_counter_vec(
"validator_monitor_missed_blocks_total",
"Number of non-finalized blocks missed",
Expand Down
Loading