Skip to content
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

SingleAttestation implementation #6488

Merged
merged 101 commits into from
Jan 16, 2025
Merged
Changes from 1 commit
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
25feedf
First pass
pawanjay176 Aug 29, 2024
4dc6e65
Add restrictions to RuntimeVariableList api
pawanjay176 Aug 30, 2024
a9cb329
Use empty_uninitialized and fix warnings
pawanjay176 Aug 30, 2024
60100fc
Fix some todos
pawanjay176 Aug 30, 2024
13f9bba
Merge branch 'unstable' into max-blobs-preset
pawanjay176 Sep 3, 2024
e71020e
Fix take impl on RuntimeFixedList
pawanjay176 Sep 4, 2024
52bb581
cleanup
pawanjay176 Sep 4, 2024
d37733b
Fix test compilations
pawanjay176 Sep 4, 2024
12c6ef1
Fix some more tests
pawanjay176 Sep 4, 2024
2fcb293
Fix test from unstable
pawanjay176 Sep 7, 2024
21ecb58
Merge branch 'unstable' into max-blobs-preset
pawanjay176 Oct 21, 2024
366bed3
SingleAttestation
eserilev Dec 4, 2024
68292ad
Add post attestation v2 endpoint logic to attestation service
eserilev Dec 13, 2024
5a4cd3b
Merge branch 'unstable' of https://github.com/sigp/lighthouse into si…
eserilev Dec 13, 2024
9d5a3af
Implement "Bugfix and more withdrawal tests"
michaelsproul Dec 19, 2024
f892849
Implement "Add missed exit checks to consolidation processing"
michaelsproul Dec 19, 2024
f27216f
Implement "Update initial earliest_exit_epoch calculation"
michaelsproul Dec 19, 2024
c31f1cc
Implement "Limit consolidating balance by validator.effective_balance"
michaelsproul Dec 20, 2024
282eefb
Implement "Use 16-bit random value in validator filter"
michaelsproul Dec 20, 2024
52e602d
Implement "Do not change creds type on consolidation"
michaelsproul Dec 20, 2024
f56083d
some tests and fixed attestqtion calc
eserilev Dec 20, 2024
44d15a9
Merge branch 'unstable' of https://github.com/sigp/lighthouse into si…
eserilev Dec 23, 2024
293db28
Rename PendingPartialWithdraw index field to validator_index
eserilev Jan 2, 2025
9b8a25f
Skip slots to get test to pass and add TODO
eserilev Jan 2, 2025
23d331b
Implement "Synchronously check all transactions to have non-zero length"
eserilev Jan 2, 2025
0c2c8c4
Merge remote-tracking branch 'origin/unstable' into max-blobs-preset
michaelsproul Jan 6, 2025
de01f92
Remove footgun function
michaelsproul Jan 6, 2025
1095d60
Minor simplifications
michaelsproul Jan 6, 2025
2e86585
Move from preset to config
michaelsproul Jan 6, 2025
32483d3
Fix typo
michaelsproul Jan 6, 2025
88bedf0
Revert "Remove footgun function"
michaelsproul Jan 6, 2025
063b79c
Try fixing tests
michaelsproul Jan 6, 2025
251bca7
Implement "bump minimal preset MAX_BLOB_COMMITMENTS_PER_BLOCK and KZG…
eserilev Jan 6, 2025
e4bfe71
Thread through ChainSpec
michaelsproul Jan 6, 2025
f66e179
Fix release tests
michaelsproul Jan 6, 2025
440e854
Move RuntimeFixedVector into module and rename
michaelsproul Jan 6, 2025
04b3743
Add test
michaelsproul Jan 6, 2025
4700ef9
Merge branch 'unstable' of https://github.com/sigp/lighthouse into si…
eserilev Jan 6, 2025
c7ef72d
Added more test coverage, simplified Attestation conversion, and othe…
eserilev Jan 6, 2025
9945079
Removed unusued codepaths
eserilev Jan 6, 2025
12e442c
Fix failing test
eserilev Jan 6, 2025
3d3bc6d
Implement "Remove post-altair `initialize_beacon_state_from_eth1` fro…
eserilev Jan 6, 2025
2dbd3b7
Update preset YAML
michaelsproul Jan 7, 2025
0cd263f
Remove empty RuntimeVarList awefullness
pawanjay176 Jan 7, 2025
3b788bf
Make max_blobs_per_block a config parameter (#6329)
michaelsproul Jan 7, 2025
7c215f8
Fix tests
pawanjay176 Jan 7, 2025
0f26408
Implement max_blobs_per_block_electra
michaelsproul Jan 7, 2025
d65e821
Fix config issues
michaelsproul Jan 7, 2025
26c409c
Simplify BlobSidecarListFromRoot
michaelsproul Jan 7, 2025
eee9218
Disable PeerDAS tests
michaelsproul Jan 7, 2025
e95f003
Cleanup single attestation imports
eserilev Jan 7, 2025
823ddf5
Fix some single attestation network plumbing
eserilev Jan 7, 2025
07c039c
Merge remote-tracking branch 'origin/unstable' into max-blobs-preset
michaelsproul Jan 9, 2025
d4e152c
Bump quota to account for new target (6)
michaelsproul Jan 9, 2025
a73ecb5
Remove clone
michaelsproul Jan 9, 2025
f13bdfc
Fix issue from review
pawanjay176 Jan 9, 2025
70917f7
Try to remove ugliness
pawanjay176 Jan 10, 2025
22b7fcb
Merge branch 'unstable' into max-blobs-preset
pawanjay176 Jan 10, 2025
9e972b1
Merge remote-tracking branch 'origin/unstable' into electra-alpha10
michaelsproul Jan 10, 2025
bb59e7a
Merge commit '04b3743ec1e0b650269dd8e58b540c02430d1c0d' into electra-…
michaelsproul Jan 10, 2025
1d4dc59
Merge remote-tracking branch 'pawan/max-blobs-preset' into electra-al…
michaelsproul Jan 10, 2025
bba7310
Update tests to v1.5.0-beta.0
michaelsproul Jan 10, 2025
8c96c35
Merge remote-tracking branch 'origin/electra-alpha10' into single_att…
michaelsproul Jan 10, 2025
d7a69e4
Fix some tests
michaelsproul Jan 10, 2025
ce488b2
Cargo fmt
michaelsproul Jan 10, 2025
b42cc84
lint
eserilev Jan 10, 2025
7bd174e
fmt
eserilev Jan 10, 2025
ef13f0f
Resolve merge conflicts
eserilev Jan 10, 2025
40f65bb
Merge branch 'electra-alpha10' of https://github.com/sigp/lighthouse …
eserilev Jan 10, 2025
fe3d5de
lint
eserilev Jan 10, 2025
72bcc8a
Linting
eserilev Jan 10, 2025
344ba2b
fmt
eserilev Jan 10, 2025
eb5d3eb
Merge branch 'electra-alpha10' of https://github.com/sigp/lighthouse …
eserilev Jan 10, 2025
fdf9af8
Fmt
eserilev Jan 10, 2025
a45c0f0
Fix test and add TODO
eserilev Jan 10, 2025
f4fe1b8
Gracefully handle slashed proposers in fork choice tests
michaelsproul Jan 13, 2025
1205d83
Merge remote-tracking branch 'origin/unstable' into electra-alpha10
michaelsproul Jan 13, 2025
3b17732
Keep latest changes from max_blobs_per_block PR in codec.rs
michaelsproul Jan 13, 2025
e2ff440
Revert a few more regressions and add a comment
michaelsproul Jan 13, 2025
6cc798a
Merge branch 'electra-alpha10' of https://github.com/sigp/lighthouse …
eserilev Jan 13, 2025
7df6560
Disable more DAS tests
michaelsproul Jan 13, 2025
4fbca37
Improve validator monitor test a little
michaelsproul Jan 13, 2025
e821e62
Make test more robust
michaelsproul Jan 13, 2025
0b36d60
Fix sync test that didn't understand blobs
michaelsproul Jan 13, 2025
4f08ac7
Fill out cropped comment
michaelsproul Jan 13, 2025
11c1949
Merge remote-tracking branch 'origin/electra-alpha10' into single_att…
michaelsproul Jan 14, 2025
e76322e
Merge remote-tracking branch 'origin/unstable' into single_attestation
michaelsproul Jan 14, 2025
d8f32de
Merge remote-tracking branch 'origin/unstable' into single_attestation
michaelsproul Jan 14, 2025
fb5e378
Merge branch 'unstable' of https://github.com/sigp/lighthouse into si…
eserilev Jan 14, 2025
2d61b65
publish_attestations should accept Either<Attestation,SingleAttestation>
eserilev Jan 14, 2025
b6d80eb
log an error when failing to convert to SingleAttestation
eserilev Jan 14, 2025
86ce323
Use Cow to avoid clone
michaelsproul Jan 15, 2025
8cc43c1
Avoid reconverting to SingleAttestation
michaelsproul Jan 15, 2025
e900bb8
Tweak VC error message
michaelsproul Jan 15, 2025
72da039
update comments
eserilev Jan 15, 2025
b9b9b99
update comments
eserilev Jan 15, 2025
4f2182e
pass in single attestation as ref to subnetid calculation method
eserilev Jan 15, 2025
aa66b06
Improved API, new error variants and other minor tweaks
eserilev Jan 15, 2025
54844b3
Fix single_attestation event topic boilerplate
eserilev Jan 15, 2025
f7a0b37
fix sse event failure
eserilev Jan 15, 2025
42c01c6
Add single_attestation event topic test coverage
eserilev Jan 16, 2025
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
Prev Previous commit
Next Next commit
Add post attestation v2 endpoint logic to attestation service
  • Loading branch information
eserilev committed Dec 13, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 68292ad9dd1d9514cba7ee0042b8d74fbab2e57c
3 changes: 2 additions & 1 deletion common/eth2/src/lib.rs
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ pub use reqwest::{StatusCode, Url};
pub use sensitive_url::{SensitiveError, SensitiveUrl};
use serde::{de::DeserializeOwned, Serialize};
use ssz::Encode;
use types::attestation::SingleAttestation;
use std::fmt;
use std::future::Future;
use std::path::PathBuf;
@@ -1316,7 +1317,7 @@ impl BeaconNodeHttpClient {
/// `POST v2/beacon/pool/attestations`
pub async fn post_beacon_pool_attestations_v2<E: EthSpec>(
&self,
attestations: &[Attestation<E>],
attestations: &[SingleAttestation],
fork_name: ForkName,
) -> Result<(), Error> {
let mut path = self.eth_path(V2)?;
199 changes: 128 additions & 71 deletions consensus/types/src/attestation.rs
Original file line number Diff line number Diff line change
@@ -232,6 +232,13 @@ impl<E: EthSpec> Attestation<E> {
Attestation::Electra(att) => att.aggregation_bits.get(index),
}
}

pub fn to_single_attestation_with_attester_index(&self, attester_index: usize) -> Result<SingleAttestation, Error> {
match self {
Self::Base(_) => Err(Error::IncorrectStateVariant),
Self::Electra(attn) => attn.to_single_attestation_with_attester_index(attester_index)
}
}
}

impl<E: EthSpec> AttestationRef<'_, E> {
@@ -288,6 +295,14 @@ impl<E: EthSpec> AttestationElectra<E> {
self.get_committee_indices().first().cloned()
}

pub fn get_aggregation_bits(&self) -> Vec<u64> {
self.aggregation_bits
.iter()
.enumerate()
.filter_map(|(index, bit)| if bit { Some(index as u64) } else { None })
.collect()
}

pub fn get_committee_indices(&self) -> Vec<u64> {
self.committee_bits
.iter()
@@ -352,12 +367,26 @@ impl<E: EthSpec> AttestationElectra<E> {
}
}

pub fn get_aggregation_bits(&self) -> Vec<u64> {
self.aggregation_bits
.iter()
.enumerate()
.filter_map(|(index, bit)| if bit { Some(index as u64) } else { None })
.collect()
pub fn to_single_attestation_with_attester_index(
&self,
attester_index: usize
) -> Result<SingleAttestation, Error> {
let committee_indices = self.get_committee_indices();

if committee_indices.len() != 1 {
return Err(Error::InvalidCommitteeLength);
}

let committee_index = *committee_indices
.first()
.ok_or(Error::InvalidCommitteeIndex)?;

Ok(SingleAttestation {
committee_index: committee_index as usize,
attester_index,
data: self.data.clone(),
signature: self.signature.clone()
})
}

pub fn to_single_attestation(
@@ -493,71 +522,6 @@ impl<E: EthSpec> SlotData for AttestationRef<'_, E> {
}
}

#[derive(
Debug,
Clone,
Serialize,
Deserialize,
Decode,
Encode,
TestRandom,
Derivative,
arbitrary::Arbitrary,
TreeHash,
PartialEq,
)]
pub struct SingleAttestation {
pub committee_index: usize,
pub attester_index: usize,
pub data: AttestationData,
pub signature: AggregateSignature,
}

