Fix clippy warnings (#1385)

## Issue Addressed

NA

## Proposed Changes

Fixes most clippy warnings and ignores the rest of them, see issue #1388.
This commit is contained in:
blacktemplar
2020-07-23 14:18:00 +00:00
parent ba10c80633
commit 23a8f31f83
93 changed files with 396 additions and 396 deletions
@@ -287,7 +287,7 @@ impl<T: BeaconChainTypes> VerifiedAggregatedAttestation<T> {
if chain
.observed_aggregators
.observe_validator(&attestation, aggregator_index as usize)
.map_err(|e| BeaconChainError::from(e))?
.map_err(BeaconChainError::from)?
{
return Err(Error::PriorAttestationKnown {
validator_index: aggregator_index,
@@ -370,7 +370,7 @@ impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<T> {
if chain
.observed_attesters
.validator_has_been_observed(&attestation, validator_index as usize)
.map_err(|e| BeaconChainError::from(e))?
.map_err(BeaconChainError::from)?
{
return Err(Error::PriorAttestationKnown {
validator_index,
@@ -390,7 +390,7 @@ impl<T: BeaconChainTypes> VerifiedUnaggregatedAttestation<T> {
if chain
.observed_attesters
.observe_validator(&attestation, validator_index as usize)
.map_err(|e| BeaconChainError::from(e))?
.map_err(BeaconChainError::from)?
{
return Err(Error::PriorAttestationKnown {
validator_index,
@@ -504,7 +504,7 @@ pub fn verify_attestation_signature<T: BeaconChainTypes>(
.canonical_head
.try_read_for(HEAD_LOCK_TIMEOUT)
.ok_or_else(|| BeaconChainError::CanonicalHeadLockTimeout)
.map(|head| head.beacon_state.fork.clone())?;
.map(|head| head.beacon_state.fork)?;
let signature_set = indexed_attestation_signature_set_from_pubkeys(
|validator_index| pubkey_cache.get(validator_index).map(Cow::Borrowed),
@@ -559,7 +559,7 @@ pub fn verify_signed_aggregate_signatures<T: BeaconChainTypes>(
.canonical_head
.try_read_for(HEAD_LOCK_TIMEOUT)
.ok_or_else(|| BeaconChainError::CanonicalHeadLockTimeout)
.map(|head| head.beacon_state.fork.clone())?;
.map(|head| head.beacon_state.fork)?;
let signature_sets = vec![
signed_aggregate_selection_proof_signature_set(
@@ -694,7 +694,7 @@ where
// The state roots are not useful for the shuffling, so there's no need to
// compute them.
per_slot_processing(&mut state, Some(Hash256::zero()), &chain.spec)
.map_err(|e| BeaconChainError::from(e))?;
.map_err(BeaconChainError::from)?;
}
metrics::stop_timer(state_skip_timer);
@@ -706,11 +706,11 @@ where
state
.build_committee_cache(relative_epoch, &chain.spec)
.map_err(|e| BeaconChainError::from(e))?;
.map_err(BeaconChainError::from)?;
let committee_cache = state
.committee_cache(relative_epoch)
.map_err(|e| BeaconChainError::from(e))?;
.map_err(BeaconChainError::from)?;
chain
.shuffling_cache
+25 -26
View File
@@ -199,6 +199,8 @@ pub struct BeaconChain<T: BeaconChainTypes> {
pub genesis_block_root: Hash256,
/// The root of the list of genesis validators, used during syncing.
pub genesis_validators_root: Hash256,
#[allow(clippy::type_complexity)]
/// A state-machine that is updated with information from the network and chooses a canonical
/// head block.
pub fork_choice: RwLock<
@@ -493,9 +495,9 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
slot: head.beacon_block.slot(),
block_root: head.beacon_block_root,
state_root: head.beacon_state_root,
current_justified_checkpoint: head.beacon_state.current_justified_checkpoint.clone(),
finalized_checkpoint: head.beacon_state.finalized_checkpoint.clone(),
fork: head.beacon_state.fork.clone(),
current_justified_checkpoint: head.beacon_state.current_justified_checkpoint,
finalized_checkpoint: head.beacon_state.finalized_checkpoint,
fork: head.beacon_state.fork,
genesis_time: head.beacon_state.genesis_time,
genesis_validators_root: head.beacon_state.genesis_validators_root,
})
@@ -853,8 +855,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
data: AttestationData {
slot,
index,
beacon_block_root: beacon_block_root,
source: state.current_justified_checkpoint.clone(),
beacon_block_root,
source: state.current_justified_checkpoint,
target: Checkpoint {
epoch,
root: target_root,
@@ -986,8 +988,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.try_read_for(HEAD_LOCK_TIMEOUT)
.ok_or_else(|| Error::CanonicalHeadLockTimeout)?
.beacon_state
.fork
.clone();
.fork;
self.op_pool
.insert_attestation(
@@ -1348,7 +1349,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
};
// Verify and import the block.
let result = match import_block(unverified_block) {
match import_block(unverified_block) {
// The block was successfully verified and imported. Yay.
Ok(block_root) => {
trace!(
@@ -1362,7 +1363,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
metrics::inc_counter(&metrics::BLOCK_PROCESSING_SUCCESSES);
let _ = self.event_handler.register(EventKind::BeaconBlockImported {
block_root: block_root,
block_root,
block: Box::new(block),
});
@@ -1399,9 +1400,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
Err(other)
}
};
result
}
}
/// Accepts a fully-verified block and imports it into the chain without performing any
@@ -1642,7 +1641,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
body: BeaconBlockBody {
randao_reveal,
eth1_data,
graffiti: self.graffiti.clone(),
graffiti: self.graffiti,
proposer_slashings: proposer_slashings.into(),
attester_slashings: attester_slashings.into(),
attestations: self
@@ -1718,7 +1717,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
.snapshot_cache
.try_read_for(BLOCK_PROCESSING_CACHE_LOCK_TIMEOUT)
.and_then(|snapshot_cache| snapshot_cache.get_cloned(beacon_block_root))
.map::<Result<_, Error>, _>(|snapshot| Ok(snapshot))
.map::<Result<_, Error>, _>(Ok)
.unwrap_or_else(|| {
let beacon_block = self
.get_block(&beacon_block_root)?
@@ -2010,8 +2009,8 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
let mut finalized_blocks: HashSet<Hash256> = HashSet::new();
let genesis_block_hash = Hash256::zero();
write!(output, "digraph beacon {{\n").unwrap();
write!(output, "\t_{:?}[label=\"genesis\"];\n", genesis_block_hash).unwrap();
writeln!(output, "digraph beacon {{").unwrap();
writeln!(output, "\t_{:?}[label=\"genesis\"];", genesis_block_hash).unwrap();
// Canonical head needs to be processed first as otherwise finalized blocks aren't detected
// properly.
@@ -2045,36 +2044,36 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}
if block_hash == canonical_head_hash {
write!(
writeln!(
output,
"\t_{:?}[label=\"{} ({})\" shape=box3d];\n",
"\t_{:?}[label=\"{} ({})\" shape=box3d];",
block_hash,
block_hash,
signed_beacon_block.slot()
)
.unwrap();
} else if finalized_blocks.contains(&block_hash) {
write!(
writeln!(
output,
"\t_{:?}[label=\"{} ({})\" shape=Msquare];\n",
"\t_{:?}[label=\"{} ({})\" shape=Msquare];",
block_hash,
block_hash,
signed_beacon_block.slot()
)
.unwrap();
} else {
write!(
writeln!(
output,
"\t_{:?}[label=\"{} ({})\" shape=box];\n",
"\t_{:?}[label=\"{} ({})\" shape=box];",
block_hash,
block_hash,
signed_beacon_block.slot()
)
.unwrap();
}
write!(
writeln!(
output,
"\t_{:?} -> _{:?};\n",
"\t_{:?} -> _{:?};",
block_hash,
signed_beacon_block.parent_root()
)
@@ -2082,7 +2081,7 @@ impl<T: BeaconChainTypes> BeaconChain<T> {
}
}
write!(output, "}}\n").unwrap();
writeln!(output, "}}").unwrap();
}
// Used for debugging
@@ -2135,7 +2134,7 @@ impl From<BeaconStateError> for Error {
}
impl ChainSegmentResult {
pub fn to_block_error(self) -> Result<(), BlockError> {
pub fn into_block_error(self) -> Result<(), BlockError> {
match self {
ChainSegmentResult::Failed { error, .. } => Err(error),
ChainSegmentResult::Successful { .. } => Ok(()),
@@ -584,8 +584,9 @@ impl<'a, T: BeaconChainTypes> FullyVerifiedBlock<'a, T> {
state_root
};
per_slot_processing(&mut state, Some(state_root), &chain.spec)?
.map(|summary| summaries.push(summary));
if let Some(summary) = per_slot_processing(&mut state, Some(state_root), &chain.spec)? {
summaries.push(summary)
}
}
expose_participation_metrics(&summaries);
+5 -7
View File
@@ -93,6 +93,7 @@ where
///
/// See the tests for an example of a complete working example.
pub struct BeaconChainBuilder<T: BeaconChainTypes> {
#[allow(clippy::type_complexity)]
store: Option<Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>>,
store_migrator: Option<T::StoreMigrator>,
canonical_head: Option<BeaconSnapshot<T::EthSpec>>,
@@ -461,13 +462,10 @@ where
.pubkey_cache_path
.ok_or_else(|| "Cannot build without a pubkey cache path".to_string())?;
let validator_pubkey_cache = self
.validator_pubkey_cache
.map(|cache| Ok(cache))
.unwrap_or_else(|| {
ValidatorPubkeyCache::new(&canonical_head.beacon_state, pubkey_cache_path)
.map_err(|e| format!("Unable to init validator pubkey cache: {:?}", e))
})?;
let validator_pubkey_cache = self.validator_pubkey_cache.map(Ok).unwrap_or_else(|| {
ValidatorPubkeyCache::new(&canonical_head.beacon_state, pubkey_cache_path)
.map_err(|e| format!("Unable to init validator pubkey cache: {:?}", e))
})?;
let persisted_fork_choice = store
.get_item::<PersistedForkChoice>(&Hash256::from_slice(&FORK_CHOICE_DB_KEY))
+2 -3
View File
@@ -331,7 +331,7 @@ impl<T: EthSpec> Eth1ChainBackend<T> for CachingEth1Backend<T> {
//
// Here we choose the eth1_data corresponding to the latest block in our voting window.
// If no votes exist, choose `state.eth1_data` as default vote.
let default_vote = votes_to_consider
votes_to_consider
.iter()
.max_by(|(_, x), (_, y)| x.cmp(y))
.map(|vote| {
@@ -355,8 +355,7 @@ impl<T: EthSpec> Eth1ChainBackend<T> for CachingEth1Backend<T> {
);
metrics::inc_counter(&metrics::DEFAULT_ETH1_VOTES);
vote
});
default_vote
})
};
debug!(
+8 -4
View File
@@ -37,7 +37,7 @@ impl<T: EthSpec> ServerSentEvents<T> {
let arc = Arc::new(mutex);
let this = Self {
head_changed_queue: arc.clone(),
log: log,
log,
_phantom: PhantomData,
};
(this, arc)
@@ -52,7 +52,10 @@ impl<T: EthSpec> EventHandler<T> for ServerSentEvents<T> {
..
} => {
let mut guard = self.head_changed_queue.lock();
if let Err(_) = guard.try_broadcast(current_head_beacon_block_root.into()) {
if guard
.try_broadcast(current_head_beacon_block_root.into())
.is_err()
{
error!(
self.log,
"Head change streaming queue full";
@@ -75,14 +78,15 @@ pub struct TeeEventHandler<E: EthSpec> {
}
impl<E: EthSpec> TeeEventHandler<E> {
#[allow(clippy::type_complexity)]
pub fn new(
log: Logger,
websockets_handler: WebSocketSender<E>,
) -> Result<(Self, Arc<Mutex<Bus<SignedBeaconBlockHash>>>), String> {
let (sse_handler, bus) = ServerSentEvents::new(log);
let result = Self {
websockets_handler: websockets_handler,
sse_handler: sse_handler,
websockets_handler,
sse_handler,
};
Ok((result, bus))
}
+2 -1
View File
@@ -154,7 +154,7 @@ pub trait Migrate<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>>:
let batch: Vec<StoreOp<E>> = abandoned_blocks
.into_iter()
.map(|block_hash| StoreOp::DeleteBlock(block_hash))
.map(StoreOp::DeleteBlock)
.chain(
abandoned_states
.into_iter()
@@ -296,6 +296,7 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> BackgroundMigrator<E, Ho
finality_distance > max_finality_distance
}
#[allow(clippy::type_complexity)]
/// Spawn a new child thread to run the migration process.
///
/// Return a channel handle for sending new finalized states to the thread.
@@ -88,9 +88,9 @@ impl Item for EpochBitfield {
.unwrap_or_else(|| {
self.bitfield
.resize(validator_index.saturating_add(1), false);
self.bitfield
.get_mut(validator_index)
.map(|mut bit| *bit = true);
if let Some(mut bit) = self.bitfield.get_mut(validator_index) {
*bit = true;
}
false
})
}
@@ -393,6 +393,7 @@ where
(block_root.into(), new_state)
}
#[allow(clippy::type_complexity)]
/// `add_block()` repeated `num_blocks` times.
pub fn add_blocks(
&self,
@@ -422,6 +423,7 @@ where
(blocks, states, slot, head_hash, state)
}
#[allow(clippy::type_complexity)]
/// A wrapper on `add_blocks()` to avoid passing enums explicitly.
pub fn add_canonical_chain_blocks(
&self,
@@ -446,6 +448,7 @@ where
)
}
#[allow(clippy::type_complexity)]
/// A wrapper on `add_blocks()` to avoid passing enums explicitly.
pub fn add_stray_blocks(
&self,
@@ -138,8 +138,8 @@ struct ValidatorPubkeyCacheFile(File);
#[derive(Debug)]
enum Error {
IoError(io::Error),
SszError(DecodeError),
Io(io::Error),
Ssz(DecodeError),
/// The file read from disk does not have a contiguous list of validator public keys. The file
/// has become corrupted.
InconsistentIndex {
@@ -162,7 +162,7 @@ impl ValidatorPubkeyCacheFile {
.write(true)
.open(path)
.map(Self)
.map_err(Error::IoError)
.map_err(Error::Io)
}
/// Opens an existing file for reading and writing.
@@ -174,7 +174,7 @@ impl ValidatorPubkeyCacheFile {
.append(true)
.open(path)
.map(Self)
.map_err(Error::IoError)
.map_err(Error::Io)
}
/// Append a public key to file.
@@ -188,10 +188,9 @@ impl ValidatorPubkeyCacheFile {
/// Creates a `ValidatorPubkeyCache` by reading and parsing the underlying file.
pub fn into_cache(mut self) -> Result<ValidatorPubkeyCache, Error> {
let mut bytes = vec![];
self.0.read_to_end(&mut bytes).map_err(Error::IoError)?;
self.0.read_to_end(&mut bytes).map_err(Error::Io)?;
let list: Vec<(usize, PublicKeyBytes)> =
Vec::from_ssz_bytes(&bytes).map_err(Error::SszError)?;
let list: Vec<(usize, PublicKeyBytes)> = Vec::from_ssz_bytes(&bytes).map_err(Error::Ssz)?;
let mut last = None;
let mut pubkeys = Vec::with_capacity(list.len());
@@ -201,7 +200,7 @@ impl ValidatorPubkeyCacheFile {
let expected = last.map(|n| n + 1);
if expected.map_or(true, |expected| index == expected) {
last = Some(index);
pubkeys.push((&pubkey).try_into().map_err(Error::SszError)?);
pubkeys.push((&pubkey).try_into().map_err(Error::Ssz)?);
indices.insert(pubkey, index);
} else {
return Err(Error::InconsistentIndex {
@@ -225,7 +224,7 @@ fn append_to_file(file: &mut File, index: usize, pubkey: &PublicKeyBytes) -> Res
index.ssz_append(&mut line);
pubkey.ssz_append(&mut line);
file.write_all(&mut line).map_err(Error::IoError)
file.write_all(&line).map_err(Error::Io)
}
#[cfg(test)]
@@ -126,13 +126,13 @@ fn chain_segment_full_segment() {
harness
.chain
.process_chain_segment(vec![])
.to_block_error()
.into_block_error()
.expect("should import empty chain segment");
harness
.chain
.process_chain_segment(blocks.clone())
.to_block_error()
.into_block_error()
.expect("should import chain segment");
harness.chain.fork_choice().expect("should run fork choice");
@@ -163,7 +163,7 @@ fn chain_segment_varying_chunk_size() {
harness
.chain
.process_chain_segment(chunk.to_vec())
.to_block_error()
.into_block_error()
.expect(&format!(
"should import chain segment of len {}",
chunk_size
@@ -203,7 +203,7 @@ fn chain_segment_non_linear_parent_roots() {
harness
.chain
.process_chain_segment(blocks.clone())
.to_block_error(),
.into_block_error(),
Err(BlockError::NonLinearParentRoots)
),
"should not import chain with missing parent"
@@ -220,7 +220,7 @@ fn chain_segment_non_linear_parent_roots() {
harness
.chain
.process_chain_segment(blocks.clone())
.to_block_error(),
.into_block_error(),
Err(BlockError::NonLinearParentRoots)
),
"should not import chain with a broken parent root link"
@@ -247,7 +247,7 @@ fn chain_segment_non_linear_slots() {
harness
.chain
.process_chain_segment(blocks.clone())
.to_block_error(),
.into_block_error(),
Err(BlockError::NonLinearSlots)
),
"should not import chain with a parent that has a lower slot than its child"
@@ -265,7 +265,7 @@ fn chain_segment_non_linear_slots() {
harness
.chain
.process_chain_segment(blocks.clone())
.to_block_error(),
.into_block_error(),
Err(BlockError::NonLinearSlots)
),
"should not import chain with a parent that has an equal slot to its child"
@@ -292,7 +292,7 @@ fn invalid_signatures() {
harness
.chain
.process_chain_segment(ancestor_blocks)
.to_block_error()
.into_block_error()
.expect("should import all blocks prior to the one being tested");
// For the given snapshots, test the following:
@@ -312,7 +312,10 @@ fn invalid_signatures() {
// Ensure the block will be rejected if imported in a chain segment.
assert!(
matches!(
harness.chain.process_chain_segment(blocks).to_block_error(),
harness
.chain
.process_chain_segment(blocks)
.into_block_error(),
Err(BlockError::InvalidSignature)
),
"should not import chain segment with an invalid {} signature",
@@ -351,7 +354,10 @@ fn invalid_signatures() {
// Ensure the block will be rejected if imported in a chain segment.
assert!(
matches!(
harness.chain.process_chain_segment(blocks).to_block_error(),
harness
.chain
.process_chain_segment(blocks)
.into_block_error(),
Err(BlockError::InvalidSignature)
),
"should not import chain segment with an invalid gossip signature",
@@ -489,7 +495,10 @@ fn invalid_signatures() {
.collect();
assert!(
!matches!(
harness.chain.process_chain_segment(blocks).to_block_error(),
harness
.chain
.process_chain_segment(blocks)
.into_block_error(),
Err(BlockError::InvalidSignature)
),
"should not throw an invalid signature error for a bad deposit signature"
+3 -1
View File
@@ -50,6 +50,7 @@ pub const ETH1_GENESIS_UPDATE_INTERVAL_MILLIS: u64 = 7_000;
/// `self.memory_store(..)` has been called.
pub struct ClientBuilder<T: BeaconChainTypes> {
slot_clock: Option<T::SlotClock>,
#[allow(clippy::type_complexity)]
store: Option<Arc<HotColdDB<T::EthSpec, T::HotStore, T::ColdStore>>>,
store_migrator: Option<T::StoreMigrator>,
runtime_context: Option<RuntimeContext<T::EthSpec>>,
@@ -134,7 +135,7 @@ where
let eth_spec_instance = self.eth_spec_instance.clone();
let data_dir = config.data_dir.clone();
let disabled_forks = config.disabled_forks.clone();
let graffiti = config.graffiti.clone();
let graffiti = config.graffiti;
let store =
store.ok_or_else(|| "beacon_chain_start_method requires a store".to_string())?;
@@ -452,6 +453,7 @@ where
THotStore: ItemStore<TEthSpec> + 'static,
TColdStore: ItemStore<TEthSpec> + 'static,
{
#[allow(clippy::type_complexity)]
/// Specifies that the `BeaconChain` should publish events using the WebSocket server.
pub fn tee_event_handler(
mut self,
-2
View File
@@ -1,5 +1,3 @@
use network;
use error_chain::error_chain;
error_chain! {
+26 -29
View File
@@ -7,7 +7,6 @@ use slog::{debug, error, info, warn};
use slot_clock::SlotClock;
use std::sync::Arc;
use std::time::{Duration, Instant};
use time;
use tokio::time::delay_for;
use types::{EthSpec, Slot};
@@ -64,7 +63,7 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
}
// Perform post-genesis logging.
while let Some(_) = interval.next().await {
while interval.next().await.is_some() {
let connected_peer_count = network.connected_peers();
let sync_state = network.sync_state();
@@ -131,34 +130,32 @@ pub fn spawn_notifier<T: BeaconChainTypes>(
"speed" => sync_speed_pretty(speedo.slots_per_second()),
"est_time" => estimated_time_pretty(speedo.estimated_time_till_slot(current_slot)),
);
} else {
if sync_state.is_synced() {
let block_info = if current_slot > head_slot {
format!(" … empty")
} else {
format!("{}", head_root)
};
info!(
log,
"Synced";
"peers" => peer_count_pretty(connected_peer_count),
"finalized_root" => format!("{}", finalized_root),
"finalized_epoch" => finalized_epoch,
"epoch" => current_epoch,
"block" => block_info,
"slot" => current_slot,
);
} else if sync_state.is_synced() {
let block_info = if current_slot > head_slot {
" … empty".to_string()
} else {
info!(
log,
"Searching for peers";
"peers" => peer_count_pretty(connected_peer_count),
"finalized_root" => format!("{}", finalized_root),
"finalized_epoch" => finalized_epoch,
"head_slot" => head_slot,
"current_slot" => current_slot,
);
}
head_root.to_string()
};
info!(
log,
"Synced";
"peers" => peer_count_pretty(connected_peer_count),
"finalized_root" => format!("{}", finalized_root),
"finalized_epoch" => finalized_epoch,
"epoch" => current_epoch,
"block" => block_info,
"slot" => current_slot,
);
} else {
info!(
log,
"Searching for peers";
"peers" => peer_count_pretty(connected_peer_count),
"finalized_root" => format!("{}", finalized_root),
"finalized_epoch" => finalized_epoch,
"head_slot" => head_slot,
"current_slot" => current_slot,
);
}
}
Ok::<(), ()>(())
+1 -1
View File
@@ -434,7 +434,7 @@ impl Service {
for (block_range, log_chunk) in logs.iter() {
let mut cache = self.deposits().write();
log_chunk
.into_iter()
.iter()
.map(|raw_log| {
DepositLog::from_log(&raw_log, self.inner.spec()).map_err(|error| {
Error::FailedToParseDepositLog {
@@ -188,10 +188,10 @@ impl<TSpec: EthSpec> ProtocolsHandler for DelegatingHandler<TSpec> {
// Identify
(
EitherOutput::Second(EitherOutput::Second(protocol)),
EitherOutput::Second(EitherOutput::Second(info)),
EitherOutput::Second(EitherOutput::Second(())),
) => self
.identify_handler
.inject_fully_negotiated_outbound(protocol, info),
.inject_fully_negotiated_outbound(protocol, ()),
// Reaching here means we got a protocol and info for different behaviours
_ => unreachable!("output and protocol don't match"),
}
@@ -201,7 +201,7 @@ impl<TSpec: EthSpec> ProtocolsHandler for DelegatingHandler<TSpec> {
match event {
DelegateIn::Gossipsub(ev) => self.gossip_handler.inject_event(ev),
DelegateIn::RPC(ev) => self.rpc_handler.inject_event(ev),
DelegateIn::Identify(ev) => self.identify_handler.inject_event(ev),
DelegateIn::Identify(()) => self.identify_handler.inject_event(()),
}
}
@@ -263,23 +263,23 @@ impl<TSpec: EthSpec> ProtocolsHandler for DelegatingHandler<TSpec> {
}
},
// Identify
EitherOutput::Second(EitherOutput::Second(info)) => match error {
EitherOutput::Second(EitherOutput::Second(())) => match error {
ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Select(err)) => {
self.identify_handler.inject_dial_upgrade_error(
info,
(),
ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Select(err)),
)
}
ProtocolsHandlerUpgrErr::Timer => self
.identify_handler
.inject_dial_upgrade_error(info, ProtocolsHandlerUpgrErr::Timer),
.inject_dial_upgrade_error((), ProtocolsHandlerUpgrErr::Timer),
ProtocolsHandlerUpgrErr::Timeout => self
.identify_handler
.inject_dial_upgrade_error(info, ProtocolsHandlerUpgrErr::Timeout),
.inject_dial_upgrade_error((), ProtocolsHandlerUpgrErr::Timeout),
ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Apply(EitherError::B(
EitherError::B(err),
))) => self.identify_handler.inject_dial_upgrade_error(
info,
(),
ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Apply(err)),
),
ProtocolsHandlerUpgrErr::Upgrade(UpgradeError::Apply(_)) => {
@@ -296,6 +296,7 @@ impl<TSpec: EthSpec> ProtocolsHandler for DelegatingHandler<TSpec> {
.max(self.identify_handler.connection_keep_alive())
}
#[allow(clippy::type_complexity)]
fn poll(
&mut self,
cx: &mut Context,
@@ -350,10 +351,10 @@ impl<TSpec: EthSpec> ProtocolsHandler for DelegatingHandler<TSpec> {
Poll::Ready(ProtocolsHandlerEvent::Close(event)) => {
return Poll::Ready(ProtocolsHandlerEvent::Close(DelegateError::Identify(event)));
}
Poll::Ready(ProtocolsHandlerEvent::OutboundSubstreamRequest { protocol, info }) => {
Poll::Ready(ProtocolsHandlerEvent::OutboundSubstreamRequest { protocol, info: () }) => {
return Poll::Ready(ProtocolsHandlerEvent::OutboundSubstreamRequest {
protocol: protocol.map_upgrade(|u| EitherUpgrade::B(EitherUpgrade::B(u))),
info: EitherOutput::Second(EitherOutput::Second(info)),
info: EitherOutput::Second(EitherOutput::Second(())),
});
}
Poll::Pending => (),
@@ -100,6 +100,7 @@ impl<TSpec: EthSpec> ProtocolsHandler for BehaviourHandler<TSpec> {
KeepAlive::Yes
}
#[allow(clippy::type_complexity)]
fn poll(
&mut self,
cx: &mut Context,
+2 -2
View File
@@ -397,7 +397,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
if self.seen_gossip_messages.put(id.clone(), ()).is_none() {
match PubsubMessage::decode(&gs_msg.topics, &gs_msg.data) {
Err(e) => {
debug!(self.log, "Could not decode gossipsub message"; "error" => format!("{}", e))
debug!(self.log, "Could not decode gossipsub message"; "error" => e)
}
Ok(msg) => {
// if this message isn't a duplicate, notify the network
@@ -412,7 +412,7 @@ impl<TSpec: EthSpec> Behaviour<TSpec> {
} else {
match PubsubMessage::<TSpec>::decode(&gs_msg.topics, &gs_msg.data) {
Err(e) => {
debug!(self.log, "Could not decode gossipsub message"; "error" => format!("{}", e))
debug!(self.log, "Could not decode gossipsub message"; "error" => e)
}
Ok(msg) => {
debug!(self.log, "A duplicate gossipsub message was received"; "message_source" => format!("{}", gs_msg.source), "propagated_peer" => format!("{}",propagation_source), "message" => format!("{}", msg));
+2 -2
View File
@@ -17,9 +17,9 @@ use std::str::FromStr;
use types::{EnrForkId, EthSpec};
/// The ENR field specifying the fork id.
pub const ETH2_ENR_KEY: &'static str = "eth2";
pub const ETH2_ENR_KEY: &str = "eth2";
/// The ENR field specifying the subnet bitfield.
pub const BITFIELD_ENR_KEY: &'static str = "attnets";
pub const BITFIELD_ENR_KEY: &str = "attnets";
/// Extension trait for ENR's within Eth2.
pub trait Eth2Enr {
@@ -197,7 +197,7 @@ pub fn peer_id_to_node_id(peer_id: &PeerId) -> Result<discv5::enr::NodeId, Strin
let mut hasher = Keccak::v256();
hasher.update(&uncompressed_key_bytes);
hasher.finalize(&mut output);
return Ok(discv5::enr::NodeId::parse(&output).expect("Must be correct length"));
Ok(discv5::enr::NodeId::parse(&output).expect("Must be correct length"))
}
PublicKey::Ed25519(pk) => {
let uncompressed_key_bytes = pk.encode();
@@ -205,9 +205,9 @@ pub fn peer_id_to_node_id(peer_id: &PeerId) -> Result<discv5::enr::NodeId, Strin
let mut hasher = Keccak::v256();
hasher.update(&uncompressed_key_bytes);
hasher.finalize(&mut output);
return Ok(discv5::enr::NodeId::parse(&output).expect("Must be correct length"));
Ok(discv5::enr::NodeId::parse(&output).expect("Must be correct length"))
}
_ => return Err("Unsupported public key".into()),
_ => Err("Unsupported public key".into()),
}
}
@@ -194,10 +194,8 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
// Update the PeerDB state.
if let Some(peer_id) = ban_peer.take() {
self.network_globals.peers.write().ban(&peer_id);
} else {
if let Some(peer_id) = unban_peer.take() {
self.network_globals.peers.write().unban(&peer_id);
}
} else if let Some(peer_id) = unban_peer.take() {
self.network_globals.peers.write().unban(&peer_id);
}
}
@@ -9,7 +9,7 @@ use serde::Serialize;
use std::time::Instant;
lazy_static! {
static ref HALFLIFE_DECAY: f64 = -2.0f64.ln() / SCORE_HALFLIFE;
static ref HALFLIFE_DECAY: f64 = -(2.0f64.ln()) / SCORE_HALFLIFE;
}
/// The default score for new peers.
@@ -196,10 +196,8 @@ impl<TSpec: EthSpec> Decoder for SSZSnappyInboundCodec<TSpec> {
Err(e) => match e.kind() {
// Haven't received enough bytes to decode yet
// TODO: check if this is the only Error variant where we return `Ok(None)`
ErrorKind::UnexpectedEof => {
return Ok(None);
}
_ => return Err(e).map_err(RPCError::from),
ErrorKind::UnexpectedEof => Ok(None),
_ => Err(e).map_err(RPCError::from),
},
}
}
@@ -368,10 +366,8 @@ impl<TSpec: EthSpec> Decoder for SSZSnappyOutboundCodec<TSpec> {
Err(e) => match e.kind() {
// Haven't received enough bytes to decode yet
// TODO: check if this is the only Error variant where we return `Ok(None)`
ErrorKind::UnexpectedEof => {
return Ok(None);
}
_ => return Err(e).map_err(RPCError::from),
ErrorKind::UnexpectedEof => Ok(None),
_ => Err(e).map_err(RPCError::from),
},
}
}
@@ -412,10 +408,8 @@ impl<TSpec: EthSpec> OutboundCodec<RPCRequest<TSpec>> for SSZSnappyOutboundCodec
Err(e) => match e.kind() {
// Haven't received enough bytes to decode yet
// TODO: check if this is the only Error variant where we return `Ok(None)`
ErrorKind::UnexpectedEof => {
return Ok(None);
}
_ => return Err(e).map_err(RPCError::from),
ErrorKind::UnexpectedEof => Ok(None),
_ => Err(e).map_err(RPCError::from),
},
}
}
+11 -14
View File
@@ -321,16 +321,13 @@ where
};
// If the response we are sending is an error, report back for handling
match response {
RPCCodedResponse::Error(ref code, ref reason) => {
let err = HandlerErr::Inbound {
id: inbound_id,
proto: inbound_info.protocol,
error: RPCError::ErrorResponse(*code, reason.to_string()),
};
self.pending_errors.push(err);
}
_ => {} // not an error, continue.
if let RPCCodedResponse::Error(ref code, ref reason) = response {
let err = HandlerErr::Inbound {
id: inbound_id,
proto: inbound_info.protocol,
error: RPCError::ErrorResponse(*code, reason.to_string()),
};
self.pending_errors.push(err);
}
if matches!(self.state, HandlerState::Deactivated) {
@@ -661,13 +658,13 @@ where
// if we can't close right now, put the substream back and try again later
Poll::Pending => info.state = InboundState::Idle(substream),
Poll::Ready(res) => {
substreams_to_remove.push(id.clone());
substreams_to_remove.push(*id);
if let Some(ref delay_key) = info.delay_key {
self.inbound_substreams_delay.remove(delay_key);
}
if let Err(error) = res {
self.pending_errors.push(HandlerErr::Inbound {
id: id.clone(),
id: *id,
error,
proto: info.protocol,
});
@@ -697,7 +694,7 @@ where
})
}
if remove {
substreams_to_remove.push(id.clone());
substreams_to_remove.push(*id);
if let Some(ref delay_key) = info.delay_key {
self.inbound_substreams_delay.remove(delay_key);
}
@@ -808,7 +805,7 @@ where
//trace!(self.log, "RPC Response - stream closed by remote");
// drop the stream
let delay_key = &entry.get().delay_key;
let request_id = *&entry.get().req_id;
let request_id = entry.get().req_id;
self.outbound_substreams_delay.remove(delay_key);
entry.remove_entry();
self.update_keep_alive();
+1 -1
View File
@@ -182,7 +182,7 @@ impl ssz::Decode for GoodbyeReason {
}
fn from_ssz_bytes(bytes: &[u8]) -> Result<Self, ssz::DecodeError> {
u64::from_ssz_bytes(bytes).and_then(|n| Ok(n.into()))
u64::from_ssz_bytes(bytes).map(|n| n.into())
}
}
@@ -2,22 +2,25 @@
//! given time. It schedules subscriptions to shard subnets, requests peer discoveries and
//! determines whether attestations should be aggregated and/or passed to the beacon node.
use crate::metrics;
use beacon_chain::{BeaconChain, BeaconChainTypes};
use eth2_libp2p::{types::GossipKind, NetworkGlobals};
use futures::prelude::*;
use hashset_delay::HashSetDelay;
use rand::seq::SliceRandom;
use rest_types::ValidatorSubscription;
use slog::{crit, debug, error, o, trace, warn};
use slot_clock::SlotClock;
use std::collections::VecDeque;
use std::pin::Pin;
use std::sync::Arc;
use std::task::{Context, Poll};
use std::time::{Duration, Instant};
use futures::prelude::*;
use rand::seq::SliceRandom;
use slog::{crit, debug, error, o, trace, warn};
use beacon_chain::{BeaconChain, BeaconChainTypes};
use eth2_libp2p::{types::GossipKind, NetworkGlobals};
use hashset_delay::HashSetDelay;
use rest_types::ValidatorSubscription;
use slot_clock::SlotClock;
use types::{Attestation, EthSpec, Slot, SubnetId};
use crate::metrics;
mod tests;
/// The minimum number of slots ahead that we attempt to discover peers for a subscription. If the
@@ -276,7 +279,7 @@ impl<T: BeaconChainTypes> AttestationService<T> {
attestation: &Attestation<T::EthSpec>,
) -> bool {
let exact_subnet = ExactSubnet {
subnet_id: subnet.clone(),
subnet_id: subnet,
slot: attestation.data.slot,
};
self.aggregate_validators_on_subnet.contains(&exact_subnet)
@@ -360,35 +363,33 @@ impl<T: BeaconChainTypes> AttestationService<T> {
let mut is_duplicate = false;
self.events.iter_mut().for_each(|event| {
match event {
AttServiceMessage::DiscoverPeers {
subnet_id: other_subnet_id,
min_ttl: other_min_ttl,
} => {
if subnet_id == *other_subnet_id {
let other_min_ttl_clone = other_min_ttl.clone();
match (min_ttl, other_min_ttl_clone) {
(Some(min_ttl_instant), Some(other_min_ttl_instant)) =>
// only update the min_ttl if it is greater than the existing min_ttl and a DURATION_DIFFERENCE padding
if let AttServiceMessage::DiscoverPeers {
subnet_id: other_subnet_id,
min_ttl: other_min_ttl,
} = event
{
if subnet_id == *other_subnet_id {
let other_min_ttl_clone = *other_min_ttl;
match (min_ttl, other_min_ttl_clone) {
(Some(min_ttl_instant), Some(other_min_ttl_instant)) =>
// only update the min_ttl if it is greater than the existing min_ttl and a DURATION_DIFFERENCE padding
{
if min_ttl_instant.saturating_duration_since(other_min_ttl_instant)
> DURATION_DIFFERENCE
{
if min_ttl_instant.saturating_duration_since(other_min_ttl_instant)
> DURATION_DIFFERENCE
{
*other_min_ttl = min_ttl;
}
*other_min_ttl = min_ttl;
}
(None, Some(_)) => {} // Keep the current one as it has an actual min_ttl
(Some(min_ttl), None) => {
// Update the request to include a min_ttl.
*other_min_ttl = Some(min_ttl);
}
(None, None) => {} // Duplicate message, do nothing.
}
is_duplicate = true;
return;
(None, Some(_)) => {} // Keep the current one as it has an actual min_ttl
(Some(min_ttl), None) => {
// Update the request to include a min_ttl.
*other_min_ttl = Some(min_ttl);
}
(None, None) => {} // Duplicate message, do nothing.
}
is_duplicate = true;
return;
}
_ => {}
};
});
if !is_duplicate {
@@ -542,8 +543,7 @@ impl<T: BeaconChainTypes> AttestationService<T> {
.gossipsub_subscriptions
.read()
.iter()
.find(|topic| topic.kind() == topic_kind)
.is_some();
.any(|topic| topic.kind() == topic_kind);
if !already_subscribed {
// send a discovery request and a subscription
@@ -735,7 +735,7 @@ impl<T: BeaconChainTypes> Stream for AttestationService<T> {
match self.discover_peers.poll_next_unpin(cx) {
Poll::Ready(Some(Ok(exact_subnet))) => self.handle_discover_peers(exact_subnet),
Poll::Ready(Some(Err(e))) => {
error!(self.log, "Failed to check for peer discovery requests"; "error"=> format ! ("{}", e));
error!(self.log, "Failed to check for peer discovery requests"; "error"=> e);
}
Poll::Ready(None) | Poll::Pending => {}
}
@@ -744,7 +744,7 @@ impl<T: BeaconChainTypes> Stream for AttestationService<T> {
match self.subscriptions.poll_next_unpin(cx) {
Poll::Ready(Some(Ok(exact_subnet))) => self.handle_subscriptions(exact_subnet),
Poll::Ready(Some(Err(e))) => {
error!(self.log, "Failed to check for subnet subscription times"; "error"=> format!("{}", e));
error!(self.log, "Failed to check for subnet subscription times"; "error"=> e);
}
Poll::Ready(None) | Poll::Pending => {}
}
@@ -753,7 +753,7 @@ impl<T: BeaconChainTypes> Stream for AttestationService<T> {
match self.unsubscriptions.poll_next_unpin(cx) {
Poll::Ready(Some(Ok(exact_subnet))) => self.handle_unsubscriptions(exact_subnet),
Poll::Ready(Some(Err(e))) => {
error!(self.log, "Failed to check for subnet unsubscription times"; "error"=> format!("{}", e));
error!(self.log, "Failed to check for subnet unsubscription times"; "error"=> e);
}
Poll::Ready(None) | Poll::Pending => {}
}
@@ -762,7 +762,7 @@ impl<T: BeaconChainTypes> Stream for AttestationService<T> {
match self.random_subnets.poll_next_unpin(cx) {
Poll::Ready(Some(Ok(subnet))) => self.handle_random_subnet_expiry(subnet),
Poll::Ready(Some(Err(e))) => {
error!(self.log, "Failed to check for random subnet cycles"; "error"=> format!("{}", e));
error!(self.log, "Failed to check for random subnet cycles"; "error"=> e);
}
Poll::Ready(None) | Poll::Pending => {}
}
@@ -773,13 +773,13 @@ impl<T: BeaconChainTypes> Stream for AttestationService<T> {
let _ = self.handle_known_validator_expiry();
}
Poll::Ready(Some(Err(e))) => {
error!(self.log, "Failed to check for random subnet cycles"; "error"=> format!("{}", e));
error!(self.log, "Failed to check for random subnet cycles"; "error"=> e);
}
Poll::Ready(None) | Poll::Pending => {}
}
// poll to remove entries on expiration, no need to act on expiration events
if let Poll::Ready(Some(Err(e))) = self.aggregate_validators_on_subnet.poll_next_unpin(cx) {
error!(self.log, "Failed to check for aggregate validator on subnet expirations"; "error"=> format!("{}", e));
error!(self.log, "Failed to check for aggregate validator on subnet expirations"; "error"=> e);
}
// process any generated events
-1
View File
@@ -1,5 +1,4 @@
use eth2_libp2p::Enr;
use rlp;
use std::sync::Arc;
use store::{DBColumn, Error as StoreError, HotColdDB, ItemStore, StoreItem};
use types::{EthSpec, Hash256};
+1
View File
@@ -92,6 +92,7 @@ pub struct NetworkService<T: BeaconChainTypes> {
}
impl<T: BeaconChainTypes> NetworkService<T> {
#[allow(clippy::type_complexity)]
pub fn start(
beacon_chain: Arc<BeaconChain<T>>,
config: &NetworkConfig,
+3 -3
View File
@@ -315,7 +315,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
if let Some(block_request) = self.single_block_lookups.get_mut(&request_id) {
// update the state of the lookup indicating a block was received from the peer
block_request.block_returned = true;
single_block_hash = Some(block_request.hash.clone());
single_block_hash = Some(block_request.hash);
}
if let Some(block_hash) = single_block_hash {
self.single_block_lookup_response(peer_id, block, block_hash);
@@ -498,8 +498,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
if self
.single_block_lookups
.values()
.find(|single_block_request| single_block_request.hash == block_hash)
.is_some()
.any(|single_block_request| single_block_request.hash == block_hash)
{
return;
}
@@ -598,6 +597,7 @@ impl<T: BeaconChainTypes> SyncManager<T> {
// These functions are called in the main poll function to transition the state of the sync
// manager
#[allow(clippy::needless_return)]
/// A new block has been received for a parent lookup query, process it.
fn process_parent_request(&mut self, mut parent_request: ParentRequests<T::EthSpec>) {
// verify the last added block is the parent of the last requested block
@@ -102,12 +102,7 @@ impl PeerSyncInfo {
/// than SLOT_IMPORT_TOLERANCE of our current head.
/// 2) The peer has a greater finalized slot/epoch than our own.
fn is_advanced_peer(&self, remote: &PeerSyncInfo) -> bool {
if remote.head_slot.sub(self.head_slot).as_usize() > SLOT_IMPORT_TOLERANCE
remote.head_slot.sub(self.head_slot).as_usize() > SLOT_IMPORT_TOLERANCE
|| self.finalized_epoch < remote.finalized_epoch
{
true
} else {
false
}
}
}
@@ -104,6 +104,7 @@ pub enum ChainSyncingState {
}
impl<T: BeaconChainTypes> SyncingChain<T> {
#[allow(clippy::too_many_arguments)]
pub fn new(
id: u64,
start_epoch: Epoch,
@@ -257,7 +258,7 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
/// Sends a batch to the batch processor.
fn process_batch(&mut self, mut batch: Batch<T::EthSpec>) {
let downloaded_blocks = std::mem::replace(&mut batch.downloaded_blocks, Vec::new());
let process_id = ProcessId::RangeBatchId(self.id.clone(), batch.id.clone());
let process_id = ProcessId::RangeBatchId(self.id, batch.id);
self.current_processing_batch = Some(batch);
spawn_block_processor(
Arc::downgrade(&self.chain.clone()),
+1 -3
View File
@@ -557,9 +557,7 @@ pub async fn attester_slashing<T: BeaconChainTypes>(
format!("Error while importing attester slashing: {:?}", e)
})
} else {
Err(format!(
"Attester slashing only covers already slashed indices"
))
Err("Attester slashing only covers already slashed indices".to_string())
}
})
.map_err(ApiError::BadRequest)
-1
View File
@@ -2,7 +2,6 @@ use crate::{ApiError, ApiResult, NetworkChannel};
use beacon_chain::{BeaconChain, BeaconChainTypes, StateSkipConfig};
use bls::PublicKeyBytes;
use eth2_libp2p::PubsubMessage;
use hex;
use http::header;
use hyper::{Body, Request};
use itertools::process_results;
+1 -2
View File
@@ -5,7 +5,6 @@ use hyper::{Body, Request};
use rest_types::{Health, SyncingResponse, SyncingStatus};
use std::sync::Arc;
use types::{EthSpec, Slot};
use version;
/// Read the version string from the current Lighthouse build.
pub fn get_version(req: Request<Body>) -> ApiResult {
@@ -43,7 +42,7 @@ pub fn syncing<T: EthSpec>(
}
pub fn get_health(req: Request<Body>) -> ApiResult {
let health = Health::observe().map_err(|e| ApiError::ServerError(e))?;
let health = Health::observe().map_err(ApiError::ServerError)?;
ResponseBuilder::new(&req)?.body_no_ssz(&health)
}
+3 -4
View File
@@ -4,7 +4,6 @@ use clap_utils::BAD_TESTNET_DIR_MESSAGE;
use client::{config::DEFAULT_DATADIR, ClientConfig, ClientGenesis};
use eth2_libp2p::{Enr, Multiaddr};
use eth2_testnet_config::Eth2TestnetConfig;
use hyper;
use slog::{crit, info, Logger};
use ssz::Encode;
use std::fs;
@@ -68,7 +67,7 @@ pub fn get_config<E: EthSpec>(
let mut log_dir = client_config.data_dir.clone();
// remove /beacon from the end
log_dir.pop();
info!(log, "Data directory initialised"; "datadir" => format!("{}",log_dir.into_os_string().into_string().expect("Datadir should be a valid os string")));
info!(log, "Data directory initialised"; "datadir" => log_dir.into_os_string().into_string().expect("Datadir should be a valid os string"));
client_config.spec_constants = spec_constants.into();
client_config.testnet_dir = get_testnet_dir(cli_args);
@@ -181,7 +180,7 @@ pub fn get_config<E: EthSpec>(
resolved_addrs
.next()
.map(|a| a.ip())
.ok_or_else(|| format!("Resolved dns addr contains no entries"))?
.ok_or_else(|| "Resolved dns addr contains no entries".to_string())?
} else {
return Err(format!("Failed to parse enr-address: {}", enr_address));
};
@@ -406,7 +405,7 @@ pub fn get_eth2_testnet_config<E: EthSpec>(
} else {
Eth2TestnetConfig::hard_coded()
.map_err(|e| format!("Error parsing hardcoded testnet: {}", e))?
.ok_or_else(|| format!("{}", BAD_TESTNET_DIR_MESSAGE))
.ok_or_else(|| BAD_TESTNET_DIR_MESSAGE.to_string())
}
}
+1 -1
View File
@@ -126,7 +126,7 @@ impl<E: EthSpec> ProductionBeaconNode<E> {
let builder = builder
.build_beacon_chain()?
.network(&mut client_config.network)?
.network(&client_config.network)?
.notifier()?;
let builder = if client_config.rest_api.enabled {
+1
View File
@@ -381,6 +381,7 @@ pub fn store_updated_vector<F: Field<E>, E: EthSpec, S: KeyValueStore<E>>(
Ok(())
}
#[allow(clippy::too_many_arguments)]
fn store_range<F, E, S, I>(
_: F,
range: I,
+1 -1
View File
@@ -78,7 +78,7 @@ impl SimpleForwardsBlockRootsIterator {
.collect::<Vec<_>>()
},
)?;
Ok(Self { values: values })
Ok(Self { values })
}
}
+2 -2
View File
@@ -77,7 +77,7 @@ impl<E: EthSpec> KeyValueStore<E> for LevelDB<E> {
}
fn sync(&self) -> Result<(), Error> {
self.put_bytes_sync("sync", "sync".as_bytes(), "sync".as_bytes())
self.put_bytes_sync("sync", b"sync", b"sync")
}
/// Retrieve some bytes in `column` with `key`.
@@ -108,7 +108,7 @@ impl<E: EthSpec> KeyValueStore<E> for LevelDB<E> {
self.db
.get(self.read_options(), BytesKey::from_vec(column_key))
.map_err(Into::into)
.and_then(|val| Ok(val.is_some()))
.map(|val| val.is_some())
}
/// Removes `key` from `column`.
@@ -75,7 +75,7 @@ impl<T: EthSpec> PartialBeaconState<T> {
genesis_time: s.genesis_time,
genesis_validators_root: s.genesis_validators_root,
slot: s.slot,
fork: s.fork.clone(),
fork: s.fork,
// History
latest_block_header: s.latest_block_header.clone(),
@@ -107,9 +107,9 @@ impl<T: EthSpec> PartialBeaconState<T> {
// Finality
justification_bits: s.justification_bits.clone(),
previous_justified_checkpoint: s.previous_justified_checkpoint.clone(),
current_justified_checkpoint: s.current_justified_checkpoint.clone(),
finalized_checkpoint: s.finalized_checkpoint.clone(),
previous_justified_checkpoint: s.previous_justified_checkpoint,
current_justified_checkpoint: s.current_justified_checkpoint,
finalized_checkpoint: s.finalized_checkpoint,
}
}