Skip to content

Commit 807ba02

Browse files
committed
remove get_uninitialized_ptc_validators
1 parent ef3ea4c commit 807ba02

File tree

5 files changed

+27
-36
lines changed

5 files changed

+27
-36
lines changed

common/eth2/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2889,6 +2889,8 @@ impl BeaconNodeHttpClient {
28892889
.await
28902890
}
28912891

2892+
// TODO(EIP-7732): Create corresponding beacon node response endpoint per spec
2893+
// https://github.com/ethereum/beacon-APIs/pull/552
28922894
/// `POST validator/duties/ptc/{epoch}`
28932895
pub async fn post_validator_duties_ptc(
28942896
&self,

common/eth2/src/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
pub use types::*;
55

66
use crate::{
7-
Error as ServerError, CONSENSUS_BLOCK_VALUE_HEADER, CONSENSUS_VERSION_HEADER,
8-
EXECUTION_PAYLOAD_BLINDED_HEADER, EXECUTION_PAYLOAD_VALUE_HEADER,
7+
CONSENSUS_BLOCK_VALUE_HEADER, CONSENSUS_VERSION_HEADER, EXECUTION_PAYLOAD_BLINDED_HEADER,
8+
EXECUTION_PAYLOAD_VALUE_HEADER, Error as ServerError,
99
};
1010
use bls::{PublicKeyBytes, SecretKey, Signature, SignatureBytes};
1111
use context_deserialize::ContextDeserialize;
12-
use mediatype::{names, MediaType, MediaTypeList};
12+
use mediatype::{MediaType, MediaTypeList, names};
1313
use reqwest::header::HeaderMap;
1414
use serde::{Deserialize, Deserializer, Serialize};
1515
use serde_utils::quoted_u64::Quoted;
@@ -1604,7 +1604,7 @@ pub struct BroadcastValidationQuery {
16041604

16051605
pub mod serde_status_code {
16061606
use crate::StatusCode;
1607-
use serde::{de::Error, Deserialize, Serialize};
1607+
use serde::{Deserialize, Serialize, de::Error};
16081608

16091609
pub fn serialize<S>(status_code: &StatusCode, ser: S) -> Result<S::Ok, S::Error>
16101610
where

validator_client/http_metrics/src/lib.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ pub fn gather_prometheus_metrics<E: EthSpec>(
197197
&[NEXT_EPOCH],
198198
duties_service.attester_count(next_epoch) as i64,
199199
);
200+
set_int_gauge(
201+
&PTC_COUNT,
202+
&[CURRENT_EPOCH],
203+
duties_service.ptc_count(current_epoch) as i64,
204+
);
205+
set_int_gauge(
206+
&PTC_COUNT,
207+
&[NEXT_EPOCH],
208+
duties_service.ptc_count(next_epoch) as i64,
209+
);
200210
}
201211
}
202212

validator_client/validator_services/src/duties_service.rs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ pub struct DutiesService<S, T> {
411411
pub proposers: RwLock<ProposerMap>,
412412
/// Map from validator index to sync committee duties.
413413
pub sync_duties: SyncDutiesMap,
414-
/// Maps an epoch to all *local* PTC duties for that epoch with their dependent root.
414+
/// Maps an epoch to PTC duties for locally-managed validators.
415415
pub ptc_duties: RwLock<PtcMap>,
416416
/// Provides the canonical list of locally-managed validators.
417417
pub validator_store: Arc<S>,
@@ -1243,25 +1243,6 @@ fn get_uninitialized_validators<S: ValidatorStore, T: SlotClock + 'static>(
12431243
.collect::<Vec<_>>()
12441244
}
12451245

1246-
/// Get a filtered list of local validators for which we don't already know their PTC duties for that epoch
1247-
fn get_uninitialized_ptc_validators<S: ValidatorStore, T: SlotClock + 'static>(
1248-
duties_service: &Arc<DutiesService<S, T>>,
1249-
epoch: &Epoch,
1250-
local_pubkeys: &HashSet<PublicKeyBytes>,
1251-
) -> Vec<u64> {
1252-
let ptc_duties = duties_service.ptc_duties.read();
1253-
1254-
local_pubkeys
1255-
.iter()
1256-
.filter(|pubkey| {
1257-
ptc_duties
1258-
.get(epoch)
1259-
.map_or(true, |(_, duties)| !duties.contains_key(pubkey))
1260-
})
1261-
.filter_map(|pubkey| duties_service.validator_store.validator_index(pubkey))
1262-
.collect::<Vec<_>>()
1263-
}
1264-
12651246
fn update_per_validator_duty_metrics<S: ValidatorStore, T: SlotClock + 'static>(
12661247
duties_service: &Arc<DutiesService<S, T>>,
12671248
epoch: Epoch,
@@ -1807,17 +1788,12 @@ async fn poll_beacon_ptc_attesters_for_epoch<
18071788
&[validator_metrics::UPDATE_PTC_FETCH],
18081789
);
18091790

