Skip to content

Commit 3d92e36

Browse files
authored
Modularize validator store (#6705)
- Create trait `ValidatorStore` with all functions used by the `validator_services` - Make `validator_services` generic on `S: ValidatorStore` - Introduce `LighthouseValidatorStore`, which has identical functionality to the old `ValidatorStore` - Remove dependencies (especially `environment`) from `validator_services` and `beacon_node_fallback` in order to be able to cleanly use them in Anchor
1 parent beb0ce6 commit 3d92e36

File tree

42 files changed

+2000
-1612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+2000
-1612
lines changed

Cargo.lock

Lines changed: 33 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@ members = [
9696
"validator_client/http_api",
9797
"validator_client/http_metrics",
9898
"validator_client/initialized_validators",
99+
"validator_client/lighthouse_validator_store",
99100
"validator_client/signing_method",
100101
"validator_client/slashing_protection",
101102
"validator_client/validator_metrics",
102103
"validator_client/validator_services",
103-
"validator_client/validator_store",
104104

105105
"validator_manager",
106106
]
@@ -228,7 +228,6 @@ compare_fields = { path = "common/compare_fields" }
228228
deposit_contract = { path = "common/deposit_contract" }
229229
directory = { path = "common/directory" }
230230
doppelganger_service = { path = "validator_client/doppelganger_service" }
231-
validator_services = { path = "validator_client/validator_services" }
232231
environment = { path = "lighthouse/environment" }
233232
eth1 = { path = "beacon_node/eth1" }
234233
eth1_test_rig = { path = "testing/eth1_test_rig" }
@@ -250,6 +249,7 @@ int_to_bytes = { path = "consensus/int_to_bytes" }
250249
kzg = { path = "crypto/kzg" }
251250
metrics = { path = "common/metrics" }
252251
lighthouse_network = { path = "beacon_node/lighthouse_network" }
252+
lighthouse_validator_store = { path = "validator_client/lighthouse_validator_store" }
253253
lighthouse_version = { path = "common/lighthouse_version" }
254254
workspace_members = { path = "common/workspace_members" }
255255
lockfile = { path = "common/lockfile" }
@@ -281,6 +281,7 @@ validator_dir = { path = "common/validator_dir" }
281281
validator_http_api = { path = "validator_client/http_api" }
282282
validator_http_metrics = { path = "validator_client/http_metrics" }
283283
validator_metrics = { path = "validator_client/validator_metrics" }
284+
validator_services = { path = "validator_client/validator_services" }
284285
validator_store = { path = "validator_client/validator_store" }
285286
validator_test_rig = { path = "testing/validator_test_rig" }
286287
warp_utils = { path = "common/warp_utils" }

consensus/types/src/attestation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use super::{
1616
Signature, SignedRoot,
1717
};
1818

19-
#[derive(Debug, PartialEq)]
19+
#[derive(Debug, PartialEq, Clone)]
2020
pub enum Error {
2121
SszTypesError(ssz_types::Error),
2222
BitfieldError(ssz::BitfieldError),

consensus/types/src/payload.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ pub trait AbstractExecPayload<E: EthSpec>:
8585
+ TryInto<Self::Deneb>
8686
+ TryInto<Self::Electra>
8787
+ TryInto<Self::Fulu>
88+
+ Sync
8889
{
8990
type Ref<'a>: ExecPayload<E>
9091
+ Copy
@@ -97,23 +98,28 @@ pub trait AbstractExecPayload<E: EthSpec>:
9798
type Bellatrix: OwnedExecPayload<E>
9899
+ Into<Self>
99100
+ for<'a> From<Cow<'a, ExecutionPayloadBellatrix<E>>>
100-
+ TryFrom<ExecutionPayloadHeaderBellatrix<E>>;
101+
+ TryFrom<ExecutionPayloadHeaderBellatrix<E>>
102+
+ Sync;
101103
type Capella: OwnedExecPayload<E>
102104
+ Into<Self>
103105
+ for<'a> From<Cow<'a, ExecutionPayloadCapella<E>>>
104-
+ TryFrom<ExecutionPayloadHeaderCapella<E>>;
106+
+ TryFrom<ExecutionPayloadHeaderCapella<E>>
107+
+ Sync;
105108
type Deneb: OwnedExecPayload<E>
106109
+ Into<Self>
107110
+ for<'a> From<Cow<'a, ExecutionPayloadDeneb<E>>>
108-
+ TryFrom<ExecutionPayloadHeaderDeneb<E>>;
111+
+ TryFrom<ExecutionPayloadHeaderDeneb<E>>
112+
+ Sync;
109113
type Electra: OwnedExecPayload<E>
110114
+ Into<Self>
111115
+ for<'a> From<Cow<'a, ExecutionPayloadElectra<E>>>
112-
+ TryFrom<ExecutionPayloadHeaderElectra<E>>;
116+
+ TryFrom<ExecutionPayloadHeaderElectra<E>>
117+
+ Sync;
113118
type Fulu: OwnedExecPayload<E>
114119
+ Into<Self>
115120
+ for<'a> From<Cow<'a, ExecutionPayloadFulu<E>>>
116-
+ TryFrom<ExecutionPayloadHeaderFulu<E>>;
121+
+ TryFrom<ExecutionPayloadHeaderFulu<E>>
122+
+ Sync;
117123
}
118124

119125
#[superstruct(

testing/web3signer_tests/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ eth2_keystore = { workspace = true }
1414
eth2_network_config = { workspace = true }
1515
futures = { workspace = true }
1616
initialized_validators = { workspace = true }
17+
lighthouse_validator_store = { workspace = true }
1718
logging = { workspace = true }
1819
parking_lot = { workspace = true }
1920
reqwest = { workspace = true }

testing/web3signer_tests/src/lib.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ mod tests {
2525
use initialized_validators::{
2626
load_pem_certificate, load_pkcs12_identity, InitializedValidators,
2727
};
28+
use lighthouse_validator_store::LighthouseValidatorStore;
2829
use parking_lot::Mutex;
2930
use reqwest::Client;
3031
use serde::Serialize;
@@ -44,7 +45,7 @@ mod tests {
4445
use tokio::time::sleep;
4546
use types::{attestation::AttestationBase, *};
4647
use url::Url;
47-
use validator_store::{Error as ValidatorStoreError, ValidatorStore};
48+
use validator_store::{Error as ValidatorStoreError, SignedBlock, ValidatorStore};
4849

4950
/// If the we are unable to reach the Web3Signer HTTP API within this time out then we will
5051
/// assume it failed to start.
@@ -73,6 +74,7 @@ mod tests {
7374
impl SignedObject for Signature {}
7475
impl SignedObject for Attestation<E> {}
7576
impl SignedObject for SignedBeaconBlock<E> {}
77+
impl SignedObject for SignedBlock<E> {}
7678
impl SignedObject for SignedAggregateAndProof<E> {}
7779
impl SignedObject for SelectionProof {}
7880
impl SignedObject for SyncSelectionProof {}
@@ -301,7 +303,7 @@ mod tests {
301303

302304
/// A testing rig which holds a `ValidatorStore`.
303305
struct ValidatorStoreRig {
304-
validator_store: Arc<ValidatorStore<TestingSlotClock, E>>,
306+
validator_store: Arc<LighthouseValidatorStore<TestingSlotClock, E>>,
305307
_validator_dir: TempDir,
306308
runtime: Arc<tokio::runtime::Runtime>,
307309
_runtime_shutdown: async_channel::Sender<()>,
@@ -352,12 +354,12 @@ mod tests {
352354

353355
let slot_clock =
354356
TestingSlotClock::new(Slot::new(0), Duration::from_secs(0), Duration::from_secs(1));
355-
let config = validator_store::Config {
357+
let config = lighthouse_validator_store::Config {
356358
enable_web3signer_slashing_protection: slashing_protection_config.local,
357359
..Default::default()
358360
};
359361

360-
let validator_store = ValidatorStore::<_, E>::new(
362+
let validator_store = LighthouseValidatorStore::<_, E>::new(
361363
initialized_validators,
362364
slashing_protection,
363365
Hash256::repeat_byte(42),
@@ -481,7 +483,7 @@ mod tests {
481483
generate_sig: F,
482484
) -> Self
483485
where
484-
F: Fn(PublicKeyBytes, Arc<ValidatorStore<TestingSlotClock, E>>) -> R,
486+
F: Fn(PublicKeyBytes, Arc<LighthouseValidatorStore<TestingSlotClock, E>>) -> R,
485487
R: Future<Output = S>,
486488
// We use the `SignedObject` trait to white-list objects for comparison. This avoids
487489
// accidentally comparing something meaningless like a `()`.
@@ -516,8 +518,8 @@ mod tests {
516518
web3signer_should_sign: bool,
517519
) -> Self
518520
where
519-
F: Fn(PublicKeyBytes, Arc<ValidatorStore<TestingSlotClock, E>>) -> R,
520-
R: Future<Output = Result<(), ValidatorStoreError>>,
521+
F: Fn(PublicKeyBytes, Arc<LighthouseValidatorStore<TestingSlotClock, E>>) -> R,
522+
R: Future<Output = Result<(), lighthouse_validator_store::Error>>,
521523
{
522524
for validator_rig in &self.validator_rigs {
523525
let result =
@@ -591,10 +593,10 @@ mod tests {
591593
.assert_signatures_match("beacon_block_base", |pubkey, validator_store| {
592594
let spec = spec.clone();
593595
async move {
594-
let block = BeaconBlock::Base(BeaconBlockBase::empty(&spec));
596+
let block = BeaconBlock::<E>::Base(BeaconBlockBase::empty(&spec));
595597
let block_slot = block.slot();
596598
validator_store
597-
.sign_block(pubkey, block, block_slot)
599+
.sign_block(pubkey, block.into(), block_slot)
598600
.await
599601
.unwrap()
600602
}
@@ -664,7 +666,11 @@ mod tests {
664666
let mut altair_block = BeaconBlockAltair::empty(&spec);
665667
altair_block.slot = altair_fork_slot;
666668
validator_store
667-
.sign_block(pubkey, BeaconBlock::Altair(altair_block), altair_fork_slot)
669+
.sign_block(
670+
pubkey,
671+
BeaconBlock::<E>::Altair(altair_block).into(),
672+
altair_fork_slot,
673+
)
668674
.await
669675
.unwrap()
670676
}
@@ -749,7 +755,7 @@ mod tests {
749755
validator_store
750756
.sign_block(
751757
pubkey,
752-
BeaconBlock::Bellatrix(bellatrix_block),
758+
BeaconBlock::<E>::Bellatrix(bellatrix_block).into(),
753759
bellatrix_fork_slot,
754760
)
755761
.await
@@ -805,7 +811,7 @@ mod tests {
805811
};
806812

807813
let first_block = || {
808-
let mut bellatrix_block = BeaconBlockBellatrix::empty(&spec);
814+
let mut bellatrix_block = BeaconBlockBellatrix::<E>::empty(&spec);
809815
bellatrix_block.slot = bellatrix_fork_slot;
810816
BeaconBlock::Bellatrix(bellatrix_block)
811817
};
@@ -871,7 +877,7 @@ mod tests {
871877
let block = first_block();
872878
let slot = block.slot();
873879
validator_store
874-
.sign_block(pubkey, block, slot)
880+
.sign_block(pubkey, block.into(), slot)
875881
.await
876882
.unwrap()
877883
})
@@ -882,7 +888,7 @@ mod tests {
882888
let block = double_vote_block();
883889
let slot = block.slot();
884890
validator_store
885-
.sign_block(pubkey, block, slot)
891+
.sign_block(pubkey, block.into(), slot)
886892
.await
887893
.map(|_| ())
888894
},

validator_client/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fdlimit = "0.3.0"
2222
graffiti_file = { workspace = true }
2323
hyper = { workspace = true }
2424
initialized_validators = { workspace = true }
25+
lighthouse_validator_store = { workspace = true }
2526
metrics = { workspace = true }
2627
monitoring_api = { workspace = true }
2728
parking_lot = { workspace = true }

validator_client/beacon_node_fallback/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ path = "src/lib.rs"
1010

1111
[dependencies]
1212
clap = { workspace = true }
13-
environment = { workspace = true }
1413
eth2 = { workspace = true }
1514
futures = { workspace = true }
1615
itertools = { workspace = true }
1716
serde = { workspace = true }
1817
slot_clock = { workspace = true }
1918
strum = { workspace = true }
19+
task_executor = { workspace = true }
2020
tokio = { workspace = true }
2121
tracing = { workspace = true }
2222
types = { workspace = true }
2323
validator_metrics = { workspace = true }
2424

2525
[dev-dependencies]
26-
logging = { workspace = true }
2726
validator_test_rig = { workspace = true }

0 commit comments

Comments
 (0)