Suggestions for Capella execution_layer
(#3983)
* Restrict Engine::request to FnOnce * Use `Into::into` * Impl IntoIterator for VariableList * Use Instant rather than SystemTime
This commit is contained in:
parent
461bda6e85
commit
4aa8a2ab12
@ -10,7 +10,7 @@ use serde_json::json;
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use tokio::sync::Mutex;
|
use tokio::sync::Mutex;
|
||||||
|
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, Instant};
|
||||||
use types::EthSpec;
|
use types::EthSpec;
|
||||||
|
|
||||||
pub use deposit_log::{DepositLog, Log};
|
pub use deposit_log::{DepositLog, Log};
|
||||||
@ -559,14 +559,14 @@ pub mod deposit_methods {
|
|||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct CapabilitiesCacheEntry {
|
pub struct CapabilitiesCacheEntry {
|
||||||
engine_capabilities: EngineCapabilities,
|
engine_capabilities: EngineCapabilities,
|
||||||
fetch_time: SystemTime,
|
fetch_time: Instant,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CapabilitiesCacheEntry {
|
impl CapabilitiesCacheEntry {
|
||||||
pub fn new(engine_capabilities: EngineCapabilities) -> Self {
|
pub fn new(engine_capabilities: EngineCapabilities) -> Self {
|
||||||
Self {
|
Self {
|
||||||
engine_capabilities,
|
engine_capabilities,
|
||||||
fetch_time: SystemTime::now(),
|
fetch_time: Instant::now(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -575,15 +575,7 @@ impl CapabilitiesCacheEntry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn age(&self) -> Duration {
|
pub fn age(&self) -> Duration {
|
||||||
// duration_since() may fail because measurements taken earlier
|
Instant::now().duration_since(self.fetch_time)
|
||||||
// are not guaranteed to always be before later measurements
|
|
||||||
// due to anomalies such as the system clock being adjusted
|
|
||||||
// either forwards or backwards
|
|
||||||
//
|
|
||||||
// In such cases, we'll just say the age is zero
|
|
||||||
SystemTime::now()
|
|
||||||
.duration_since(self.fetch_time)
|
|
||||||
.unwrap_or(Duration::ZERO)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// returns `true` if the entry's age is >= age_limit
|
/// returns `true` if the entry's age is >= age_limit
|
||||||
|
@ -145,7 +145,6 @@ impl<T: EthSpec> From<ExecutionPayloadCapella<T>> for JsonExecutionPayloadV2<T>
|
|||||||
withdrawals: payload
|
withdrawals: payload
|
||||||
.withdrawals
|
.withdrawals
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.cloned()
|
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into(),
|
.into(),
|
||||||
@ -173,7 +172,6 @@ impl<T: EthSpec> From<ExecutionPayloadEip4844<T>> for JsonExecutionPayloadV3<T>
|
|||||||
withdrawals: payload
|
withdrawals: payload
|
||||||
.withdrawals
|
.withdrawals
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.cloned()
|
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into(),
|
.into(),
|
||||||
@ -231,7 +229,6 @@ impl<T: EthSpec> From<JsonExecutionPayloadV2<T>> for ExecutionPayloadCapella<T>
|
|||||||
withdrawals: payload
|
withdrawals: payload
|
||||||
.withdrawals
|
.withdrawals
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.cloned()
|
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into(),
|
.into(),
|
||||||
@ -259,7 +256,6 @@ impl<T: EthSpec> From<JsonExecutionPayloadV3<T>> for ExecutionPayloadEip4844<T>
|
|||||||
withdrawals: payload
|
withdrawals: payload
|
||||||
.withdrawals
|
.withdrawals
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.cloned()
|
|
||||||
.map(Into::into)
|
.map(Into::into)
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.into(),
|
.into(),
|
||||||
|
@ -341,7 +341,7 @@ impl Engine {
|
|||||||
/// deadlock.
|
/// deadlock.
|
||||||
pub async fn request<'a, F, G, H>(self: &'a Arc<Self>, func: F) -> Result<H, EngineError>
|
pub async fn request<'a, F, G, H>(self: &'a Arc<Self>, func: F) -> Result<H, EngineError>
|
||||||
where
|
where
|
||||||
F: Fn(&'a Engine) -> G,
|
F: FnOnce(&'a Engine) -> G,
|
||||||
G: Future<Output = Result<H, EngineApiError>>,
|
G: Future<Output = Result<H, EngineApiError>>,
|
||||||
{
|
{
|
||||||
match func(self).await {
|
match func(self).await {
|
||||||
|
@ -1348,16 +1348,11 @@ impl<T: EthSpec> ExecutionLayer<T> {
|
|||||||
.set_latest_forkchoice_state(forkchoice_state)
|
.set_latest_forkchoice_state(forkchoice_state)
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let payload_attributes_ref = &payload_attributes;
|
|
||||||
let result = self
|
let result = self
|
||||||
.engine()
|
.engine()
|
||||||
.request(|engine| async move {
|
.request(|engine| async move {
|
||||||
engine
|
engine
|
||||||
.notify_forkchoice_updated(
|
.notify_forkchoice_updated(forkchoice_state, payload_attributes, self.log())
|
||||||
forkchoice_state,
|
|
||||||
payload_attributes_ref.clone(),
|
|
||||||
self.log(),
|
|
||||||
)
|
|
||||||
.await
|
.await
|
||||||
})
|
})
|
||||||
.await;
|
.await;
|
||||||
@ -1723,7 +1718,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
|
|||||||
capella_block
|
capella_block
|
||||||
.withdrawals
|
.withdrawals
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|w| w.into())
|
.map(Into::into)
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
.map_err(ApiError::DeserializeWithdrawals)?;
|
.map_err(ApiError::DeserializeWithdrawals)?;
|
||||||
@ -1750,7 +1745,7 @@ impl<T: EthSpec> ExecutionLayer<T> {
|
|||||||
eip4844_block
|
eip4844_block
|
||||||
.withdrawals
|
.withdrawals
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|w| w.into())
|
.map(Into::into)
|
||||||
.collect(),
|
.collect(),
|
||||||
)
|
)
|
||||||
.map_err(ApiError::DeserializeWithdrawals)?;
|
.map_err(ApiError::DeserializeWithdrawals)?;
|
||||||
|
@ -176,6 +176,15 @@ impl<'a, T, N: Unsigned> IntoIterator for &'a VariableList<T, N> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T, N: Unsigned> IntoIterator for VariableList<T, N> {
|
||||||
|
type Item = T;
|
||||||
|
type IntoIter = std::vec::IntoIter<T>;
|
||||||
|
|
||||||
|
fn into_iter(self) -> Self::IntoIter {
|
||||||
|
self.vec.into_iter()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T, N: Unsigned> tree_hash::TreeHash for VariableList<T, N>
|
impl<T, N: Unsigned> tree_hash::TreeHash for VariableList<T, N>
|
||||||
where
|
where
|
||||||
T: tree_hash::TreeHash,
|
T: tree_hash::TreeHash,
|
||||||
|
Loading…
Reference in New Issue
Block a user