@@ -25,12 +25,26 @@ pub async fn validate_beacon_attestation(
2525 let store = beacon_chain. store . lock ( ) . await ;
2626
2727 let head_root = store. get_head ( ) ?;
28- let state: BeaconState = store
28+ let mut state: BeaconState = store
2929 . db
3030 . state_provider ( )
3131 . get ( head_root) ?
3232 . ok_or_else ( || anyhow ! ( "No beacon state found for head root: {head_root}" ) ) ?;
3333
34+ let current_slot = store. get_current_slot ( ) ?;
35+
36+ // [IGNORE] attestation.data.slot is equal to or earlier than the current_slot (with a
37+ // MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance)
38+ if attestation. data . slot > current_slot {
39+ return Ok ( ValidationResult :: Ignore (
40+ "Attestation is from a future slot" . to_string ( ) ,
41+ ) ) ;
42+ }
43+
44+ if state. slot < attestation. data . slot {
45+ state. process_slots ( attestation. data . slot ) ?;
46+ }
47+
3448 let committee_index = attestation. committee_index ;
3549 let committees_per_slot = state. get_committee_count_per_slot ( attestation. data . target . epoch ) ;
3650
@@ -58,27 +72,11 @@ pub async fn validate_beacon_attestation(
5872 ) ) ;
5973 }
6074
61- let block = store
62- . db
63- . block_provider ( )
64- . get ( head_root) ?
65- . ok_or_else ( || anyhow ! ( "Could not get block for head root: {head_root}" ) ) ?;
66-
67- let current_slot = block. message . slot ;
68-
69- // [IGNORE] attestation.data.slot is equal to or earlier than the current_slot (with a
70- // MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance)
71- if attestation. data . slot > current_slot {
72- return Ok ( ValidationResult :: Ignore (
73- "Attestation is from a future slot" . to_string ( ) ,
74- ) ) ;
75- }
76-
7775 // [IGNORE] the epoch of attestation.data.slot is either the current or previous epoch (with a
7876 // MAXIMUM_GOSSIP_CLOCK_DISPARITY allowance)
7977 let attestation_epoch = compute_epoch_at_slot ( attestation. data . slot ) ;
80- let current_epoch = state . get_current_epoch ( ) ;
81- let previous_epoch = state . get_previous_epoch ( ) ;
78+ let current_epoch = compute_epoch_at_slot ( current_slot ) ;
79+ let previous_epoch = current_epoch . saturating_sub ( 1 ) ;
8280
8381 if attestation_epoch != current_epoch && attestation_epoch != previous_epoch {
8482 return Ok ( ValidationResult :: Ignore (
0 commit comments