1810-
// Request duties for all uninitialized validators. If there isn't any, we will just request for
1811-
// `INITIAL_PTC_DUTIES_QUERY_SIZE` validators. We use the `dependent_root` in the response to
1812-
// determine whether validator duties need to be updated. This is to ensure that we don't
1813-
// request for extra data unless necessary in order to save on network bandwidth.
1814-
let uninitialized_validators =
1815-
get_uninitialized_ptc_validators(duties_service, &epoch, local_pubkeys);
1816-
let initial_indices_to_request = if !uninitialized_validators.is_empty() {
1817-
uninitialized_validators.as_slice()
1818-
} else {
1819-
&local_indices[0..min(INITIAL_PTC_DUTIES_QUERY_SIZE, local_indices.len())]
1820-
};
1791+
// Make a small initial request to check the dependent_root and determine if we need to fetch
1792+
// all duties. We use the `dependent_root` in the response to determine whether validator
1793+
// duties need to be updated. This is to ensure that we don't request for extra data unless
1794+
// necessary in order to save on network bandwidth.
1795+
let initial_indices_to_request =
1796+
&local_indices[0..min(INITIAL_PTC_DUTIES_QUERY_SIZE, local_indices.len())];
18211797

18221798
let response =
18231799
post_validator_duties_ptc(duties_service, epoch, initial_indices_to_request).await?;
@@ -1830,7 +1806,7 @@ async fn poll_beacon_ptc_attesters_for_epoch<
18301806
let ptc_duties = duties_service.ptc_duties.read();
18311807
let needs_update = ptc_duties
18321808
.get(&epoch)
1833-
.map_or(true, |(prior_root, _duties)| {
1809+
.is_none_or(|(prior_root, _duties)| {
18341810
// Update if dependent_root changed
18351811
*prior_root != dependent_root
18361812
});

validator_client/validator_services/src/notifier_service.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ pub async fn notify<S: ValidatorStore, T: SlotClock + 'static>(
109109
let total_validators = duties_service.total_validator_count();
110110
let proposing_validators = duties_service.proposer_count(epoch);
111111
let attesting_validators = duties_service.attester_count(epoch);
112+
let ptc_validators = duties_service.ptc_count(epoch);
112113
let doppelganger_detecting_validators = duties_service.doppelganger_detecting_count();
113114

114115
if doppelganger_detecting_validators > 0 {
@@ -126,6 +127,7 @@ pub async fn notify<S: ValidatorStore, T: SlotClock + 'static>(
126127
} else if total_validators == attesting_validators {
127128
info!(
128129
current_epoch_proposers = proposing_validators,
130+
current_epoch_ptc = ptc_validators,
129131
active_validators = attesting_validators,
130132
total_validators = total_validators,
131133
%epoch,
@@ -135,6 +137,7 @@ pub async fn notify<S: ValidatorStore, T: SlotClock + 'static>(
135137
} else if attesting_validators > 0 {
136138
info!(
137139
current_epoch_proposers = proposing_validators,
140+
current_epoch_ptc = ptc_validators,
138141
active_validators = attesting_validators,
139142
total_validators = total_validators,
140143
%epoch,

0 commit comments

Comments
 (0)