-
Notifications
You must be signed in to change notification settings - Fork 741
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* basic scaffold * remove unnecessary ? * check if committee cache is init * typed ValidatorMonitor with ethspecs + store attestations within * nits * process unaggregated attestation * typo * extract in func * add tests * better naming * better naming 2 * less verbose * use same naming as validator monitor * use attestation_simulator * add metrics * remove cache * refacto flag_indices process * add lag * remove copying state * clean and lint * extract metrics * nits * compare prom metrics in tests * implement lag * nits * nits * add attestation simulator service * fmt * return beacon_chain as arc * nit: debug * sed s/unaggregated/unagg.// * fmt * fmt * nit: remove unused comments * increase max unaggregated attestation hashmap to 64 * nit: sed s/clone/copied// * improve perf: remove unecessary hashmap copy * fix flag indices comp * start service in client builder * remove // * cargo fmt * lint * cloned keys * fmt * use Slot value instead of pointer * Update beacon_node/beacon_chain/src/attestation_simulator.rs Co-authored-by: Paul Hauner <paul@paulhauner.com> --------- Co-authored-by: Paul Hauner <paul@paulhauner.com>
- Loading branch information
1 parent
a3a3703
commit 189430a
Showing
9 changed files
with
397 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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.