Skip to content

Commit 00bc481

Browse files
committed
Fix Rust 1.61 clippy lints (#3192)
## Issue Addressed This fixes the low-hanging Clippy lints introduced in Rust 1.61 (due any hour now). It _ignores_ one lint, because fixing it requires a structural refactor of the validator client that needs to be done delicately. I've started on that refactor and will create another PR that can be reviewed in more depth in the coming days. I think we should merge this PR in the meantime to unblock CI.
1 parent 54b58fd commit 00bc481

File tree

8 files changed

+53
-52
lines changed

8 files changed

+53
-52
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

beacon_node/beacon_chain/src/block_verification.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ use crate::{
5353
},
5454
metrics, BeaconChain, BeaconChainError, BeaconChainTypes,
5555
};
56+
use derivative::Derivative;
5657
use eth2::types::EventKind;
5758
use execution_layer::PayloadStatus;
5859
use fork_choice::{ForkChoice, ForkChoiceStore, PayloadVerificationStatus};
@@ -537,7 +538,8 @@ pub fn signature_verify_chain_segment<T: BeaconChainTypes>(
537538

538539
/// A wrapper around a `SignedBeaconBlock` that indicates it has been approved for re-gossiping on
539540
/// the p2p network.
540-
#[derive(Debug)]
541+
#[derive(Derivative)]
542+
#[derivative(Debug(bound = "T: BeaconChainTypes"))]
541543
pub struct GossipVerifiedBlock<T: BeaconChainTypes> {
542544
pub block: SignedBeaconBlock<T::EthSpec>,
543545
pub block_root: Hash256,

beacon_node/network/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,4 @@ lru_cache = { path = "../../common/lru_cache" }
4343
if-addrs = "0.6.4"
4444
strum = "0.24.0"
4545
tokio-util = { version = "0.6.3", features = ["time"] }
46+
derivative = "2.2.0"

beacon_node/network/src/beacon_processor/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ use crate::sync::manager::BlockProcessType;
4242
use crate::{metrics, service::NetworkMessage, sync::SyncMessage};
4343
use beacon_chain::parking_lot::Mutex;
4444
use beacon_chain::{BeaconChain, BeaconChainTypes, GossipVerifiedBlock};
45+
use derivative::Derivative;
4546
use futures::stream::{Stream, StreamExt};
4647
use futures::task::Poll;
4748
use lighthouse_network::{
@@ -51,7 +52,6 @@ use lighthouse_network::{
5152
use logging::TimeLatch;
5253
use slog::{crit, debug, error, trace, warn, Logger};
5354
use std::collections::VecDeque;
54-
use std::fmt;
5555
use std::pin::Pin;
5656
use std::sync::{Arc, Weak};
5757
use std::task::Context;
@@ -331,17 +331,13 @@ impl DuplicateCache {
331331
}
332332

333333
/// An event to be processed by the manager task.
334+
#[derive(Derivative)]
335+
#[derivative(Debug(bound = "T: BeaconChainTypes"))]
334336
pub struct WorkEvent<T: BeaconChainTypes> {
335337
drop_during_sync: bool,
336338
work: Work<T>,
337339
}
338340

339-
impl<T: BeaconChainTypes> fmt::Debug for WorkEvent<T> {
340-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
341-
write!(f, "{:?}", self)
342-
}
343-
}
344-
345341
impl<T: BeaconChainTypes> WorkEvent<T> {
346342
/// Create a new `Work` event for some unaggregated attestation.
347343
pub fn unaggregated_attestation(
@@ -615,7 +611,8 @@ impl<T: BeaconChainTypes> std::convert::From<ReadyWork<T>> for WorkEvent<T> {
615611
}
616612

617613
/// A consensus message (or multiple) from the network that requires processing.
618-
#[derive(Debug)]
614+
#[derive(Derivative)]
615+
#[derivative(Debug(bound = "T: BeaconChainTypes"))]
619616
pub enum Work<T: BeaconChainTypes> {
620617
GossipAttestation {
621618
message_id: MessageId,

beacon_node/network/src/sync/range_sync/chain.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ const BATCH_BUFFER_SIZE: u8 = 5;
2626
/// A return type for functions that act on a `Chain` which informs the caller whether the chain
2727
/// has been completed and should be removed or to be kept if further processing is
2828
/// required.
29-
#[must_use = "Should be checked, since a failed chain must be removed. A chain that requested
30-
being removed and continued is now in an inconsistent state"]
29+
///
30+
/// Should be checked, since a failed chain must be removed. A chain that requested being removed
31+
/// and continued is now in an inconsistent state.
3132
pub type ProcessingResult = Result<KeepChain, RemoveChain>;
3233

3334
/// Reasons for removing a chain

testing/simulator/src/local_network.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,15 +107,16 @@ impl<E: EthSpec> LocalNetwork<E> {
107107
beacon_config.network.discv5_config.table_filter = |_| true;
108108
}
109109

110-
let mut write_lock = self_1.beacon_nodes.write();
111-
let index = write_lock.len();
112-
110+
// We create the beacon node without holding the lock, so that the lock isn't held
111+
// across the await. This is only correct if this function never runs in parallel
112+
// with itself (which at the time of writing, it does not).
113+
let index = self_1.beacon_nodes.read().len();
113114
let beacon_node = LocalBeaconNode::production(
114115
self.context.service_context(format!("node_{}", index)),
115116
beacon_config,
116117
)
117118
.await?;
118-
write_lock.push(beacon_node);
119+
self_1.beacon_nodes.write().push(beacon_node);
119120
Ok(())
120121
}
121122

validator_client/src/preparation_service.rs

Lines changed: 33 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ impl<T: SlotClock + 'static, E: EthSpec> PreparationService<T, E> {
199199
.map_err(|e| {
200200
error!(
201201
log,
202-
"{}", format!("Error loading fee-recipient file: {:?}", e);
202+
"Error loading fee-recipient file";
203+
"error" => ?e
203204
);
204205
})
205206
.unwrap_or(());
@@ -213,44 +214,39 @@ impl<T: SlotClock + 'static, E: EthSpec> PreparationService<T, E> {
213214
all_pubkeys
214215
.into_iter()
215216
.filter_map(|pubkey| {
216-
let validator_index = self.validator_store.validator_index(&pubkey);
217-
if let Some(validator_index) = validator_index {
218-
let fee_recipient = if let Some(from_validator_defs) =
219-
self.validator_store.suggested_fee_recipient(&pubkey)
220-
{
221-
// If there is a `suggested_fee_recipient` in the validator definitions yaml
222-
// file, use that value.
223-
Some(from_validator_defs)
224-
} else {
225-
// If there's nothing in the validator defs file, check the fee recipient
226-
// file.
217+
// Ignore fee recipients for keys without indices, they are inactive.
218+
let validator_index = self.validator_store.validator_index(&pubkey)?;
219+
220+
// If there is a `suggested_fee_recipient` in the validator definitions yaml
221+
// file, use that value.
222+
let fee_recipient = self
223+
.validator_store
224+
.suggested_fee_recipient(&pubkey)
225+
.or_else(|| {
226+
// If there's nothing in the validator defs file, check the fee
227+
// recipient file.
227228
fee_recipient_file
228-
.as_ref()
229-
.and_then(|f| match f.get_fee_recipient(&pubkey) {
230-
Ok(f) => f,
231-
Err(_e) => None,
232-
})
233-
// If there's nothing in the file, try the process-level default value.
234-
.or(self.fee_recipient)
235-
};
236-
237-
if let Some(fee_recipient) = fee_recipient {
238-
Some(ProposerPreparationData {
239-
validator_index,
240-
fee_recipient,
241-
})
242-
} else {
243-
if spec.bellatrix_fork_epoch.is_some() {
244-
error!(
245-
log,
246-
"Validator is missing fee recipient";
247-
"msg" => "update validator_definitions.yml",
248-
"pubkey" => ?pubkey
249-
);
250-
}
251-
None
252-
}
229+
.as_ref()?
230+
.get_fee_recipient(&pubkey)
231+
.ok()?
232+
})
233+
// If there's nothing in the file, try the process-level default value.
234+
.or(self.fee_recipient);
235+
236+
if let Some(fee_recipient) = fee_recipient {
237+
Some(ProposerPreparationData {
238+
validator_index,
239+
fee_recipient,
240+
})
253241
} else {
242+
if spec.bellatrix_fork_epoch.is_some() {
243+
error!(
244+
log,
245+
"Validator is missing fee recipient";
246+
"msg" => "update validator_definitions.yml",
247+
"pubkey" => ?pubkey
248+
);
249+
}
254250
None
255251
}
256252
})

validator_client/src/validator_store.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ impl<T: SlotClock + 'static, E: EthSpec> ValidatorStore<T, E> {
171171
/// - Adding the validator definition to the YAML file, saving it to the filesystem.
172172
/// - Enabling the validator with the slashing protection database.
173173
/// - If `enable == true`, starting to perform duties for the validator.
174+
// FIXME: ignore this clippy lint until the validator store is refactored to use async locks
175+
#[allow(clippy::await_holding_lock)]
174176
pub async fn add_validator(
175177
&self,
176178
validator_def: ValidatorDefinition,

0 commit comments

Comments
 (0)