mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-16 19:32:55 +00:00
Anchor pre-PR: Modularize validator store (#6771)
* pass slots_per_epoch at runtime * remove generic E from unrequired types * move `validator_store` to `lighthouse_validator_store` * make validator_store into a trait * further reduce dependencies * remove `environment` dependency on `beacon_node_fallback` * Manually pull in some changes from tracing-integration (thanks sayan!) Co-authored-by: ThreeHrSleep <threehrsleep@gmail.com> * remove `environment` from `validator_services` * unify boost factor accessors * add builder for DutiesService * Manually merge tracing PR for beacon_node_fallback Co-authored-by: ThreeHrSleep <threehrsleep@gmail.com> * Fix chain_spec for BlockService * address review * remove PhantomData from SyncDutiesMap * fix tests * correct test * Add `E` to `ValidatorStore` as associated type * fix tests * derive Clone for ValidatorStore's Error and required sub-errors * switch to enum for block signing to allow differing types --------- Co-authored-by: João Oliveira <hello@jxs.pt> Co-authored-by: ThreeHrSleep <threehrsleep@gmail.com> Co-authored-by: Jimmy Chen <jimmy@sigmaprime.io>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
use bls::{PublicKey, PublicKeyBytes};
|
||||
use eth2::types::GenericResponse;
|
||||
use lighthouse_validator_store::LighthouseValidatorStore;
|
||||
use slog::{info, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
use std::sync::Arc;
|
||||
@@ -9,7 +10,7 @@ use validator_store::ValidatorStore;
|
||||
pub async fn create_signed_voluntary_exit<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
pubkey: PublicKey,
|
||||
maybe_epoch: Option<Epoch>,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
slot_clock: T,
|
||||
log: Logger,
|
||||
) -> Result<GenericResponse<SignedVoluntaryExit>, warp::Rejection> {
|
||||
|
||||
@@ -5,12 +5,11 @@ use account_utils::{
|
||||
random_mnemonic, random_password,
|
||||
};
|
||||
use eth2::lighthouse_vc::types::{self as api_types};
|
||||
use lighthouse_validator_store::LighthouseValidatorStore;
|
||||
use slot_clock::SlotClock;
|
||||
use std::path::{Path, PathBuf};
|
||||
use types::ChainSpec;
|
||||
use types::EthSpec;
|
||||
use types::{ChainSpec, EthSpec};
|
||||
use validator_dir::{keystore_password_path, Builder as ValidatorDirBuilder};
|
||||
use validator_store::ValidatorStore;
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
/// Create some validator EIP-2335 keystores and store them on disk. Then, enroll the validators in
|
||||
@@ -30,7 +29,7 @@ pub async fn create_validators_mnemonic<P: AsRef<Path>, T: 'static + SlotClock,
|
||||
validator_requests: &[api_types::ValidatorRequest],
|
||||
validator_dir: P,
|
||||
secrets_dir: Option<PathBuf>,
|
||||
validator_store: &ValidatorStore<T, E>,
|
||||
validator_store: &LighthouseValidatorStore<T, E>,
|
||||
spec: &ChainSpec,
|
||||
) -> Result<(Vec<api_types::CreatedValidator>, Mnemonic), warp::Rejection> {
|
||||
let mnemonic = mnemonic_opt.unwrap_or_else(random_mnemonic);
|
||||
@@ -178,7 +177,7 @@ pub async fn create_validators_mnemonic<P: AsRef<Path>, T: 'static + SlotClock,
|
||||
|
||||
pub async fn create_validators_web3signer<T: 'static + SlotClock, E: EthSpec>(
|
||||
validators: Vec<ValidatorDefinition>,
|
||||
validator_store: &ValidatorStore<T, E>,
|
||||
validator_store: &LighthouseValidatorStore<T, E>,
|
||||
) -> Result<(), warp::Rejection> {
|
||||
for validator in validators {
|
||||
validator_store
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use bls::PublicKey;
|
||||
use lighthouse_validator_store::LighthouseValidatorStore;
|
||||
use slot_clock::SlotClock;
|
||||
use std::sync::Arc;
|
||||
use types::{graffiti::GraffitiString, EthSpec, Graffiti};
|
||||
use validator_store::ValidatorStore;
|
||||
|
||||
pub fn get_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
validator_pubkey: PublicKey,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
graffiti_flag: Option<Graffiti>,
|
||||
) -> Result<Graffiti, warp::Rejection> {
|
||||
let initialized_validators_rw_lock = validator_store.initialized_validators();
|
||||
@@ -29,7 +29,7 @@ pub fn get_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
pub fn set_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
validator_pubkey: PublicKey,
|
||||
graffiti: GraffitiString,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
) -> Result<(), warp::Rejection> {
|
||||
let initialized_validators_rw_lock = validator_store.initialized_validators();
|
||||
let mut initialized_validators = initialized_validators_rw_lock.write();
|
||||
@@ -55,7 +55,7 @@ pub fn set_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
|
||||
pub fn delete_graffiti<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
validator_pubkey: PublicKey,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
) -> Result<(), warp::Rejection> {
|
||||
let initialized_validators_rw_lock = validator_store.initialized_validators();
|
||||
let mut initialized_validators = initialized_validators_rw_lock.write();
|
||||
|
||||
@@ -10,6 +10,7 @@ use eth2::lighthouse_vc::{
|
||||
};
|
||||
use eth2_keystore::Keystore;
|
||||
use initialized_validators::{Error, InitializedValidators};
|
||||
use lighthouse_validator_store::LighthouseValidatorStore;
|
||||
use signing_method::SigningMethod;
|
||||
use slog::{info, warn, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
@@ -19,13 +20,12 @@ use task_executor::TaskExecutor;
|
||||
use tokio::runtime::Handle;
|
||||
use types::{EthSpec, PublicKeyBytes};
|
||||
use validator_dir::{keystore_password_path, Builder as ValidatorDirBuilder};
|
||||
use validator_store::ValidatorStore;
|
||||
use warp::Rejection;
|
||||
use warp_utils::reject::{custom_bad_request, custom_server_error};
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
pub fn list<T: SlotClock + 'static, E: EthSpec>(
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
) -> ListKeystoresResponse {
|
||||
let initialized_validators_rwlock = validator_store.initialized_validators();
|
||||
let initialized_validators = initialized_validators_rwlock.read();
|
||||
@@ -62,7 +62,7 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
|
||||
request: ImportKeystoresRequest,
|
||||
validator_dir: PathBuf,
|
||||
secrets_dir: Option<PathBuf>,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
task_executor: TaskExecutor,
|
||||
log: Logger,
|
||||
) -> Result<ImportKeystoresResponse, Rejection> {
|
||||
@@ -122,7 +122,7 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
|
||||
)
|
||||
} else if let Some(handle) = task_executor.handle() {
|
||||
// Import the keystore.
|
||||
match import_single_keystore(
|
||||
match import_single_keystore::<_, E>(
|
||||
keystore,
|
||||
password,
|
||||
validator_dir.clone(),
|
||||
@@ -171,7 +171,7 @@ fn import_single_keystore<T: SlotClock + 'static, E: EthSpec>(
|
||||
password: Zeroizing<String>,
|
||||
validator_dir_path: PathBuf,
|
||||
secrets_dir: Option<PathBuf>,
|
||||
validator_store: &ValidatorStore<T, E>,
|
||||
validator_store: &LighthouseValidatorStore<T, E>,
|
||||
handle: Handle,
|
||||
) -> Result<ImportKeystoreStatus, String> {
|
||||
// Check if the validator key already exists, erroring if it is a remote signer validator.
|
||||
@@ -241,7 +241,7 @@ fn import_single_keystore<T: SlotClock + 'static, E: EthSpec>(
|
||||
|
||||
pub fn delete<T: SlotClock + 'static, E: EthSpec>(
|
||||
request: DeleteKeystoresRequest,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
task_executor: TaskExecutor,
|
||||
log: Logger,
|
||||
) -> Result<DeleteKeystoresResponse, Rejection> {
|
||||
@@ -274,7 +274,7 @@ pub fn delete<T: SlotClock + 'static, E: EthSpec>(
|
||||
|
||||
pub fn export<T: SlotClock + 'static, E: EthSpec>(
|
||||
request: DeleteKeystoresRequest,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
task_executor: TaskExecutor,
|
||||
log: Logger,
|
||||
) -> Result<ExportKeystoresResponse, Rejection> {
|
||||
|
||||
@@ -13,6 +13,7 @@ use graffiti::{delete_graffiti, get_graffiti, set_graffiti};
|
||||
|
||||
use create_signed_voluntary_exit::create_signed_voluntary_exit;
|
||||
use graffiti_file::{determine_graffiti, GraffitiFile};
|
||||
use lighthouse_validator_store::LighthouseValidatorStore;
|
||||
use validator_store::ValidatorStore;
|
||||
|
||||
use account_utils::{
|
||||
@@ -40,7 +41,6 @@ use slog::{crit, info, warn, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
use std::collections::HashMap;
|
||||
use std::future::Future;
|
||||
use std::marker::PhantomData;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
@@ -75,11 +75,11 @@ impl From<String> for Error {
|
||||
/// A wrapper around all the items required to spawn the HTTP server.
|
||||
///
|
||||
/// The server will gracefully handle the case where any fields are `None`.
|
||||
pub struct Context<T: SlotClock, E: EthSpec> {
|
||||
pub struct Context<T: SlotClock, E> {
|
||||
pub task_executor: TaskExecutor,
|
||||
pub api_secret: ApiSecret,
|
||||
pub block_service: Option<BlockService<T, E>>,
|
||||
pub validator_store: Option<Arc<ValidatorStore<T, E>>>,
|
||||
pub block_service: Option<BlockService<LighthouseValidatorStore<T, E>, T>>,
|
||||
pub validator_store: Option<Arc<LighthouseValidatorStore<T, E>>>,
|
||||
pub validator_dir: Option<PathBuf>,
|
||||
pub secrets_dir: Option<PathBuf>,
|
||||
pub graffiti_file: Option<GraffitiFile>,
|
||||
@@ -89,7 +89,6 @@ pub struct Context<T: SlotClock, E: EthSpec> {
|
||||
pub log: Logger,
|
||||
pub sse_logging_components: Option<SSELoggingComponents>,
|
||||
pub slot_clock: T,
|
||||
pub _phantom: PhantomData<E>,
|
||||
}
|
||||
|
||||
/// Configuration for the HTTP server.
|
||||
@@ -324,7 +323,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(warp::path("validators"))
|
||||
.and(warp::path::end())
|
||||
.and(validator_store_filter.clone())
|
||||
.then(|validator_store: Arc<ValidatorStore<T, E>>| {
|
||||
.then(|validator_store: Arc<LighthouseValidatorStore<T, E>>| {
|
||||
blocking_json_task(move || {
|
||||
let validators = validator_store
|
||||
.initialized_validators()
|
||||
@@ -349,7 +348,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(warp::path::end())
|
||||
.and(validator_store_filter.clone())
|
||||
.then(
|
||||
|validator_pubkey: PublicKey, validator_store: Arc<ValidatorStore<T, E>>| {
|
||||
|validator_pubkey: PublicKey, validator_store: Arc<LighthouseValidatorStore<T, E>>| {
|
||||
blocking_json_task(move || {
|
||||
let validator = validator_store
|
||||
.initialized_validators()
|
||||
@@ -400,10 +399,10 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(graffiti_flag_filter)
|
||||
.and(log_filter.clone())
|
||||
.then(
|
||||
|validator_store: Arc<ValidatorStore<T, E>>,
|
||||
|validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
graffiti_file: Option<GraffitiFile>,
|
||||
graffiti_flag: Option<Graffiti>,
|
||||
log| {
|
||||
_log| {
|
||||
blocking_json_task(move || {
|
||||
let mut result = HashMap::new();
|
||||
for (key, graffiti_definition) in validator_store
|
||||
@@ -413,7 +412,6 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
{
|
||||
let graffiti = determine_graffiti(
|
||||
key,
|
||||
&log,
|
||||
graffiti_file.clone(),
|
||||
graffiti_definition,
|
||||
graffiti_flag,
|
||||
@@ -431,33 +429,35 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(warp::path("fallback_health"))
|
||||
.and(warp::path::end())
|
||||
.and(block_service_filter.clone())
|
||||
.then(|block_filter: BlockService<T, E>| async move {
|
||||
let mut result: HashMap<String, Vec<CandidateInfo>> = HashMap::new();
|
||||
.then(
|
||||
|block_filter: BlockService<LighthouseValidatorStore<T, E>, T>| async move {
|
||||
let mut result: HashMap<String, Vec<CandidateInfo>> = HashMap::new();
|
||||
|
||||
let mut beacon_nodes = Vec::new();
|
||||
for node in &*block_filter.beacon_nodes.candidates.read().await {
|
||||
beacon_nodes.push(CandidateInfo {
|
||||
index: node.index,
|
||||
endpoint: node.beacon_node.to_string(),
|
||||
health: *node.health.read().await,
|
||||
});
|
||||
}
|
||||
result.insert("beacon_nodes".to_string(), beacon_nodes);
|
||||
|
||||
if let Some(proposer_nodes_list) = &block_filter.proposer_nodes {
|
||||
let mut proposer_nodes = Vec::new();
|
||||
for node in &*proposer_nodes_list.candidates.read().await {
|
||||
proposer_nodes.push(CandidateInfo {
|
||||
let mut beacon_nodes = Vec::new();
|
||||
for node in &*block_filter.beacon_nodes.candidates.read().await {
|
||||
beacon_nodes.push(CandidateInfo {
|
||||
index: node.index,
|
||||
endpoint: node.beacon_node.to_string(),
|
||||
health: *node.health.read().await,
|
||||
});
|
||||
}
|
||||
result.insert("proposer_nodes".to_string(), proposer_nodes);
|
||||
}
|
||||
result.insert("beacon_nodes".to_string(), beacon_nodes);
|
||||
|
||||
blocking_json_task(move || Ok(api_types::GenericResponse::from(result))).await
|
||||
});
|
||||
if let Some(proposer_nodes_list) = &block_filter.proposer_nodes {
|
||||
let mut proposer_nodes = Vec::new();
|
||||
for node in &*proposer_nodes_list.candidates.read().await {
|
||||
proposer_nodes.push(CandidateInfo {
|
||||
index: node.index,
|
||||
endpoint: node.beacon_node.to_string(),
|
||||
health: *node.health.read().await,
|
||||
});
|
||||
}
|
||||
result.insert("proposer_nodes".to_string(), proposer_nodes);
|
||||
}
|
||||
|
||||
blocking_json_task(move || Ok(api_types::GenericResponse::from(result))).await
|
||||
},
|
||||
);
|
||||
|
||||
// POST lighthouse/validators/
|
||||
let post_validators = warp::path("lighthouse")
|
||||
@@ -473,14 +473,14 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
move |body: Vec<api_types::ValidatorRequest>,
|
||||
validator_dir: PathBuf,
|
||||
secrets_dir: PathBuf,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
spec: Arc<ChainSpec>,
|
||||
task_executor: TaskExecutor| {
|
||||
blocking_json_task(move || {
|
||||
let secrets_dir = store_passwords_in_secrets_dir.then_some(secrets_dir);
|
||||
if let Some(handle) = task_executor.handle() {
|
||||
let (validators, mnemonic) =
|
||||
handle.block_on(create_validators_mnemonic(
|
||||
handle.block_on(create_validators_mnemonic::<_, _, E>(
|
||||
None,
|
||||
None,
|
||||
&body,
|
||||
@@ -518,7 +518,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
move |body: api_types::CreateValidatorsMnemonicRequest,
|
||||
validator_dir: PathBuf,
|
||||
secrets_dir: PathBuf,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
spec: Arc<ChainSpec>,
|
||||
task_executor: TaskExecutor| {
|
||||
blocking_json_task(move || {
|
||||
@@ -532,7 +532,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
))
|
||||
})?;
|
||||
let (validators, _mnemonic) =
|
||||
handle.block_on(create_validators_mnemonic(
|
||||
handle.block_on(create_validators_mnemonic::<_, _, E>(
|
||||
Some(mnemonic),
|
||||
Some(body.key_derivation_path_offset),
|
||||
&body.validators,
|
||||
@@ -565,7 +565,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
move |body: api_types::KeystoreValidatorsPostRequest,
|
||||
validator_dir: PathBuf,
|
||||
secrets_dir: PathBuf,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
task_executor: TaskExecutor| {
|
||||
blocking_json_task(move || {
|
||||
// Check to ensure the password is correct.
|
||||
@@ -651,7 +651,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(task_executor_filter.clone())
|
||||
.then(
|
||||
|body: Vec<api_types::Web3SignerValidatorRequest>,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
task_executor: TaskExecutor| {
|
||||
blocking_json_task(move || {
|
||||
if let Some(handle) = task_executor.handle() {
|
||||
@@ -679,7 +679,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
),
|
||||
})
|
||||
.collect();
|
||||
handle.block_on(create_validators_web3signer(
|
||||
handle.block_on(create_validators_web3signer::<_, E>(
|
||||
web3signers,
|
||||
&validator_store,
|
||||
))?;
|
||||
@@ -705,7 +705,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.then(
|
||||
|validator_pubkey: PublicKey,
|
||||
body: api_types::ValidatorPatchRequest,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
graffiti_file: Option<GraffitiFile>,
|
||||
task_executor: TaskExecutor| {
|
||||
blocking_json_task(move || {
|
||||
@@ -859,7 +859,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(warp::path::end())
|
||||
.and(validator_store_filter.clone())
|
||||
.then(
|
||||
|validator_pubkey: PublicKey, validator_store: Arc<ValidatorStore<T, E>>| {
|
||||
|validator_pubkey: PublicKey, validator_store: Arc<LighthouseValidatorStore<T, E>>| {
|
||||
blocking_json_task(move || {
|
||||
if validator_store
|
||||
.initialized_validators()
|
||||
@@ -900,7 +900,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.then(
|
||||
|validator_pubkey: PublicKey,
|
||||
request: api_types::UpdateFeeRecipientRequest,
|
||||
validator_store: Arc<ValidatorStore<T, E>>| {
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>| {
|
||||
blocking_json_task(move || {
|
||||
if validator_store
|
||||
.initialized_validators()
|
||||
@@ -936,7 +936,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(warp::path::end())
|
||||
.and(validator_store_filter.clone())
|
||||
.then(
|
||||
|validator_pubkey: PublicKey, validator_store: Arc<ValidatorStore<T, E>>| {
|
||||
|validator_pubkey: PublicKey, validator_store: Arc<LighthouseValidatorStore<T, E>>| {
|
||||
blocking_json_task(move || {
|
||||
if validator_store
|
||||
.initialized_validators()
|
||||
@@ -972,7 +972,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(warp::path::end())
|
||||
.and(validator_store_filter.clone())
|
||||
.then(
|
||||
|validator_pubkey: PublicKey, validator_store: Arc<ValidatorStore<T, E>>| {
|
||||
|validator_pubkey: PublicKey, validator_store: Arc<LighthouseValidatorStore<T, E>>| {
|
||||
blocking_json_task(move || {
|
||||
if validator_store
|
||||
.initialized_validators()
|
||||
@@ -1005,7 +1005,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.then(
|
||||
|validator_pubkey: PublicKey,
|
||||
request: api_types::UpdateGasLimitRequest,
|
||||
validator_store: Arc<ValidatorStore<T, E>>| {
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>| {
|
||||
blocking_json_task(move || {
|
||||
if validator_store
|
||||
.initialized_validators()
|
||||
@@ -1041,7 +1041,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(warp::path::end())
|
||||
.and(validator_store_filter.clone())
|
||||
.then(
|
||||
|validator_pubkey: PublicKey, validator_store: Arc<ValidatorStore<T, E>>| {
|
||||
|validator_pubkey: PublicKey, validator_store: Arc<LighthouseValidatorStore<T, E>>| {
|
||||
blocking_json_task(move || {
|
||||
if validator_store
|
||||
.initialized_validators()
|
||||
@@ -1083,14 +1083,14 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.then(
|
||||
|pubkey: PublicKey,
|
||||
query: api_types::VoluntaryExitQuery,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
slot_clock: T,
|
||||
log,
|
||||
task_executor: TaskExecutor| {
|
||||
blocking_json_task(move || {
|
||||
if let Some(handle) = task_executor.handle() {
|
||||
let signed_voluntary_exit =
|
||||
handle.block_on(create_signed_voluntary_exit(
|
||||
handle.block_on(create_signed_voluntary_exit::<T, E>(
|
||||
pubkey,
|
||||
query.epoch,
|
||||
validator_store,
|
||||
@@ -1117,7 +1117,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(graffiti_flag_filter)
|
||||
.then(
|
||||
|pubkey: PublicKey,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
graffiti_flag: Option<Graffiti>| {
|
||||
blocking_json_task(move || {
|
||||
let graffiti = get_graffiti(pubkey.clone(), validator_store, graffiti_flag)?;
|
||||
@@ -1141,7 +1141,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.then(
|
||||
|pubkey: PublicKey,
|
||||
query: SetGraffitiRequest,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
graffiti_file: Option<GraffitiFile>| {
|
||||
blocking_json_task(move || {
|
||||
if graffiti_file.is_some() {
|
||||
@@ -1166,7 +1166,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(graffiti_file_filter.clone())
|
||||
.then(
|
||||
|pubkey: PublicKey,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
graffiti_file: Option<GraffitiFile>| {
|
||||
blocking_json_task(move || {
|
||||
if graffiti_file.is_some() {
|
||||
@@ -1183,7 +1183,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
|
||||
// GET /eth/v1/keystores
|
||||
let get_std_keystores = std_keystores.and(validator_store_filter.clone()).then(
|
||||
|validator_store: Arc<ValidatorStore<T, E>>| {
|
||||
|validator_store: Arc<LighthouseValidatorStore<T, E>>| {
|
||||
blocking_json_task(move || Ok(keystores::list(validator_store)))
|
||||
},
|
||||
);
|
||||
@@ -1200,7 +1200,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
move |request, validator_dir, secrets_dir, validator_store, task_executor, log| {
|
||||
let secrets_dir = store_passwords_in_secrets_dir.then_some(secrets_dir);
|
||||
blocking_json_task(move || {
|
||||
keystores::import(
|
||||
keystores::import::<_, E>(
|
||||
request,
|
||||
validator_dir,
|
||||
secrets_dir,
|
||||
@@ -1226,7 +1226,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
|
||||
// GET /eth/v1/remotekeys
|
||||
let get_std_remotekeys = std_remotekeys.and(validator_store_filter.clone()).then(
|
||||
|validator_store: Arc<ValidatorStore<T, E>>| {
|
||||
|validator_store: Arc<LighthouseValidatorStore<T, E>>| {
|
||||
blocking_json_task(move || Ok(remotekeys::list(validator_store)))
|
||||
},
|
||||
);
|
||||
@@ -1239,7 +1239,7 @@ pub fn serve<T: 'static + SlotClock + Clone, E: EthSpec>(
|
||||
.and(log_filter.clone())
|
||||
.then(|request, validator_store, task_executor, log| {
|
||||
blocking_json_task(move || {
|
||||
remotekeys::import(request, validator_store, task_executor, log)
|
||||
remotekeys::import::<_, E>(request, validator_store, task_executor, log)
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use eth2::lighthouse_vc::std_types::{
|
||||
ListRemotekeysResponse, SingleListRemotekeysResponse, Status,
|
||||
};
|
||||
use initialized_validators::{Error, InitializedValidators};
|
||||
use lighthouse_validator_store::LighthouseValidatorStore;
|
||||
use slog::{info, warn, Logger};
|
||||
use slot_clock::SlotClock;
|
||||
use std::sync::Arc;
|
||||
@@ -15,12 +16,11 @@ use task_executor::TaskExecutor;
|
||||
use tokio::runtime::Handle;
|
||||
use types::{EthSpec, PublicKeyBytes};
|
||||
use url::Url;
|
||||
use validator_store::ValidatorStore;
|
||||
use warp::Rejection;
|
||||
use warp_utils::reject::custom_server_error;
|
||||
|
||||
pub fn list<T: SlotClock + 'static, E: EthSpec>(
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
) -> ListRemotekeysResponse {
|
||||
let initialized_validators_rwlock = validator_store.initialized_validators();
|
||||
let initialized_validators = initialized_validators_rwlock.read();
|
||||
@@ -50,7 +50,7 @@ pub fn list<T: SlotClock + 'static, E: EthSpec>(
|
||||
|
||||
pub fn import<T: SlotClock + 'static, E: EthSpec>(
|
||||
request: ImportRemotekeysRequest,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
task_executor: TaskExecutor,
|
||||
log: Logger,
|
||||
) -> Result<ImportRemotekeysResponse, Rejection> {
|
||||
@@ -65,8 +65,12 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
|
||||
for remotekey in request.remote_keys {
|
||||
let status = if let Some(handle) = task_executor.handle() {
|
||||
// Import the keystore.
|
||||
match import_single_remotekey(remotekey.pubkey, remotekey.url, &validator_store, handle)
|
||||
{
|
||||
match import_single_remotekey::<_, E>(
|
||||
remotekey.pubkey,
|
||||
remotekey.url,
|
||||
&validator_store,
|
||||
handle,
|
||||
) {
|
||||
Ok(status) => Status::ok(status),
|
||||
Err(e) => {
|
||||
warn!(
|
||||
@@ -92,7 +96,7 @@ pub fn import<T: SlotClock + 'static, E: EthSpec>(
|
||||
fn import_single_remotekey<T: SlotClock + 'static, E: EthSpec>(
|
||||
pubkey: PublicKeyBytes,
|
||||
url: String,
|
||||
validator_store: &ValidatorStore<T, E>,
|
||||
validator_store: &LighthouseValidatorStore<T, E>,
|
||||
handle: Handle,
|
||||
) -> Result<ImportRemotekeyStatus, String> {
|
||||
if let Err(url_err) = Url::parse(&url) {
|
||||
@@ -146,7 +150,7 @@ fn import_single_remotekey<T: SlotClock + 'static, E: EthSpec>(
|
||||
|
||||
pub fn delete<T: SlotClock + 'static, E: EthSpec>(
|
||||
request: DeleteRemotekeysRequest,
|
||||
validator_store: Arc<ValidatorStore<T, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<T, E>>,
|
||||
task_executor: TaskExecutor,
|
||||
log: Logger,
|
||||
) -> Result<DeleteRemotekeysResponse, Rejection> {
|
||||
|
||||
@@ -14,20 +14,20 @@ use eth2::{
|
||||
use eth2_keystore::KeystoreBuilder;
|
||||
use initialized_validators::key_cache::{KeyCache, CACHE_FILENAME};
|
||||
use initialized_validators::{InitializedValidators, OnDecryptFailure};
|
||||
use lighthouse_validator_store::{Config as ValidatorStoreConfig, LighthouseValidatorStore};
|
||||
use logging::test_logger;
|
||||
use parking_lot::RwLock;
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use slashing_protection::{SlashingDatabase, SLASHING_PROTECTION_FILENAME};
|
||||
use slot_clock::{SlotClock, TestingSlotClock};
|
||||
use std::future::Future;
|
||||
use std::marker::PhantomData;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use task_executor::test_utils::TestRuntime;
|
||||
use tempfile::{tempdir, TempDir};
|
||||
use tokio::sync::oneshot;
|
||||
use validator_store::{Config as ValidatorStoreConfig, ValidatorStore};
|
||||
use validator_services::block_service::BlockService;
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
pub const PASSWORD_BYTES: &[u8] = &[42, 50, 37];
|
||||
@@ -55,7 +55,7 @@ pub struct Web3SignerValidatorScenario {
|
||||
pub struct ApiTester {
|
||||
pub client: ValidatorClientHttpClient,
|
||||
pub initialized_validators: Arc<RwLock<InitializedValidators>>,
|
||||
pub validator_store: Arc<ValidatorStore<TestingSlotClock, E>>,
|
||||
pub validator_store: Arc<LighthouseValidatorStore<TestingSlotClock, E>>,
|
||||
pub url: SensitiveUrl,
|
||||
pub api_token: String,
|
||||
pub test_runtime: TestRuntime,
|
||||
@@ -105,7 +105,7 @@ impl ApiTester {
|
||||
|
||||
let test_runtime = TestRuntime::default();
|
||||
|
||||
let validator_store = Arc::new(ValidatorStore::<_, E>::new(
|
||||
let validator_store = Arc::new(LighthouseValidatorStore::new(
|
||||
initialized_validators,
|
||||
slashing_protection,
|
||||
Hash256::repeat_byte(42),
|
||||
@@ -126,7 +126,7 @@ impl ApiTester {
|
||||
let context = Arc::new(Context {
|
||||
task_executor: test_runtime.task_executor.clone(),
|
||||
api_secret,
|
||||
block_service: None,
|
||||
block_service: None::<BlockService<LighthouseValidatorStore<_, _>, _>>,
|
||||
validator_dir: Some(validator_dir.path().into()),
|
||||
secrets_dir: Some(secrets_dir.path().into()),
|
||||
validator_store: Some(validator_store.clone()),
|
||||
@@ -137,7 +137,6 @@ impl ApiTester {
|
||||
log,
|
||||
sse_logging_components: None,
|
||||
slot_clock,
|
||||
_phantom: PhantomData,
|
||||
});
|
||||
let ctx = context;
|
||||
let (shutdown_tx, shutdown_rx) = oneshot::channel();
|
||||
@@ -145,7 +144,7 @@ impl ApiTester {
|
||||
// It's not really interesting why this triggered, just that it happened.
|
||||
let _ = shutdown_rx.await;
|
||||
};
|
||||
let (listening_socket, server) = super::serve(ctx, server_shutdown).unwrap();
|
||||
let (listening_socket, server) = super::serve::<_, E>(ctx, server_shutdown).unwrap();
|
||||
|
||||
tokio::spawn(server);
|
||||
|
||||
|
||||
@@ -18,13 +18,13 @@ use eth2::{
|
||||
Error as ApiError,
|
||||
};
|
||||
use eth2_keystore::KeystoreBuilder;
|
||||
use lighthouse_validator_store::{Config as ValidatorStoreConfig, LighthouseValidatorStore};
|
||||
use logging::test_logger;
|
||||
use parking_lot::RwLock;
|
||||
use sensitive_url::SensitiveUrl;
|
||||
use slashing_protection::{SlashingDatabase, SLASHING_PROTECTION_FILENAME};
|
||||
use slot_clock::{SlotClock, TestingSlotClock};
|
||||
use std::future::Future;
|
||||
use std::marker::PhantomData;
|
||||
use std::net::{IpAddr, Ipv4Addr};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
@@ -32,7 +32,7 @@ use std::time::Duration;
|
||||
use task_executor::test_utils::TestRuntime;
|
||||
use tempfile::{tempdir, TempDir};
|
||||
use types::graffiti::GraffitiString;
|
||||
use validator_store::{Config as ValidatorStoreConfig, ValidatorStore};
|
||||
use validator_store::ValidatorStore;
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
const PASSWORD_BYTES: &[u8] = &[42, 50, 37];
|
||||
@@ -43,7 +43,7 @@ type E = MainnetEthSpec;
|
||||
struct ApiTester {
|
||||
client: ValidatorClientHttpClient,
|
||||
initialized_validators: Arc<RwLock<InitializedValidators>>,
|
||||
validator_store: Arc<ValidatorStore<TestingSlotClock, E>>,
|
||||
validator_store: Arc<LighthouseValidatorStore<TestingSlotClock, E>>,
|
||||
url: SensitiveUrl,
|
||||
slot_clock: TestingSlotClock,
|
||||
_validator_dir: TempDir,
|
||||
@@ -95,7 +95,7 @@ impl ApiTester {
|
||||
|
||||
let test_runtime = TestRuntime::default();
|
||||
|
||||
let validator_store = Arc::new(ValidatorStore::<_, E>::new(
|
||||
let validator_store = Arc::new(LighthouseValidatorStore::new(
|
||||
initialized_validators,
|
||||
slashing_protection,
|
||||
Hash256::repeat_byte(42),
|
||||
@@ -135,11 +135,10 @@ impl ApiTester {
|
||||
sse_logging_components: None,
|
||||
log,
|
||||
slot_clock: slot_clock.clone(),
|
||||
_phantom: PhantomData,
|
||||
});
|
||||
let ctx = context.clone();
|
||||
let (listening_socket, server) =
|
||||
super::serve(ctx, test_runtime.task_executor.exit()).unwrap();
|
||||
super::serve::<_, E>(ctx, test_runtime.task_executor.exit()).unwrap();
|
||||
|
||||
tokio::spawn(server);
|
||||
|
||||
@@ -708,7 +707,7 @@ impl ApiTester {
|
||||
|
||||
assert_eq!(
|
||||
self.validator_store
|
||||
.determine_validator_builder_boost_factor(&validator.voting_pubkey),
|
||||
.determine_builder_boost_factor(&validator.voting_pubkey),
|
||||
builder_boost_factor
|
||||
);
|
||||
|
||||
@@ -718,7 +717,7 @@ impl ApiTester {
|
||||
pub fn assert_default_builder_boost_factor(self, builder_boost_factor: Option<u64>) -> Self {
|
||||
assert_eq!(
|
||||
self.validator_store
|
||||
.determine_default_builder_boost_factor(),
|
||||
.determine_builder_boost_factor(&PublicKeyBytes::empty()),
|
||||
builder_boost_factor
|
||||
);
|
||||
|
||||
@@ -1165,7 +1164,7 @@ async fn validator_derived_builder_boost_factor_with_process_defaults() {
|
||||
})
|
||||
.await
|
||||
.assert_default_builder_boost_factor(Some(80))
|
||||
.assert_validator_derived_builder_boost_factor(0, None)
|
||||
.assert_validator_derived_builder_boost_factor(0, Some(80))
|
||||
.await
|
||||
.set_builder_proposals(0, false)
|
||||
.await
|
||||
|
||||
@@ -8,12 +8,13 @@ use eth2::lighthouse_vc::{
|
||||
types::Web3SignerValidatorRequest,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use lighthouse_validator_store::DEFAULT_GAS_LIMIT;
|
||||
use rand::{rngs::SmallRng, Rng, SeedableRng};
|
||||
use slashing_protection::interchange::{Interchange, InterchangeMetadata};
|
||||
use std::{collections::HashMap, path::Path};
|
||||
use tokio::runtime::Handle;
|
||||
use types::{attestation::AttestationBase, Address};
|
||||
use validator_store::DEFAULT_GAS_LIMIT;
|
||||
use validator_store::ValidatorStore;
|
||||
use zeroize::Zeroizing;
|
||||
|
||||
fn new_keystore(password: Zeroizing<String>) -> Keystore {
|
||||
|
||||
Reference in New Issue
Block a user