diff --git a/Cargo.lock b/Cargo.lock index cac5905593..a50141e193 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5472,8 +5472,14 @@ name = "lighthouse_validator_store" version = "0.1.0" dependencies = [ "account_utils", + "beacon_node_fallback", "doppelganger_service", + "either", + "environment", + "eth2", + "futures", "initialized_validators", + "logging", "parking_lot 0.12.3", "serde", "signing_method", @@ -5481,6 +5487,7 @@ dependencies = [ "slog", "slot_clock", "task_executor", + "tokio", "types", "validator_metrics", "validator_store", @@ -9905,7 +9912,6 @@ dependencies = [ "types", "validator_metrics", "validator_services", - "validator_store", "warp", "warp_utils", ] diff --git a/Cargo.toml b/Cargo.toml index db365738be..36f5efe2d8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -233,7 +233,6 @@ compare_fields = { path = "common/compare_fields" } deposit_contract = { path = "common/deposit_contract" } directory = { path = "common/directory" } doppelganger_service = { path = "validator_client/doppelganger_service" } -validator_services = { path = "validator_client/validator_services" } environment = { path = "lighthouse/environment" } eth1 = { path = "beacon_node/eth1" } eth1_test_rig = { path = "testing/eth1_test_rig" } @@ -287,6 +286,7 @@ validator_dir = { path = "common/validator_dir" } validator_http_api = { path = "validator_client/http_api" } validator_http_metrics = { path = "validator_client/http_metrics" } validator_metrics = { path = "validator_client/validator_metrics" } +validator_services = { path = "validator_client/validator_services" } validator_store = { path = "validator_client/validator_store" } validator_test_rig = { path = "testing/validator_test_rig" } warp_utils = { path = "common/warp_utils" } diff --git a/testing/web3signer_tests/src/lib.rs b/testing/web3signer_tests/src/lib.rs index 87c809f8c8..05512e9608 100644 --- a/testing/web3signer_tests/src/lib.rs +++ b/testing/web3signer_tests/src/lib.rs @@ -46,7 +46,7 @@ mod tests { use tokio::time::sleep; use types::{attestation::AttestationBase, *}; use url::Url; - use validator_store::{Error as ValidatorStoreError, SignBlock, ValidatorStore}; + use validator_store::{Error as ValidatorStoreError, SignedBlock, ValidatorStore}; /// If the we are unable to reach the Web3Signer HTTP API within this time out then we will /// assume it failed to start. @@ -75,6 +75,7 @@ mod tests { impl SignedObject for Signature {} impl SignedObject for Attestation {} impl SignedObject for SignedBeaconBlock {} + impl SignedObject for SignedBlock {} impl SignedObject for SignedAggregateAndProof {} impl SignedObject for SelectionProof {} impl SignedObject for SyncSelectionProof {} @@ -599,10 +600,10 @@ mod tests { .assert_signatures_match("beacon_block_base", |pubkey, validator_store| { let spec = spec.clone(); async move { - let block = BeaconBlock::Base(BeaconBlockBase::empty(&spec)); + let block = BeaconBlock::::Base(BeaconBlockBase::empty(&spec)); let block_slot = block.slot(); validator_store - .sign_block(pubkey, block, block_slot) + .sign_block(pubkey, block.into(), block_slot) .await .unwrap() } @@ -669,10 +670,14 @@ mod tests { .assert_signatures_match("beacon_block_altair", |pubkey, validator_store| { let spec = spec.clone(); async move { - let mut altair_block = BeaconBlockAltair::empty(&spec); + let mut altair_block = BeaconBlockAltair::::empty(&spec); altair_block.slot = altair_fork_slot; validator_store - .sign_block(pubkey, BeaconBlock::Altair(altair_block), altair_fork_slot) + .sign_block( + pubkey, + BeaconBlock::Altair(altair_block).into(), + altair_fork_slot, + ) .await .unwrap() } @@ -752,12 +757,12 @@ mod tests { .assert_signatures_match("beacon_block_bellatrix", |pubkey, validator_store| { let spec = spec.clone(); async move { - let mut bellatrix_block = BeaconBlockBellatrix::empty(&spec); + let mut bellatrix_block = BeaconBlockBellatrix::::empty(&spec); bellatrix_block.slot = bellatrix_fork_slot; validator_store .sign_block( pubkey, - BeaconBlock::Bellatrix(bellatrix_block), + BeaconBlock::Bellatrix(bellatrix_block).into(), bellatrix_fork_slot, ) .await @@ -813,7 +818,7 @@ mod tests { }; let first_block = || { - let mut bellatrix_block = BeaconBlockBellatrix::empty(&spec); + let mut bellatrix_block = BeaconBlockBellatrix::::empty(&spec); bellatrix_block.slot = bellatrix_fork_slot; BeaconBlock::Bellatrix(bellatrix_block) }; @@ -879,7 +884,7 @@ mod tests { let block = first_block(); let slot = block.slot(); validator_store - .sign_block(pubkey, block, slot) + .sign_block(pubkey, block.into(), slot) .await .unwrap() }) @@ -890,7 +895,7 @@ mod tests { let block = double_vote_block(); let slot = block.slot(); validator_store - .sign_block(pubkey, block, slot) + .sign_block(pubkey, block.into(), slot) .await .map(|_| ()) }, diff --git a/validator_client/doppelganger_service/src/lib.rs b/validator_client/doppelganger_service/src/lib.rs index c195b3e8ca..49e70a335a 100644 --- a/validator_client/doppelganger_service/src/lib.rs +++ b/validator_client/doppelganger_service/src/lib.rs @@ -236,7 +236,7 @@ impl DoppelgangerService { // Define the `get_liveness` function as one that queries the beacon node API. let log = service.log.clone(); let get_liveness = move |current_epoch, validator_indices| { - beacon_node_liveness( + beacon_node_liveness::( beacon_nodes.clone(), log.clone(), current_epoch, @@ -332,17 +332,18 @@ impl DoppelgangerService { /// /// Validators added during the genesis epoch will not have doppelganger protection applied to /// them. - pub fn register_new_validator( + pub fn register_new_validator( &self, validator: PublicKeyBytes, slot_clock: &T, + slots_per_epoch: u64, ) -> Result<(), String> { let current_epoch = slot_clock // If registering before genesis, use the genesis slot. .now_or_genesis() .ok_or_else(|| "Unable to read slot clock when registering validator".to_string())? - .epoch(E::slots_per_epoch()); - let genesis_epoch = slot_clock.genesis_slot().epoch(E::slots_per_epoch()); + .epoch(slots_per_epoch); + let genesis_epoch = slot_clock.genesis_slot().epoch(slots_per_epoch); let remaining_epochs = if current_epoch <= genesis_epoch { // Disable doppelganger protection when the validator was initialized before genesis. @@ -738,7 +739,7 @@ mod test { .expect("index should exist"); self.doppelganger - .register_new_validator::(pubkey, &self.slot_clock) + .register_new_validator(pubkey, &self.slot_clock, E::slots_per_epoch()) .unwrap(); self.doppelganger .doppelganger_states diff --git a/validator_client/http_api/src/tests.rs b/validator_client/http_api/src/tests.rs index aa87b60161..62ae832794 100644 --- a/validator_client/http_api/src/tests.rs +++ b/validator_client/http_api/src/tests.rs @@ -113,7 +113,7 @@ impl ApiTester { let initialized_validators = validator_store.initialized_validators(); - let context = Arc::new(Context { + let context = Arc::new(Context::<_, E> { task_executor: test_runtime.task_executor.clone(), api_secret, block_service: None, diff --git a/validator_client/http_metrics/Cargo.toml b/validator_client/http_metrics/Cargo.toml index ad256c07d8..bc1860c6ff 100644 --- a/validator_client/http_metrics/Cargo.toml +++ b/validator_client/http_metrics/Cargo.toml @@ -17,6 +17,5 @@ slot_clock = { workspace = true } types = { workspace = true } validator_metrics = { workspace = true } validator_services = { workspace = true } -validator_store = { workspace = true } warp = { workspace = true } warp_utils = { workspace = true } diff --git a/validator_client/lighthouse_validator_store/Cargo.toml b/validator_client/lighthouse_validator_store/Cargo.toml index 3997453e2c..5d38d6dd11 100644 --- a/validator_client/lighthouse_validator_store/Cargo.toml +++ b/validator_client/lighthouse_validator_store/Cargo.toml @@ -6,7 +6,11 @@ authors = ["Sigma Prime "] [dependencies] account_utils = { workspace = true } +beacon_node_fallback = { workspace = true } doppelganger_service = { workspace = true } +either = { workspace = true } +environment = { workspace = true } +eth2 = { workspace = true } initialized_validators = { workspace = true } parking_lot = { workspace = true } serde = { workspace = true } @@ -15,6 +19,11 @@ slashing_protection = { workspace = true } slog = { workspace = true } slot_clock = { workspace = true } task_executor = { workspace = true } +tokio = { workspace = true } types = { workspace = true } validator_metrics = { workspace = true } validator_store = { workspace = true } + +[dev-dependencies] +futures = { workspace = true } +logging = { workspace = true } diff --git a/validator_client/lighthouse_validator_store/src/lib.rs b/validator_client/lighthouse_validator_store/src/lib.rs index 5d438e50c0..0306015523 100644 --- a/validator_client/lighthouse_validator_store/src/lib.rs +++ b/validator_client/lighthouse_validator_store/src/lib.rs @@ -117,7 +117,11 @@ impl LighthouseValidatorStore { pub fn register_all_in_doppelganger_protection_if_enabled(&self) -> Result<(), String> { if let Some(doppelganger_service) = &self.doppelganger_service { for pubkey in self.validators.read().iter_voting_pubkeys() { - doppelganger_service.register_new_validator::(*pubkey, &self.slot_clock)? + doppelganger_service.register_new_validator( + *pubkey, + &self.slot_clock, + E::slots_per_epoch(), + )? } } @@ -193,8 +197,11 @@ impl LighthouseValidatorStore { .map_err(|e| format!("failed to register validator: {:?}", e))?; if let Some(doppelganger_service) = &self.doppelganger_service { - doppelganger_service - .register_new_validator::(validator_pubkey, &self.slot_clock)?; + doppelganger_service.register_new_validator( + validator_pubkey, + &self.slot_clock, + E::slots_per_epoch(), + )?; } self.validators diff --git a/validator_client/validator_services/Cargo.toml b/validator_client/validator_services/Cargo.toml index c3c5ff1768..86208dadef 100644 --- a/validator_client/validator_services/Cargo.toml +++ b/validator_client/validator_services/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Sigma Prime "] [dependencies] beacon_node_fallback = { workspace = true } -bls = { workspace = true } +bls = { workspace = true } either = { workspace = true } eth2 = { workspace = true } futures = { workspace = true } diff --git a/validator_client/validator_services/src/duties_service.rs b/validator_client/validator_services/src/duties_service.rs index cdbbd95a10..3f987b63ed 100644 --- a/validator_client/validator_services/src/duties_service.rs +++ b/validator_client/validator_services/src/duties_service.rs @@ -381,7 +381,7 @@ impl DutiesService { /// It is possible that multiple validators have an identical proposal slot, however that is /// likely the result of heavy forking (lol) or inconsistent beacon node connections. pub fn block_proposers(&self, slot: Slot) -> HashSet { - let epoch = slot.epoch(E::slots_per_epoch()); + let epoch = slot.epoch(S::E::slots_per_epoch()); // Only collect validators that are considered safe in terms of doppelganger protection. let signing_pubkeys: HashSet<_> = self diff --git a/validator_client/validator_store/src/lib.rs b/validator_client/validator_store/src/lib.rs index 503c693191..6e0a3b0e2e 100644 --- a/validator_client/validator_store/src/lib.rs +++ b/validator_client/validator_store/src/lib.rs @@ -177,6 +177,7 @@ pub trait ValidatorStore: Send + Sync { fn proposal_data(&self, pubkey: &PublicKeyBytes) -> Option; } +#[derive(Clone, Debug, PartialEq)] pub enum UnsignedBlock { Full(BeaconBlock), Blinded(BlindedBeaconBlock), @@ -194,6 +195,7 @@ impl From> for UnsignedBlock { } } +#[derive(Clone, Debug, PartialEq)] pub enum SignedBlock { Full(SignedBeaconBlock), Blinded(SignedBlindedBeaconBlock),