diff --git a/beacon_node/beacon_chain/src/beacon_chain.rs b/beacon_node/beacon_chain/src/beacon_chain.rs index 600c453fd..a22f4179e 100644 --- a/beacon_node/beacon_chain/src/beacon_chain.rs +++ b/beacon_node/beacon_chain/src/beacon_chain.rs @@ -497,21 +497,17 @@ where } else { // If the current head block is not from this slot, use the slot from the previous // epoch. - let root = *self.state.read().get_block_root( + *self.state.read().get_block_root( current_epoch_start_slot - self.spec.slots_per_epoch, &self.spec, - )?; - - root + )? } } else { // If we're not on the first slot of the epoch. - let root = *self + *self .state .read() - .get_block_root(current_epoch_start_slot, &self.spec)?; - - root + .get_block_root(current_epoch_start_slot, &self.spec)? }; Ok(AttestationData { diff --git a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs index 33c12d7c7..aeb734a4e 100644 --- a/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs +++ b/beacon_node/beacon_chain/test_harness/src/beacon_chain_harness.rs @@ -211,9 +211,8 @@ impl BeaconChainHarness { // Ensure the validators slot clock is accurate. self.validators[proposer].set_slot(present_slot); - let block = self.validators[proposer].produce_block().unwrap(); - block + self.validators[proposer].produce_block().unwrap() } /// Advances the chain with a BeaconBlock and attestations from all validators. @@ -245,7 +244,7 @@ impl BeaconChainHarness { .for_each(|(i, attestation)| { self.beacon_chain .process_attestation(attestation.clone()) - .expect(&format!("Attestation {} invalid: {:?}", i, attestation)); + .unwrap_or_else(|_| panic!("Attestation {} invalid: {:?}", i, attestation)); }); debug!("Attestations processed."); diff --git a/beacon_node/beacon_chain/test_harness/src/test_case/state_check.rs b/beacon_node/beacon_chain/test_harness/src/test_case/state_check.rs index 7ac33c86c..c6bdf8978 100644 --- a/beacon_node/beacon_chain/test_harness/src/test_case/state_check.rs +++ b/beacon_node/beacon_chain/test_harness/src/test_case/state_check.rs @@ -52,6 +52,7 @@ impl StateCheck { /// # Panics /// /// Panics with an error message if any test fails. + #[allow(clippy::cyclomatic_complexity)] pub fn assert_valid(&self, state: &BeaconState, spec: &ChainSpec) { let state_epoch = state.slot.epoch(spec.slots_per_epoch); diff --git a/beacon_node/beacon_chain/test_harness/src/validator_harness/direct_beacon_node.rs b/beacon_node/beacon_chain/test_harness/src/validator_harness/direct_beacon_node.rs index 2d2b9e84d..d47fd44b9 100644 --- a/beacon_node/beacon_chain/test_harness/src/validator_harness/direct_beacon_node.rs +++ b/beacon_node/beacon_chain/test_harness/src/validator_harness/direct_beacon_node.rs @@ -14,9 +14,6 @@ use slot_clock::SlotClock; use std::sync::Arc; use types::{AttestationData, BeaconBlock, FreeAttestation, Signature, Slot}; -// mod attester; -// mod producer; - /// Connect directly to a borrowed `BeaconChain` instance so an attester/producer can request/submit /// blocks/attestations. /// @@ -42,11 +39,6 @@ impl DirectBeaconNode { pub fn last_published_block(&self) -> Option { Some(self.published_blocks.read().last()?.clone()) } - - /// Get the last published attestation (if any). - pub fn last_published_free_attestation(&self) -> Option { - Some(self.published_attestations.read().last()?.clone()) - } } impl AttesterBeaconNode for DirectBeaconNode { diff --git a/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs b/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs index 91a679463..815d4b23b 100644 --- a/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs +++ b/beacon_node/beacon_chain/test_harness/src/validator_harness/mod.rs @@ -2,8 +2,7 @@ mod direct_beacon_node; mod direct_duties; mod local_signer; -use attester::PollOutcome as AttestationPollOutcome; -use attester::{Attester, Error as AttestationPollError}; +use attester::Attester; use beacon_chain::BeaconChain; use block_proposer::PollOutcome as BlockPollOutcome; use block_proposer::{BlockProducer, Error as BlockPollError}; @@ -14,7 +13,7 @@ use fork_choice::BitwiseLMDGhost; use local_signer::LocalSigner; use slot_clock::TestingSlotClock; use std::sync::Arc; -use types::{BeaconBlock, ChainSpec, FreeAttestation, Keypair, Slot}; +use types::{BeaconBlock, ChainSpec, Keypair, Slot}; #[derive(Debug, PartialEq)] pub enum BlockProduceError { @@ -22,12 +21,6 @@ pub enum BlockProduceError { PollError(BlockPollError), } -#[derive(Debug, PartialEq)] -pub enum AttestationProduceError { - DidNotProduce(AttestationPollOutcome), - PollError(AttestationPollError), -} - type TestingBlockProducer = BlockProducer< TestingSlotClock, DirectBeaconNode>, @@ -117,21 +110,6 @@ impl ValidatorHarness { .expect("Unable to obtain produced block.")) } - /// Run the `poll` function on the `Attester` and produce a `FreeAttestation`. - /// - /// An error is returned if the attester refuses to attest. - pub fn produce_free_attestation(&mut self) -> Result { - match self.attester.poll() { - Ok(AttestationPollOutcome::AttestationProduced(_)) => {} - Ok(outcome) => return Err(AttestationProduceError::DidNotProduce(outcome)), - Err(error) => return Err(AttestationProduceError::PollError(error)), - }; - Ok(self - .beacon_node - .last_published_free_attestation() - .expect("Unable to obtain produced attestation.")) - } - /// Set the validators slot clock to the specified slot. /// /// The validators slot clock will always read this value until it is set to something else. diff --git a/beacon_node/client/src/lib.rs b/beacon_node/client/src/lib.rs index 6b4277c26..6a21493b1 100644 --- a/beacon_node/client/src/lib.rs +++ b/beacon_node/client/src/lib.rs @@ -25,9 +25,9 @@ use tokio::timer::Interval; /// sub-services in multiple threads. pub struct Client { /// Configuration for the lighthouse client. - config: ClientConfig, + _config: ClientConfig, /// The beacon chain for the running client. - beacon_chain: Arc>, + _beacon_chain: Arc>, /// Reference to the network service. pub network: Arc, /// Signal to terminate the RPC server. @@ -90,17 +90,18 @@ impl Client { network_logger, )?; - let mut rpc_exit_signal = None; // spawn the RPC server - if config.rpc_conf.enabled { - rpc_exit_signal = Some(rpc::start_server( + let rpc_exit_signal = if config.rpc_conf.enabled { + Some(rpc::start_server( &config.rpc_conf, executor, network_send, beacon_chain.clone(), &log, - )); - } + )) + } else { + None + }; let (slot_timer_exit_signal, exit) = exit_future::signal(); if let Ok(Some(duration_to_next_slot)) = beacon_chain.slot_clock.duration_to_next_slot() { @@ -129,8 +130,8 @@ impl Client { } Ok(Client { - config, - beacon_chain, + _config: config, + _beacon_chain: beacon_chain, rpc_exit_signal, slot_timer_exit_signal: Some(slot_timer_exit_signal), log, diff --git a/beacon_node/client/src/notifier.rs b/beacon_node/client/src/notifier.rs index 1a5ecbb53..aa1e43c3c 100644 --- a/beacon_node/client/src/notifier.rs +++ b/beacon_node/client/src/notifier.rs @@ -14,7 +14,7 @@ pub fn run(client: &Client, executor: TaskExecutor, exit: Exi // notification heartbeat let interval = Interval::new(Instant::now(), Duration::from_secs(5)); - let log = client.log.new(o!("Service" => "Notifier")); + let _log = client.log.new(o!("Service" => "Notifier")); // TODO: Debugging only let counter = Arc::new(Mutex::new(0)); diff --git a/beacon_node/eth2-libp2p/src/behaviour.rs b/beacon_node/eth2-libp2p/src/behaviour.rs index 88bfd0042..e1112e6ff 100644 --- a/beacon_node/eth2-libp2p/src/behaviour.rs +++ b/beacon_node/eth2-libp2p/src/behaviour.rs @@ -65,17 +65,11 @@ impl NetworkBehaviourEventProcess {} + GossipsubEvent::Subscribed { .. } => {} + GossipsubEvent::Unsubscribed { .. } => {} } } } @@ -110,7 +104,8 @@ impl NetworkBehaviourEventProcess {} IdentifyEvent::SendBack { .. } => {} @@ -183,12 +178,12 @@ impl Behaviour { pub enum BehaviourEvent { RPC(PeerId, RPCEvent), PeerDialed(PeerId), - Identified(PeerId, IdentifyInfo), + Identified(PeerId, Box), // TODO: This is a stub at the moment GossipMessage { source: PeerId, topics: Vec, - message: PubsubMessage, + message: Box, }, } diff --git a/beacon_node/eth2-libp2p/src/rpc/mod.rs b/beacon_node/eth2-libp2p/src/rpc/mod.rs index 08573aa52..57d7dadbe 100644 --- a/beacon_node/eth2-libp2p/src/rpc/mod.rs +++ b/beacon_node/eth2-libp2p/src/rpc/mod.rs @@ -26,7 +26,7 @@ pub struct Rpc { /// Pins the generic substream. marker: PhantomData, /// Slog logger for RPC behaviour. - log: slog::Logger, + _log: slog::Logger, } impl Rpc { @@ -35,7 +35,7 @@ impl Rpc { Rpc { events: Vec::new(), marker: PhantomData, - log, + _log: log, } } @@ -65,7 +65,7 @@ where fn inject_connected(&mut self, peer_id: PeerId, connected_point: ConnectedPoint) { // if initialised the connection, report this upwards to send the HELLO request - if let ConnectedPoint::Dialer { address: _ } = connected_point { + if let ConnectedPoint::Dialer { .. } = connected_point { self.events.push(NetworkBehaviourAction::GenerateEvent( RPCMessage::PeerDialed(peer_id), )); diff --git a/beacon_node/eth2-libp2p/src/rpc/protocol.rs b/beacon_node/eth2-libp2p/src/rpc/protocol.rs index 314be1037..5c1c47fbf 100644 --- a/beacon_node/eth2-libp2p/src/rpc/protocol.rs +++ b/beacon_node/eth2-libp2p/src/rpc/protocol.rs @@ -31,7 +31,7 @@ impl Default for RPCProtocol { } /// A monotonic counter for ordering `RPCRequest`s. -#[derive(Debug, Clone, PartialEq, Default)] +#[derive(Debug, Clone, Default)] pub struct RequestId(u64); impl RequestId { @@ -48,6 +48,12 @@ impl RequestId { impl Eq for RequestId {} +impl PartialEq for RequestId { + fn eq(&self, other: &RequestId) -> bool { + self.0 == other.0 + } +} + impl Hash for RequestId { fn hash(&self, state: &mut H) { self.0.hash(state); @@ -104,17 +110,15 @@ impl UpgradeInfo for RPCEvent { } } +type FnDecodeRPCEvent = fn(Vec, ()) -> Result; + impl InboundUpgrade for RPCProtocol where TSocket: AsyncRead + AsyncWrite, { type Output = RPCEvent; type Error = DecodeError; - type Future = upgrade::ReadOneThen< - upgrade::Negotiated, - (), - fn(Vec, ()) -> Result, - >; + type Future = upgrade::ReadOneThen, (), FnDecodeRPCEvent>; fn upgrade_inbound(self, socket: upgrade::Negotiated, _: Self::Info) -> Self::Future { upgrade::read_one_then(socket, MAX_READ_SIZE, (), |packet, ()| Ok(decode(packet)?)) diff --git a/beacon_node/eth2-libp2p/src/service.rs b/beacon_node/eth2-libp2p/src/service.rs index f52d11ef1..07a36e408 100644 --- a/beacon_node/eth2-libp2p/src/service.rs +++ b/beacon_node/eth2-libp2p/src/service.rs @@ -19,13 +19,16 @@ use std::io::{Error, ErrorKind}; use std::time::Duration; use types::{TopicBuilder, TopicHash}; +type Libp2pStream = Boxed<(PeerId, StreamMuxerBox), Error>; +type Libp2pBehaviour = Behaviour>; + /// The configuration and state of the libp2p components for the beacon node. pub struct Service { /// The libp2p Swarm handler. //TODO: Make this private - pub swarm: Swarm, Behaviour>>, + pub swarm: Swarm, /// This node's PeerId. - local_peer_id: PeerId, + _local_peer_id: PeerId, /// The libp2p logger handle. pub log: slog::Logger, } @@ -89,7 +92,7 @@ impl Service { info!(log, "Subscribed to topics: {:?}", subscribed_topics); Ok(Service { - local_peer_id, + _local_peer_id: local_peer_id, swarm, log, }) @@ -179,11 +182,11 @@ pub enum Libp2pEvent { /// Initiated the connection to a new peer. PeerDialed(PeerId), /// Received information about a peer on the network. - Identified(PeerId, IdentifyInfo), + Identified(PeerId, Box), /// Received pubsub message. PubsubMessage { source: PeerId, topics: Vec, - message: PubsubMessage, + message: Box, }, } diff --git a/beacon_node/network/src/message_handler.rs b/beacon_node/network/src/message_handler.rs index 098a5b4bf..c5ba25f82 100644 --- a/beacon_node/network/src/message_handler.rs +++ b/beacon_node/network/src/message_handler.rs @@ -41,7 +41,7 @@ pub enum HandlerMessage { /// An RPC response/request has been received. RPC(PeerId, RPCEvent), /// A gossip message has been received. - PubsubMessage(PeerId, PubsubMessage), + PubsubMessage(PeerId, Box), } impl MessageHandler { @@ -93,7 +93,7 @@ impl MessageHandler { } // we have received an RPC message request/response HandlerMessage::PubsubMessage(peer_id, gossip) => { - self.handle_gossip(peer_id, gossip); + self.handle_gossip(peer_id, *gossip); } //TODO: Handle all messages _ => {} diff --git a/beacon_node/network/src/service.rs b/beacon_node/network/src/service.rs index aee7eb466..06e3f7af9 100644 --- a/beacon_node/network/src/service.rs +++ b/beacon_node/network/src/service.rs @@ -17,7 +17,7 @@ use types::Topic; /// Service that handles communication between internal services and the eth2_libp2p network service. pub struct Service { //libp2p_service: Arc>, - libp2p_exit: oneshot::Sender<()>, + _libp2p_exit: oneshot::Sender<()>, network_send: crossbeam_channel::Sender, //message_handler: MessageHandler, //message_handler_send: Sender, @@ -54,7 +54,7 @@ impl Service { log, )?; let network_service = Service { - libp2p_exit, + _libp2p_exit: libp2p_exit, network_send: network_send.clone(), }; @@ -131,9 +131,7 @@ fn network_service( ); } Libp2pEvent::PubsubMessage { - source, - topics: _, - message, + source, message, .. } => { //TODO: Decide if we need to propagate the topic upwards. (Potentially for //attestations) @@ -167,7 +165,7 @@ fn network_service( } Ok(NetworkMessage::Publish { topics, message }) => { debug!(log, "Sending pubsub message on topics {:?}", topics); - libp2p_service.swarm.publish(topics, message); + libp2p_service.swarm.publish(topics, *message); } Err(TryRecvError::Empty) => break, Err(TryRecvError::Disconnected) => { @@ -190,7 +188,7 @@ pub enum NetworkMessage { /// Publish a message to pubsub mechanism. Publish { topics: Vec, - message: PubsubMessage, + message: Box, }, } diff --git a/beacon_node/network/src/sync/simple_sync.rs b/beacon_node/network/src/sync/simple_sync.rs index 9a1e51bdd..824458b89 100644 --- a/beacon_node/network/src/sync/simple_sync.rs +++ b/beacon_node/network/src/sync/simple_sync.rs @@ -65,7 +65,7 @@ pub enum PeerStatus { } impl PeerStatus { - pub fn should_handshake(&self) -> bool { + pub fn should_handshake(self) -> bool { match self { PeerStatus::DifferentNetworkId => false, PeerStatus::FinalizedEpochNotInChain => false, diff --git a/beacon_node/rpc/src/attestation.rs b/beacon_node/rpc/src/attestation.rs index abef49df1..3abfdac59 100644 --- a/beacon_node/rpc/src/attestation.rs +++ b/beacon_node/rpc/src/attestation.rs @@ -43,9 +43,9 @@ impl AttestationService for AttestationServiceInstance { let f = sink .fail(RpcStatus::new( RpcStatusCode::OutOfRange, - Some(format!( - "AttestationData request for a slot that is in the future." - )), + Some( + "AttestationData request for a slot that is in the future.".to_string(), + ), )) .map_err(move |e| { error!(log_clone, "Failed to reply with failure {:?}: {:?}", req, e) @@ -58,9 +58,7 @@ impl AttestationService for AttestationServiceInstance { let f = sink .fail(RpcStatus::new( RpcStatusCode::InvalidArgument, - Some(format!( - "AttestationData request for a slot that is in the past." - )), + Some("AttestationData request for a slot that is in the past.".to_string()), )) .map_err(move |e| { error!(log_clone, "Failed to reply with failure {:?}: {:?}", req, e) diff --git a/beacon_node/rpc/src/beacon_block.rs b/beacon_node/rpc/src/beacon_block.rs index 0b90f774a..450bcbca1 100644 --- a/beacon_node/rpc/src/beacon_block.rs +++ b/beacon_node/rpc/src/beacon_block.rs @@ -43,7 +43,7 @@ impl BeaconBlockService for BeaconBlockServiceInstance { let f = sink .fail(RpcStatus::new( RpcStatusCode::InvalidArgument, - Some(format!("Invalid randao reveal signature")), + Some("Invalid randao reveal signature".to_string()), )) .map_err(move |e| warn!(log_clone, "failed to reply {:?}: {:?}", req, e)); return ctx.spawn(f); @@ -114,7 +114,7 @@ impl BeaconBlockService for BeaconBlockServiceInstance { self.network_chan .send(NetworkMessage::Publish { topics: vec![topic], - message, + message: Box::new(message), }) .unwrap_or_else(|e| { error!( diff --git a/beacon_node/rpc/src/beacon_node.rs b/beacon_node/rpc/src/beacon_node.rs index c92ab6616..a9b8df343 100644 --- a/beacon_node/rpc/src/beacon_node.rs +++ b/beacon_node/rpc/src/beacon_node.rs @@ -24,7 +24,7 @@ impl BeaconNodeService for BeaconNodeServiceInstance { // get the chain state let state = self.chain.get_state(); let state_fork = state.fork.clone(); - let genesis_time = state.genesis_time.clone(); + let genesis_time = state.genesis_time; // build the rpc fork struct let mut fork = Fork::new(); @@ -35,7 +35,7 @@ impl BeaconNodeService for BeaconNodeServiceInstance { node_info.set_fork(fork); node_info.set_genesis_time(genesis_time); node_info.set_genesis_slot(self.chain.get_spec().genesis_slot.as_u64()); - node_info.set_chain_id(self.chain.get_spec().chain_id as u32); + node_info.set_chain_id(u32::from(self.chain.get_spec().chain_id)); // send the node_info the requester let error_log = self.log.clone(); diff --git a/eth2/state_processing/tests/tests.rs b/eth2/state_processing/tests/tests.rs index 12b78c08f..1394eeba0 100644 --- a/eth2/state_processing/tests/tests.rs +++ b/eth2/state_processing/tests/tests.rs @@ -82,8 +82,7 @@ fn run_state_transition_tests_small() { for block in test_case.blocks.iter() { while block.slot > state.slot { let latest_block_header = state.latest_block_header.clone(); - let res = per_slot_processing(&mut state, &latest_block_header, &test_case.config) - .unwrap(); + per_slot_processing(&mut state, &latest_block_header, &test_case.config).unwrap(); } if test_case.verify_signatures { let res = per_block_processing(&mut state, &block, &test_case.config); diff --git a/eth2/types/src/test_utils/testing_beacon_state_builder.rs b/eth2/types/src/test_utils/testing_beacon_state_builder.rs index 445debae7..9bdd9e149 100644 --- a/eth2/types/src/test_utils/testing_beacon_state_builder.rs +++ b/eth2/types/src/test_utils/testing_beacon_state_builder.rs @@ -6,8 +6,7 @@ use dirs; use log::debug; use rayon::prelude::*; use std::path::{Path, PathBuf}; -//TODO: testing only -use std::time::{Duration, SystemTime}; +use std::time::SystemTime; pub const KEYPAIRS_FILE: &str = "keypairs.raw_keypairs"; diff --git a/eth2/utils/bls/src/keypair.rs b/eth2/utils/bls/src/keypair.rs index 2f0e794a6..75960a47d 100644 --- a/eth2/utils/bls/src/keypair.rs +++ b/eth2/utils/bls/src/keypair.rs @@ -3,7 +3,7 @@ use serde_derive::{Deserialize, Serialize}; use std::fmt; use std::hash::{Hash, Hasher}; -#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Debug, Clone, Eq, Serialize, Deserialize)] pub struct Keypair { pub sk: SecretKey, pub pk: PublicKey, @@ -22,6 +22,12 @@ impl Keypair { } } +impl PartialEq for Keypair { + fn eq(&self, other: &Keypair) -> bool { + self == other + } +} + impl Hash for Keypair { /// Note: this is distinct from consensus serialization, it will produce a different hash. /// diff --git a/validator_client/src/config.rs b/validator_client/src/config.rs index 3d426e8c7..903da047e 100644 --- a/validator_client/src/config.rs +++ b/validator_client/src/config.rs @@ -81,6 +81,7 @@ impl Config { } /// Try to load keys from validator_dir, returning None if none are found or an error. + #[allow(dead_code)] pub fn fetch_keys(&self, log: &slog::Logger) -> Option> { let key_pairs: Vec = fs::read_dir(&self.data_dir) .unwrap() @@ -144,6 +145,7 @@ impl Config { } /// Saves a keypair to a file inside the appropriate validator directory. Returns the saved path filename. + #[allow(dead_code)] pub fn save_key(&self, key: &Keypair) -> Result { let validator_config_path = self.data_dir.join(key.identifier()); let key_path = validator_config_path.join(DEFAULT_PRIVATE_KEY_FILENAME); diff --git a/validator_client/src/service.rs b/validator_client/src/service.rs index ce19c23e9..a8a8325dd 100644 --- a/validator_client/src/service.rs +++ b/validator_client/src/service.rs @@ -29,7 +29,7 @@ use std::sync::RwLock; use std::time::{Duration, Instant, SystemTime}; use tokio::prelude::*; use tokio::runtime::Builder; -use tokio::timer::{Delay, Interval}; +use tokio::timer::Interval; use tokio_timer::clock::Clock; use types::test_utils::generate_deterministic_keypairs; use types::{ChainSpec, Epoch, Fork, Slot};