mirror of
https://github.com/sigp/lighthouse.git
synced 2026-06-15 09:48:20 +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:
@@ -337,9 +337,9 @@ pub fn register_sync_committee_error(error: &SyncCommitteeError) {
|
||||
inc_counter_vec(&GOSSIP_SYNC_COMMITTEE_ERRORS_PER_TYPE, &[error.as_ref()]);
|
||||
}
|
||||
|
||||
pub fn update_gossip_metrics<T: EthSpec>(
|
||||
pub fn update_gossip_metrics<E: EthSpec>(
|
||||
gossipsub: &Gossipsub,
|
||||
network_globals: &Arc<NetworkGlobals<T>>,
|
||||
network_globals: &Arc<NetworkGlobals<E>>,
|
||||
) {
|
||||
// Mesh peers per client
|
||||
// Reset the gauges
|
||||
@@ -398,7 +398,7 @@ pub fn update_gossip_metrics<T: EthSpec>(
|
||||
}
|
||||
}
|
||||
|
||||
pub fn update_sync_metrics<T: EthSpec>(network_globals: &Arc<NetworkGlobals<T>>) {
|
||||
pub fn update_sync_metrics<E: EthSpec>(network_globals: &Arc<NetworkGlobals<E>>) {
|
||||
// reset the counts
|
||||
if PEERS_PER_SYNC_TYPE
|
||||
.as_ref()
|
||||
|
||||
@@ -78,8 +78,8 @@ impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedUnaggregate<T> {
|
||||
}
|
||||
|
||||
/// An attestation that failed validation by the `BeaconChain`.
|
||||
struct RejectedUnaggregate<T: EthSpec> {
|
||||
attestation: Box<Attestation<T>>,
|
||||
struct RejectedUnaggregate<E: EthSpec> {
|
||||
attestation: Box<Attestation<E>>,
|
||||
error: AttnError,
|
||||
}
|
||||
|
||||
@@ -112,26 +112,26 @@ impl<T: BeaconChainTypes> VerifiedAttestation<T> for VerifiedAggregate<T> {
|
||||
}
|
||||
|
||||
/// An attestation that failed validation by the `BeaconChain`.
|
||||
struct RejectedAggregate<T: EthSpec> {
|
||||
signed_aggregate: Box<SignedAggregateAndProof<T>>,
|
||||
struct RejectedAggregate<E: EthSpec> {
|
||||
signed_aggregate: Box<SignedAggregateAndProof<E>>,
|
||||
error: AttnError,
|
||||
}
|
||||
|
||||
/// Data for an aggregated or unaggregated attestation that failed verification.
|
||||
enum FailedAtt<T: EthSpec> {
|
||||
enum FailedAtt<E: EthSpec> {
|
||||
Unaggregate {
|
||||
attestation: Box<Attestation<T>>,
|
||||
attestation: Box<Attestation<E>>,
|
||||
subnet_id: SubnetId,
|
||||
should_import: bool,
|
||||
seen_timestamp: Duration,
|
||||
},
|
||||
Aggregate {
|
||||
attestation: Box<SignedAggregateAndProof<T>>,
|
||||
attestation: Box<SignedAggregateAndProof<E>>,
|
||||
seen_timestamp: Duration,
|
||||
},
|
||||
}
|
||||
|
||||
impl<T: EthSpec> FailedAtt<T> {
|
||||
impl<E: EthSpec> FailedAtt<E> {
|
||||
pub fn beacon_block_root(&self) -> &Hash256 {
|
||||
&self.attestation().data.beacon_block_root
|
||||
}
|
||||
@@ -143,7 +143,7 @@ impl<T: EthSpec> FailedAtt<T> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn attestation(&self) -> &Attestation<T> {
|
||||
pub fn attestation(&self) -> &Attestation<E> {
|
||||
match self {
|
||||
FailedAtt::Unaggregate { attestation, .. } => attestation,
|
||||
FailedAtt::Aggregate { attestation, .. } => &attestation.message.aggregate,
|
||||
|
||||
@@ -49,7 +49,7 @@ pub struct Router<T: BeaconChainTypes> {
|
||||
|
||||
/// Types of messages the router can receive.
|
||||
#[derive(Debug)]
|
||||
pub enum RouterMessage<T: EthSpec> {
|
||||
pub enum RouterMessage<E: EthSpec> {
|
||||
/// Peer has disconnected.
|
||||
PeerDisconnected(PeerId),
|
||||
/// An RPC request has been received.
|
||||
@@ -62,7 +62,7 @@ pub enum RouterMessage<T: EthSpec> {
|
||||
RPCResponseReceived {
|
||||
peer_id: PeerId,
|
||||
request_id: RequestId,
|
||||
response: Response<T>,
|
||||
response: Response<E>,
|
||||
},
|
||||
/// An RPC request failed
|
||||
RPCFailed {
|
||||
@@ -73,7 +73,7 @@ pub enum RouterMessage<T: EthSpec> {
|
||||
/// A gossip message has been received. The fields are: message id, the peer that sent us this
|
||||
/// message, the message itself and a bool which indicates if the message should be processed
|
||||
/// by the beacon chain after successful verification.
|
||||
PubsubMessage(MessageId, PeerId, PubsubMessage<T>, bool),
|
||||
PubsubMessage(MessageId, PeerId, PubsubMessage<E>, bool),
|
||||
/// The peer manager has requested we re-status a peer.
|
||||
StatusPeer(PeerId),
|
||||
}
|
||||
@@ -645,20 +645,20 @@ impl<T: BeaconChainTypes> Router<T> {
|
||||
/// Wraps a Network Channel to employ various RPC related network functionality for the
|
||||
/// processor.
|
||||
#[derive(Clone)]
|
||||
pub struct HandlerNetworkContext<T: EthSpec> {
|
||||
pub struct HandlerNetworkContext<E: EthSpec> {
|
||||
/// The network channel to relay messages to the Network service.
|
||||
network_send: mpsc::UnboundedSender<NetworkMessage<T>>,
|
||||
network_send: mpsc::UnboundedSender<NetworkMessage<E>>,
|
||||
/// Logger for the `NetworkContext`.
|
||||
log: slog::Logger,
|
||||
}
|
||||
|
||||
impl<T: EthSpec> HandlerNetworkContext<T> {
|
||||
pub fn new(network_send: mpsc::UnboundedSender<NetworkMessage<T>>, log: slog::Logger) -> Self {
|
||||
impl<E: EthSpec> HandlerNetworkContext<E> {
|
||||
pub fn new(network_send: mpsc::UnboundedSender<NetworkMessage<E>>, log: slog::Logger) -> Self {
|
||||
Self { network_send, log }
|
||||
}
|
||||
|
||||
/// Sends a message to the network task.
|
||||
fn inform_network(&mut self, msg: NetworkMessage<T>) {
|
||||
fn inform_network(&mut self, msg: NetworkMessage<E>) {
|
||||
self.network_send.send(msg).unwrap_or_else(
|
||||
|e| warn!(self.log, "Could not send message to the network service"; "error" => %e),
|
||||
)
|
||||
@@ -674,7 +674,7 @@ impl<T: EthSpec> HandlerNetworkContext<T> {
|
||||
}
|
||||
|
||||
/// Sends a response to the network task.
|
||||
pub fn send_response(&mut self, peer_id: PeerId, response: Response<T>, id: PeerRequestId) {
|
||||
pub fn send_response(&mut self, peer_id: PeerId, response: Response<E>, id: PeerRequestId) {
|
||||
self.inform_network(NetworkMessage::SendResponse {
|
||||
peer_id,
|
||||
id,
|
||||
|
||||
@@ -61,7 +61,7 @@ pub enum RequestId {
|
||||
/// Types of messages that the network service can receive.
|
||||
#[derive(Debug, IntoStaticStr)]
|
||||
#[strum(serialize_all = "snake_case")]
|
||||
pub enum NetworkMessage<T: EthSpec> {
|
||||
pub enum NetworkMessage<E: EthSpec> {
|
||||
/// Subscribes the beacon node to the core gossipsub topics. We do this when we are either
|
||||
/// synced or close to the head slot.
|
||||
SubscribeCoreTopics,
|
||||
@@ -74,7 +74,7 @@ pub enum NetworkMessage<T: EthSpec> {
|
||||
/// Send a successful Response to the libp2p service.
|
||||
SendResponse {
|
||||
peer_id: PeerId,
|
||||
response: Response<T>,
|
||||
response: Response<E>,
|
||||
id: PeerRequestId,
|
||||
},
|
||||
/// Sends an error response to an RPC request.
|
||||
@@ -85,7 +85,7 @@ pub enum NetworkMessage<T: EthSpec> {
|
||||
id: PeerRequestId,
|
||||
},
|
||||
/// Publish a list of messages to the gossipsub protocol.
|
||||
Publish { messages: Vec<PubsubMessage<T>> },
|
||||
Publish { messages: Vec<PubsubMessage<E>> },
|
||||
/// Validates a received gossipsub message. This will propagate the message on the network.
|
||||
ValidationResult {
|
||||
/// The peer that sent us the message. We don't send back to this peer.
|
||||
|
||||
@@ -55,7 +55,7 @@ impl BatchConfig for BackFillBatchConfig {
|
||||
fn max_batch_processing_attempts() -> u8 {
|
||||
MAX_BATCH_PROCESSING_ATTEMPTS
|
||||
}
|
||||
fn batch_attempt_hash<T: EthSpec>(blocks: &[RpcBlock<T>]) -> u64 {
|
||||
fn batch_attempt_hash<E: EthSpec>(blocks: &[RpcBlock<E>]) -> u64 {
|
||||
use std::collections::hash_map::DefaultHasher;
|
||||
use std::hash::{Hash, Hasher};
|
||||
let mut hasher = DefaultHasher::new();
|
||||
|
||||
@@ -40,7 +40,7 @@ mod single_block_lookup;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
|
||||
pub type DownloadedBlock<T> = (Hash256, RpcBlock<T>);
|
||||
pub type DownloadedBlock<E> = (Hash256, RpcBlock<E>);
|
||||
|
||||
const FAILED_CHAINS_CACHE_EXPIRY_SECONDS: u64 = 60;
|
||||
pub const SINGLE_BLOCK_LOOKUP_MAX_ATTEMPTS: u8 = 3;
|
||||
|
||||
@@ -319,13 +319,13 @@ impl<L: Lookup, T: BeaconChainTypes> SingleBlockLookup<L, T> {
|
||||
}
|
||||
|
||||
/// The state of the blob request component of a `SingleBlockLookup`.
|
||||
pub struct BlobRequestState<L: Lookup, T: EthSpec> {
|
||||
pub struct BlobRequestState<L: Lookup, E: EthSpec> {
|
||||
/// The latest picture of which blobs still need to be requested. This includes information
|
||||
/// from both block/blobs downloaded in the network layer and any blocks/blobs that exist in
|
||||
/// the data availability checker.
|
||||
pub requested_ids: MissingBlobs,
|
||||
/// Where we store blobs until we receive the stream terminator.
|
||||
pub blob_download_queue: FixedBlobSidecarList<T>,
|
||||
pub blob_download_queue: FixedBlobSidecarList<E>,
|
||||
pub state: SingleLookupRequestState,
|
||||
_phantom: PhantomData<L>,
|
||||
}
|
||||
|
||||
@@ -4,33 +4,33 @@ use std::{collections::VecDeque, sync::Arc};
|
||||
use types::{BlobSidecar, EthSpec, SignedBeaconBlock};
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
pub struct BlocksAndBlobsRequestInfo<T: EthSpec> {
|
||||
pub struct BlocksAndBlobsRequestInfo<E: EthSpec> {
|
||||
/// Blocks we have received awaiting for their corresponding sidecar.
|
||||
accumulated_blocks: VecDeque<Arc<SignedBeaconBlock<T>>>,
|
||||
accumulated_blocks: VecDeque<Arc<SignedBeaconBlock<E>>>,
|
||||
/// Sidecars we have received awaiting for their corresponding block.
|
||||
accumulated_sidecars: VecDeque<Arc<BlobSidecar<T>>>,
|
||||
accumulated_sidecars: VecDeque<Arc<BlobSidecar<E>>>,
|
||||
/// Whether the individual RPC request for blocks is finished or not.
|
||||
is_blocks_stream_terminated: bool,
|
||||
/// Whether the individual RPC request for sidecars is finished or not.
|
||||
is_sidecars_stream_terminated: bool,
|
||||
}
|
||||
|
||||
impl<T: EthSpec> BlocksAndBlobsRequestInfo<T> {
|
||||
pub fn add_block_response(&mut self, block_opt: Option<Arc<SignedBeaconBlock<T>>>) {
|
||||
impl<E: EthSpec> BlocksAndBlobsRequestInfo<E> {
|
||||
pub fn add_block_response(&mut self, block_opt: Option<Arc<SignedBeaconBlock<E>>>) {
|
||||
match block_opt {
|
||||
Some(block) => self.accumulated_blocks.push_back(block),
|
||||
None => self.is_blocks_stream_terminated = true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_sidecar_response(&mut self, sidecar_opt: Option<Arc<BlobSidecar<T>>>) {
|
||||
pub fn add_sidecar_response(&mut self, sidecar_opt: Option<Arc<BlobSidecar<E>>>) {
|
||||
match sidecar_opt {
|
||||
Some(sidecar) => self.accumulated_sidecars.push_back(sidecar),
|
||||
None => self.is_sidecars_stream_terminated = true,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn into_responses(self) -> Result<Vec<RpcBlock<T>>, String> {
|
||||
pub fn into_responses(self) -> Result<Vec<RpcBlock<E>>, String> {
|
||||
let BlocksAndBlobsRequestInfo {
|
||||
accumulated_blocks,
|
||||
accumulated_sidecars,
|
||||
@@ -42,7 +42,7 @@ impl<T: EthSpec> BlocksAndBlobsRequestInfo<T> {
|
||||
let mut responses = Vec::with_capacity(accumulated_blocks.len());
|
||||
let mut blob_iter = accumulated_sidecars.into_iter().peekable();
|
||||
for block in accumulated_blocks.into_iter() {
|
||||
let mut blob_list = Vec::with_capacity(T::max_blobs_per_block());
|
||||
let mut blob_list = Vec::with_capacity(E::max_blobs_per_block());
|
||||
while {
|
||||
let pair_next_blob = blob_iter
|
||||
.peek()
|
||||
@@ -53,7 +53,7 @@ impl<T: EthSpec> BlocksAndBlobsRequestInfo<T> {
|
||||
blob_list.push(blob_iter.next().ok_or("Missing next blob".to_string())?);
|
||||
}
|
||||
|
||||
let mut blobs_buffer = vec![None; T::max_blobs_per_block()];
|
||||
let mut blobs_buffer = vec![None; E::max_blobs_per_block()];
|
||||
for blob in blob_list {
|
||||
let blob_index = blob.index as usize;
|
||||
let Some(blob_opt) = blobs_buffer.get_mut(blob_index) else {
|
||||
|
||||
@@ -107,7 +107,7 @@ pub enum RequestId {
|
||||
|
||||
#[derive(Debug)]
|
||||
/// A message that can be sent to the sync manager thread.
|
||||
pub enum SyncMessage<T: EthSpec> {
|
||||
pub enum SyncMessage<E: EthSpec> {
|
||||
/// A useful peer has been discovered.
|
||||
AddPeer(PeerId, SyncInfo),
|
||||
|
||||
@@ -115,7 +115,7 @@ pub enum SyncMessage<T: EthSpec> {
|
||||
RpcBlock {
|
||||
request_id: RequestId,
|
||||
peer_id: PeerId,
|
||||
beacon_block: Option<Arc<SignedBeaconBlock<T>>>,
|
||||
beacon_block: Option<Arc<SignedBeaconBlock<E>>>,
|
||||
seen_timestamp: Duration,
|
||||
},
|
||||
|
||||
@@ -123,15 +123,15 @@ pub enum SyncMessage<T: EthSpec> {
|
||||
RpcBlob {
|
||||
request_id: RequestId,
|
||||
peer_id: PeerId,
|
||||
blob_sidecar: Option<Arc<BlobSidecar<T>>>,
|
||||
blob_sidecar: Option<Arc<BlobSidecar<E>>>,
|
||||
seen_timestamp: Duration,
|
||||
},
|
||||
|
||||
/// A block with an unknown parent has been received.
|
||||
UnknownParentBlock(PeerId, RpcBlock<T>, Hash256),
|
||||
UnknownParentBlock(PeerId, RpcBlock<E>, Hash256),
|
||||
|
||||
/// A blob with an unknown parent has been received.
|
||||
UnknownParentBlob(PeerId, Arc<BlobSidecar<T>>),
|
||||
UnknownParentBlob(PeerId, Arc<BlobSidecar<E>>),
|
||||
|
||||
/// A peer has sent an attestation that references a block that is unknown. This triggers the
|
||||
/// manager to attempt to find the block matching the unknown hash.
|
||||
@@ -156,7 +156,7 @@ pub enum SyncMessage<T: EthSpec> {
|
||||
/// Block processed
|
||||
BlockComponentProcessed {
|
||||
process_type: BlockProcessType,
|
||||
result: BlockProcessingResult<T>,
|
||||
result: BlockProcessingResult<E>,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -169,9 +169,9 @@ pub enum BlockProcessType {
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum BlockProcessingResult<T: EthSpec> {
|
||||
pub enum BlockProcessingResult<E: EthSpec> {
|
||||
Ok(AvailabilityProcessingStatus),
|
||||
Err(BlockError<T>),
|
||||
Err(BlockError<E>),
|
||||
Ignored,
|
||||
}
|
||||
|
||||
@@ -1077,10 +1077,10 @@ impl<T: BeaconChainTypes> SyncManager<T> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec> From<Result<AvailabilityProcessingStatus, BlockError<T>>>
|
||||
for BlockProcessingResult<T>
|
||||
impl<E: EthSpec> From<Result<AvailabilityProcessingStatus, BlockError<E>>>
|
||||
for BlockProcessingResult<E>
|
||||
{
|
||||
fn from(result: Result<AvailabilityProcessingStatus, BlockError<T>>) -> Self {
|
||||
fn from(result: Result<AvailabilityProcessingStatus, BlockError<E>>) -> Self {
|
||||
match result {
|
||||
Ok(status) => BlockProcessingResult::Ok(status),
|
||||
Err(e) => BlockProcessingResult::Err(e),
|
||||
@@ -1088,8 +1088,8 @@ impl<T: EthSpec> From<Result<AvailabilityProcessingStatus, BlockError<T>>>
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec> From<BlockError<T>> for BlockProcessingResult<T> {
|
||||
fn from(e: BlockError<T>) -> Self {
|
||||
impl<E: EthSpec> From<BlockError<E>> for BlockProcessingResult<E> {
|
||||
fn from(e: BlockError<E>) -> Self {
|
||||
BlockProcessingResult::Err(e)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,15 +21,15 @@ use std::sync::Arc;
|
||||
use tokio::sync::mpsc;
|
||||
use types::{BlobSidecar, EthSpec, SignedBeaconBlock};
|
||||
|
||||
pub struct BlocksAndBlobsByRangeResponse<T: EthSpec> {
|
||||
pub struct BlocksAndBlobsByRangeResponse<E: EthSpec> {
|
||||
pub batch_id: BatchId,
|
||||
pub responses: Result<Vec<RpcBlock<T>>, String>,
|
||||
pub responses: Result<Vec<RpcBlock<E>>, String>,
|
||||
}
|
||||
|
||||
pub struct BlocksAndBlobsByRangeRequest<T: EthSpec> {
|
||||
pub struct BlocksAndBlobsByRangeRequest<E: EthSpec> {
|
||||
pub chain_id: ChainId,
|
||||
pub batch_id: BatchId,
|
||||
pub block_blob_info: BlocksAndBlobsRequestInfo<T>,
|
||||
pub block_blob_info: BlocksAndBlobsRequestInfo<E>,
|
||||
}
|
||||
|
||||
/// Wraps a Network channel to employ various RPC related network functionality for the Sync manager. This includes management of a global RPC request Id.
|
||||
@@ -67,19 +67,19 @@ pub struct SyncNetworkContext<T: BeaconChainTypes> {
|
||||
}
|
||||
|
||||
/// Small enumeration to make dealing with block and blob requests easier.
|
||||
pub enum BlockOrBlob<T: EthSpec> {
|
||||
Block(Option<Arc<SignedBeaconBlock<T>>>),
|
||||
Blob(Option<Arc<BlobSidecar<T>>>),
|
||||
pub enum BlockOrBlob<E: EthSpec> {
|
||||
Block(Option<Arc<SignedBeaconBlock<E>>>),
|
||||
Blob(Option<Arc<BlobSidecar<E>>>),
|
||||
}
|
||||
|
||||
impl<T: EthSpec> From<Option<Arc<SignedBeaconBlock<T>>>> for BlockOrBlob<T> {
|
||||
fn from(block: Option<Arc<SignedBeaconBlock<T>>>) -> Self {
|
||||
impl<E: EthSpec> From<Option<Arc<SignedBeaconBlock<E>>>> for BlockOrBlob<E> {
|
||||
fn from(block: Option<Arc<SignedBeaconBlock<E>>>) -> Self {
|
||||
BlockOrBlob::Block(block)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec> From<Option<Arc<BlobSidecar<T>>>> for BlockOrBlob<T> {
|
||||
fn from(blob: Option<Arc<BlobSidecar<T>>>) -> Self {
|
||||
impl<E: EthSpec> From<Option<Arc<BlobSidecar<E>>>> for BlockOrBlob<E> {
|
||||
fn from(blob: Option<Arc<BlobSidecar<E>>>) -> Self {
|
||||
BlockOrBlob::Blob(blob)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ pub trait BatchConfig {
|
||||
/// Note that simpler hashing functions considered in the past (hash of first block, hash of last
|
||||
/// block, number of received blocks) are not good enough to differentiate attempts. For this
|
||||
/// reason, we hash the complete set of blocks both in RangeSync and BackFillSync.
|
||||
fn batch_attempt_hash<T: EthSpec>(blocks: &[RpcBlock<T>]) -> u64;
|
||||
fn batch_attempt_hash<E: EthSpec>(blocks: &[RpcBlock<E>]) -> u64;
|
||||
}
|
||||
|
||||
pub struct RangeSyncBatchConfig {}
|
||||
@@ -68,7 +68,7 @@ impl BatchConfig for RangeSyncBatchConfig {
|
||||
fn max_batch_processing_attempts() -> u8 {
|
||||
MAX_BATCH_PROCESSING_ATTEMPTS
|
||||
}
|
||||
fn batch_attempt_hash<T: EthSpec>(blocks: &[RpcBlock<T>]) -> u64 {
|
||||
fn batch_attempt_hash<E: EthSpec>(blocks: &[RpcBlock<E>]) -> u64 {
|
||||
let mut hasher = std::collections::hash_map::DefaultHasher::new();
|
||||
blocks.hash(&mut hasher);
|
||||
hasher.finish()
|
||||
@@ -92,7 +92,7 @@ pub enum BatchProcessingResult {
|
||||
}
|
||||
|
||||
/// A segment of a chain.
|
||||
pub struct BatchInfo<T: EthSpec, B: BatchConfig = RangeSyncBatchConfig> {
|
||||
pub struct BatchInfo<E: EthSpec, B: BatchConfig = RangeSyncBatchConfig> {
|
||||
/// Start slot of the batch.
|
||||
start_slot: Slot,
|
||||
/// End slot of the batch.
|
||||
@@ -104,7 +104,7 @@ pub struct BatchInfo<T: EthSpec, B: BatchConfig = RangeSyncBatchConfig> {
|
||||
/// The number of download retries this batch has undergone due to a failed request.
|
||||
failed_download_attempts: Vec<PeerId>,
|
||||
/// State of the batch.
|
||||
state: BatchState<T>,
|
||||
state: BatchState<E>,
|
||||
/// Whether this batch contains all blocks or all blocks and blobs.
|
||||
batch_type: ByRangeRequestType,
|
||||
/// Pin the generic
|
||||
@@ -112,13 +112,13 @@ pub struct BatchInfo<T: EthSpec, B: BatchConfig = RangeSyncBatchConfig> {
|
||||
}
|
||||
|
||||
/// Current state of a batch
|
||||
pub enum BatchState<T: EthSpec> {
|
||||
pub enum BatchState<E: EthSpec> {
|
||||
/// The batch has failed either downloading or processing, but can be requested again.
|
||||
AwaitingDownload,
|
||||
/// The batch is being downloaded.
|
||||
Downloading(PeerId, Vec<RpcBlock<T>>, Id),
|
||||
Downloading(PeerId, Vec<RpcBlock<E>>, Id),
|
||||
/// The batch has been completely downloaded and is ready for processing.
|
||||
AwaitingProcessing(PeerId, Vec<RpcBlock<T>>),
|
||||
AwaitingProcessing(PeerId, Vec<RpcBlock<E>>),
|
||||
/// The batch is being processed.
|
||||
Processing(Attempt),
|
||||
/// The batch was successfully processed and is waiting to be validated.
|
||||
@@ -134,14 +134,14 @@ pub enum BatchState<T: EthSpec> {
|
||||
Failed,
|
||||
}
|
||||
|
||||
impl<T: EthSpec> BatchState<T> {
|
||||
impl<E: EthSpec> BatchState<E> {
|
||||
/// Helper function for poisoning a state.
|
||||
pub fn poison(&mut self) -> BatchState<T> {
|
||||
pub fn poison(&mut self) -> BatchState<E> {
|
||||
std::mem::replace(self, BatchState::Poisoned)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec, B: BatchConfig> BatchInfo<T, B> {
|
||||
impl<E: EthSpec, B: BatchConfig> BatchInfo<E, B> {
|
||||
/// Batches are downloaded excluding the first block of the epoch assuming it has already been
|
||||
/// downloaded.
|
||||
///
|
||||
@@ -156,8 +156,8 @@ impl<T: EthSpec, B: BatchConfig> BatchInfo<T, B> {
|
||||
/// deal with this for now.
|
||||
/// This means finalization might be slower in deneb
|
||||
pub fn new(start_epoch: &Epoch, num_of_epochs: u64, batch_type: ByRangeRequestType) -> Self {
|
||||
let start_slot = start_epoch.start_slot(T::slots_per_epoch());
|
||||
let end_slot = start_slot + num_of_epochs * T::slots_per_epoch();
|
||||
let start_slot = start_epoch.start_slot(E::slots_per_epoch());
|
||||
let end_slot = start_slot + num_of_epochs * E::slots_per_epoch();
|
||||
BatchInfo {
|
||||
start_slot,
|
||||
end_slot,
|
||||
@@ -242,7 +242,7 @@ impl<T: EthSpec, B: BatchConfig> BatchInfo<T, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn state(&self) -> &BatchState<T> {
|
||||
pub fn state(&self) -> &BatchState<E> {
|
||||
&self.state
|
||||
}
|
||||
|
||||
@@ -251,7 +251,7 @@ impl<T: EthSpec, B: BatchConfig> BatchInfo<T, B> {
|
||||
}
|
||||
|
||||
/// Adds a block to a downloading batch.
|
||||
pub fn add_block(&mut self, block: RpcBlock<T>) -> Result<(), WrongState> {
|
||||
pub fn add_block(&mut self, block: RpcBlock<E>) -> Result<(), WrongState> {
|
||||
match self.state.poison() {
|
||||
BatchState::Downloading(peer, mut blocks, req_id) => {
|
||||
blocks.push(block);
|
||||
@@ -383,10 +383,10 @@ impl<T: EthSpec, B: BatchConfig> BatchInfo<T, B> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn start_processing(&mut self) -> Result<Vec<RpcBlock<T>>, WrongState> {
|
||||
pub fn start_processing(&mut self) -> Result<Vec<RpcBlock<E>>, WrongState> {
|
||||
match self.state.poison() {
|
||||
BatchState::AwaitingProcessing(peer, blocks) => {
|
||||
self.state = BatchState::Processing(Attempt::new::<B, T>(peer, &blocks));
|
||||
self.state = BatchState::Processing(Attempt::new::<B, E>(peer, &blocks));
|
||||
Ok(blocks)
|
||||
}
|
||||
BatchState::Poisoned => unreachable!("Poisoned batch"),
|
||||
@@ -481,13 +481,13 @@ pub struct Attempt {
|
||||
}
|
||||
|
||||
impl Attempt {
|
||||
fn new<B: BatchConfig, T: EthSpec>(peer_id: PeerId, blocks: &[RpcBlock<T>]) -> Self {
|
||||
fn new<B: BatchConfig, E: EthSpec>(peer_id: PeerId, blocks: &[RpcBlock<E>]) -> Self {
|
||||
let hash = B::batch_attempt_hash(blocks);
|
||||
Attempt { peer_id, hash }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec, B: BatchConfig> slog::KV for &mut BatchInfo<T, B> {
|
||||
impl<E: EthSpec, B: BatchConfig> slog::KV for &mut BatchInfo<E, B> {
|
||||
fn serialize(
|
||||
&self,
|
||||
record: &slog::Record,
|
||||
@@ -497,7 +497,7 @@ impl<T: EthSpec, B: BatchConfig> slog::KV for &mut BatchInfo<T, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec, B: BatchConfig> slog::KV for BatchInfo<T, B> {
|
||||
impl<E: EthSpec, B: BatchConfig> slog::KV for BatchInfo<E, B> {
|
||||
fn serialize(
|
||||
&self,
|
||||
record: &slog::Record,
|
||||
@@ -520,7 +520,7 @@ impl<T: EthSpec, B: BatchConfig> slog::KV for BatchInfo<T, B> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: EthSpec> std::fmt::Debug for BatchState<T> {
|
||||
impl<E: EthSpec> std::fmt::Debug for BatchState<E> {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
BatchState::Processing(Attempt {
|
||||
|
||||
Reference in New Issue
Block a user