impl SingleAttestation {
pub fn to_attestation<E: EthSpec>(
&self,
committees: &[BeaconCommittee],
) -> Result<Attestation<E>, Error> {
let beacon_committee = committees
.get(self.committee_index)
.ok_or(Error::InvalidAggregationBit)?;
let aggregation_bits = beacon_committee
.committee
.iter()
.enumerate()
.filter_map(|(i, &validator_index)| {
if self.attester_index == validator_index {
return Some(i);
}
None
})
.collect::<Vec<_>>();

if aggregation_bits.len() != 1 {
return Err(Error::InvalidAggregationBit);
}

let aggregation_bit = aggregation_bits.first().unwrap();

let mut committee_bits: BitVector<E::MaxCommitteesPerSlot> = BitVector::default();
committee_bits
.set(self.committee_index, true)
.map_err(|_| Error::InvalidCommitteeIndex)?;

let mut aggregation_bits = BitList::with_capacity(beacon_committee.committee.len())
.map_err(|_| Error::InvalidCommitteeLength)?;

aggregation_bits.set(*aggregation_bit, true)?;

Ok(Attestation::Electra(AttestationElectra {
aggregation_bits,
committee_bits,
data: self.data.clone(),
signature: self.signature.clone(),
}))
}
}

#[derive(Debug, Clone, Encode, Decode, PartialEq)]
#[ssz(enum_behaviour = "union")]
pub enum AttestationOnDisk<E: EthSpec> {
@@ -657,6 +621,99 @@ impl<E: EthSpec> ForkVersionDeserialize for Vec<Attestation<E>> {
}
}

