@@ -28,6 +28,7 @@ pub struct MetadataService<E: EthSpec, T: SlotClock + 'static> {
2828 beacon_nodes : Arc < BeaconNodeFallback < T > > ,
2929 executor : TaskExecutor ,
3030 spec : Arc < ChainSpec > ,
31+ weighted_attestation_data : bool ,
3132}
3233
3334impl < E : EthSpec , T : SlotClock + ' static > MetadataService < E , T > {
@@ -38,6 +39,7 @@ impl<E: EthSpec, T: SlotClock + 'static> MetadataService<E, T> {
3839 beacon_nodes : Arc < BeaconNodeFallback < T > > ,
3940 executor : TaskExecutor ,
4041 spec : Arc < ChainSpec > ,
42+ weighted_attestation_data : bool ,
4143 ) -> Self {
4244 Self {
4345 duties_service,
@@ -46,6 +48,7 @@ impl<E: EthSpec, T: SlotClock + 'static> MetadataService<E, T> {
4648 beacon_nodes,
4749 executor,
4850 spec,
51+ weighted_attestation_data,
4952 }
5053 }
5154
@@ -88,10 +91,7 @@ impl<E: EthSpec, T: SlotClock + 'static> MetadataService<E, T> {
8891 async fn update_metadata ( & self ) -> Result < ( ) , String > {
8992 let slot = self . slot_clock . now ( ) . ok_or ( "Failed to read slot clock" ) ?;
9093
91- // For testing
92- let weighted = false ;
93-
94- let attestation_data = if weighted {
94+ let attestation_data = if self . weighted_attestation_data {
9595 self . weighted_calculation ( slot) . await ?
9696 } else {
9797 self . beacon_nodes
@@ -382,24 +382,37 @@ impl<E: EthSpec, T: SlotClock + 'static> MetadataService<E, T> {
382382 . await
383383 {
384384 Some ( head_slot) => {
385- // Increase score based on the nearness of the head slot
386- // TODO: double check calculation
387- let distance = slot. as_u64 ( ) . saturating_sub ( head_slot. as_u64 ( ) ) ;
388- let bonus = 1.0 / ( 1 + distance) as f64 ;
389-
390- trace ! (
391- client = %client_addr,
392- head_slot = head_slot. as_u64( ) ,
393- attestation_slot = slot. as_u64( ) ,
394- source_epoch = attestation_data. source. epoch. as_u64( ) ,
395- target_epoch = attestation_data. target. epoch. as_u64( ) ,
396- base_score,
397- bonus,
398- total_score = base_score + bonus,
399- "Scored attestation data"
400- ) ;
385+ let attestation_slot_u64 = slot. as_u64 ( ) ;
386+ let head_slot_u64 = head_slot. as_u64 ( ) ;
387+
388+ if head_slot_u64 <= attestation_slot_u64 {
389+ // Increase score based on the nearness of the head slot
390+ let distance = attestation_slot_u64 - head_slot_u64;
391+ let bonus = 1.0 / ( 1 + distance) as f64 ;
392+
393+ trace ! (
394+ client = %client_addr,
395+ head_slot = head_slot_u64,
396+ attestation_slot = attestation_slot_u64,
397+ source_epoch = attestation_data. source. epoch. as_u64( ) ,
398+ target_epoch = attestation_data. target. epoch. as_u64( ) ,
399+ distance,
400+ base_score,
401+ bonus,
402+ total_score = base_score + bonus,
403+ "Scored attestation data"
404+ ) ;
401405
402- base_score + bonus
406+ base_score + bonus
407+ } else {
408+ warn ! (
409+ client = %client_addr,
410+ head_slot = head_slot_u64,
411+ attestation_slot = attestation_slot_u64,
412+ "Block slot is after attestation slot, skipping proximity bonus"
413+ ) ;
414+ base_score
415+ }
403416 }
404417 None => {
405418 trace ! (
@@ -419,6 +432,7 @@ impl<E: EthSpec, T: SlotClock + 'static> MetadataService<E, T> {
419432 }
420433
421434 /// Get the slot number for a given block root with timeout
435+ // Does this retry??
422436 async fn get_block_slot (
423437 & self ,
424438 client : & BeaconNodeHttpClient ,
0 commit comments