mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-06 10:11:44 +00:00
De-duplicate attestations in the slasher (#2767)
## Issue Addressed
Closes https://github.com/sigp/lighthouse/issues/2112
Closes https://github.com/sigp/lighthouse/issues/1861
## Proposed Changes
Collect attestations by validator index in the slasher, and use the magic of reference counting to automatically discard redundant attestations. This results in us storing only 1-2% of the attestations observed when subscribed to all subnets, which carries over to a 50-100x reduction in data stored 🎉
## Additional Info
There's some nuance to the configuration of the `slot-offset`. It has a profound effect on the effictiveness of de-duplication, see the docs added to the book for an explanation: 5442e695e5/book/src/slasher.md (slot-offset)
This commit is contained in:
@@ -55,11 +55,18 @@ impl<T: BeaconChainTypes> SlasherService<T> {
|
||||
// don't need to burden them with more work (we can wait).
|
||||
let (notif_sender, notif_receiver) = sync_channel(1);
|
||||
let update_period = slasher.config().update_period;
|
||||
let slot_offset = slasher.config().slot_offset;
|
||||
let beacon_chain = self.beacon_chain.clone();
|
||||
let network_sender = self.network_sender.clone();
|
||||
|
||||
executor.spawn(
|
||||
Self::run_notifier(beacon_chain.clone(), update_period, notif_sender, log),
|
||||
Self::run_notifier(
|
||||
beacon_chain.clone(),
|
||||
update_period,
|
||||
slot_offset,
|
||||
notif_sender,
|
||||
log,
|
||||
),
|
||||
"slasher_server_notifier",
|
||||
);
|
||||
|
||||
@@ -75,12 +82,19 @@ impl<T: BeaconChainTypes> SlasherService<T> {
|
||||
async fn run_notifier(
|
||||
beacon_chain: Arc<BeaconChain<T>>,
|
||||
update_period: u64,
|
||||
slot_offset: f64,
|
||||
notif_sender: SyncSender<Epoch>,
|
||||
log: Logger,
|
||||
) {
|
||||
// NOTE: could align each run to some fixed point in each slot, see:
|
||||
// https://github.com/sigp/lighthouse/issues/1861
|
||||
let mut interval = interval_at(Instant::now(), Duration::from_secs(update_period));
|
||||
let slot_offset = Duration::from_secs_f64(slot_offset);
|
||||
let start_instant =
|
||||
if let Some(duration_to_next_slot) = beacon_chain.slot_clock.duration_to_next_slot() {
|
||||
Instant::now() + duration_to_next_slot + slot_offset
|
||||
} else {
|
||||
error!(log, "Error aligning slasher to slot clock");
|
||||
Instant::now()
|
||||
};
|
||||
let mut interval = interval_at(start_instant, Duration::from_secs(update_period));
|
||||
|
||||
loop {
|
||||
interval.tick().await;
|
||||
|
||||
Reference in New Issue
Block a user