mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-03 00:31:50 +00:00
Use E for EthSpec globally (#5264)
* Use `E` for `EthSpec` globally * Fix tests * Merge branch 'unstable' into e-ethspec * Merge branch 'unstable' into e-ethspec # Conflicts: # beacon_node/execution_layer/src/engine_api.rs # beacon_node/execution_layer/src/engine_api/http.rs # beacon_node/execution_layer/src/engine_api/json_structures.rs # beacon_node/execution_layer/src/test_utils/handle_rpc.rs # beacon_node/store/src/partial_beacon_state.rs # consensus/types/src/beacon_block.rs # consensus/types/src/beacon_block_body.rs # consensus/types/src/beacon_state.rs # consensus/types/src/config_and_preset.rs # consensus/types/src/execution_payload.rs # consensus/types/src/execution_payload_header.rs # consensus/types/src/light_client_optimistic_update.rs # consensus/types/src/payload.rs # lcli/src/parse_ssz.rs
This commit is contained in:
@@ -175,10 +175,10 @@ impl SlashingDatabase {
|
||||
}
|
||||
|
||||
/// Execute a database transaction as a closure, committing if `f` returns `Ok`.
|
||||
pub fn with_transaction<T, E, F>(&self, f: F) -> Result<T, E>
|
||||
pub fn with_transaction<T, U, F>(&self, f: F) -> Result<T, U>
|
||||
where
|
||||
F: FnOnce(&Transaction) -> Result<T, E>,
|
||||
E: From<NotSafe>,
|
||||
F: FnOnce(&Transaction) -> Result<T, U>,
|
||||
U: From<NotSafe>,
|
||||
{
|
||||
let mut conn = self.conn_pool.get().map_err(NotSafe::from)?;
|
||||
let txn = conn.transaction().map_err(NotSafe::from)?;
|
||||
|
||||
@@ -101,15 +101,15 @@ impl PartialEq<bool> for RequireSynced {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error<E> {
|
||||
pub enum Error<T> {
|
||||
/// The node was unavailable and we didn't attempt to contact it.
|
||||
Unavailable(CandidateError),
|
||||
/// We attempted to contact the node but it failed.
|
||||
RequestFailed(E),
|
||||
RequestFailed(T),
|
||||
}
|
||||
|
||||
impl<E> Error<E> {
|
||||
pub fn request_failure(&self) -> Option<&E> {
|
||||
impl<T> Error<T> {
|
||||
pub fn request_failure(&self) -> Option<&T> {
|
||||
match self {
|
||||
Error::RequestFailed(e) => Some(e),
|
||||
_ => None,
|
||||
@@ -118,9 +118,9 @@ impl<E> Error<E> {
|
||||
}
|
||||
|
||||
/// The list of errors encountered whilst attempting to perform a query.
|
||||
pub struct Errors<E>(pub Vec<(String, Error<E>)>);
|
||||
pub struct Errors<T>(pub Vec<(String, Error<T>)>);
|
||||
|
||||
impl<E: Debug> fmt::Display for Errors<E> {
|
||||
impl<T: Debug> fmt::Display for Errors<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
if !self.0.is_empty() {
|
||||
write!(f, "Some endpoints failed, num_failed: {}", self.0.len())?;
|
||||
|
||||
@@ -203,8 +203,8 @@ lazy_static::lazy_static! {
|
||||
);
|
||||
}
|
||||
|
||||
pub fn gather_prometheus_metrics<T: EthSpec>(
|
||||
ctx: &Context<T>,
|
||||
pub fn gather_prometheus_metrics<E: EthSpec>(
|
||||
ctx: &Context<E>,
|
||||
) -> std::result::Result<String, String> {
|
||||
let mut buffer = vec![];
|
||||
let encoder = TextEncoder::new();
|
||||
@@ -221,7 +221,7 @@ pub fn gather_prometheus_metrics<T: EthSpec>(
|
||||
|
||||
if let Some(duties_service) = &shared.duties_service {
|
||||
if let Some(slot) = duties_service.slot_clock.now() {
|
||||
let current_epoch = slot.epoch(T::slots_per_epoch());
|
||||
let current_epoch = slot.epoch(E::slots_per_epoch());
|
||||
let next_epoch = current_epoch + 1;
|
||||
|
||||
set_int_gauge(
|
||||
|
||||
@@ -34,18 +34,18 @@ impl From<String> for Error {
|
||||
}
|
||||
|
||||
/// Contains objects which have shared access from inside/outside of the metrics server.
|
||||
pub struct Shared<T: EthSpec> {
|
||||
pub validator_store: Option<Arc<ValidatorStore<SystemTimeSlotClock, T>>>,
|
||||
pub duties_service: Option<Arc<DutiesService<SystemTimeSlotClock, T>>>,
|
||||
pub struct Shared<E: EthSpec> {
|
||||
pub validator_store: Option<Arc<ValidatorStore<SystemTimeSlotClock, E>>>,
|
||||
pub duties_service: Option<Arc<DutiesService<SystemTimeSlotClock, E>>>,
|
||||
pub genesis_time: Option<u64>,
|
||||
}
|
||||
|
||||
/// 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: EthSpec> {
|
||||
pub struct Context<E: EthSpec> {
|
||||
pub config: Config,
|
||||
pub shared: RwLock<Shared<T>>,
|
||||
pub shared: RwLock<Shared<E>>,
|
||||
pub log: Logger,
|
||||
}
|
||||
|
||||
@@ -86,8 +86,8 @@ impl Default for Config {
|
||||
///
|
||||
/// Returns an error if the server is unable to bind or there is another error during
|
||||
/// configuration.
|
||||
pub fn serve<T: EthSpec>(
|
||||
ctx: Arc<Context<T>>,
|
||||
pub fn serve<E: EthSpec>(
|
||||
ctx: Arc<Context<E>>,
|
||||
shutdown: impl Future<Output = ()> + Send + Sync + 'static,
|
||||
) -> Result<(SocketAddr, impl Future<Output = ()>), Error> {
|
||||
let config = &ctx.config;
|
||||
@@ -118,7 +118,7 @@ pub fn serve<T: EthSpec>(
|
||||
let routes = warp::get()
|
||||
.and(warp::path("metrics"))
|
||||
.map(move || inner_ctx.clone())
|
||||
.and_then(|ctx: Arc<Context<T>>| async move {
|
||||
.and_then(|ctx: Arc<Context<E>>| async move {
|
||||
Ok::<_, warp::Rejection>(
|
||||
metrics::gather_prometheus_metrics(&ctx)
|
||||
.map(|body| {
|
||||
|
||||
@@ -88,27 +88,27 @@ const HTTP_GET_VALIDATOR_BLOCK_TIMEOUT_QUOTIENT: u32 = 4;
|
||||
const DOPPELGANGER_SERVICE_NAME: &str = "doppelganger";
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ProductionValidatorClient<T: EthSpec> {
|
||||
context: RuntimeContext<T>,
|
||||
duties_service: Arc<DutiesService<SystemTimeSlotClock, T>>,
|
||||
block_service: BlockService<SystemTimeSlotClock, T>,
|
||||
attestation_service: AttestationService<SystemTimeSlotClock, T>,
|
||||
sync_committee_service: SyncCommitteeService<SystemTimeSlotClock, T>,
|
||||
pub struct ProductionValidatorClient<E: EthSpec> {
|
||||
context: RuntimeContext<E>,
|
||||
duties_service: Arc<DutiesService<SystemTimeSlotClock, E>>,
|
||||
block_service: BlockService<SystemTimeSlotClock, E>,
|
||||
attestation_service: AttestationService<SystemTimeSlotClock, E>,
|
||||
sync_committee_service: SyncCommitteeService<SystemTimeSlotClock, E>,
|
||||
doppelganger_service: Option<Arc<DoppelgangerService>>,
|
||||
preparation_service: PreparationService<SystemTimeSlotClock, T>,
|
||||
validator_store: Arc<ValidatorStore<SystemTimeSlotClock, T>>,
|
||||
preparation_service: PreparationService<SystemTimeSlotClock, E>,
|
||||
validator_store: Arc<ValidatorStore<SystemTimeSlotClock, E>>,
|
||||
slot_clock: SystemTimeSlotClock,
|
||||
http_api_listen_addr: Option<SocketAddr>,
|
||||
config: Config,
|
||||
beacon_nodes: Arc<BeaconNodeFallback<SystemTimeSlotClock, T>>,
|
||||
beacon_nodes: Arc<BeaconNodeFallback<SystemTimeSlotClock, E>>,
|
||||
genesis_time: u64,
|
||||
}
|
||||
|
||||
impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
impl<E: EthSpec> ProductionValidatorClient<E> {
|
||||
/// Instantiates the validator client, _without_ starting the timers to trigger block
|
||||
/// and attestation production.
|
||||
pub async fn new_from_cli(
|
||||
context: RuntimeContext<T>,
|
||||
context: RuntimeContext<E>,
|
||||
cli_args: &ArgMatches<'_>,
|
||||
) -> Result<Self, String> {
|
||||
let config = Config::from_cli(cli_args, context.log())
|
||||
@@ -118,7 +118,7 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
|
||||
/// Instantiates the validator client, _without_ starting the timers to trigger block
|
||||
/// and attestation production.
|
||||
pub async fn new(context: RuntimeContext<T>, config: Config) -> Result<Self, String> {
|
||||
pub async fn new(context: RuntimeContext<E>, config: Config) -> Result<Self, String> {
|
||||
let log = context.log().clone();
|
||||
|
||||
info!(
|
||||
@@ -136,7 +136,7 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
duties_service: None,
|
||||
};
|
||||
|
||||
let ctx: Arc<http_metrics::Context<T>> = Arc::new(http_metrics::Context {
|
||||
let ctx: Arc<http_metrics::Context<E>> = Arc::new(http_metrics::Context {
|
||||
config: config.http_metrics.clone(),
|
||||
shared: RwLock::new(shared),
|
||||
log: log.clone(),
|
||||
@@ -368,14 +368,14 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
// Initialize the number of connected, avaliable beacon nodes to 0.
|
||||
set_gauge(&http_metrics::metrics::AVAILABLE_BEACON_NODES_COUNT, 0);
|
||||
|
||||
let mut beacon_nodes: BeaconNodeFallback<_, T> = BeaconNodeFallback::new(
|
||||
let mut beacon_nodes: BeaconNodeFallback<_, E> = BeaconNodeFallback::new(
|
||||
candidates,
|
||||
config.broadcast_topics.clone(),
|
||||
context.eth2_config.spec.clone(),
|
||||
log.clone(),
|
||||
);
|
||||
|
||||
let mut proposer_nodes: BeaconNodeFallback<_, T> = BeaconNodeFallback::new(
|
||||
let mut proposer_nodes: BeaconNodeFallback<_, E> = BeaconNodeFallback::new(
|
||||
proposer_candidates,
|
||||
config.broadcast_topics.clone(),
|
||||
context.eth2_config.spec.clone(),
|
||||
@@ -444,7 +444,7 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
// oversized from having not been pruned (by a prior version) we don't want to prune
|
||||
// concurrently, as it will hog the lock and cause the attestation service to spew CRITs.
|
||||
if let Some(slot) = slot_clock.now() {
|
||||
validator_store.prune_slashing_protection_db(slot.epoch(T::slots_per_epoch()), true);
|
||||
validator_store.prune_slashing_protection_db(slot.epoch(E::slots_per_epoch()), true);
|
||||
}
|
||||
|
||||
let duties_context = context.service_context("duties".into());
|
||||
@@ -528,7 +528,7 @@ impl<T: EthSpec> ProductionValidatorClient<T> {
|
||||
// We use `SLOTS_PER_EPOCH` as the capacity of the block notification channel, because
|
||||
// we don't expect notifications to be delayed by more than a single slot, let alone a
|
||||
// whole epoch!
|
||||
let channel_capacity = T::slots_per_epoch() as usize;
|
||||
let channel_capacity = E::slots_per_epoch() as usize;
|
||||
let (block_service_tx, block_service_rx) = mpsc::channel(channel_capacity);
|
||||
let log = self.context.log();
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ use tokio::time::{sleep, Duration};
|
||||
use types::EthSpec;
|
||||
|
||||
/// Spawns a notifier service which periodically logs information about the node.
|
||||
pub fn spawn_notifier<T: EthSpec>(client: &ProductionValidatorClient<T>) -> Result<(), String> {
|
||||
pub fn spawn_notifier<E: EthSpec>(client: &ProductionValidatorClient<E>) -> Result<(), String> {
|
||||
let context = client.context.service_context("notifier".into());
|
||||
let executor = context.executor.clone();
|
||||
let duties_service = client.duties_service.clone();
|
||||
|
||||
@@ -34,23 +34,23 @@ pub enum Error {
|
||||
}
|
||||
|
||||
/// Enumerates all messages that can be signed by a validator.
|
||||
pub enum SignableMessage<'a, T: EthSpec, Payload: AbstractExecPayload<T> = FullPayload<T>> {
|
||||
pub enum SignableMessage<'a, E: EthSpec, Payload: AbstractExecPayload<E> = FullPayload<E>> {
|
||||
RandaoReveal(Epoch),
|
||||
BeaconBlock(&'a BeaconBlock<T, Payload>),
|
||||
BeaconBlock(&'a BeaconBlock<E, Payload>),
|
||||
AttestationData(&'a AttestationData),
|
||||
SignedAggregateAndProof(&'a AggregateAndProof<T>),
|
||||
SignedAggregateAndProof(&'a AggregateAndProof<E>),
|
||||
SelectionProof(Slot),
|
||||
SyncSelectionProof(&'a SyncAggregatorSelectionData),
|
||||
SyncCommitteeSignature {
|
||||
beacon_block_root: Hash256,
|
||||
slot: Slot,
|
||||
},
|
||||
SignedContributionAndProof(&'a ContributionAndProof<T>),
|
||||
SignedContributionAndProof(&'a ContributionAndProof<E>),
|
||||
ValidatorRegistration(&'a ValidatorRegistrationData),
|
||||
VoluntaryExit(&'a VoluntaryExit),
|
||||
}
|
||||
|
||||
impl<'a, T: EthSpec, Payload: AbstractExecPayload<T>> SignableMessage<'a, T, Payload> {
|
||||
impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> SignableMessage<'a, E, Payload> {
|
||||
/// Returns the `SignedRoot` for the contained message.
|
||||
///
|
||||
/// The actual `SignedRoot` trait is not used since it also requires a `TreeHash` impl, which is
|
||||
@@ -132,9 +132,9 @@ impl SigningMethod {
|
||||
}
|
||||
|
||||
/// Return the signature of `signable_message`, with respect to the `signing_context`.
|
||||
pub async fn get_signature<T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||
pub async fn get_signature<E: EthSpec, Payload: AbstractExecPayload<E>>(
|
||||
&self,
|
||||
signable_message: SignableMessage<'_, T, Payload>,
|
||||
signable_message: SignableMessage<'_, E, Payload>,
|
||||
signing_context: SigningContext,
|
||||
spec: &ChainSpec,
|
||||
executor: &TaskExecutor,
|
||||
@@ -157,9 +157,9 @@ impl SigningMethod {
|
||||
.await
|
||||
}
|
||||
|
||||
pub async fn get_signature_from_root<T: EthSpec, Payload: AbstractExecPayload<T>>(
|
||||
pub async fn get_signature_from_root<E: EthSpec, Payload: AbstractExecPayload<E>>(
|
||||
&self,
|
||||
signable_message: SignableMessage<'_, T, Payload>,
|
||||
signable_message: SignableMessage<'_, E, Payload>,
|
||||
signing_root: Hash256,
|
||||
executor: &TaskExecutor,
|
||||
fork_info: Option<ForkInfo>,
|
||||
|
||||
@@ -38,17 +38,17 @@ pub struct ForkInfo {
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
#[serde(bound = "T: EthSpec", rename_all = "snake_case")]
|
||||
pub enum Web3SignerObject<'a, T: EthSpec, Payload: AbstractExecPayload<T>> {
|
||||
#[serde(bound = "E: EthSpec", rename_all = "snake_case")]
|
||||
pub enum Web3SignerObject<'a, E: EthSpec, Payload: AbstractExecPayload<E>> {
|
||||
AggregationSlot {
|
||||
slot: Slot,
|
||||
},
|
||||
AggregateAndProof(&'a AggregateAndProof<T>),
|
||||
AggregateAndProof(&'a AggregateAndProof<E>),
|
||||
Attestation(&'a AttestationData),
|
||||
BeaconBlock {
|
||||
version: ForkName,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
block: Option<&'a BeaconBlock<T, Payload>>,
|
||||
block: Option<&'a BeaconBlock<E, Payload>>,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
block_header: Option<BeaconBlockHeader>,
|
||||
},
|
||||
@@ -70,12 +70,12 @@ pub enum Web3SignerObject<'a, T: EthSpec, Payload: AbstractExecPayload<T>> {
|
||||
slot: Slot,
|
||||
},
|
||||
SyncAggregatorSelectionData(&'a SyncAggregatorSelectionData),
|
||||
ContributionAndProof(&'a ContributionAndProof<T>),
|
||||
ContributionAndProof(&'a ContributionAndProof<E>),
|
||||
ValidatorRegistration(&'a ValidatorRegistrationData),
|
||||
}
|
||||
|
||||
impl<'a, T: EthSpec, Payload: AbstractExecPayload<T>> Web3SignerObject<'a, T, Payload> {
|
||||
pub fn beacon_block(block: &'a BeaconBlock<T, Payload>) -> Result<Self, Error> {
|
||||
impl<'a, E: EthSpec, Payload: AbstractExecPayload<E>> Web3SignerObject<'a, E, Payload> {
|
||||
pub fn beacon_block(block: &'a BeaconBlock<E, Payload>) -> Result<Self, Error> {
|
||||
match block {
|
||||
BeaconBlock::Base(_) => Ok(Web3SignerObject::BeaconBlock {
|
||||
version: ForkName::Phase0,
|
||||
@@ -132,8 +132,8 @@ impl<'a, T: EthSpec, Payload: AbstractExecPayload<T>> Web3SignerObject<'a, T, Pa
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Serialize)]
|
||||
#[serde(bound = "T: EthSpec")]
|
||||
pub struct SigningRequest<'a, T: EthSpec, Payload: AbstractExecPayload<T>> {
|
||||
#[serde(bound = "E: EthSpec")]
|
||||
pub struct SigningRequest<'a, E: EthSpec, Payload: AbstractExecPayload<E>> {
|
||||
#[serde(rename = "type")]
|
||||
pub message_type: MessageType,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
@@ -141,7 +141,7 @@ pub struct SigningRequest<'a, T: EthSpec, Payload: AbstractExecPayload<T>> {
|
||||
#[serde(rename = "signingRoot")]
|
||||
pub signing_root: Hash256,
|
||||
#[serde(flatten)]
|
||||
pub object: Web3SignerObject<'a, T, Payload>,
|
||||
pub object: Web3SignerObject<'a, E, Payload>,
|
||||
}
|
||||
|
||||
#[derive(Debug, PartialEq, Deserialize)]
|
||||
|
||||
Reference in New Issue
Block a user