Skip to content

Commit a1dae51

Browse files
committed
Add E to ValidatorStore as associated type
1 parent f7506e3 commit a1dae51

File tree

19 files changed

+378
-405
lines changed

19 files changed

+378
-405
lines changed

validator_client/doppelganger_service/src/lib.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use std::sync::Arc;
4141
use task_executor::ShutdownReason;
4242
use tokio::time::sleep;
4343
use types::{Epoch, EthSpec, PublicKeyBytes, Slot};
44-
use validator_store::DoppelgangerStatus;
44+
use validator_store::{DoppelgangerStatus, ValidatorStore};
4545

4646
struct LivenessResponses {
4747
current_epoch_responses: Vec<LivenessResponseData>,
@@ -52,13 +52,6 @@ struct LivenessResponses {
5252
/// validators on the network.
5353
pub const DEFAULT_REMAINING_DETECTION_EPOCHS: u64 = 1;
5454

55-
/// This crate cannot depend on ValidatorStore as validator_store depends on this crate and
56-
/// initialises the doppelganger protection. For this reason, we abstract the validator store
57-
/// functions this service needs through the following trait
58-
pub trait DoppelgangerValidatorStore {
59-
fn get_validator_index(&self, pubkey: &PublicKeyBytes) -> Option<u64>;
60-
}
61-
6255
/// Store the per-validator status of doppelganger checking.
6356
#[derive(Debug, PartialEq)]
6457
pub struct DoppelgangerState {
@@ -235,10 +228,10 @@ impl DoppelgangerService {
235228
where
236229
E: EthSpec,
237230
T: 'static + SlotClock,
238-
V: DoppelgangerValidatorStore + Send + Sync + 'static,
231+
V: ValidatorStore<E = E> + Send + Sync + 'static,
239232
{
240233
// Define the `get_index` function as one that uses the validator store.
241-
let get_index = move |pubkey| validator_store.get_validator_index(&pubkey);
234+
let get_index = move |pubkey| validator_store.validator_index(&pubkey);
242235

243236
// Define the `get_liveness` function as one that queries the beacon node API.
244237
let log = service.log.clone();

validator_client/http_api/src/create_signed_voluntary_exit.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use validator_store::ValidatorStore;
1010
pub async fn create_signed_voluntary_exit<T: 'static + SlotClock + Clone, E: EthSpec>(
1111
pubkey: PublicKey,
1212
maybe_epoch: Option<Epoch>,
13-
validator_store: Arc<LighthouseValidatorStore<T>>,
13+
validator_store: Arc<LighthouseValidatorStore<T, E>>,
1414
slot_clock: T,
1515
log: Logger,
1616
) -> Result<GenericResponse<SignedVoluntaryExit>, warp::Rejection> {
@@ -53,7 +53,7 @@ pub async fn create_signed_voluntary_exit<T: 'static + SlotClock + Clone, E: Eth
5353
);
5454

5555
let signed_voluntary_exit = validator_store
56-
.sign_voluntary_exit::<E>(pubkey_bytes, voluntary_exit)
56+
.sign_voluntary_exit(pubkey_bytes, voluntary_exit)
5757
.await
5858
.map_err(|e| {
5959
warp_utils::reject::custom_server_error(format!(

validator_client/http_api/src/create_validator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub async fn create_validators_mnemonic<P: AsRef<Path>, T: 'static + SlotClock,
2929
validator_requests: &[api_types::ValidatorRequest],
3030
validator_dir: P,
3131
secrets_dir: Option<PathBuf>,
32-
validator_store: &LighthouseValidatorStore<T>,
32+
validator_store: &LighthouseValidatorStore<T, E>,
3333
spec: &ChainSpec,
3434
) -> Result<(Vec<api_types::CreatedValidator>, Mnemonic), warp::Rejection> {
3535
let mnemonic = mnemonic_opt.unwrap_or_else(random_mnemonic);
@@ -140,7 +140,7 @@ pub async fn create_validators_mnemonic<P: AsRef<Path>, T: 'static + SlotClock,
140140
drop(validator_dir);
141141

142142
validator_store
143-
.add_validator_keystore::<_, E>(
143+
.add_validator_keystore(
144144
voting_keystore_path,
145145
voting_password_storage,
146146
request.enable,
@@ -177,11 +177,11 @@ pub async fn create_validators_mnemonic<P: AsRef<Path>, T: 'static + SlotClock,
177177

178178
pub async fn create_validators_web3signer<T: 'static + SlotClock, E: EthSpec>(
179179
validators: Vec<ValidatorDefinition>,
180-
validator_store: &LighthouseValidatorStore<T>,
180+
validator_store: &LighthouseValidatorStore<T, E>,
181181
) -> Result<(), warp::Rejection> {
182182
for validator in validators {
183183
validator_store
184-
.add_validator::<E>(validator)
184+
.add_validator(validator)
185185
.await
186186
.map_err(|e| {
187187
warp_utils::reject::custom_server_error(format!(

validator_client/http_api/src/graffiti.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ use bls::PublicKey;
22
use lighthouse_validator_store::LighthouseValidatorStore;
33
use slot_clock::SlotClock;
44
use std::sync::Arc;
5-
use types::{graffiti::GraffitiString, Graffiti};
5+
use types::{graffiti::GraffitiString, EthSpec, Graffiti};
66

7-
pub fn get_graffiti<T: 'static + SlotClock + Clone>(
7+
pub fn get_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
88
validator_pubkey: PublicKey,
9-
validator_store: Arc<LighthouseValidatorStore<T>>,
9+
validator_store: Arc<LighthouseValidatorStore<T, E>>,
1010
graffiti_flag: Option<Graffiti>,
1111
) -> Result<Graffiti, warp::Rejection> {
1212
let initialized_validators_rw_lock = validator_store.initialized_validators();
@@ -26,10 +26,10 @@ pub fn get_graffiti<T: 'static + SlotClock + Clone>(
2626
}
2727
}
2828

29-
pub fn set_graffiti<T: 'static + SlotClock + Clone>(
29+
pub fn set_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
3030
validator_pubkey: PublicKey,
3131
graffiti: GraffitiString,
32-
validator_store: Arc<LighthouseValidatorStore<T>>,
32+
validator_store: Arc<LighthouseValidatorStore<T, E>>,
3333
) -> Result<(), warp::Rejection> {
3434
let initialized_validators_rw_lock = validator_store.initialized_validators();
3535
let mut initialized_validators = initialized_validators_rw_lock.write();
@@ -53,9 +53,9 @@ pub fn set_graffiti<T: 'static + SlotClock + Clone>(
5353
}
5454
}
5555

56-
pub fn delete_graffiti<T: 'static + SlotClock + Clone>(
56+
pub fn delete_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
5757
validator_pubkey: PublicKey,
58-
validator_store: Arc<LighthouseValidatorStore<T>>,
58+
validator_store: Arc<LighthouseValidatorStore<T, E>>,
5959
) -> Result<(), warp::Rejection> {
6060
let initialized_validators_rw_lock = validator_store.initialized_validators();
6161
let mut initialized_validators = initialized_validators_rw_lock.write();

validator_client/http_api/src/keystores.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ use warp::Rejection;
2424
use warp_utils::reject::{custom_bad_request, custom_server_error};
2525
use zeroize::Zeroizing;
2626

27-
pub fn list<T: SlotClock + 'static>(
28-
validator_store: Arc<LighthouseValidatorStore<T>>,
27+
pub fn list<T: SlotClock + 'static, E: EthSpec>(
28+
validator_store: Arc<LighthouseValidatorStore<T, E>>,
2929
) -> ListKeystoresResponse {
3030
let initialized_validators_rwlock = validator_store.initialized_validators();
3131
let initialized_validators = initialized_validators_rwlock.read();
@@ -62,7 +62,7 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
6262
request: ImportKeystoresRequest,
6363
validator_dir: PathBuf,
6464
secrets_dir: Option<PathBuf>,
65-
validator_store: Arc<LighthouseValidatorStore<T>>,
65+
validator_store: Arc<LighthouseValidatorStore<T, E>>,
6666
task_executor: TaskExecutor,
6767
log: Logger,
6868
) -> Result<ImportKeystoresResponse, Rejection> {
@@ -171,7 +171,7 @@ fn import_single_keystore<T: SlotClock + 'static, E: EthSpec>(
171171
password: Zeroizing<String>,
172172
validator_dir_path: PathBuf,
173173
secrets_dir: Option<PathBuf>,
174-
validator_store: &LighthouseValidatorStore<T>,
174+
validator_store: &LighthouseValidatorStore<T, E>,
175175
handle: Handle,
176176
) -> Result<ImportKeystoreStatus, String> {
177177
// Check if the validator key already exists, erroring if it is a remote signer validator.
@@ -223,7 +223,7 @@ fn import_single_keystore<T: SlotClock + 'static, E: EthSpec>(
223223
drop(validator_dir);
224224

225225
handle
226-
.block_on(validator_store.add_validator_keystore::<_, E>(
226+
.block_on(validator_store.add_validator_keystore(
227227
voting_keystore_path,
228228
password_storage,
229229
true,
@@ -239,9 +239,9 @@ fn import_single_keystore<T: SlotClock + 'static, E: EthSpec>(
239239
Ok(ImportKeystoreStatus::Imported)
240240
}
241241

242-
pub fn delete<T: SlotClock + 'static>(
242+
pub fn delete<T: SlotClock + 'static, E: EthSpec>(
243243
request: DeleteKeystoresRequest,
244-
validator_store: Arc<LighthouseValidatorStore<T>>,
244+
validator_store: Arc<LighthouseValidatorStore<T, E>>,
245245
task_executor: TaskExecutor,
246246
log: Logger,
247247
) -> Result<DeleteKeystoresResponse, Rejection> {
@@ -272,9 +272,9 @@ pub fn delete<T: SlotClock + 'static>(
272272
})
273273
}
274274

275-
pub fn export<T: SlotClock + 'static>(
275+
pub fn export<T: SlotClock + 'static, E: EthSpec>(
276276
request: DeleteKeystoresRequest,
277-
validator_store: Arc<LighthouseValidatorStore<T>>,
277+
validator_store: Arc<LighthouseValidatorStore<T, E>>,
278278
task_executor: TaskExecutor,
279279
log: Logger,
280280
) -> Result<ExportKeystoresResponse, Rejection> {

0 commit comments

Comments
 (0)