Skip to content

Commit 6269b6d

Browse files
committed
add CLI flag for weighted_attestation_data - fix
1 parent 33f93d7 commit 6269b6d

File tree

4 files changed

+48
-21
lines changed

4 files changed

+48
-21
lines changed

anchor/client/src/cli.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,13 @@ pub struct Node {
532532

533533
#[clap(flatten)]
534534
pub logging_flags: FileLoggingFlags,
535+
536+
#[clap(
537+
long,
538+
help = "Enable attestation data scoring across multiple beacon nodes.",
539+
display_order = 0
540+
)]
541+
pub with_weighted_attestation_data: bool,
535542
}
536543

537544
pub fn get_color_style() -> Styles {

anchor/client/src/config.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ pub struct Config {
7272
pub prefer_builder_proposals: bool,
7373
/// Controls whether the latency measurement service is enabled
7474
pub disable_latency_measurement_service: bool,
75+
/// Enable attestation data scoring across multiple beacon nodes
76+
pub with_weighted_attestation_data: bool,
7577
}
7678

7779
impl Config {
@@ -115,6 +117,7 @@ impl Config {
115117
prefer_builder_proposals: false,
116118
gas_limit: 36_000_000,
117119
disable_latency_measurement_service: false,
120+
with_weighted_attestation_data: false,
118121
}
119122
}
120123
}
@@ -260,6 +263,8 @@ pub fn from_cli(cli_args: &Node, global_config: GlobalConfig) -> Result<Config,
260263
config.processor.queue_size.insert(queue, size);
261264
}
262265

266+
config.with_weighted_attestation_data = cli_args.with_weighted_attestation_data;
267+
263268
Ok(config)
264269
}
265270

anchor/client/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,7 @@ impl Client {
618618
beacon_nodes.clone(),
619619
executor.clone(),
620620
spec.clone(),
621+
config.with_weighted_attestation_data,
621622
);
622623

623624
// We use `SLOTS_PER_EPOCH` as the capacity of the block notification channel, because

anchor/validator_store/src/metadata_service.rs

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -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

3334
impl<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

Comments
 (0)