Skip to content

Commit ec2d8aa

Browse files
committed
remove get_uninitialized_ptc_validators
1 parent 32c3f0a commit ec2d8aa

File tree

4 files changed

+22
-31
lines changed

4 files changed

+22
-31
lines changed

common/eth2/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2861,6 +2861,8 @@ impl BeaconNodeHttpClient {
28612861
.await
28622862
}
28632863

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

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: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ pub struct DutiesService<S, T> {
410410
pub proposers: RwLock<ProposerMap>,
411411
/// Map from validator index to sync committee duties.
412412
pub sync_duties: SyncDutiesMap,
413-
/// Maps an epoch to all *local* PTC duties for that epoch with their dependent root.
413+
/// Maps an epoch to PTC duties for locally-managed validators.
414414
pub ptc_duties: RwLock<PtcMap>,
415415
/// Provides the canonical list of locally-managed validators.
416416
pub validator_store: Arc<S>,
@@ -1242,25 +1242,6 @@ fn get_uninitialized_validators<S: ValidatorStore, T: SlotClock + 'static>(
12421242
.collect::<Vec<_>>()
12431243
}
12441244

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

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

18211797
let response =
18221798
post_validator_duties_ptc(duties_service, epoch, initial_indices_to_request).await?;

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)