Apply clippy fixes
This commit is contained in:
parent
a0d0d297d9
commit
f04f4f0b98
|
@ -0,0 +1 @@
|
|||
type-complexity-threshold = 999999
|
|
@ -7,7 +7,6 @@ mod tests;
|
|||
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use chrono::{DateTime, TimeZone, Utc};
|
||||
use hex;
|
||||
use std::{fmt, io};
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
|
@ -31,6 +31,8 @@ use crate::types::{BlockHeight, LockTime};
|
|||
/// internally by different enum variants. Because we checkpoint on Sapling
|
||||
/// activation, we do not parse any pre-Sapling transaction types.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
// XXX consider boxing the Optional fields of V4 txs
|
||||
#[allow(clippy::large_enum_variant)]
|
||||
pub enum Transaction {
|
||||
/// A fully transparent transaction (`version = 1`).
|
||||
V1 {
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
use std::fmt;
|
||||
|
||||
use hex;
|
||||
|
||||
#[cfg(test)]
|
||||
use proptest_derive::Arbitrary;
|
||||
|
||||
|
|
|
@ -105,8 +105,8 @@ impl<P: ZkSnarkProof + Arbitrary + 'static> Arbitrary for JoinSplitData<P> {
|
|||
)
|
||||
.prop_map(|(first, rest, pub_key_bytes, sig_bytes)| {
|
||||
return Self {
|
||||
first: first,
|
||||
rest: rest,
|
||||
first,
|
||||
rest,
|
||||
pub_key: ed25519_zebra::PublicKeyBytes::from(pub_key_bytes),
|
||||
sig: ed25519_zebra::Signature::from({
|
||||
let mut b = [0u8; 64];
|
||||
|
|
|
@ -12,8 +12,8 @@ use crate::types::Script;
|
|||
|
||||
use super::*;
|
||||
|
||||
const OVERWINTER_VERSION_GROUP_ID: u32 = 0x03C48270;
|
||||
const SAPLING_VERSION_GROUP_ID: u32 = 0x892F2085;
|
||||
const OVERWINTER_VERSION_GROUP_ID: u32 = 0x03C4_8270;
|
||||
const SAPLING_VERSION_GROUP_ID: u32 = 0x892F_2085;
|
||||
|
||||
impl ZcashSerialize for OutPoint {
|
||||
fn zcash_serialize<W: io::Write>(&self, mut writer: W) -> Result<(), SerializationError> {
|
||||
|
@ -373,14 +373,14 @@ impl ZcashDeserialize for Transaction {
|
|||
let joinsplit_data = OptV4JSD::zcash_deserialize(&mut reader)?;
|
||||
|
||||
use futures::future::Either::*;
|
||||
let shielded_data = if shielded_spends.len() > 0 {
|
||||
let shielded_data = if !shielded_spends.is_empty() {
|
||||
Some(ShieldedData {
|
||||
first: Left(shielded_spends.remove(0)),
|
||||
rest_spends: shielded_spends,
|
||||
rest_outputs: shielded_outputs,
|
||||
binding_sig: reader.read_64_bytes()?.into(),
|
||||
})
|
||||
} else if shielded_outputs.len() > 0 {
|
||||
} else if !shielded_outputs.is_empty() {
|
||||
Some(ShieldedData {
|
||||
first: Right(shielded_outputs.remove(0)),
|
||||
rest_spends: shielded_spends,
|
||||
|
|
|
@ -53,8 +53,8 @@ impl Arbitrary for SpendDescription {
|
|||
.prop_map(
|
||||
|(cv_bytes, anchor, nullifier_bytes, rpk_bytes, proof, sig_bytes)| {
|
||||
return Self {
|
||||
anchor,
|
||||
cv: cv_bytes,
|
||||
anchor: anchor,
|
||||
nullifier: nullifier_bytes,
|
||||
rk: redjubjub::PublicKeyBytes::from(rpk_bytes),
|
||||
zkproof: proof,
|
||||
|
@ -186,14 +186,14 @@ impl Arbitrary for ShieldedData {
|
|||
vec(any::<OutputDescription>(), 0..10),
|
||||
vec(any::<u8>(), 64),
|
||||
)
|
||||
.prop_map(|(first, rest_spends, rest_outputs, sig)| {
|
||||
.prop_map(|(first, rest_spends, rest_outputs, sig_bytes)| {
|
||||
return Self {
|
||||
first: first,
|
||||
rest_spends: rest_spends,
|
||||
rest_outputs: rest_outputs,
|
||||
first,
|
||||
rest_spends,
|
||||
rest_outputs,
|
||||
binding_sig: redjubjub::Signature::from({
|
||||
let mut b = [0u8; 64];
|
||||
b.copy_from_slice(sig.as_slice());
|
||||
b.copy_from_slice(sig_bytes.as_slice());
|
||||
b
|
||||
}),
|
||||
};
|
||||
|
|
|
@ -7,7 +7,6 @@ use std::{
|
|||
|
||||
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
|
||||
use chrono::{DateTime, TimeZone, Utc};
|
||||
use hex;
|
||||
|
||||
#[cfg(test)]
|
||||
use proptest_derive::Arbitrary;
|
||||
|
|
|
@ -24,6 +24,7 @@ pub struct AddressBook {
|
|||
span: Span,
|
||||
}
|
||||
|
||||
#[allow(clippy::len_without_is_empty)]
|
||||
impl AddressBook {
|
||||
/// Construct an `AddressBook` with the given [`tracing::Span`].
|
||||
pub fn new(span: Span) -> AddressBook {
|
||||
|
@ -76,17 +77,14 @@ impl AddressBook {
|
|||
#[cfg(test)]
|
||||
self.assert_consistency();
|
||||
|
||||
match self.get_by_addr(new.addr) {
|
||||
Some(prev) => {
|
||||
if prev.last_seen > new.last_seen {
|
||||
return;
|
||||
} else {
|
||||
self.by_time
|
||||
.take(&prev)
|
||||
.expect("cannot have by_addr entry without by_time entry");
|
||||
}
|
||||
if let Some(prev) = self.get_by_addr(new.addr) {
|
||||
if prev.last_seen > new.last_seen {
|
||||
return;
|
||||
} else {
|
||||
self.by_time
|
||||
.take(&prev)
|
||||
.expect("cannot have by_addr entry without by_time entry");
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
self.by_time.insert(new);
|
||||
self.by_addr.insert(new.addr, (new.last_seen, new.services));
|
||||
|
@ -115,7 +113,7 @@ impl AddressBook {
|
|||
pub fn is_potentially_connected(&self, addr: &SocketAddr) -> bool {
|
||||
let _guard = self.span.enter();
|
||||
match self.by_addr.get(addr) {
|
||||
None => return false,
|
||||
None => false,
|
||||
Some((ref last_seen, _)) => last_seen > &AddressBook::cutoff_time(),
|
||||
}
|
||||
}
|
||||
|
@ -192,9 +190,9 @@ impl<'a> Iterator for Drain<'a> {
|
|||
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
let next_item = if self.newest_first {
|
||||
self.book.by_time.iter().next()?.clone()
|
||||
*self.book.by_time.iter().next()?
|
||||
} else {
|
||||
self.book.by_time.iter().rev().next()?.clone()
|
||||
*self.book.by_time.iter().rev().next()?
|
||||
};
|
||||
self.book.by_time.remove(&next_item);
|
||||
self.book
|
||||
|
|
|
@ -32,7 +32,7 @@ pub const HEARTBEAT_INTERVAL: Duration = Duration::from_secs(60);
|
|||
pub const TIMESTAMP_TRUNCATION_SECONDS: i64 = 30 * 60;
|
||||
|
||||
/// The User-Agent string provided by the node.
|
||||
pub const USER_AGENT: &'static str = "🦓Zebra v2.0.0-alpha.0🦓";
|
||||
pub const USER_AGENT: &str = "🦓Zebra v2.0.0-alpha.0🦓";
|
||||
|
||||
/// The Zcash network protocol version used on mainnet.
|
||||
pub const CURRENT_VERSION: Version = Version(170_007);
|
||||
|
|
|
@ -11,7 +11,7 @@ pub enum Network {
|
|||
|
||||
impl Network {
|
||||
/// Get the magic value associated to this `Network`.
|
||||
pub fn magic(&self) -> Magic {
|
||||
pub fn magic(self) -> Magic {
|
||||
match self {
|
||||
Network::Mainnet => magics::MAINNET,
|
||||
Network::Testnet => magics::TESTNET,
|
||||
|
|
|
@ -39,7 +39,7 @@ impl Service<Request> for Client {
|
|||
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
||||
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
if let Err(_) = ready!(self.server_tx.poll_ready(cx)) {
|
||||
if ready!(self.server_tx.poll_ready(cx)).is_err() {
|
||||
Poll::Ready(Err(self
|
||||
.error_slot
|
||||
.try_get_error()
|
||||
|
|
|
@ -347,9 +347,8 @@ where
|
|||
}
|
||||
};
|
||||
|
||||
match req {
|
||||
Some(req) => self.drive_peer_request(req).await,
|
||||
None => {}
|
||||
if let Some(req) = req {
|
||||
self.drive_peer_request(req).await
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -362,7 +361,7 @@ where
|
|||
trace!(?req);
|
||||
use tower::{load_shed::error::Overloaded, ServiceExt};
|
||||
|
||||
if let Err(_) = self.svc.ready().await {
|
||||
if self.svc.ready().await.is_err() {
|
||||
// Treat all service readiness errors as Overloaded
|
||||
self.fail_with(PeerError::Overloaded);
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ impl ErrorSlot {
|
|||
.lock()
|
||||
.expect("error mutex should be unpoisoned")
|
||||
.as_ref()
|
||||
.map(|e| e.clone())
|
||||
.cloned()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,7 +72,7 @@ impl ErrorSlot {
|
|||
pub enum HandshakeError {
|
||||
/// The remote peer sent an unexpected message during the handshake.
|
||||
#[error("The remote peer sent an unexpected message: {0:?}")]
|
||||
UnexpectedMessage(crate::protocol::external::Message),
|
||||
UnexpectedMessage(Box<crate::protocol::external::Message>),
|
||||
/// The peer connector detected handshake nonce reuse, possibly indicating self-connection.
|
||||
#[error("Detected nonce reuse, possible self-connection")]
|
||||
NonceReuse,
|
||||
|
|
|
@ -102,7 +102,7 @@ where
|
|||
let internal_service = self.internal_service.clone();
|
||||
let timestamp_collector = self.timestamp_collector.clone();
|
||||
let user_agent = self.config.user_agent.clone();
|
||||
let network = self.config.network.clone();
|
||||
let network = self.config.network;
|
||||
|
||||
let fut = async move {
|
||||
info!("connecting to remote peer");
|
||||
|
@ -149,17 +149,18 @@ where
|
|||
{
|
||||
(nonce, services)
|
||||
} else {
|
||||
return Err(HandshakeError::UnexpectedMessage(remote_msg));
|
||||
return Err(HandshakeError::UnexpectedMessage(Box::new(remote_msg)));
|
||||
};
|
||||
|
||||
// Check for nonce reuse, indicating self-connection.
|
||||
if {
|
||||
let nonce_reuse = {
|
||||
let mut locked_nonces = nonces.lock().expect("mutex should be unpoisoned");
|
||||
let nonce_reuse = locked_nonces.contains(&remote_nonce);
|
||||
// Regardless of whether we observed nonce reuse, clean up the nonce set.
|
||||
locked_nonces.remove(&local_nonce);
|
||||
nonce_reuse
|
||||
} {
|
||||
};
|
||||
if nonce_reuse {
|
||||
return Err(HandshakeError::NonceReuse);
|
||||
}
|
||||
|
||||
|
@ -172,7 +173,7 @@ where
|
|||
if let Message::Verack = remote_msg {
|
||||
debug!("got verack from remote peer");
|
||||
} else {
|
||||
return Err(HandshakeError::UnexpectedMessage(remote_msg));
|
||||
return Err(HandshakeError::UnexpectedMessage(Box::new(remote_msg)));
|
||||
}
|
||||
|
||||
// XXX here is where we would set the version to the minimum of the
|
||||
|
@ -208,7 +209,7 @@ where
|
|||
.then(move |msg| {
|
||||
let mut timestamp_collector = timestamp_collector.clone();
|
||||
async move {
|
||||
if let Ok(_) = msg {
|
||||
if msg.is_ok() {
|
||||
use futures::sink::SinkExt;
|
||||
let _ = timestamp_collector
|
||||
.send(MetaAddr {
|
||||
|
|
|
@ -152,8 +152,7 @@ where
|
|||
.drain_oldest()
|
||||
.chain(self.gossiped.drain_newest())
|
||||
.chain(self.failed.drain_oldest())
|
||||
.filter(|meta| !guard.is_potentially_connected(&meta.addr))
|
||||
.next()
|
||||
.find(|meta| !guard.is_potentially_connected(&meta.addr))
|
||||
}
|
||||
|
||||
pub fn report_failed(&mut self, mut addr: MetaAddr) {
|
||||
|
|
|
@ -220,6 +220,7 @@ where
|
|||
type Future =
|
||||
Pin<Box<dyn Future<Output = Result<Self::Response, Self::Error>> + Send + 'static>>;
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
// Process peer discovery updates.
|
||||
let _ = self.poll_discover(cx)?;
|
||||
|
|
|
@ -293,6 +293,7 @@ impl Decoder for Codec {
|
|||
type Item = Message;
|
||||
type Error = Error;
|
||||
|
||||
#[allow(clippy::cognitive_complexity)]
|
||||
fn decode(&mut self, src: &mut BytesMut) -> Result<Option<Self::Item>, Self::Error> {
|
||||
use Error::Parse;
|
||||
match self.state {
|
||||
|
@ -467,7 +468,7 @@ impl Codec {
|
|||
fn read_block<R: Read>(&self, mut reader: R) -> Result<Message, Error> {
|
||||
Ok(Message::Block {
|
||||
version: Version(reader.read_u32::<LittleEndian>()?),
|
||||
block: Block::zcash_deserialize(&mut reader)?,
|
||||
block: Box::new(Block::zcash_deserialize(&mut reader)?),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -511,7 +512,7 @@ impl Codec {
|
|||
fn read_tx<R: Read>(&self, mut reader: R) -> Result<Message, Error> {
|
||||
Ok(Message::Tx {
|
||||
version: Version(reader.read_u32::<LittleEndian>()?),
|
||||
transaction: Transaction::zcash_deserialize(&mut reader)?,
|
||||
transaction: Box::new(Transaction::zcash_deserialize(&mut reader)?),
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -546,9 +547,7 @@ impl Codec {
|
|||
let mut bytes = Vec::new();
|
||||
|
||||
// Maximum size of data is 520 bytes.
|
||||
let mut handle = reader.take(520);
|
||||
|
||||
handle.read(&mut bytes)?;
|
||||
reader.take(520).read_exact(&mut bytes)?;
|
||||
|
||||
Ok(Message::FilterAdd { data: bytes })
|
||||
}
|
||||
|
|
|
@ -134,10 +134,11 @@ pub enum Message {
|
|||
/// [Bitcoin reference](https://en.bitcoin.it/wiki/Protocol_documentation#block)
|
||||
Block {
|
||||
/// Transaction data format version (note, this is signed).
|
||||
// XXX does this get folded into the Block struct?
|
||||
version: Version,
|
||||
|
||||
/// The block itself.
|
||||
block: Block,
|
||||
block: Box<Block>,
|
||||
},
|
||||
|
||||
/// A `getblocks` message.
|
||||
|
@ -255,10 +256,11 @@ pub enum Message {
|
|||
// `tx_witnesses` aren't either, as they go if `flag` goes.
|
||||
Tx {
|
||||
/// Transaction data format version (note, this is signed).
|
||||
// XXX do we still need this with the transaction data handling?
|
||||
version: Version,
|
||||
|
||||
/// The `Transaction` type itself.
|
||||
transaction: Transaction,
|
||||
transaction: Box<Transaction>,
|
||||
},
|
||||
|
||||
/// A `mempool` message.
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use hex;
|
||||
use std::fmt;
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -29,7 +28,7 @@ bitflags! {
|
|||
/// NODE_NETWORK means that the node is a full node capable of serving
|
||||
/// blocks, as opposed to a light client that makes network requests but
|
||||
/// does not provide network services.
|
||||
const NODE_NETWORK = (1 << 0);
|
||||
const NODE_NETWORK = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ impl Configurable<ZebradConfig> for ZebradCmd {
|
|||
|
||||
let if_exists = |f: PathBuf| if f.exists() { Some(f) } else { None };
|
||||
|
||||
filename.and_then(|f| if_exists(f))
|
||||
filename.and_then(if_exists)
|
||||
}
|
||||
|
||||
/// Apply changes to the config after it's been loaded, e.g. overriding
|
||||
|
|
|
@ -49,11 +49,9 @@ impl ConnectCmd {
|
|||
use tower::{buffer::Buffer, service_fn, Service, ServiceExt};
|
||||
|
||||
let node = Buffer::new(
|
||||
service_fn(|req| {
|
||||
async move {
|
||||
info!(?req);
|
||||
Ok::<Response, Error>(Response::Ok)
|
||||
}
|
||||
service_fn(|req| async move {
|
||||
info!(?req);
|
||||
Ok::<Response, Error>(Response::Ok)
|
||||
}),
|
||||
1,
|
||||
);
|
||||
|
|
|
@ -41,20 +41,20 @@ impl Service<Request> for SeedService {
|
|||
#[instrument(skip(self, _cx))]
|
||||
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
|
||||
match self.state {
|
||||
SeederState::Ready(_) => return Poll::Ready(Ok(())),
|
||||
SeederState::Ready(_) => Poll::Ready(Ok(())),
|
||||
SeederState::AwaitingAddressBook(ref mut rx) => match rx.try_recv() {
|
||||
Err(e) => {
|
||||
error!("oneshot sender dropped, failing service: {:?}", e);
|
||||
return Poll::Ready(Err(e.into()));
|
||||
Poll::Ready(Err(e.into()))
|
||||
}
|
||||
Ok(None) => {
|
||||
trace!("awaiting address book, service is unready");
|
||||
return Poll::Pending;
|
||||
Poll::Pending
|
||||
}
|
||||
Ok(Some(address_book)) => {
|
||||
debug!("received address_book via oneshot, service becomes ready");
|
||||
self.state = SeederState::Ready(address_book);
|
||||
return Poll::Ready(Ok(()));
|
||||
Poll::Ready(Ok(()))
|
||||
}
|
||||
},
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ impl Service<Request> for SeedService {
|
|||
Ok(Response::Ok)
|
||||
}
|
||||
};
|
||||
return Box::pin(futures::future::ready(response));
|
||||
Box::pin(futures::future::ready(response))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue