Skip to content

Commit

Permalink
rust 1.53.0 updates (#2411)
Browse files Browse the repository at this point in the history
## Issue Addressed

`make lint` failing on rust 1.53.0.

## Proposed Changes

1.53.0 updates

## Additional Info

I haven't figure out why yet, we were now hitting the recursion limit in a few crates. So I had to add `#![recursion_limit = "256"]` in a few places


Co-authored-by: realbigsean <[email protected]>
Co-authored-by: Michael Sproul <[email protected]>
  • Loading branch information
3 people committed Jun 18, 2021
1 parent 3dc1eb5 commit 6f2b216
Show file tree
Hide file tree
Showing 30 changed files with 98 additions and 133 deletions.
4 changes: 2 additions & 2 deletions account_manager/src/validator/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ pub fn cli_run<T: EthSpec>(
.map_err(|e| {
format!(
"Error registering validator {}: {:?}",
voting_pubkey.to_hex_string(),
voting_pubkey.as_hex_string(),
e
)
})?;
Expand All @@ -250,7 +250,7 @@ pub fn cli_run<T: EthSpec>(
.build()
.map_err(|e| format!("Unable to build validator directory: {:?}", e))?;

println!("{}/{}\t{}", i + 1, n, voting_pubkey.to_hex_string());
println!("{}/{}\t{}", i + 1, n, voting_pubkey.as_hex_string());
}

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion account_manager/src/validator/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ pub fn cli_run(matches: &ArgMatches, validator_dir: PathBuf) -> Result<(), Strin
.map_err(|e| {
format!(
"Error registering validator {}: {:?}",
voting_pubkey.to_hex_string(),
voting_pubkey.as_hex_string(),
e
)
})?;
Expand Down
16 changes: 8 additions & 8 deletions beacon_node/beacon_chain/src/eth1_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -762,8 +762,8 @@ mod test {

let eth1_chain = get_eth1_chain();

assert_eq!(
eth1_chain.use_dummy_backend, false,
assert!(
!eth1_chain.use_dummy_backend,
"test should not use dummy backend"
);

Expand Down Expand Up @@ -795,8 +795,8 @@ mod test {
let eth1_chain = get_eth1_chain();
let max_deposits = <E as EthSpec>::MaxDeposits::to_u64();

assert_eq!(
eth1_chain.use_dummy_backend, false,
assert!(
!eth1_chain.use_dummy_backend,
"test should not use dummy backend"
);

Expand Down Expand Up @@ -877,8 +877,8 @@ mod test {

let eth1_chain = get_eth1_chain();

assert_eq!(
eth1_chain.use_dummy_backend, false,
assert!(
!eth1_chain.use_dummy_backend,
"test should not use dummy backend"
);

Expand All @@ -901,8 +901,8 @@ mod test {

let eth1_chain = get_eth1_chain();

assert_eq!(
eth1_chain.use_dummy_backend, false,
assert!(
!eth1_chain.use_dummy_backend,
"test should not use dummy backend"
);

Expand Down
10 changes: 5 additions & 5 deletions beacon_node/beacon_chain/src/state_advance_timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,11 +353,11 @@ mod tests {
#[test]
fn lock() {
let lock = Lock::new();
assert_eq!(lock.lock(), false);
assert_eq!(lock.lock(), true);
assert_eq!(lock.lock(), true);
assert!(!lock.lock());
assert!(lock.lock());
assert!(lock.lock());
lock.unlock();
assert_eq!(lock.lock(), false);
assert_eq!(lock.lock(), true);
assert!(!lock.lock());
assert!(lock.lock());
}
}
10 changes: 5 additions & 5 deletions beacon_node/eth2_libp2p/src/discovery/enr_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,22 +88,22 @@ impl EnrExt for Enr {
if let Some(udp) = self.udp() {
let mut multiaddr: Multiaddr = ip.into();
multiaddr.push(Protocol::Udp(udp));
multiaddr.push(Protocol::P2p(peer_id.clone().into()));
multiaddr.push(Protocol::P2p(peer_id.into()));
multiaddrs.push(multiaddr);
}

if let Some(tcp) = self.tcp() {
let mut multiaddr: Multiaddr = ip.into();
multiaddr.push(Protocol::Tcp(tcp));
multiaddr.push(Protocol::P2p(peer_id.clone().into()));
multiaddr.push(Protocol::P2p(peer_id.into()));
multiaddrs.push(multiaddr);
}
}
if let Some(ip6) = self.ip6() {
if let Some(udp6) = self.udp6() {
let mut multiaddr: Multiaddr = ip6.into();
multiaddr.push(Protocol::Udp(udp6));
multiaddr.push(Protocol::P2p(peer_id.clone().into()));
multiaddr.push(Protocol::P2p(peer_id.into()));
multiaddrs.push(multiaddr);
}

Expand All @@ -128,7 +128,7 @@ impl EnrExt for Enr {
if let Some(tcp) = self.tcp() {
let mut multiaddr: Multiaddr = ip.into();
multiaddr.push(Protocol::Tcp(tcp));
multiaddr.push(Protocol::P2p(peer_id.clone().into()));
multiaddr.push(Protocol::P2p(peer_id.into()));
multiaddrs.push(multiaddr);
}
}
Expand All @@ -154,7 +154,7 @@ impl EnrExt for Enr {
if let Some(udp) = self.udp() {
let mut multiaddr: Multiaddr = ip.into();
multiaddr.push(Protocol::Udp(udp));
multiaddr.push(Protocol::P2p(peer_id.clone().into()));
multiaddr.push(Protocol::P2p(peer_id.into()));
multiaddrs.push(multiaddr);
}
}
Expand Down
10 changes: 2 additions & 8 deletions beacon_node/eth2_libp2p/src/peer_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -556,20 +556,18 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
if known_meta_data.seq_number < meta_data.seq_number {
debug!(self.log, "Updating peer's metadata";
"peer_id" => %peer_id, "known_seq_no" => known_meta_data.seq_number, "new_seq_no" => meta_data.seq_number);
peer_info.meta_data = Some(meta_data);
} else {
debug!(self.log, "Received old metadata";
"peer_id" => %peer_id, "known_seq_no" => known_meta_data.seq_number, "new_seq_no" => meta_data.seq_number);
// Updating metadata even in this case to prevent storing
// incorrect `metadata.attnets` for a peer
peer_info.meta_data = Some(meta_data);
}
} else {
// we have no meta-data for this peer, update
debug!(self.log, "Obtained peer's metadata";
"peer_id" => %peer_id, "new_seq_no" => meta_data.seq_number);
peer_info.meta_data = Some(meta_data);
}
peer_info.meta_data = Some(meta_data);
} else {
crit!(self.log, "Received METADATA from an unknown peer";
"peer_id" => %peer_id);
Expand All @@ -583,11 +581,7 @@ impl<TSpec: EthSpec> PeerManager<TSpec> {
// port is removed, which is assumed to be associated with the discv5 protocol (and
// therefore irrelevant for other libp2p components).
let mut out_list = enr.multiaddr();
out_list.retain(|addr| {
addr.iter()
.find(|v| matches!(v, MProtocol::Udp(_)))
.is_none()
});
out_list.retain(|addr| !addr.iter().any(|v| matches!(v, MProtocol::Udp(_))));

out_list
} else {
Expand Down
14 changes: 7 additions & 7 deletions beacon_node/eth2_libp2p/src/peer_manager/peer_sync_status.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ impl PeerSyncStatus {
matches!(self, PeerSyncStatus::Behind { .. })
}

/// Updates the peer's sync status, returning whether the status transitioned.
///
/// E.g. returns `true` if the state changed from `Synced` to `Advanced`, but not if
/// the status remained `Synced` with different `SyncInfo` within.
pub fn update(&mut self, new_state: PeerSyncStatus) -> bool {
if *self == new_state {
*self = new_state;
false // state was not updated
} else {
*self = new_state;
true
}
let changed_status = *self != new_state;
*self = new_state;
changed_status
}

pub fn as_str(&self) -> &'static str {
Expand Down
5 changes: 2 additions & 3 deletions beacon_node/eth2_libp2p/src/rpc/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ where
match std::mem::replace(&mut info.state, InboundState::Poisoned) {
InboundState::Idle(substream) if !deactivated => {
if !info.pending_items.is_empty() {
let to_send = std::mem::replace(&mut info.pending_items, vec![]);
let to_send = std::mem::take(&mut info.pending_items);
let fut = process_inbound_substream(
substream,
info.remaining_chunks,
Expand Down Expand Up @@ -665,8 +665,7 @@ where
// elements

if !deactivated && !info.pending_items.is_empty() {
let to_send =
std::mem::replace(&mut info.pending_items, vec![]);
let to_send = std::mem::take(&mut info.pending_items);
let fut = process_inbound_substream(
substream,
info.remaining_chunks,
Expand Down
3 changes: 0 additions & 3 deletions beacon_node/http_api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1254,7 +1254,6 @@ pub fn serve<T: BeaconChainTypes>(

// GET config/fork_schedule
let get_config_fork_schedule = config_path
.clone()
.and(warp::path("fork_schedule"))
.and(warp::path::end())
.and(chain_filter.clone())
Expand All @@ -1268,7 +1267,6 @@ pub fn serve<T: BeaconChainTypes>(

// GET config/spec
let get_config_spec = config_path
.clone()
.and(warp::path("spec"))
.and(warp::path::end())
.and(chain_filter.clone())
Expand All @@ -1284,7 +1282,6 @@ pub fn serve<T: BeaconChainTypes>(

// GET config/deposit_contract
let get_config_deposit_contract = config_path
.clone()
.and(warp::path("deposit_contract"))
.and(warp::path::end())
.and(chain_filter.clone())
Expand Down
3 changes: 2 additions & 1 deletion beacon_node/http_api/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(not(debug_assertions))] // Tests are too slow in debug.
#![recursion_limit = "256"]

use beacon_chain::{
test_utils::{AttestationStrategy, BeaconChainHarness, BlockStrategy, EphemeralHarnessType},
Expand Down Expand Up @@ -2333,7 +2334,7 @@ async fn poll_events<S: Stream<Item = Result<EventKind<T>, eth2::Error>> + Unpin
};

tokio::select! {
_ = collect_stream_fut => {return events}
_ = collect_stream_fut => {events}
_ = tokio::time::sleep(timeout) => { return events; }
}
}
Expand Down
10 changes: 4 additions & 6 deletions beacon_node/network/src/attestation_service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,10 @@ impl<T: BeaconChainTypes> AttestationService<T> {
return;
}
// If there are no unsubscription events for `subnet_id`, we unsubscribe immediately.
if self
if !self
.unsubscriptions
.keys()
.find(|s| s.subnet_id == subnet_id)
.is_none()
.any(|s| s.subnet_id == subnet_id)
{
// we are not at capacity, unsubscribe from the current subnet.
debug!(self.log, "Unsubscribing from random subnet"; "subnet_id" => *subnet_id);
Expand Down Expand Up @@ -601,11 +600,10 @@ impl<T: BeaconChainTypes> AttestationService<T> {

for subnet_id in to_remove_subnets {
// If there are no unsubscription events for `subnet_id`, we unsubscribe immediately.
if self
if !self
.unsubscriptions
.keys()
.find(|s| s.subnet_id == *subnet_id)
.is_none()
.any(|s| s.subnet_id == *subnet_id)
{
self.events
.push_back(AttServiceMessage::Unsubscribe(*subnet_id));
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/network/src/attestation_service/tests/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,10 @@ async fn get_events<S: Stream<Item = AttServiceMessage> + Unpin>(
};

tokio::select! {
_ = collect_stream_fut => {return events}
_ = collect_stream_fut => {events}
_ = tokio::time::sleep(
Duration::from_millis(SLOT_DURATION_MILLIS) * num_slots_before_timeout,
) => { return events; }
) => { events }
}
}

Expand Down
2 changes: 1 addition & 1 deletion beacon_node/network/src/nat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ pub fn construct_upnp_mappings<T: EthSpec>(
"tcp",
&log,
).and_then(|_| {
let external_socket = external_ip.as_ref().map(|ip| SocketAddr::new(ip.clone().into(), config.tcp_port)).map_err(|_| ());
let external_socket = external_ip.as_ref().map(|ip| SocketAddr::new((*ip).into(), config.tcp_port)).map_err(|_| ());
info!(log, "UPnP TCP route established"; "external_socket" => format!("{}:{}", external_socket.as_ref().map(|ip| ip.to_string()).unwrap_or_else(|_| "".into()), config.tcp_port));
external_socket
}).ok();
Expand Down
4 changes: 2 additions & 2 deletions beacon_node/network/src/sync/range_sync/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,10 +933,10 @@ impl<T: BeaconChainTypes> SyncingChain<T> {
// check if we have the batch for our optimistic start. If not, request it first.
// We wait for this batch before requesting any other batches.
if let Some(epoch) = self.optimistic_start {
if !self.batches.contains_key(&epoch) {
if let Entry::Vacant(entry) = self.batches.entry(epoch) {
if let Some(peer) = idle_peers.pop() {
let optimistic_batch = BatchInfo::new(&epoch, EPOCHS_PER_BATCH);
self.batches.insert(epoch, optimistic_batch);
entry.insert(optimistic_batch);
self.send_batch(network, epoch, peer)?;
}
}
Expand Down
3 changes: 1 addition & 2 deletions beacon_node/store/src/hot_cold_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,12 +285,11 @@ impl<E: EthSpec, Hot: ItemStore<E>, Cold: ItemStore<E>> HotColdDB<E, Hot, Cold>

/// Store a state in the store.
pub fn put_state(&self, state_root: &Hash256, state: &BeaconState<E>) -> Result<(), Error> {
let mut ops: Vec<KeyValueStoreOp> = Vec::new();
if state.slot < self.get_split_slot() {
let mut ops: Vec<KeyValueStoreOp> = Vec::new();
self.store_cold_state(state_root, &state, &mut ops)?;
self.cold_db.do_atomically(ops)
} else {
let mut ops: Vec<KeyValueStoreOp> = Vec::new();
self.store_hot_state(state_root, state, &mut ops)?;
self.hot_db.do_atomically(ops)
}
Expand Down
12 changes: 6 additions & 6 deletions beacon_node/store/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,18 +251,18 @@ mod tests {
let key = Hash256::random();
let item = StorableThing { a: 1, b: 42 };

assert_eq!(store.exists::<StorableThing>(&key).unwrap(), false);
assert!(!store.exists::<StorableThing>(&key).unwrap());

store.put(&key, &item).unwrap();

assert_eq!(store.exists::<StorableThing>(&key).unwrap(), true);
assert!(store.exists::<StorableThing>(&key).unwrap());

let retrieved = store.get(&key).unwrap().unwrap();
assert_eq!(item, retrieved);

store.delete::<StorableThing>(&key).unwrap();

assert_eq!(store.exists::<StorableThing>(&key).unwrap(), false);
assert!(!store.exists::<StorableThing>(&key).unwrap());

assert_eq!(store.get::<StorableThing>(&key).unwrap(), None);
}
Expand All @@ -289,14 +289,14 @@ mod tests {
let key = Hash256::random();
let item = StorableThing { a: 1, b: 42 };

assert_eq!(store.exists::<StorableThing>(&key).unwrap(), false);
assert!(!store.exists::<StorableThing>(&key).unwrap());

store.put(&key, &item).unwrap();

assert_eq!(store.exists::<StorableThing>(&key).unwrap(), true);
assert!(store.exists::<StorableThing>(&key).unwrap());

store.delete::<StorableThing>(&key).unwrap();

assert_eq!(store.exists::<StorableThing>(&key).unwrap(), false);
assert!(!store.exists::<StorableThing>(&key).unwrap());
}
}
1 change: 1 addition & 0 deletions beacon_node/tests/test.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#![cfg(test)]
#![recursion_limit = "256"]

use beacon_chain::StateSkipConfig;
use node_test_rig::{
Expand Down
2 changes: 1 addition & 1 deletion common/validator_dir/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<'a> Builder<'a> {
if self.store_withdrawal_keystore {
// Write the withdrawal password to file.
write_password_to_file(
password_dir.join(withdrawal_keypair.pk.to_hex_string()),
password_dir.join(withdrawal_keypair.pk.as_hex_string()),
withdrawal_password.as_bytes(),
)?;

Expand Down
Loading

0 comments on commit 6f2b216

Please sign in to comment.