Update Rust Edition to 2024 (#7766)

* #7749

Thanks @dknopik and @michaelsproul for your help!
This commit is contained in:
chonghe
2025-08-13 11:04:31 +08:00
committed by GitHub
parent bd6b8b6a65
commit 522bd9e9c6
468 changed files with 3594 additions and 3396 deletions

View File

@@ -1,7 +1,7 @@
use beacon_chain::block_verification_types::RpcBlock;
use lighthouse_network::PeerId;
use lighthouse_network::rpc::methods::BlocksByRangeRequest;
use lighthouse_network::service::api_types::Id;
use lighthouse_network::PeerId;
use std::collections::HashSet;
use std::fmt;
use std::hash::{Hash, Hasher};
@@ -459,17 +459,15 @@ impl Attempt {
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 {
ref peer_id,
hash: _,
}) => write!(f, "Processing({})", peer_id),
BatchState::AwaitingValidation(Attempt {
ref peer_id,
hash: _,
}) => write!(f, "AwaitingValidation({})", peer_id),
BatchState::Processing(Attempt { peer_id, hash: _ }) => {
write!(f, "Processing({})", peer_id)
}
BatchState::AwaitingValidation(Attempt { peer_id, hash: _ }) => {
write!(f, "AwaitingValidation({})", peer_id)
}
BatchState::AwaitingDownload => f.write_str("AwaitingDownload"),
BatchState::Failed => f.write_str("Failed"),
BatchState::AwaitingProcessing(ref peer, ref blocks, _) => {
BatchState::AwaitingProcessing(peer, blocks, _) => {
write!(f, "AwaitingProcessing({}, {} blocks)", peer, blocks.len())
}
BatchState::Downloading(request_id) => {

View File

@@ -1,16 +1,16 @@
use super::batch::{BatchInfo, BatchProcessingResult, BatchState};
use super::RangeSyncType;
use super::batch::{BatchInfo, BatchProcessingResult, BatchState};
use crate::metrics;
use crate::network_beacon_processor::ChainSegmentProcessId;
use crate::sync::block_sidecar_coupling::CouplingError;
use crate::sync::network_context::{RangeRequestId, RpcRequestSendError, RpcResponseError};
use crate::sync::{network_context::SyncNetworkContext, BatchOperationOutcome, BatchProcessResult};
use beacon_chain::block_verification_types::RpcBlock;
use crate::sync::{BatchOperationOutcome, BatchProcessResult, network_context::SyncNetworkContext};
use beacon_chain::BeaconChainTypes;
use beacon_chain::block_verification_types::RpcBlock;
use lighthouse_network::service::api_types::Id;
use lighthouse_network::{PeerAction, PeerId};
use logging::crit;
use std::collections::{btree_map::Entry, BTreeMap, HashSet};
use std::collections::{BTreeMap, HashSet, btree_map::Entry};
use strum::IntoStaticStr;
use tracing::{debug, warn};
use types::{ColumnIndex, Epoch, EthSpec, Hash256, Slot};
@@ -311,43 +311,41 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
//
// First try our optimistic start, if any. If this batch is ready, we process it. If the
// batch has not already been completed, check the current chain target.
if let Some(epoch) = self.optimistic_start {
if let Some(batch) = self.batches.get(&epoch) {
let state = batch.state();
match state {
BatchState::AwaitingProcessing(..) => {
// this batch is ready
debug!(%epoch, "Processing optimistic start");
return self.process_batch(network, epoch);
}
BatchState::Downloading(..) => {
// The optimistic batch is being downloaded. We wait for this before
// attempting to process other batches.
return Ok(KeepChain);
}
BatchState::Poisoned => unreachable!("Poisoned batch"),
BatchState::Processing(_)
| BatchState::AwaitingDownload
| BatchState::Failed => {
// these are all inconsistent states:
// - Processing -> `self.current_processing_batch` is None
// - Failed -> non recoverable batch. For an optimistic batch, it should
// have been removed
// - AwaitingDownload -> A recoverable failed batch should have been
// re-requested.
return Err(RemoveChain::WrongChainState(format!(
"Optimistic batch indicates inconsistent chain state: {:?}",
state
)));
}
BatchState::AwaitingValidation(_) => {
// If an optimistic start is given to the chain after the corresponding
// batch has been requested and processed we can land here. We drop the
// optimistic candidate since we can't conclude whether the batch included
// blocks or not at this point
debug!(batch = %epoch, "Dropping optimistic candidate");
self.optimistic_start = None;
}
if let Some(epoch) = self.optimistic_start
&& let Some(batch) = self.batches.get(&epoch)
{
let state = batch.state();
match state {
BatchState::AwaitingProcessing(..) => {
// this batch is ready
debug!(%epoch, "Processing optimistic start");
return self.process_batch(network, epoch);
}
BatchState::Downloading(..) => {
// The optimistic batch is being downloaded. We wait for this before
// attempting to process other batches.
return Ok(KeepChain);
}
BatchState::Poisoned => unreachable!("Poisoned batch"),
BatchState::Processing(_) | BatchState::AwaitingDownload | BatchState::Failed => {
// these are all inconsistent states:
// - Processing -> `self.current_processing_batch` is None
// - Failed -> non recoverable batch. For an optimistic batch, it should
// have been removed
// - AwaitingDownload -> A recoverable failed batch should have been
// re-requested.
return Err(RemoveChain::WrongChainState(format!(
"Optimistic batch indicates inconsistent chain state: {:?}",
state
)));
}
BatchState::AwaitingValidation(_) => {
// If an optimistic start is given to the chain after the corresponding
// batch has been requested and processed we can land here. We drop the
// optimistic candidate since we can't conclude whether the batch included
// blocks or not at this point
debug!(batch = %epoch, "Dropping optimistic candidate");
self.optimistic_start = None;
}
}
}
@@ -616,7 +614,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
// only for batches awaiting validation can we be sure the last attempt is
// right, and thus, that any different attempt is wrong
match batch.state() {
BatchState::AwaitingValidation(ref processed_attempt) => {
BatchState::AwaitingValidation(processed_attempt) => {
for attempt in batch.attempts() {
// The validated batch has been re-processed
if attempt.hash != processed_attempt.hash {
@@ -662,10 +660,10 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
BatchState::AwaitingProcessing(..) => {}
BatchState::Processing(_) => {
debug!(batch = %id, %batch, "Advancing chain while processing a batch");
if let Some(processing_id) = self.current_processing_batch {
if id <= processing_id {
self.current_processing_batch = None;
}
if let Some(processing_id) = self.current_processing_batch
&& id <= processing_id
{
self.current_processing_batch = None;
}
}
}
@@ -680,11 +678,12 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
// won't have this batch, so we need to request it.
self.to_be_downloaded += EPOCHS_PER_BATCH;
}
if let Some(epoch) = self.optimistic_start {
if epoch <= validating_epoch {
self.optimistic_start = None;
}
if let Some(epoch) = self.optimistic_start
&& epoch <= validating_epoch
{
self.optimistic_start = None;
}
debug!(
previous_start = %old_start,
new_start = %self.start_epoch,
@@ -962,10 +961,10 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
return Err(RemoveChain::ChainFailed {
blacklist,
failing_batch: batch_id,
})
});
}
BatchOperationOutcome::Continue => {
return self.send_batch(network, batch_id)
return self.send_batch(network, batch_id);
}
}
}
@@ -1088,7 +1087,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
) -> bool {
if network.chain.spec.is_peer_das_enabled_for_epoch(epoch) {
// Require peers on all sampling column subnets before sending batches
let peers_on_all_custody_subnets = network
network
.network_globals()
.sampling_subnets()
.iter()
@@ -1102,8 +1101,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
})
.count();
peer_count > 0
});
peers_on_all_custody_subnets
})
} else {
true
}

View File

@@ -9,13 +9,13 @@ use crate::metrics;
use crate::sync::network_context::SyncNetworkContext;
use beacon_chain::{BeaconChain, BeaconChainTypes};
use fnv::FnvHashMap;
use lighthouse_network::service::api_types::Id;
use lighthouse_network::PeerId;
use lighthouse_network::SyncInfo;
use lighthouse_network::service::api_types::Id;
use logging::crit;
use smallvec::SmallVec;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::sync::Arc;
use tracing::{debug, error};
use types::EthSpec;
@@ -93,7 +93,7 @@ impl<T: BeaconChainTypes> ChainCollection<T> {
if let Some(index) = syncing_head_ids
.iter()
.enumerate()
.find(|(_, &chain_id)| &chain_id == id)
.find(|&(_, &chain_id)| &chain_id == id)
.map(|(i, _)| i)
{
// a syncing head chain was removed

View File

@@ -44,8 +44,8 @@ use super::chain_collection::{ChainCollection, SyncChainStatus};
use super::sync_type::RangeSyncType;
use crate::metrics;
use crate::status::ToStatusMessage;
use crate::sync::network_context::{RpcResponseError, SyncNetworkContext};
use crate::sync::BatchProcessResult;
use crate::sync::network_context::{RpcResponseError, SyncNetworkContext};
use beacon_chain::block_verification_types::RpcBlock;
use beacon_chain::{BeaconChain, BeaconChainTypes};
use lighthouse_network::rpc::GoodbyeReason;
@@ -336,15 +336,16 @@ where
debug!(id = chain.id(), ?sync_type, reason = ?remove_reason, op, "Chain removed");
}
if let RemoveChain::ChainFailed { blacklist, .. } = remove_reason {
if RangeSyncType::Finalized == sync_type && blacklist {
warn!(
id = chain.id(),
"Chain failed! Syncing to its head won't be retried for at least the next {} seconds",
FAILED_CHAINS_EXPIRY_SECONDS
);
self.failed_chains.insert(chain.target_head_root);
}
if let RemoveChain::ChainFailed { blacklist, .. } = remove_reason
&& RangeSyncType::Finalized == sync_type
&& blacklist
{
warn!(
id = chain.id(),
"Chain failed! Syncing to its head won't be retried for at least the next {} seconds",
FAILED_CHAINS_EXPIRY_SECONDS
);
self.failed_chains.insert(chain.target_head_root);
}
metrics::inc_counter_vec_by(