mirror of
https://github.com/sigp/lighthouse.git
synced 2026-05-08 09:16:00 +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"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"account_utils",
|
"account_utils",
|
||||||
|
"beacon_node_fallback",
|
||||||
"doppelganger_service",
|
"doppelganger_service",
|
||||||
|
"either",
|
||||||
|
"environment",
|
||||||
|
"eth2",
|
||||||
|
"futures",
|
||||||
"initialized_validators",
|
"initialized_validators",
|
||||||
|
"logging",
|
||||||
"parking_lot 0.12.3",
|
"parking_lot 0.12.3",
|
||||||
"serde",
|
"serde",
|
||||||
"signing_method",
|
"signing_method",
|
||||||
@@ -5481,6 +5487,7 @@ dependencies = [
|
|||||||
"slog",
|
"slog",
|
||||||
"slot_clock",
|
"slot_clock",
|
||||||
"task_executor",
|
"task_executor",
|
||||||
|
"tokio",
|
||||||
"types",
|
"types",
|
||||||
"validator_metrics",
|
"validator_metrics",
|
||||||
"validator_store",
|
"validator_store",
|
||||||
@@ -9905,7 +9912,6 @@ dependencies = [
|
|||||||
"types",
|
"types",
|
||||||
"validator_metrics",
|
"validator_metrics",
|
||||||
"validator_services",
|
"validator_services",
|
||||||
"validator_store",
|
|
||||||
"warp",
|
"warp",
|
||||||
"warp_utils",
|
"warp_utils",
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -233,7 +233,6 @@ compare_fields = { path = "common/compare_fields" }
|
|||||||
deposit_contract = { path = "common/deposit_contract" }
|
deposit_contract = { path = "common/deposit_contract" }
|
||||||
directory = { path = "common/directory" }
|
directory = { path = "common/directory" }
|
||||||
doppelganger_service = { path = "validator_client/doppelganger_service" }
|
doppelganger_service = { path = "validator_client/doppelganger_service" }
|
||||||
validator_services = { path = "validator_client/validator_services" }
|
|
||||||
environment = { path = "lighthouse/environment" }
|
environment = { path = "lighthouse/environment" }
|
||||||
eth1 = { path = "beacon_node/eth1" }
|
eth1 = { path = "beacon_node/eth1" }
|
||||||
eth1_test_rig = { path = "testing/eth1_test_rig" }
|
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_api = { path = "validator_client/http_api" }
|
||||||
validator_http_metrics = { path = "validator_client/http_metrics" }
|
validator_http_metrics = { path = "validator_client/http_metrics" }
|
||||||
validator_metrics = { path = "validator_client/validator_metrics" }
|
validator_metrics = { path = "validator_client/validator_metrics" }
|
||||||
|
validator_services = { path = "validator_client/validator_services" }
|
||||||
validator_store = { path = "validator_client/validator_store" }
|
validator_store = { path = "validator_client/validator_store" }
|
||||||
validator_test_rig = { path = "testing/validator_test_rig" }
|
validator_test_rig = { path = "testing/validator_test_rig" }
|
||||||
warp_utils = { path = "common/warp_utils" }
|
warp_utils = { path = "common/warp_utils" }
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ mod tests {
|
|||||||
use tokio::time::sleep;
|
use tokio::time::sleep;
|
||||||
use types::{attestation::AttestationBase, *};
|
use types::{attestation::AttestationBase, *};
|
||||||
use url::Url;
|
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
|
/// If the we are unable to reach the Web3Signer HTTP API within this time out then we will
|
||||||
/// assume it failed to start.
|
/// assume it failed to start.
|
||||||
@@ -75,6 +75,7 @@ mod tests {
|
|||||||
impl SignedObject for Signature {}
|
impl SignedObject for Signature {}
|
||||||
impl SignedObject for Attestation<E> {}
|
impl SignedObject for Attestation<E> {}
|
||||||
impl SignedObject for SignedBeaconBlock<E> {}
|
impl SignedObject for SignedBeaconBlock<E> {}
|
||||||
|
impl SignedObject for SignedBlock<E> {}
|
||||||
impl SignedObject for SignedAggregateAndProof<E> {}
|
impl SignedObject for SignedAggregateAndProof<E> {}
|
||||||
impl SignedObject for SelectionProof {}
|
impl SignedObject for SelectionProof {}
|
||||||
impl SignedObject for SyncSelectionProof {}
|
impl SignedObject for SyncSelectionProof {}
|
||||||
@@ -599,10 +600,10 @@ mod tests {
|
|||||||
.assert_signatures_match("beacon_block_base", |pubkey, validator_store| {
|
.assert_signatures_match("beacon_block_base", |pubkey, validator_store| {
|
||||||
let spec = spec.clone();
|
let spec = spec.clone();
|
||||||
async move {
|
async move {
|
||||||
let block = BeaconBlock::Base(BeaconBlockBase::empty(&spec));
|
let block = BeaconBlock::<E>::Base(BeaconBlockBase::empty(&spec));
|
||||||
let block_slot = block.slot();
|
let block_slot = block.slot();
|
||||||
validator_store
|
validator_store
|
||||||
.sign_block(pubkey, block, block_slot)
|
.sign_block(pubkey, block.into(), block_slot)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
@@ -669,10 +670,14 @@ mod tests {
|
|||||||
.assert_signatures_match("beacon_block_altair", |pubkey, validator_store| {
|
.assert_signatures_match("beacon_block_altair", |pubkey, validator_store| {
|
||||||
let spec = spec.clone();
|
let spec = spec.clone();
|
||||||
async move {
|
async move {
|
||||||
let mut altair_block = BeaconBlockAltair::empty(&spec);
|
let mut altair_block = BeaconBlockAltair::<E>::empty(&spec);
|
||||||
altair_block.slot = altair_fork_slot;
|
altair_block.slot = altair_fork_slot;
|
||||||
validator_store
|
validator_store
|
||||||
.sign_block(pubkey, BeaconBlock::Altair(altair_block), altair_fork_slot)
|
.sign_block(
|
||||||
|
pubkey,
|
||||||
|
BeaconBlock::Altair(altair_block).into(),
|
||||||
|
altair_fork_slot,
|
||||||
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
@@ -752,12 +757,12 @@ mod tests {
|
|||||||
.assert_signatures_match("beacon_block_bellatrix", |pubkey, validator_store| {
|
.assert_signatures_match("beacon_block_bellatrix", |pubkey, validator_store| {
|
||||||
let spec = spec.clone();
|
let spec = spec.clone();
|
||||||
async move {
|
async move {
|
||||||
let mut bellatrix_block = BeaconBlockBellatrix::empty(&spec);
|
let mut bellatrix_block = BeaconBlockBellatrix::<E>::empty(&spec);
|
||||||
bellatrix_block.slot = bellatrix_fork_slot;
|
bellatrix_block.slot = bellatrix_fork_slot;
|
||||||
validator_store
|
validator_store
|
||||||
.sign_block(
|
.sign_block(
|
||||||
pubkey,
|
pubkey,
|
||||||
BeaconBlock::Bellatrix(bellatrix_block),
|
BeaconBlock::Bellatrix(bellatrix_block).into(),
|
||||||
bellatrix_fork_slot,
|
bellatrix_fork_slot,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
@@ -813,7 +818,7 @@ mod tests {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let first_block = || {
|
let first_block = || {
|
||||||
let mut bellatrix_block = BeaconBlockBellatrix::empty(&spec);
|
let mut bellatrix_block = BeaconBlockBellatrix::<E>::empty(&spec);
|
||||||
bellatrix_block.slot = bellatrix_fork_slot;
|
bellatrix_block.slot = bellatrix_fork_slot;
|
||||||
BeaconBlock::Bellatrix(bellatrix_block)
|
BeaconBlock::Bellatrix(bellatrix_block)
|
||||||
};
|
};
|
||||||
@@ -879,7 +884,7 @@ mod tests {
|
|||||||
let block = first_block();
|
let block = first_block();
|
||||||
let slot = block.slot();
|
let slot = block.slot();
|
||||||
validator_store
|
validator_store
|
||||||
.sign_block(pubkey, block, slot)
|
.sign_block(pubkey, block.into(), slot)
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap()
|
||||||
})
|
})
|
||||||
@@ -890,7 +895,7 @@ mod tests {
|
|||||||
let block = double_vote_block();
|
let block = double_vote_block();
|
||||||
let slot = block.slot();
|
let slot = block.slot();
|
||||||
validator_store
|
validator_store
|
||||||
.sign_block(pubkey, block, slot)
|
.sign_block(pubkey, block.into(), slot)
|
||||||
.await
|
.await
|
||||||
.map(|_| ())
|
.map(|_| ())
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ impl DoppelgangerService {
|
|||||||
// Define the `get_liveness` function as one that queries the beacon node API.
|
// Define the `get_liveness` function as one that queries the beacon node API.
|
||||||
let log = service.log.clone();
|
let log = service.log.clone();
|
||||||
let get_liveness = move |current_epoch, validator_indices| {
|
let get_liveness = move |current_epoch, validator_indices| {
|
||||||
beacon_node_liveness(
|
beacon_node_liveness::<T>(
|
||||||
beacon_nodes.clone(),
|
beacon_nodes.clone(),
|
||||||
log.clone(),
|
log.clone(),
|
||||||
current_epoch,
|
current_epoch,
|
||||||
@@ -332,17 +332,18 @@ impl DoppelgangerService {
|
|||||||
///
|
///
|
||||||
/// Validators added during the genesis epoch will not have doppelganger protection applied to
|
/// Validators added during the genesis epoch will not have doppelganger protection applied to
|
||||||
/// them.
|
/// them.
|
||||||
pub fn register_new_validator<E: EthSpec, T: SlotClock>(
|
pub fn register_new_validator<T: SlotClock>(
|
||||||
&self,
|
&self,
|
||||||
validator: PublicKeyBytes,
|
validator: PublicKeyBytes,
|
||||||
slot_clock: &T,
|
slot_clock: &T,
|
||||||
|
slots_per_epoch: u64,
|
||||||
) -> Result<(), String> {
|
) -> Result<(), String> {
|
||||||
let current_epoch = slot_clock
|
let current_epoch = slot_clock
|
||||||
// If registering before genesis, use the genesis slot.
|
// If registering before genesis, use the genesis slot.
|
||||||
.now_or_genesis()
|
.now_or_genesis()
|
||||||
.ok_or_else(|| "Unable to read slot clock when registering validator".to_string())?
|
.ok_or_else(|| "Unable to read slot clock when registering validator".to_string())?
|
||||||
.epoch(E::slots_per_epoch());
|
.epoch(slots_per_epoch);
|
||||||
let genesis_epoch = slot_clock.genesis_slot().epoch(E::slots_per_epoch());
|
let genesis_epoch = slot_clock.genesis_slot().epoch(slots_per_epoch);
|
||||||
|
|
||||||
let remaining_epochs = if current_epoch <= genesis_epoch {
|
let remaining_epochs = if current_epoch <= genesis_epoch {
|
||||||
// Disable doppelganger protection when the validator was initialized before genesis.
|
// Disable doppelganger protection when the validator was initialized before genesis.
|
||||||
@@ -738,7 +739,7 @@ mod test {
|
|||||||
.expect("index should exist");
|
.expect("index should exist");
|
||||||
|
|
||||||
self.doppelganger
|
self.doppelganger
|
||||||
.register_new_validator::<E, _>(pubkey, &self.slot_clock)
|
.register_new_validator(pubkey, &self.slot_clock, E::slots_per_epoch())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
self.doppelganger
|
self.doppelganger
|
||||||
.doppelganger_states
|
.doppelganger_states
|
||||||
|
|||||||
@@ -113,7 +113,7 @@ impl ApiTester {
|
|||||||
|
|
||||||
let initialized_validators = validator_store.initialized_validators();
|
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(),
|
task_executor: test_runtime.task_executor.clone(),
|
||||||
api_secret,
|
api_secret,
|
||||||
block_service: None,
|
block_service: None,
|
||||||
|
|||||||
@@ -17,6 +17,5 @@ slot_clock = { workspace = true }
|
|||||||
types = { workspace = true }
|
types = { workspace = true }
|
||||||
validator_metrics = { workspace = true }
|
validator_metrics = { workspace = true }
|
||||||
validator_services = { workspace = true }
|
validator_services = { workspace = true }
|
||||||
validator_store = { workspace = true }
|
|
||||||
warp = { workspace = true }
|
warp = { workspace = true }
|
||||||
warp_utils = { workspace = true }
|
warp_utils = { workspace = true }
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ authors = ["Sigma Prime <contact@sigmaprime.io>"]
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
account_utils = { workspace = true }
|
account_utils = { workspace = true }
|
||||||
|
beacon_node_fallback = { workspace = true }
|
||||||
doppelganger_service = { workspace = true }
|
doppelganger_service = { workspace = true }
|
||||||
|
either = { workspace = true }
|
||||||
|
environment = { workspace = true }
|
||||||
|
eth2 = { workspace = true }
|
||||||
initialized_validators = { workspace = true }
|
initialized_validators = { workspace = true }
|
||||||
parking_lot = { workspace = true }
|
parking_lot = { workspace = true }
|
||||||
serde = { workspace = true }
|
serde = { workspace = true }
|
||||||
@@ -15,6 +19,11 @@ slashing_protection = { workspace = true }
|
|||||||
slog = { workspace = true }
|
slog = { workspace = true }
|
||||||
slot_clock = { workspace = true }
|
slot_clock = { workspace = true }
|
||||||
task_executor = { workspace = true }
|
task_executor = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
types = { workspace = true }
|
types = { workspace = true }
|
||||||
validator_metrics = { workspace = true }
|
validator_metrics = { workspace = true }
|
||||||
validator_store = { 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> {
|
pub fn register_all_in_doppelganger_protection_if_enabled(&self) -> Result<(), String> {
|
||||||
if let Some(doppelganger_service) = &self.doppelganger_service {
|
if let Some(doppelganger_service) = &self.doppelganger_service {
|
||||||
for pubkey in self.validators.read().iter_voting_pubkeys() {
|
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))?;
|
.map_err(|e| format!("failed to register validator: {:?}", e))?;
|
||||||
|
|
||||||
if let Some(doppelganger_service) = &self.doppelganger_service {
|
if let Some(doppelganger_service) = &self.doppelganger_service {
|
||||||
doppelganger_service
|
doppelganger_service.register_new_validator(
|
||||||
.register_new_validator::<E, _>(validator_pubkey, &self.slot_clock)?;
|
validator_pubkey,
|
||||||
|
&self.slot_clock,
|
||||||
|
E::slots_per_epoch(),
|
||||||
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.validators
|
self.validators
|
||||||
|
|||||||
@@ -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
|
/// 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.
|
/// likely the result of heavy forking (lol) or inconsistent beacon node connections.
|
||||||
pub fn block_proposers<E: EthSpec>(&self, slot: Slot) -> HashSet<PublicKeyBytes> {
|
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.
|
// Only collect validators that are considered safe in terms of doppelganger protection.
|
||||||
let signing_pubkeys: HashSet<_> = self
|
let signing_pubkeys: HashSet<_> = self
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ pub trait ValidatorStore: Send + Sync {
|
|||||||
fn proposal_data(&self, pubkey: &PublicKeyBytes) -> Option<ProposalData>;
|
fn proposal_data(&self, pubkey: &PublicKeyBytes) -> Option<ProposalData>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
pub enum UnsignedBlock<E: EthSpec> {
|
pub enum UnsignedBlock<E: EthSpec> {
|
||||||
Full(BeaconBlock<E>),
|
Full(BeaconBlock<E>),
|
||||||
Blinded(BlindedBeaconBlock<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> {
|
pub enum SignedBlock<E: EthSpec> {
|
||||||
Full(SignedBeaconBlock<E>),
|
Full(SignedBeaconBlock<E>),
|
||||||
Blinded(SignedBlindedBeaconBlock<E>),
|
Blinded(SignedBlindedBeaconBlock<E>),
|
||||||
|
|||||||
Reference in New Issue
Block a user