@@ -55,8 +55,8 @@ use std::borrow::Cow;
55
55
use strum:: AsRefStr ;
56
56
use tree_hash:: TreeHash ;
57
57
use types:: {
58
- Attestation , BeaconCommittee , ChainSpec , CommitteeIndex , Epoch , EthSpec , ForkName , Hash256 ,
59
- IndexedAttestation , SelectionProof , SignedAggregateAndProof , Slot , SubnetId ,
58
+ Attestation , AttestationRef , BeaconCommittee , ChainSpec , CommitteeIndex , Epoch , EthSpec ,
59
+ ForkName , Hash256 , IndexedAttestation , SelectionProof , SignedAggregateAndProof , Slot , SubnetId ,
60
60
} ;
61
61
62
62
pub use batch:: { batch_verify_aggregated_attestations, batch_verify_unaggregated_attestations} ;
@@ -274,7 +274,7 @@ struct IndexedAggregatedAttestation<'a, T: BeaconChainTypes> {
274
274
///
275
275
/// These attestations have *not* undergone signature verification.
276
276
struct IndexedUnaggregatedAttestation < ' a , T : BeaconChainTypes > {
277
- attestation : & ' a Attestation < T :: EthSpec > ,
277
+ attestation : AttestationRef < ' a , T :: EthSpec > ,
278
278
indexed_attestation : IndexedAttestation < T :: EthSpec > ,
279
279
subnet_id : SubnetId ,
280
280
validator_index : u64 ,
@@ -295,7 +295,7 @@ impl<'a, T: BeaconChainTypes> VerifiedAggregatedAttestation<'a, T> {
295
295
296
296
/// Wraps an `Attestation` that has been fully verified for propagation on the gossip network.
297
297
pub struct VerifiedUnaggregatedAttestation < ' a , T : BeaconChainTypes > {
298
- attestation : & ' a Attestation < T :: EthSpec > ,
298
+ attestation : AttestationRef < ' a , T :: EthSpec > ,
299
299
indexed_attestation : IndexedAttestation < T :: EthSpec > ,
300
300
subnet_id : SubnetId ,
301
301
}
@@ -322,20 +322,20 @@ impl<'a, T: BeaconChainTypes> Clone for IndexedUnaggregatedAttestation<'a, T> {
322
322
/// A helper trait implemented on wrapper types that can be progressed to a state where they can be
323
323
/// verified for application to fork choice.
324
324
pub trait VerifiedAttestation < T : BeaconChainTypes > : Sized {
325
- fn attestation ( & self ) -> & Attestation < T :: EthSpec > ;
325
+ fn attestation ( & self ) -> AttestationRef < T :: EthSpec > ;
326
326
327
327
fn indexed_attestation ( & self ) -> & IndexedAttestation < T :: EthSpec > ;
328
328
329
329
// Inefficient default implementation. This is overridden for gossip verified attestations.
330
330
fn into_attestation_and_indices ( self ) -> ( Attestation < T :: EthSpec > , Vec < u64 > ) {
331
- let attestation = self . attestation ( ) . clone ( ) ;
331
+ let attestation = self . attestation ( ) . clone_as_attestation ( ) ;
332
332
let attesting_indices = self . indexed_attestation ( ) . attesting_indices_to_vec ( ) ;
333
333
( attestation, attesting_indices)
334
334
}
335
335
}
336
336
337
337
impl < ' a , T : BeaconChainTypes > VerifiedAttestation < T > for VerifiedAggregatedAttestation < ' a , T > {
338
- fn attestation ( & self ) -> & Attestation < T :: EthSpec > {
338
+ fn attestation ( & self ) -> AttestationRef < T :: EthSpec > {
339
339
self . attestation ( )
340
340
}
341
341
@@ -345,7 +345,7 @@ impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregatedAttes
345
345
}
346
346
347
347
impl < ' a , T : BeaconChainTypes > VerifiedAttestation < T > for VerifiedUnaggregatedAttestation < ' a , T > {
348
- fn attestation ( & self ) -> & Attestation < T :: EthSpec > {
348
+ fn attestation ( & self ) -> AttestationRef < T :: EthSpec > {
349
349
self . attestation
350
350
}
351
351
@@ -357,7 +357,7 @@ impl<'a, T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedUnaggregatedAtt
357
357
/// Information about invalid attestations which might still be slashable despite being invalid.
358
358
pub enum AttestationSlashInfo < ' a , T : BeaconChainTypes , TErr > {
359
359
/// The attestation is invalid, but its signature wasn't checked.
360
- SignatureNotChecked ( & ' a Attestation < T :: EthSpec > , TErr ) ,
360
+ SignatureNotChecked ( AttestationRef < ' a , T :: EthSpec > , TErr ) ,
361
361
/// As for `SignatureNotChecked`, but we know the `IndexedAttestation`.
362
362
SignatureNotCheckedIndexed ( IndexedAttestation < T :: EthSpec > , TErr ) ,
363
363
/// The attestation's signature is invalid, so it will never be slashable.
@@ -446,7 +446,7 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
446
446
signed_aggregate : & SignedAggregateAndProof < T :: EthSpec > ,
447
447
chain : & BeaconChain < T > ,
448
448
) -> Result < Hash256 , Error > {
449
- let attestation = & signed_aggregate. message . aggregate ;
449
+ let attestation = signed_aggregate. message ( ) . aggregate ( ) ;
450
450
451
451
// Ensure attestation is within the last ATTESTATION_PROPAGATION_SLOT_RANGE slots (within a
452
452
// MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance).
@@ -471,14 +471,14 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
471
471
if chain
472
472
. observed_attestations
473
473
. write ( )
474
- . is_known_subset ( attestation. to_ref ( ) , attestation_data_root)
474
+ . is_known_subset ( attestation, attestation_data_root)
475
475
. map_err ( |e| Error :: BeaconChainError ( e. into ( ) ) ) ?
476
476
{
477
477
metrics:: inc_counter ( & metrics:: AGGREGATED_ATTESTATION_SUBSETS ) ;
478
478
return Err ( Error :: AttestationSupersetKnown ( attestation_data_root) ) ;
479
479
}
480
480
481
- let aggregator_index = signed_aggregate. message . aggregator_index ;
481
+ let aggregator_index = signed_aggregate. message ( ) . aggregator_index ( ) ;
482
482
483
483
// Ensure there has been no other observed aggregate for the given `aggregator_index`.
484
484
//
@@ -532,11 +532,16 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
532
532
) -> Result < Self , AttestationSlashInfo < ' a , T , Error > > {
533
533
use AttestationSlashInfo :: * ;
534
534
535
- let attestation = & signed_aggregate. message . aggregate ;
536
- let aggregator_index = signed_aggregate. message . aggregator_index ;
535
+ let attestation = signed_aggregate. message ( ) . aggregate ( ) ;
536
+ let aggregator_index = signed_aggregate. message ( ) . aggregator_index ( ) ;
537
537
let attestation_data_root = match Self :: verify_early_checks ( signed_aggregate, chain) {
538
538
Ok ( root) => root,
539
- Err ( e) => return Err ( SignatureNotChecked ( & signed_aggregate. message . aggregate , e) ) ,
539
+ Err ( e) => {
540
+ return Err ( SignatureNotChecked (
541
+ signed_aggregate. message ( ) . aggregate ( ) ,
542
+ e,
543
+ ) )
544
+ }
540
545
} ;
541
546
542
547
let get_indexed_attestation_with_committee =
@@ -545,7 +550,7 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
545
550
//
546
551
// Future optimizations should remove this clone.
547
552
let selection_proof =
548
- SelectionProof :: from ( signed_aggregate. message . selection_proof . clone ( ) ) ;
553
+ SelectionProof :: from ( signed_aggregate. message ( ) . selection_proof ( ) . clone ( ) ) ;
549
554
550
555
if !selection_proof
551
556
. is_aggregator ( committee. committee . len ( ) , & chain. spec )
@@ -559,7 +564,7 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
559
564
return Err ( Error :: AggregatorNotInCommittee { aggregator_index } ) ;
560
565
}
561
566
562
- get_indexed_attestation ( committee. committee , attestation. to_ref ( ) )
567
+ get_indexed_attestation ( committee. committee , attestation)
563
568
. map_err ( |e| BeaconChainError :: from ( e) . into ( ) )
564
569
} ;
565
570
@@ -569,7 +574,12 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
569
574
get_indexed_attestation_with_committee,
570
575
) {
571
576
Ok ( indexed_attestation) => indexed_attestation,
572
- Err ( e) => return Err ( SignatureNotChecked ( & signed_aggregate. message . aggregate , e) ) ,
577
+ Err ( e) => {
578
+ return Err ( SignatureNotChecked (
579
+ signed_aggregate. message ( ) . aggregate ( ) ,
580
+ e,
581
+ ) )
582
+ }
573
583
} ;
574
584
575
585
Ok ( IndexedAggregatedAttestation {
@@ -587,8 +597,8 @@ impl<'a, T: BeaconChainTypes> VerifiedAggregatedAttestation<'a, T> {
587
597
attestation_data_root : Hash256 ,
588
598
chain : & BeaconChain < T > ,
589
599
) -> Result < ( ) , Error > {
590
- let attestation = & signed_aggregate. message . aggregate ;
591
- let aggregator_index = signed_aggregate. message . aggregator_index ;
600
+ let attestation = signed_aggregate. message ( ) . aggregate ( ) ;
601
+ let aggregator_index = signed_aggregate. message ( ) . aggregator_index ( ) ;
592
602
593
603
// Observe the valid attestation so we do not re-process it.
594
604
//
@@ -597,7 +607,7 @@ impl<'a, T: BeaconChainTypes> VerifiedAggregatedAttestation<'a, T> {
597
607
if let ObserveOutcome :: Subset = chain
598
608
. observed_attestations
599
609
. write ( )
600
- . observe_item ( attestation. to_ref ( ) , Some ( attestation_data_root) )
610
+ . observe_item ( attestation, Some ( attestation_data_root) )
601
611
. map_err ( |e| Error :: BeaconChainError ( e. into ( ) ) ) ?
602
612
{
603
613
metrics:: inc_counter ( & metrics:: AGGREGATED_ATTESTATION_SUBSETS ) ;
@@ -696,8 +706,8 @@ impl<'a, T: BeaconChainTypes> VerifiedAggregatedAttestation<'a, T> {
696
706
}
697
707
698
708
/// Returns the underlying `attestation` for the `signed_aggregate`.
699
- pub fn attestation ( & self ) -> & Attestation < T :: EthSpec > {
700
- & self . signed_aggregate . message . aggregate
709
+ pub fn attestation ( & self ) -> AttestationRef < ' a , T :: EthSpec > {
710
+ self . signed_aggregate . message ( ) . aggregate ( )
701
711
}
702
712
703
713
/// Returns the underlying `signed_aggregate`.
@@ -709,7 +719,7 @@ impl<'a, T: BeaconChainTypes> VerifiedAggregatedAttestation<'a, T> {
709
719
impl < ' a , T : BeaconChainTypes > IndexedUnaggregatedAttestation < ' a , T > {
710
720
/// Run the checks that happen before an indexed attestation is constructed.
711
721
pub fn verify_early_checks (
712
- attestation : & Attestation < T :: EthSpec > ,
722
+ attestation : AttestationRef < T :: EthSpec > ,
713
723
chain : & BeaconChain < T > ,
714
724
) -> Result < ( ) , Error > {
715
725
let attestation_epoch = attestation. data ( ) . slot . epoch ( T :: EthSpec :: slots_per_epoch ( ) ) ;
@@ -750,7 +760,7 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
750
760
751
761
/// Run the checks that apply to the indexed attestation before the signature is checked.
752
762
pub fn verify_middle_checks (
753
- attestation : & Attestation < T :: EthSpec > ,
763
+ attestation : AttestationRef < T :: EthSpec > ,
754
764
indexed_attestation : & IndexedAttestation < T :: EthSpec > ,
755
765
committees_per_slot : u64 ,
756
766
subnet_id : Option < SubnetId > ,
@@ -806,7 +816,7 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
806
816
subnet_id : Option < SubnetId > ,
807
817
chain : & BeaconChain < T > ,
808
818
) -> Result < Self , Error > {
809
- Self :: verify_slashable ( attestation, subnet_id, chain)
819
+ Self :: verify_slashable ( attestation. to_ref ( ) , subnet_id, chain)
810
820
. map ( |verified_unaggregated| {
811
821
if let Some ( slasher) = chain. slasher . as_ref ( ) {
812
822
slasher. accept_attestation ( verified_unaggregated. indexed_attestation . clone ( ) ) ;
@@ -818,7 +828,7 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
818
828
819
829
/// Verify the attestation, producing extra information about whether it might be slashable.
820
830
pub fn verify_slashable (
821
- attestation : & ' a Attestation < T :: EthSpec > ,
831
+ attestation : AttestationRef < ' a , T :: EthSpec > ,
822
832
subnet_id : Option < SubnetId > ,
823
833
chain : & BeaconChain < T > ,
824
834
) -> Result < Self , AttestationSlashInfo < ' a , T , Error > > {
@@ -867,7 +877,7 @@ impl<'a, T: BeaconChainTypes> IndexedUnaggregatedAttestation<'a, T> {
867
877
impl < ' a , T : BeaconChainTypes > VerifiedUnaggregatedAttestation < ' a , T > {
868
878
/// Run the checks that apply after the signature has been checked.
869
879
fn verify_late_checks (
870
- attestation : & Attestation < T :: EthSpec > ,
880
+ attestation : AttestationRef < T :: EthSpec > ,
871
881
validator_index : u64 ,
872
882
chain : & BeaconChain < T > ,
873
883
) -> Result < ( ) , Error > {
@@ -961,7 +971,7 @@ impl<'a, T: BeaconChainTypes> VerifiedUnaggregatedAttestation<'a, T> {
961
971
}
962
972
963
973
/// Returns the wrapped `attestation`.
964
- pub fn attestation ( & self ) -> & Attestation < T :: EthSpec > {
974
+ pub fn attestation ( & self ) -> AttestationRef < T :: EthSpec > {
965
975
self . attestation
966
976
}
967
977
@@ -991,7 +1001,7 @@ impl<'a, T: BeaconChainTypes> VerifiedUnaggregatedAttestation<'a, T> {
991
1001
/// already finalized.
992
1002
fn verify_head_block_is_known < T : BeaconChainTypes > (
993
1003
chain : & BeaconChain < T > ,
994
- attestation : & Attestation < T :: EthSpec > ,
1004
+ attestation : AttestationRef < T :: EthSpec > ,
995
1005
max_skip_slots : Option < u64 > ,
996
1006
) -> Result < ProtoBlock , Error > {
997
1007
let block_opt = chain
@@ -1039,7 +1049,7 @@ fn verify_head_block_is_known<T: BeaconChainTypes>(
1039
1049
/// Accounts for `MAXIMUM_GOSSIP_CLOCK_DISPARITY`.
1040
1050
pub fn verify_propagation_slot_range < S : SlotClock , E : EthSpec > (
1041
1051
slot_clock : & S ,
1042
- attestation : & Attestation < E > ,
1052
+ attestation : AttestationRef < E > ,
1043
1053
spec : & ChainSpec ,
1044
1054
) -> Result < ( ) , Error > {
1045
1055
let attestation_slot = attestation. data ( ) . slot ;
@@ -1124,7 +1134,7 @@ pub fn verify_attestation_signature<T: BeaconChainTypes>(
1124
1134
/// `attestation.data.beacon_block_root`.
1125
1135
pub fn verify_attestation_target_root < E : EthSpec > (
1126
1136
head_block : & ProtoBlock ,
1127
- attestation : & Attestation < E > ,
1137
+ attestation : AttestationRef < E > ,
1128
1138
) -> Result < ( ) , Error > {
1129
1139
// Check the attestation target root.
1130
1140
let head_block_epoch = head_block. slot . epoch ( E :: slots_per_epoch ( ) ) ;
@@ -1193,7 +1203,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
1193
1203
. try_read_for ( VALIDATOR_PUBKEY_CACHE_LOCK_TIMEOUT )
1194
1204
. ok_or ( BeaconChainError :: ValidatorPubkeyCacheLockTimeout ) ?;
1195
1205
1196
- let aggregator_index = signed_aggregate. message . aggregator_index ;
1206
+ let aggregator_index = signed_aggregate. message ( ) . aggregator_index ( ) ;
1197
1207
if aggregator_index >= pubkey_cache. len ( ) as u64 {
1198
1208
return Err ( Error :: AggregatorPubkeyUnknown ( aggregator_index) ) ;
1199
1209
}
@@ -1240,10 +1250,10 @@ type CommitteesPerSlot = u64;
1240
1250
/// public keys cached in the `chain`.
1241
1251
pub fn obtain_indexed_attestation_and_committees_per_slot < T : BeaconChainTypes > (
1242
1252
chain : & BeaconChain < T > ,
1243
- attestation : & Attestation < T :: EthSpec > ,
1253
+ attestation : AttestationRef < T :: EthSpec > ,
1244
1254
) -> Result < ( IndexedAttestation < T :: EthSpec > , CommitteesPerSlot ) , Error > {
1245
1255
map_attestation_committee ( chain, attestation, |( committee, committees_per_slot) | {
1246
- get_indexed_attestation ( committee. committee , attestation. to_ref ( ) )
1256
+ get_indexed_attestation ( committee. committee , attestation)
1247
1257
. map ( |attestation| ( attestation, committees_per_slot) )
1248
1258
. map_err ( Error :: Invalid )
1249
1259
} )
@@ -1260,7 +1270,7 @@ pub fn obtain_indexed_attestation_and_committees_per_slot<T: BeaconChainTypes>(
1260
1270
/// from disk and then update the `shuffling_cache`.
1261
1271
fn map_attestation_committee < T , F , R > (
1262
1272
chain : & BeaconChain < T > ,
1263
- attestation : & Attestation < T :: EthSpec > ,
1273
+ attestation : AttestationRef < T :: EthSpec > ,
1264
1274
map_fn : F ,
1265
1275
) -> Result < R , Error >
1266
1276
where
0 commit comments