Skip to content

Commit e5a7d6c

Browse files
committed
fix tests
1 parent 4a7a1e7 commit e5a7d6c

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

beacon_node/beacon_chain/src/attestation_verification.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1123,7 +1123,9 @@ impl<'a, T: BeaconChainTypes> VerifiedUnaggregatedAttestation<'a, T> {
11231123
return Err(SignatureValid(indexed_attestation, e));
11241124
}
11251125

1126-
//TODO(single-attestation)
1126+
let fork_name = chain
1127+
.spec
1128+
.fork_name_at_slot::<T::EthSpec>(attestation.data.slot);
11271129

11281130
let regular_attestation = chain
11291131
.with_committee_cache(
@@ -1142,6 +1144,7 @@ impl<'a, T: BeaconChainTypes> VerifiedUnaggregatedAttestation<'a, T> {
11421144
Ok(single_attestation_to_attestation(
11431145
attestation,
11441146
committee.committee,
1147+
fork_name,
11451148
))
11461149
},
11471150
)
Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
use crate::attestation_verification::Error;
2-
use types::{Attestation, AttestationElectra, BitList, BitVector, EthSpec, SingleAttestation};
2+
use types::{
3+
Attestation, AttestationBase, AttestationElectra, BitList, BitVector, EthSpec, ForkName,
4+
SingleAttestation,
5+
};
36

47
pub fn single_attestation_to_attestation<E: EthSpec>(
58
single_attestation: &SingleAttestation,
69
committee: &[usize],
10+
fork_name: ForkName,
711
) -> Result<Attestation<E>, Error> {
812
let attester_index = single_attestation.attester_index;
913
let committee_index = single_attestation.committee_index;
@@ -24,23 +28,33 @@ pub fn single_attestation_to_attestation<E: EthSpec>(
2428
slot,
2529
})?;
2630

27-
let mut committee_bits: BitVector<E::MaxCommitteesPerSlot> = BitVector::default();
28-
committee_bits
29-
.set(committee_index as usize, true)
30-
.map_err(|e| Error::Invalid(e.into()))?;
31+
if fork_name.electra_enabled() {
32+
let mut committee_bits: BitVector<E::MaxCommitteesPerSlot> = BitVector::default();
33+
committee_bits
34+
.set(committee_index as usize, true)
35+
.map_err(|e| Error::Invalid(e.into()))?;
3136

32-
let mut aggregation_bits =
33-
BitList::with_capacity(committee.len()).map_err(|e| Error::Invalid(e.into()))?;
34-
aggregation_bits
35-
.set(aggregation_bit, true)
36-
.map_err(|e| Error::Invalid(e.into()))?;
37-
38-
// TODO(electra): consider eventually allowing conversion to non-Electra attestations as well
39-
// to maintain invertability (`Attestation` -> `SingleAttestation` -> `Attestation`).
40-
Ok(Attestation::Electra(AttestationElectra {
41-
aggregation_bits,
42-
committee_bits,
43-
data: single_attestation.data.clone(),
44-
signature: single_attestation.signature.clone(),
45-
}))
37+
let mut aggregation_bits =
38+
BitList::with_capacity(committee.len()).map_err(|e| Error::Invalid(e.into()))?;
39+
aggregation_bits
40+
.set(aggregation_bit, true)
41+
.map_err(|e| Error::Invalid(e.into()))?;
42+
Ok(Attestation::Electra(AttestationElectra {
43+
aggregation_bits,
44+
committee_bits,
45+
data: single_attestation.data.clone(),
46+
signature: single_attestation.signature.clone(),
47+
}))
48+
} else {
49+
let mut aggregation_bits =
50+
BitList::with_capacity(committee.len()).map_err(|e| Error::Invalid(e.into()))?;
51+
aggregation_bits
52+
.set(aggregation_bit, true)
53+
.map_err(|e| Error::Invalid(e.into()))?;
54+
Ok(Attestation::Base(AttestationBase {
55+
aggregation_bits,
56+
data: single_attestation.data.clone(),
57+
signature: single_attestation.signature.clone(),
58+
}))
59+
}
4660
}

beacon_node/beacon_chain/src/test_utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1164,8 +1164,10 @@ where
11641164
let single_attestation =
11651165
attestation.to_single_attestation_with_attester_index(attester_index as u64)?;
11661166

1167+
let fork_name = self.spec.fork_name_at_slot::<E>(attestation.data().slot);
11671168
let attestation: Attestation<E> =
1168-
single_attestation_to_attestation(&single_attestation, committee.committee).unwrap();
1169+
single_attestation_to_attestation(&single_attestation, committee.committee, fork_name)
1170+
.unwrap();
11691171

11701172
assert_eq!(
11711173
single_attestation.committee_index,

beacon_node/beacon_chain/tests/attestation_verification.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,10 @@ impl GossipTester {
334334
valid_attestation.committee_index,
335335
)
336336
.unwrap();
337+
let fork_name = harness
338+
.chain
339+
.spec
340+
.fork_name_at_slot::<E>(valid_attestation.data().slot);
337341
let valid_aggregate_attestation =
338342
single_attestation_to_attestation(&valid_attestation, committee.committee).unwrap();
339343

@@ -1399,6 +1403,10 @@ async fn verify_aggregate_for_gossip_doppelganger_detection() {
13991403
valid_attestation.committee_index,
14001404
)
14011405
.unwrap();
1406+
let fork_name = harness
1407+
.chain
1408+
.spec
1409+
.fork_name_at_slot::<E>(valid_attestation.data().slot);
14021410
let valid_attestation =
14031411
single_attestation_to_attestation(&valid_attestation, committee.committee).unwrap();
14041412
let (valid_aggregate, _, _) =

0 commit comments

Comments
 (0)