Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup(rust): Simplify code using closure capture in Rust 2021 edition #6737

Merged
merged 3 commits into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions zebra-consensus/src/transaction/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,8 +866,7 @@ async fn v5_transaction_is_rejected_before_nu5_activation() {
let verifier = Verifier::new(network, state_service);

let transaction = fake_v5_transactions_for_network(network, blocks)
.rev()
.next()
.next_back()
.expect("At least one fake V5 transaction in the test vectors");

let result = verifier
Expand Down Expand Up @@ -918,8 +917,7 @@ fn v5_transaction_is_accepted_after_nu5_activation_for_network(network: Network)
let verifier = Verifier::new(network, state_service);

let mut transaction = fake_v5_transactions_for_network(network, blocks)
.rev()
.next()
.next_back()
.expect("At least one fake V5 transaction in the test vectors");
if transaction
.expiry_height()
Expand Down
7 changes: 2 additions & 5 deletions zebra-network/src/peer_set/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,15 +504,12 @@ where
/// Checks if the minimum peer version has changed, and disconnects from outdated peers.
fn disconnect_from_outdated_peers(&mut self) {
if let Some(minimum_version) = self.minimum_peer_version.changed() {
// TODO: Remove when the code base migrates to Rust 2021 edition (#2709).
let preselected_p2c_peer = &mut self.preselected_p2c_peer;

self.ready_services.retain(|address, peer| {
if peer.remote_version() >= minimum_version {
true
} else {
if *preselected_p2c_peer == Some(*address) {
*preselected_p2c_peer = None;
if self.preselected_p2c_peer == Some(*address) {
self.preselected_p2c_peer = None;
}

false
Expand Down
3 changes: 3 additions & 0 deletions zebra-rpc/src/server/tests/vectors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
//! Fixed test vectors for the RPC server.

// These tests call functions which can take unit arguments if some features aren't enabled.
#![allow(clippy::unit_arg)]

use std::{
net::{Ipv4Addr, SocketAddrV4},
time::Duration,
Expand Down
2 changes: 1 addition & 1 deletion zebra-state/src/service/non_finalized_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ impl NonFinalizedState {

/// Return the non-finalized portion of the current best chain.
pub fn best_chain(&self) -> Option<&Arc<Chain>> {
self.chain_set.iter().rev().next()
self.chain_iter().next()
}

/// Return the number of chains.
Expand Down