Skip to content

Commit 33f93d7

Browse files
committed
add CLI flag for weighted_attestation_data
1 parent b48c0c6 commit 33f93d7

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

anchor/validator_store/src/metadata_service.rs

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use crate::{AnchorValidatorStore, ContributionWaiter, SlotMetadata};
1919

2020
const SOFT_TIMEOUT: Duration = Duration::from_millis(500);
2121
const HARD_TIMEOUT: Duration = Duration::from_secs(1);
22-
const BLOCK_SLOT_LOOKUP_TIMEOUT: Duration = Duration::from_millis(250);
22+
const BLOCK_SLOT_LOOKUP_TIMEOUT: Duration = Duration::from_millis(125);
2323

2424
pub struct MetadataService<E: EthSpec, T: SlotClock + 'static> {
2525
duties_service: Arc<DutiesService<AnchorValidatorStore<T, E>, T>>,
@@ -88,27 +88,27 @@ impl<E: EthSpec, T: SlotClock + 'static> MetadataService<E, T> {
8888
async fn update_metadata(&self) -> Result<(), String> {
8989
let slot = self.slot_clock.now().ok_or("Failed to read slot clock")?;
9090

91+
// For testing
9192
let weighted = false;
9293

93-
if weighted {
94-
self.weighted_calculation(slot).await?;
95-
}
96-
97-
let attestation_data = self
98-
.beacon_nodes
99-
.first_success(|beacon_node| async move {
100-
let _timer = validator_metrics::start_timer_vec(
101-
&validator_metrics::ATTESTATION_SERVICE_TIMES,
102-
&[validator_metrics::ATTESTATIONS_HTTP_GET],
103-
);
104-
beacon_node
105-
.get_validator_attestation_data(slot, 0)
106-
.await
107-
.map_err(|e| format!("Failed to produce attestation data: {e:?}"))
108-
.map(|result| result.data)
109-
})
110-
.await
111-
.map_err(|e| e.to_string())?;
94+
let attestation_data = if weighted {
95+
self.weighted_calculation(slot).await?
96+
} else {
97+
self.beacon_nodes
98+
.first_success(|beacon_node| async move {
99+
let _timer = validator_metrics::start_timer_vec(
100+
&validator_metrics::ATTESTATION_SERVICE_TIMES,
101+
&[validator_metrics::ATTESTATIONS_HTTP_GET],
102+
);
103+
beacon_node
104+
.get_validator_attestation_data(slot, 0)
105+
.await
106+
.map_err(|e| format!("Failed to produce attestation data: {e:?}"))
107+
.map(|result| result.data)
108+
})
109+
.await
110+
.map_err(|e| e.to_string())?
111+
};
112112

113113
let beacon_vote = BeaconVote {
114114
block_root: attestation_data.beacon_block_root,
@@ -382,7 +382,8 @@ impl<E: EthSpec, T: SlotClock + 'static> MetadataService<E, T> {
382382
.await
383383
{
384384
Some(head_slot) => {
385-
// Bonus based on how close head is to attestation slot
385+
// Increase score based on the nearness of the head slot
386+
// TODO: double check calculation
386387
let distance = slot.as_u64().saturating_sub(head_slot.as_u64());
387388
let bonus = 1.0 / (1 + distance) as f64;
388389

0 commit comments

Comments
 (0)