Skip to content

Commit e2f26c0

Browse files
Create SlashingDatabase trait and rename struct to SqliteSlashingDatabase
Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
1 parent e7ca777 commit e2f26c0

File tree

19 files changed

+893
-99
lines changed

19 files changed

+893
-99
lines changed

account_manager/src/validator/create.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use clap_utils::FLAG_HEADER;
99
use directory::{DEFAULT_SECRET_DIR, DEFAULT_WALLET_DIR, parse_path_or_default_with_flag};
1010
use environment::Environment;
1111
use eth2_wallet_manager::WalletManager;
12-
use slashing_protection::{SLASHING_PROTECTION_FILENAME, SlashingDatabase};
12+
use slashing_protection::{SLASHING_PROTECTION_FILENAME, SqliteSlashingDatabase};
1313
use std::ffi::OsStr;
1414
use std::fs;
1515
use std::fs::create_dir_all;
@@ -203,7 +203,7 @@ pub fn cli_run<E: EthSpec>(
203203

204204
let slashing_protection_path = validator_dir.join(SLASHING_PROTECTION_FILENAME);
205205
let slashing_protection =
206-
SlashingDatabase::open_or_create(&slashing_protection_path).map_err(|e| {
206+
SqliteSlashingDatabase::open_or_create(&slashing_protection_path).map_err(|e| {
207207
format!(
208208
"Unable to open or create slashing protection database at {}: {:?}",
209209
slashing_protection_path.display(),

account_manager/src/validator/import.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use account_utils::{
1111
};
1212
use clap::{Arg, ArgAction, ArgMatches, Command};
1313
use clap_utils::FLAG_HEADER;
14-
use slashing_protection::{SLASHING_PROTECTION_FILENAME, SlashingDatabase};
14+
use slashing_protection::{SLASHING_PROTECTION_FILENAME, SqliteSlashingDatabase};
1515
use std::fs;
1616
use std::path::PathBuf;
1717
use std::thread::sleep;
@@ -97,7 +97,7 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
9797

9898
let slashing_protection_path = validator_dir.join(SLASHING_PROTECTION_FILENAME);
9999
let slashing_protection =
100-
SlashingDatabase::open_or_create(&slashing_protection_path).map_err(|e| {
100+
SqliteSlashingDatabase::open_or_create(&slashing_protection_path).map_err(|e| {
101101
format!(
102102
"Unable to open or create slashing protection database at {}: {:?}",
103103
slashing_protection_path.display(),

validator_client/http_api/src/create_signed_voluntary_exit.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use slashing_protection::SlashingDatabase;
12
use bls::{PublicKey, PublicKeyBytes};
23
use eth2::types::GenericResponse;
34
use lighthouse_validator_store::LighthouseValidatorStore;
@@ -7,10 +8,10 @@ use tracing::info;
78
use types::{Epoch, EthSpec, SignedVoluntaryExit, VoluntaryExit};
89
use validator_store::ValidatorStore;
910

10-
pub async fn create_signed_voluntary_exit<T: 'static + SlotClock + Clone, E: EthSpec>(
11+
pub async fn create_signed_voluntary_exit<T: 'static + SlotClock + Clone, E: EthSpec, S: SlashingDatabase + Send + Sync + 'static>(
1112
pubkey: PublicKey,
1213
maybe_epoch: Option<Epoch>,
13-
validator_store: Arc<LighthouseValidatorStore<T, E>>,
14+
validator_store: Arc<LighthouseValidatorStore<T, E, S>>,
1415
slot_clock: T,
1516
) -> Result<GenericResponse<SignedVoluntaryExit>, warp::Rejection> {
1617
let epoch = match maybe_epoch {
@@ -64,6 +65,6 @@ pub async fn create_signed_voluntary_exit<T: 'static + SlotClock + Clone, E: Eth
6465
}
6566

6667
/// Calculates the current epoch from the genesis time and current time.
67-
fn get_current_epoch<T: 'static + SlotClock + Clone, E: EthSpec>(slot_clock: T) -> Option<Epoch> {
68+
fn get_current_epoch<T: 'static + SlotClock + Clone, E: EthSpec, S: SlashingDatabase + Send + Sync + 'static>(slot_clock: T) -> Option<Epoch> {
6869
slot_clock.now().map(|s| s.epoch(E::slots_per_epoch()))
6970
}

validator_client/http_api/src/create_validator.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use slashing_protection::SlashingDatabase;
12
use account_utils::validator_definitions::{PasswordStorage, ValidatorDefinition};
23
use account_utils::{
34
eth2_keystore::Keystore,
@@ -29,7 +30,7 @@ pub async fn create_validators_mnemonic<P: AsRef<Path>, T: 'static + SlotClock,
2930
validator_requests: &[api_types::ValidatorRequest],
3031
validator_dir: P,
3132
secrets_dir: Option<PathBuf>,
32-
validator_store: &LighthouseValidatorStore<T, E>,
33+
validator_store: &LighthouseValidatorStore<T, E, S>,
3334
spec: &ChainSpec,
3435
) -> Result<(Vec<api_types::CreatedValidator>, Mnemonic), warp::Rejection> {
3536
let mnemonic = mnemonic_opt.unwrap_or_else(random_mnemonic);
@@ -175,9 +176,9 @@ pub async fn create_validators_mnemonic<P: AsRef<Path>, T: 'static + SlotClock,
175176
Ok((validators, mnemonic))
176177
}
177178

178-
pub async fn create_validators_web3signer<T: 'static + SlotClock, E: EthSpec>(
179+
pub async fn create_validators_web3signer<T: 'static + SlotClock, E: EthSpec, S: SlashingDatabase + Send + Sync + 'static>(
179180
validators: Vec<ValidatorDefinition>,
180-
validator_store: &LighthouseValidatorStore<T, E>,
181+
validator_store: &LighthouseValidatorStore<T, E, S>,
181182
) -> Result<(), warp::Rejection> {
182183
for validator in validators {
183184
validator_store

validator_client/http_api/src/graffiti.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
use slashing_protection::SlashingDatabase;
12
use bls::PublicKey;
23
use lighthouse_validator_store::LighthouseValidatorStore;
34
use slot_clock::SlotClock;
45
use std::sync::Arc;
56
use types::{EthSpec, Graffiti, graffiti::GraffitiString};
67

7-
pub fn get_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
8+
pub fn get_graffiti<T: 'static + SlotClock + Clone, E: EthSpec, S: SlashingDatabase + Send + Sync + 'static>(
89
validator_pubkey: PublicKey,
9-
validator_store: Arc<LighthouseValidatorStore<T, E>>,
10+
validator_store: Arc<LighthouseValidatorStore<T, E, S>>,
1011
graffiti_flag: Option<Graffiti>,
1112
) -> Result<Graffiti, warp::Rejection> {
1213
let initialized_validators_rw_lock = validator_store.initialized_validators();
@@ -26,10 +27,10 @@ pub fn get_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
2627
}
2728
}
2829

29-
pub fn set_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
30+
pub fn set_graffiti<T: 'static + SlotClock + Clone, E: EthSpec, S: SlashingDatabase + Send + Sync + 'static>(
3031
validator_pubkey: PublicKey,
3132
graffiti: GraffitiString,
32-
validator_store: Arc<LighthouseValidatorStore<T, E>>,
33+
validator_store: Arc<LighthouseValidatorStore<T, E, S>>,
3334
) -> Result<(), warp::Rejection> {
3435
let initialized_validators_rw_lock = validator_store.initialized_validators();
3536
let mut initialized_validators = initialized_validators_rw_lock.write();
@@ -53,9 +54,9 @@ pub fn set_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
5354
}
5455
}
5556

56-
pub fn delete_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
57+
pub fn delete_graffiti<T: 'static + SlotClock + Clone, E: EthSpec, S: SlashingDatabase + Send + Sync + 'static>(
5758
validator_pubkey: PublicKey,
58-
validator_store: Arc<LighthouseValidatorStore<T, E>>,
59+
validator_store: Arc<LighthouseValidatorStore<T, E, S>>,
5960
) -> Result<(), warp::Rejection> {
6061
let initialized_validators_rw_lock = validator_store.initialized_validators();
6162
let mut initialized_validators = initialized_validators_rw_lock.write();

validator_client/http_api/src/keystores.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use slashing_protection::SlashingDatabase;
12
//! Implementation of the standard keystore management API.
23
use account_utils::validator_definitions::PasswordStorage;
34
use bls::PublicKeyBytes;
@@ -26,7 +27,7 @@ use warp_utils::reject::{custom_bad_request, custom_server_error};
2627
use zeroize::Zeroizing;
2728

2829
pub fn list<T: SlotClock + 'static, E: EthSpec>(
29-
validator_store: Arc<LighthouseValidatorStore<T, E>>,
30+
validator_store: Arc<LighthouseValidatorStore<T, E, S>>,
3031
) -> ListKeystoresResponse {
3132
let initialized_validators_rwlock = validator_store.initialized_validators();
3233
let initialized_validators = initialized_validators_rwlock.read();
@@ -63,7 +64,7 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
6364
request: ImportKeystoresRequest,
6465
validator_dir: PathBuf,
6566
secrets_dir: Option<PathBuf>,
66-
validator_store: Arc<LighthouseValidatorStore<T, E>>,
67+
validator_store: Arc<LighthouseValidatorStore<T, E, S>>,
6768
task_executor: TaskExecutor,
6869
) -> Result<ImportKeystoresResponse, Rejection> {
6970
// Check request validity. This is the only cases in which we should return a 4xx code.
@@ -118,7 +119,7 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
118119
)
119120
} else if let Some(handle) = task_executor.handle() {
120121
// Import the keystore.
121-
match import_single_keystore::<_, E>(
122+
match import_single_keystore::<_, E, S>(
122123
keystore,
123124
password,
124125
validator_dir.clone(),
@@ -165,7 +166,7 @@ fn import_single_keystore<T: SlotClock + 'static, E: EthSpec>(
165166
password: Zeroizing<String>,
166167
validator_dir_path: PathBuf,
167168
secrets_dir: Option<PathBuf>,
168-
validator_store: &LighthouseValidatorStore<T, E>,
169+
validator_store: &LighthouseValidatorStore<T, E, S>,
169170
handle: Handle,
170171
) -> Result<ImportKeystoreStatus, String> {
171172
// Check if the validator key already exists, erroring if it is a remote signer validator.
@@ -235,7 +236,7 @@ fn import_single_keystore<T: SlotClock + 'static, E: EthSpec>(
235236

236237
pub fn delete<T: SlotClock + 'static, E: EthSpec>(
237238
request: DeleteKeystoresRequest,
238-
validator_store: Arc<LighthouseValidatorStore<T, E>>,
239+
validator_store: Arc<LighthouseValidatorStore<T, E, S>>,
239240
task_executor: TaskExecutor,
240241
) -> Result<DeleteKeystoresResponse, Rejection> {
241242
let export_response = export(request, validator_store, task_executor)?;
@@ -266,7 +267,7 @@ pub fn delete<T: SlotClock + 'static, E: EthSpec>(
266267

267268
pub fn export<T: SlotClock + 'static, E: EthSpec>(
268269
request: DeleteKeystoresRequest,
269-
validator_store: Arc<LighthouseValidatorStore<T, E>>,
270+
validator_store: Arc<LighthouseValidatorStore<T, E, S>>,
270271
task_executor: TaskExecutor,
271272
) -> Result<ExportKeystoresResponse, Rejection> {
272273
// Remove from initialized validators.

0 commit comments

Comments
 (0)