Skip to content

Commit

Permalink
Fix Rust beta compiler errors (1.77) (sigp#5180)
Browse files Browse the repository at this point in the history
* Lint fixes

* More fixes for beta compiler.

* Format fixes

* Move `#[allow(dead_code)]` to field level.

* Remove old comment.

* Update beacon_node/execution_layer/src/test_utils/mod.rs

Co-authored-by: João Oliveira <[email protected]>

* remove duplicate line
  • Loading branch information
jimmygchen authored Feb 5, 2024
1 parent 8fb6989 commit 39e9f7d
Show file tree
Hide file tree
Showing 19 changed files with 64 additions and 46 deletions.
16 changes: 11 additions & 5 deletions beacon_node/beacon_chain/src/attestation_verification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,8 +539,8 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {
Err(e) => return Err(SignatureNotChecked(&signed_aggregate.message.aggregate, e)),
};

let indexed_attestation =
match map_attestation_committee(chain, attestation, |(committee, _)| {
let get_indexed_attestation_with_committee =
|(committee, _): (BeaconCommittee, CommitteesPerSlot)| {
// Note: this clones the signature which is known to be a relatively slow operation.
//
// Future optimizations should remove this clone.
Expand All @@ -561,11 +561,17 @@ impl<'a, T: BeaconChainTypes> IndexedAggregatedAttestation<'a, T> {

get_indexed_attestation(committee.committee, attestation)
.map_err(|e| BeaconChainError::from(e).into())
}) {
Ok(indexed_attestation) => indexed_attestation,
Err(e) => return Err(SignatureNotChecked(&signed_aggregate.message.aggregate, e)),
};

let indexed_attestation = match map_attestation_committee(
chain,
attestation,
get_indexed_attestation_with_committee,
) {
Ok(indexed_attestation) => indexed_attestation,
Err(e) => return Err(SignatureNotChecked(&signed_aggregate.message.aggregate, e)),
};

Ok(IndexedAggregatedAttestation {
signed_aggregate,
indexed_attestation,
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/beacon_chain/src/eth1_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ mod test {
let spec = &E::default_spec();
let state: BeaconState<E> = BeaconState::new(0, get_eth1_data(0), spec);

let blocks = vec![];
let blocks = [];

assert_eq!(
get_votes_to_consider(
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/beacon_chain/src/state_advance_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ const MAX_BLOCK_PRODUCTION_CACHE_DISTANCE: u64 = 4;
#[derive(Debug)]
enum Error {
BeaconChain(BeaconChainError),
HeadMissingFromSnapshotCache(Hash256),
// We don't use the inner value directly, but it's used in the Debug impl.
HeadMissingFromSnapshotCache(#[allow(dead_code)] Hash256),
MaxDistanceExceeded {
current_slot: Slot,
head_slot: Slot,
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/execution_layer/src/test_utils/mock_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ impl Operation {
}

#[derive(Debug)]
struct Custom(String);
// We don't use the string value directly, but it's used in the Debug impl which is required by `warp::reject::Reject`.
struct Custom(#[allow(dead_code)] String);

impl warp::reject::Reject for Custom {}

Expand Down
4 changes: 2 additions & 2 deletions beacon_node/execution_layer/src/test_utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,8 @@ async fn handle_rejection(err: Rejection) -> Result<impl warp::Reply, Infallible
let code;
let message;

if let Some(e) = err.find::<AuthError>() {
message = format!("Authorization error: {:?}", e);
if let Some(AuthError(e)) = err.find::<AuthError>() {
message = format!("Authorization error: {}", e);
code = StatusCode::UNAUTHORIZED;
} else {
message = "BAD_REQUEST".to_string();
Expand Down
9 changes: 5 additions & 4 deletions beacon_node/http_api/src/attestation_performance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ const MAX_REQUEST_RANGE_EPOCHS: usize = 100;
const BLOCK_ROOT_CHUNK_SIZE: usize = 100;

#[derive(Debug)]
// We don't use the inner values directly, but they're used in the Debug impl.
enum AttestationPerformanceError {
BlockReplay(BlockReplayError),
BeaconState(BeaconStateError),
ParticipationCache(ParticipationCacheError),
UnableToFindValidator(usize),
BlockReplay(#[allow(dead_code)] BlockReplayError),
BeaconState(#[allow(dead_code)] BeaconStateError),
ParticipationCache(#[allow(dead_code)] ParticipationCacheError),
UnableToFindValidator(#[allow(dead_code)] usize),
}

impl From<BlockReplayError> for AttestationPerformanceError {
Expand Down
7 changes: 4 additions & 3 deletions beacon_node/http_api/src/block_packing_efficiency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ use warp_utils::reject::{beacon_chain_error, custom_bad_request, custom_server_e
const BLOCK_ROOT_CHUNK_SIZE: usize = 100;

#[derive(Debug)]
// We don't use the inner values directly, but they're used in the Debug impl.
enum PackingEfficiencyError {
BlockReplay(BlockReplayError),
BeaconState(BeaconStateError),
CommitteeStoreError(Slot),
BlockReplay(#[allow(dead_code)] BlockReplayError),
BeaconState(#[allow(dead_code)] BeaconStateError),
CommitteeStoreError(#[allow(dead_code)] Slot),
InvalidAttestationError,
}

Expand Down
4 changes: 2 additions & 2 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ pub fn serve<T: BeaconChainTypes>(
Ok((
state
.get_built_sync_committee(epoch, &chain.spec)
.map(|committee| committee.clone())
.cloned()
.map_err(|e| match e {
BeaconStateError::SyncCommitteeNotKnown { .. } => {
warp_utils::reject::custom_bad_request(format!(
Expand Down Expand Up @@ -2858,7 +2858,7 @@ pub fn serve<T: BeaconChainTypes>(
hex::encode(
meta_data
.syncnets()
.map(|x| x.clone())
.cloned()
.unwrap_or_default()
.into_bytes()
)
Expand Down
26 changes: 13 additions & 13 deletions beacon_node/lighthouse_network/src/gossipsub/behaviour/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ fn inject_nodes1() -> InjectNodes<IdentityTransform, AllowAllSubscriptionFilter>

fn add_peer<D, F>(
gs: &mut Behaviour<D, F>,
topic_hashes: &Vec<TopicHash>,
topic_hashes: &[TopicHash],
outbound: bool,
explicit: bool,
) -> (PeerId, RpcReceiver)
Expand All @@ -187,7 +187,7 @@ where

fn add_peer_with_addr<D, F>(
gs: &mut Behaviour<D, F>,
topic_hashes: &Vec<TopicHash>,
topic_hashes: &[TopicHash],
outbound: bool,
explicit: bool,
address: Multiaddr,
Expand All @@ -208,7 +208,7 @@ where

fn add_peer_with_addr_and_kind<D, F>(
gs: &mut Behaviour<D, F>,
topic_hashes: &Vec<TopicHash>,
topic_hashes: &[TopicHash],
outbound: bool,
explicit: bool,
address: Multiaddr,
Expand Down Expand Up @@ -3218,7 +3218,7 @@ fn test_scoring_p1() {
);
}

fn random_message(seq: &mut u64, topics: &Vec<TopicHash>) -> RawMessage {
fn random_message(seq: &mut u64, topics: &[TopicHash]) -> RawMessage {
let mut rng = rand::thread_rng();
*seq += 1;
RawMessage {
Expand Down Expand Up @@ -4080,20 +4080,20 @@ fn test_scoring_p6() {
//create 5 peers with the same ip
let addr = Multiaddr::from(Ipv4Addr::new(10, 1, 2, 3));
let peers = vec![
add_peer_with_addr(&mut gs, &vec![], false, false, addr.clone()).0,
add_peer_with_addr(&mut gs, &vec![], false, false, addr.clone()).0,
add_peer_with_addr(&mut gs, &vec![], true, false, addr.clone()).0,
add_peer_with_addr(&mut gs, &vec![], true, false, addr.clone()).0,
add_peer_with_addr(&mut gs, &vec![], true, true, addr.clone()).0,
add_peer_with_addr(&mut gs, &[], false, false, addr.clone()).0,
add_peer_with_addr(&mut gs, &[], false, false, addr.clone()).0,
add_peer_with_addr(&mut gs, &[], true, false, addr.clone()).0,
add_peer_with_addr(&mut gs, &[], true, false, addr.clone()).0,
add_peer_with_addr(&mut gs, &[], true, true, addr.clone()).0,
];

//create 4 other peers with other ip
let addr2 = Multiaddr::from(Ipv4Addr::new(10, 1, 2, 4));
let others = vec![
add_peer_with_addr(&mut gs, &vec![], false, false, addr2.clone()).0,
add_peer_with_addr(&mut gs, &vec![], false, false, addr2.clone()).0,
add_peer_with_addr(&mut gs, &vec![], true, false, addr2.clone()).0,
add_peer_with_addr(&mut gs, &vec![], true, false, addr2.clone()).0,
add_peer_with_addr(&mut gs, &[], false, false, addr2.clone()).0,
add_peer_with_addr(&mut gs, &[], false, false, addr2.clone()).0,
add_peer_with_addr(&mut gs, &[], true, false, addr2.clone()).0,
add_peer_with_addr(&mut gs, &[], true, false, addr2.clone()).0,
];

//no penalties yet
Expand Down
7 changes: 6 additions & 1 deletion beacon_node/lighthouse_network/tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@ pub fn fork_context(fork_name: ForkName) -> ForkContext {
ForkContext::new::<E>(current_slot, Hash256::zero(), &chain_spec)
}

pub struct Libp2pInstance(LibP2PService<ReqId, E>, exit_future::Signal);
pub struct Libp2pInstance(
LibP2PService<ReqId, E>,
#[allow(dead_code)]
// This field is managed for lifetime purposes may not be used directly, hence the `#[allow(dead_code)]` attribute.
exit_future::Signal,
);

impl std::ops::Deref for Libp2pInstance {
type Target = LibP2PService<ReqId, E>;
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/network/src/subnet_service/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ mod attestation_service {
&attestation_service.beacon_chain.spec,
)
.unwrap();
let expected = vec![
let expected = [
SubnetServiceMessage::Subscribe(Subnet::Attestation(subnet_id)),
SubnetServiceMessage::Unsubscribe(Subnet::Attestation(subnet_id)),
];
Expand Down
2 changes: 1 addition & 1 deletion beacon_node/store/src/hot_cold_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,7 +1344,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>
high_restore_point
.get_block_root(slot)
.or_else(|_| high_restore_point.get_oldest_block_root())
.map(|x| *x)
.copied()
.map_err(HotColdDBError::RestorePointBlockHashError)
}

Expand Down
2 changes: 2 additions & 0 deletions common/validator_dir/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ impl<'a> Builder<'a> {
.write(true)
.read(true)
.create(true)
.truncate(true)
.open(path)
.map_err(Error::UnableToSaveDepositData)?
.write_all(hex.as_bytes())
Expand All @@ -231,6 +232,7 @@ impl<'a> Builder<'a> {
.write(true)
.read(true)
.create(true)
.truncate(true)
.open(path)
.map_err(Error::UnableToSaveDepositAmount)?
.write_all(format!("{}", amount).as_bytes())
Expand Down
6 changes: 2 additions & 4 deletions consensus/cached_tree_hash/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ pub fn u64_leaf_count(len: usize) -> usize {

pub fn hash256_iter(
values: &[Hash256],
) -> impl Iterator<Item = [u8; BYTES_PER_CHUNK]> + ExactSizeIterator + '_ {
) -> impl ExactSizeIterator<Item = [u8; BYTES_PER_CHUNK]> + '_ {
values.iter().copied().map(Hash256::to_fixed_bytes)
}

pub fn u64_iter(
values: &[u64],
) -> impl Iterator<Item = [u8; BYTES_PER_CHUNK]> + ExactSizeIterator + '_ {
pub fn u64_iter(values: &[u64]) -> impl ExactSizeIterator<Item = [u8; BYTES_PER_CHUNK]> + '_ {
let type_size = size_of::<u64>();
let vals_per_chunk = BYTES_PER_CHUNK / type_size;
values.chunks(vals_per_chunk).map(move |xs| {
Expand Down
6 changes: 3 additions & 3 deletions consensus/types/src/beacon_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ impl<T: EthSpec> BeaconState<T> {
if self.slot() <= decision_slot {
Ok(block_root)
} else {
self.get_block_root(decision_slot).map(|root| *root)
self.get_block_root(decision_slot).copied()
}
}

Expand All @@ -657,7 +657,7 @@ impl<T: EthSpec> BeaconState<T> {
if self.slot() == decision_slot {
Ok(block_root)
} else {
self.get_block_root(decision_slot).map(|root| *root)
self.get_block_root(decision_slot).copied()
}
}

Expand All @@ -683,7 +683,7 @@ impl<T: EthSpec> BeaconState<T> {
if self.slot() == decision_slot {
Ok(block_root)
} else {
self.get_block_root(decision_slot).map(|root| *root)
self.get_block_root(decision_slot).copied()
}
}

Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/historical_summary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ impl<'a, N: Unsigned> CachedTreeHash<TreeHashCache> for HistoricalSummaryCache<'

pub fn leaf_iter(
values: &[HistoricalSummary],
) -> impl Iterator<Item = [u8; BYTES_PER_CHUNK]> + ExactSizeIterator + '_ {
) -> impl ExactSizeIterator<Item = [u8; BYTES_PER_CHUNK]> + '_ {
values
.iter()
.map(|value| value.tree_hash_root())
Expand Down
2 changes: 1 addition & 1 deletion consensus/types/src/participation_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn leaf_count(len: usize) -> usize {

pub fn leaf_iter(
values: &[ParticipationFlags],
) -> impl Iterator<Item = [u8; BYTES_PER_CHUNK]> + ExactSizeIterator + '_ {
) -> impl ExactSizeIterator<Item = [u8; BYTES_PER_CHUNK]> + '_ {
values.chunks(BYTES_PER_CHUNK).map(|xs| {
// Zero-pad chunks on the right.
let mut chunk = [0u8; BYTES_PER_CHUNK];
Expand Down
1 change: 1 addition & 0 deletions database_manager/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ pub fn inspect_db<E: EthSpec>(

let write_result = fs::OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&file_path)
.map_err(|e| format!("Failed to open file: {:?}", e))
Expand Down
6 changes: 4 additions & 2 deletions lighthouse/environment/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl<E: EthSpec> Environment<E> {
async move { rx.next().await.ok_or("Internal shutdown channel exhausted") };
futures::pin_mut!(inner_shutdown);

match self.runtime().block_on(async {
let register_handlers = async {
let mut handles = vec![];

// setup for handling SIGTERM
Expand Down Expand Up @@ -465,7 +465,9 @@ impl<E: EthSpec> Environment<E> {
}

future::select(inner_shutdown, future::select_all(handles.into_iter())).await
}) {
};

match self.runtime().block_on(register_handlers) {
future::Either::Left((Ok(reason), _)) => {
info!(self.log, "Internal shutdown received"; "reason" => reason.message());
Ok(reason)
Expand Down

0 comments on commit 39e9f7d

Please sign in to comment.