-
Notifications
You must be signed in to change notification settings - Fork 890
Batch attestation slashibility checking #6219
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
Open
eserilev
wants to merge
29
commits into
sigp:unstable
Choose a base branch
from
eserilev:batch-attestation-slashibility-checking
base: unstable
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
b5ac2a6
refactor to separate attn signing and db slashibility checks
eserilev a7fe031
adding comments, a few logs, some more TODO's
eserilev ee691f9
only download attn data once and mutate index when required
eserilev 14cbae8
batch db txn
eserilev 9b1302a
fix some tests, linting, logs
eserilev 57bd693
remove unneeded clones
eserilev e4d5e79
Merge branch 'unstable' of https://github.com/sigp/lighthouse into ba…
eserilev 73f1d55
linnt
eserilev d07564c
fmt
eserilev 420ce57
working on test fixes
eserilev e9112b1
fix test
eserilev d7a023f
Merge branch 'unstable' of https://github.com/sigp/lighthouse into ba…
eserilev ecf42f0
prevent db commit when slashing is not avail
eserilev b469d65
add more granular metrics
eserilev cdf219b
fix test
eserilev 9140a6d
Merge branch 'unstable' into batch-attestation-slashibility-checking
eserilev b3b818f
resolve merge conflicts
eserilev 4715750
Resolve merge conflicts
eserilev 509d926
merge conflicts
eserilev f5dacb6
remove unused import
eserilev 98b2f7c
fix
eserilev 67c6f3a
retry
eserilev c5c6c5b
merge conflicts
eserilev 6ece2be
fix test
eserilev dece5b6
optimize publish aggs
eserilev d9e27c6
fix lint
eserilev a463e8d
fmt
eserilev f35a028
Merge branch 'unstable' of https://github.com/sigp/lighthouse into ba…
eserilev d8d6da9
linting
eserilev 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
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
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,84 @@ | ||
use std::{collections::HashMap, sync::Arc}; | ||
|
||
use slot_clock::SlotClock; | ||
use types::{AttestationData, CommitteeIndex, EthSpec, ForkName, Slot}; | ||
|
||
use crate::{ | ||
beacon_node_fallback::{BeaconNodeFallback, OfflineOnFailure, RequireSynced}, | ||
http_metrics::metrics, | ||
}; | ||
|
||
/// The AttestationDataService is responsible for downloading and caching attestation data at a given slot | ||
/// for a range of committee indexes. It also helps prevent us from re-downloading identical attestation data. | ||
pub struct AttestationDataService<T: SlotClock, E: EthSpec> { | ||
attestation_data_by_committee: HashMap<CommitteeIndex, AttestationData>, | ||
beacon_nodes: Arc<BeaconNodeFallback<T, E>>, | ||
} | ||
|
||
impl<T: SlotClock, E: EthSpec> AttestationDataService<T, E> { | ||
pub fn new(beacon_nodes: Arc<BeaconNodeFallback<T, E>>) -> Self { | ||
Self { | ||
attestation_data_by_committee: HashMap::new(), | ||
beacon_nodes, | ||
} | ||
} | ||
|
||
/// Get previously downloaded attestation data by a given committee index. If the Electra fork is enabled | ||
/// we don't care about the committee index | ||
pub fn get_data_by_committee_index( | ||
&self, | ||
committee_index: &CommitteeIndex, | ||
fork_name: &ForkName, | ||
) -> Option<AttestationData> { | ||
if fork_name.electra_enabled() { | ||
let data = self.attestation_data_by_committee.iter().next(); | ||
if let Some((_, data)) = data { | ||
return Some(data.clone()); | ||
} | ||
None | ||
} else { | ||
self.attestation_data_by_committee | ||
.get(committee_index) | ||
.cloned() | ||
} | ||
} | ||
|
||
/// Download attestation data for this slot/committee index from the beacon node. | ||
pub async fn download_data( | ||
&mut self, | ||
committee_index: &CommitteeIndex, | ||
slot: &Slot, | ||
fork_name: &ForkName, | ||
) -> Result<(), String> { | ||
// If we've already downloaded data for this committee index OR electra is enabled and | ||
// we've already downloaded data for this slot, there's no need to re-download the data. | ||
if let Some(_) = self.get_data_by_committee_index(committee_index, fork_name) { | ||
return Ok(()); | ||
} | ||
|
||
let attestation_data = self | ||
.beacon_nodes | ||
.first_success( | ||
RequireSynced::No, | ||
OfflineOnFailure::Yes, | ||
|beacon_node| async move { | ||
let _timer = metrics::start_timer_vec( | ||
&metrics::ATTESTATION_SERVICE_TIMES, | ||
&[metrics::ATTESTATIONS_HTTP_GET], | ||
); | ||
beacon_node | ||
.get_validator_attestation_data(slot.clone(), *committee_index) | ||
.await | ||
.map_err(|e| format!("Failed to produce attestation data: {:?}", e)) | ||
.map(|result| result.data) | ||
}, | ||
) | ||
.await | ||
.map_err(|e| e.to_string())?; | ||
|
||
self.attestation_data_by_committee | ||
.insert(*committee_index, attestation_data); | ||
|
||
Ok(()) | ||
} | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that all attestations votes are the same on each committee, the only change is in the
index
field which equals the key of this hashmapCommitteeIndex
. If you are refactoring the flow you can consider an optimization to only get a singleAttestationData
for all committees.However, some DVT solution relies on a call for each
CommitteeIndex
being made. I'm not sure if this is the case but it was ~1.5 years ago.