mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 17:26:04 +00:00
Squashed changed from modularized-validator-store
This commit is contained in:
8
Cargo.lock
generated
8
Cargo.lock
generated
@@ -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",
|
||||
]
|
||||
|
||||
@@ -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" }
|
||||
|
||||
@@ -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<E> {}
|
||||
impl SignedObject for SignedBeaconBlock<E> {}
|
||||
impl SignedObject for SignedBlock<E> {}
|
||||
impl SignedObject for SignedAggregateAndProof<E> {}
|
||||
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::<E>::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::<E>::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::<E>::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::<E>::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(|_| ())
|
||||
},
|
||||
|
||||
@@ -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::<T>(
|
||||
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<E: EthSpec, T: SlotClock>(
|
||||
pub fn register_new_validator<T: SlotClock>(
|
||||
&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::<E, _>(pubkey, &self.slot_clock)
|
||||
.register_new_validator(pubkey, &self.slot_clock, E::slots_per_epoch())
|
||||
.unwrap();
|
||||
self.doppelganger
|
||||
.doppelganger_states
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -6,7 +6,11 @@ authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
|
||||
[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 }
|
||||
|
||||
@@ -117,7 +117,11 @@ impl<T: SlotClock + 'static, E: EthSpec> LighthouseValidatorStore<T, E> {
|
||||
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::<E, _>(*pubkey, &self.slot_clock)?
|
||||
doppelganger_service.register_new_validator(
|
||||
*pubkey,
|
||||
&self.slot_clock,
|
||||
E::slots_per_epoch(),
|
||||
)?
|
||||
}
|
||||
}
|
||||
|
||||
@@ -193,8 +197,11 @@ impl<T: SlotClock + 'static, E: EthSpec> LighthouseValidatorStore<T, E> {
|
||||
.map_err(|e| format!("failed to register validator: {:?}", e))?;
|
||||
|
||||
if let Some(doppelganger_service) = &self.doppelganger_service {
|
||||
doppelganger_service
|
||||
.register_new_validator::<E, _>(validator_pubkey, &self.slot_clock)?;
|
||||
doppelganger_service.register_new_validator(
|
||||
validator_pubkey,
|
||||
&self.slot_clock,
|
||||
E::slots_per_epoch(),
|
||||
)?;
|
||||
}
|
||||
|
||||
self.validators
|
||||
|
||||
@@ -6,7 +6,7 @@ authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
||||
|
||||
[dependencies]
|
||||
beacon_node_fallback = { workspace = true }
|
||||
bls = { workspace = true }
|
||||
bls = { workspace = true }
|
||||
either = { workspace = true }
|
||||
eth2 = { workspace = true }
|
||||
futures = { workspace = true }
|
||||
|
||||
@@ -381,7 +381,7 @@ impl<S: ValidatorStore, T: SlotClock + 'static> DutiesService<S, T> {
|
||||
/// 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<E: EthSpec>(&self, slot: Slot) -> HashSet<PublicKeyBytes> {
|
||||
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
|
||||
|
||||
@@ -177,6 +177,7 @@ pub trait ValidatorStore: Send + Sync {
|
||||
fn proposal_data(&self, pubkey: &PublicKeyBytes) -> Option<ProposalData>;
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum UnsignedBlock<E: EthSpec> {
|
||||
Full(BeaconBlock<E>),
|
||||
Blinded(BlindedBeaconBlock<E>),
|
||||
@@ -194,6 +195,7 @@ impl<E: EthSpec> From<BlindedBeaconBlock<E>> for UnsignedBlock<E> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum SignedBlock<E: EthSpec> {
|
||||
Full(SignedBeaconBlock<E>),
|
||||
Blinded(SignedBlindedBeaconBlock<E>),
|
||||
|
||||
Reference in New Issue
Block a user