-
Notifications
You must be signed in to change notification settings - Fork 910
Add attestation simulator #4880
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
paulhauner
merged 48 commits into
sigp:unstable
from
v4lproik:attestation-simulator-performance-metric
Dec 14, 2023
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
d31ea37
basic scaffold
v4lproik 20c462c
remove unnecessary ?
v4lproik 1bb4f4d
check if committee cache is init
v4lproik 498911d
typed ValidatorMonitor with ethspecs + store attestations within
v4lproik df5c68a
nits
v4lproik 03ccb26
process unaggregated attestation
v4lproik 857bfdd
typo
v4lproik 7e1f6d8
extract in func
v4lproik 51fdf14
add tests
v4lproik 5d97fb4
better naming
v4lproik 7e45dbc
better naming 2
v4lproik 702de94
less verbose
v4lproik f515ed9
use same naming as validator monitor
v4lproik fc9d26f
use attestation_simulator
v4lproik d3d2294
add metrics
v4lproik 8d88571
remove cache
v4lproik 6363c5d
refacto flag_indices process
v4lproik 7267646
add lag
v4lproik 8921e6b
remove copying state
v4lproik 8e985dc
clean and lint
v4lproik 1f4065d
extract metrics
v4lproik 2241b42
nits
v4lproik 95792ad
compare prom metrics in tests
v4lproik 862c140
implement lag
v4lproik 6cfd407
nits
v4lproik dc7356e
nits
v4lproik 8593771
add attestation simulator service
v4lproik b19b14c
fmt
v4lproik 00b439e
return beacon_chain as arc
v4lproik b16c4ad
nit: debug
v4lproik 6cd5c07
sed s/unaggregated/unagg.//
v4lproik 84a09fb
fmt
v4lproik ecf5b97
fmt
v4lproik ab8bdaa
nit: remove unused comments
v4lproik d030811
increase max unaggregated attestation hashmap to 64
v4lproik 6d7a667
nit: sed s/clone/copied//
v4lproik 4dccdd2
improve perf: remove unecessary hashmap copy
v4lproik 1b376cc
fix flag indices comp
v4lproik 72e175e
start service in client builder
v4lproik cd0fb62
remove //
v4lproik afb204a
cargo fmt
v4lproik 0f66b32
lint
v4lproik cd1b468
cloned keys
v4lproik 32e7910
fmt
v4lproik ff9b6b5
use Slot value instead of pointer
v4lproik 997e023
Merge branch 'unstable' into 4880-testing
paulhauner c59635f
Update beacon_node/beacon_chain/src/attestation_simulator.rs
v4lproik fcbbd56
Merge commit '997e023efb05cb56316bf1c9166850ccdccaaf8a' into attestat…
v4lproik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.