#[derive(
Debug,
Clone,
Serialize,
Deserialize,
Decode,
Encode,
TestRandom,
Derivative,
arbitrary::Arbitrary,
TreeHash,
PartialEq,
)]
pub struct SingleAttestation {
pub committee_index: usize,
pub attester_index: usize,
pub data: AttestationData,
pub signature: AggregateSignature,
}

impl SingleAttestation {
/// Produces a `SingleAttestation` with empty signature and empty attester index.
/// ONLY USE IN ELECTRA
pub fn empty_for_signing(
committee_index: usize,
slot: Slot,
beacon_block_root: Hash256,
source: Checkpoint,
target: Checkpoint,
) -> Self {
Self {
committee_index,
attester_index: 0,
data: AttestationData {
slot,
index: 0,
beacon_block_root,
source,
target,
},
signature: AggregateSignature::infinity(),
}
}

pub fn add_signature(&mut self, signature: &AggregateSignature, committee_position: usize) {
self.attester_index = committee_position;
self.signature = signature.clone();
}

pub fn to_attestation<E: EthSpec>(
&self,
committees: &[BeaconCommittee],
) -> Result<Attestation<E>, Error> {
let beacon_committee = committees
.get(self.committee_index)
.ok_or(Error::InvalidAggregationBit)?;
let aggregation_bits = beacon_committee
.committee
.iter()
.enumerate()
.filter_map(|(i, &validator_index)| {
if self.attester_index == validator_index {
return Some(i);
}
None
})
.collect::<Vec<_>>();

if aggregation_bits.len() != 1 {
return Err(Error::InvalidAggregationBit);
}

let aggregation_bit = aggregation_bits.first().unwrap();

let mut committee_bits: BitVector<E::MaxCommitteesPerSlot> = BitVector::default();
committee_bits
.set(self.committee_index, true)
.map_err(|_| Error::InvalidCommitteeIndex)?;

let mut aggregation_bits = BitList::with_capacity(beacon_committee.committee.len())
.map_err(|_| Error::InvalidCommitteeLength)?;

aggregation_bits.set(*aggregation_bit, true)?;

Ok(Attestation::Electra(AttestationElectra {
aggregation_bits,
committee_bits,
data: self.data.clone(),
signature: self.signature.clone(),
}))
}
}

#[cfg(test)]
mod tests {
use super::*;
Original file line number Diff line number Diff line change
@@ -457,8 +457,11 @@ impl<T: SlotClock + 'static, E: EthSpec> AttestationService<T, E> {
&[validator_metrics::ATTESTATIONS_HTTP_POST],
);
if fork_name.electra_enabled() {
let single_attestations = attestations.iter().zip(validator_indices).filter_map(|(a, i)| {
a.to_single_attestation_with_attester_index(*i as usize).ok()
}).collect::<Vec<_>>();
beacon_node
.post_beacon_pool_attestations_v2(attestations, fork_name)
.post_beacon_pool_attestations_v2::<E>(&single_attestations, fork_name)
.await
} else {
beacon_node