Skip to content

chore: adapt codebase to Rust 1.86 #2618

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion bridges/centralized-ethereum/src/actors/dr_reporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ impl Handler<DrReporterMsg> for DrReporter {
// Error in call_with_confirmations
log::error!(
"{}: {:?}",
format!("Cannot call reportResultBatch{:?}", &batched_report),
format_args!("Cannot call reportResultBatch{:?}", &batched_report),
e
);
}
Expand Down
2 changes: 1 addition & 1 deletion bridges/centralized-ethereum/src/actors/eth_poller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl EthPoller {
"Fail to get status of queries #{} to #{}: {}",
init_index,
next_dr_id,
queries_status.unwrap_err().to_string()
queries_status.unwrap_err()
);
}
}
Expand Down
5 changes: 1 addition & 4 deletions bridges/centralized-ethereum/src/actors/watch_dog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -441,10 +441,7 @@ async fn fetch_wit_info(
let req = jsonrpc::Request::method("getPkh").timeout(Duration::from_secs(5));
let res = wit_client.send(req).await;
let wit_account = match res {
Ok(Ok(res)) => match serde_json::from_value::<String>(res) {
Ok(pkh) => Some(pkh),
Err(_) => None,
},
Ok(Ok(res)) => serde_json::from_value::<String>(res).ok(),
Ok(Err(_)) => None,
Err(err) => {
log::debug!("fetch_wit_info => method: getPkh; error: {}", err);
Expand Down
2 changes: 1 addition & 1 deletion crypto/src/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn merkle_tree_root_with_hashing_function<T: Copy>(hash_concat: fn(T, T) -> T, h
n => {
// n nodes: split into 2 and calculate the root for each half
// split at the first power of two greater or equal to n / 2
let (left, right) = hashes.split_at(((n + 1) / 2).next_power_of_two());
let (left, right) = hashes.split_at(n.div_ceil(2).next_power_of_two());
let left_hash = merkle_tree_root_with_hashing_function(hash_concat, left);
let right_hash = merkle_tree_root_with_hashing_function(hash_concat, right);

Expand Down
11 changes: 5 additions & 6 deletions data_structures/benches/sort_active_identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,19 +105,18 @@ where
}

fn staggered(take: usize) -> impl Iterator<Item = u32> {
iter::repeat(10000)
.take(take)
.chain(iter::repeat(1000).take(take))
.chain(iter::repeat(100).take(take))
.chain(iter::repeat(10).take(take))
iter::repeat_n(10000, take)
.chain(iter::repeat_n(1000, take))
.chain(iter::repeat_n(100, take))
.chain(iter::repeat_n(10, take))
}

fn all_unique(n: u32) -> impl Iterator<Item = u32> {
1..=n
}

fn all_equal(n: usize) -> impl Iterator<Item = u32> {
iter::repeat(1).take(n)
iter::repeat_n(1, n)
}

fn b_staggered_10000(b: &mut Bencher) {
Expand Down
6 changes: 3 additions & 3 deletions data_structures/src/radon_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ where
///
/// * `subscript_index` is used to distinguish the different subscripts in one RADON script.
/// * `operator_index` is the index of the operator inside the subscript: the partial result.
/// The first element is always the input value, and the last element is the result of the
/// subscript.
/// The first element is always the input value, and the last element is the result of the
/// subscript.
/// * `element_index` is the index of the element inside the array that serves as the input of
/// the subscript.
/// the subscript.
pub subscript_partial_results: Vec<Vec<Vec<RT>>>,
}

Expand Down
22 changes: 10 additions & 12 deletions net/src/client/http/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,28 @@ impl WitnetHttpClient {
reqwest::redirect::Policy::none()
};

let client;
match proxy {
let client = match proxy {
Some(proxy) => {
let proxy = reqwest::Proxy::http(proxy).map_err(|err| {
WitnetHttpError::ClientBuildError {
msg: err.to_string(),
}
})?;
client = reqwest::Client::builder()

reqwest::Client::builder()
.proxy(proxy)
.redirect(redirect_policy)
.build()
.map_err(|err| WitnetHttpError::ClientBuildError {
msg: err.to_string(),
})?;
}
None => {
client = reqwest::Client::builder()
.redirect(redirect_policy)
.build()
.map_err(|err| WitnetHttpError::ClientBuildError {
msg: err.to_string(),
})?;
})?
}
None => reqwest::Client::builder()
.redirect(redirect_policy)
.build()
.map_err(|err| WitnetHttpError::ClientBuildError {
msg: err.to_string(),
})?,
};

Ok(Self { client })
Expand Down
11 changes: 3 additions & 8 deletions node/src/actors/chain_manager/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use witnet_data_structures::{
proto::versioning::ProtocolVersion,
refresh_protocol_version,
staking::{
errors::StakesError,
prelude::{Power, StakeKey},
stakes::QueryStakesKey,
},
Expand Down Expand Up @@ -861,7 +860,7 @@ impl PeersBeacons {
b.as_ref()
.map(|last_beacon| last_beacon.highest_superblock_checkpoint)
})
.chain(std::iter::repeat(None).take(num_missing_peers)),
.chain(std::iter::repeat_n(None, num_missing_peers)),
consensus_threshold,
)
// Flatten result:
Expand Down Expand Up @@ -1023,7 +1022,7 @@ impl Handler<PeersBeacons> for ChainManager {
let peers_needed_for_consensus = outbound_limit
.map(|x| {
// ceil(x * consensus_threshold / 100)
(usize::from(x) * consensus_threshold + 99) / 100
(usize::from(x) * consensus_threshold).div_ceil(100)
})
.unwrap_or(1);

Expand Down Expand Up @@ -1553,11 +1552,7 @@ impl Handler<QueryStakes> for ChainManager {
let limit = params.limit.unwrap_or(u16::MAX) as usize;

// fetch filtered stake entries from current chain state:
let mut stakes = self
.chain_state
.stakes
.query_stakes(filter.clone())
.map_err(StakesError::from)?;
let mut stakes = self.chain_state.stakes.query_stakes(filter.clone())?;

// filter out stake entries having a nonce, last mining or witnessing epochs (depending
// on actual ordering field) older than calculated `since_epoch`:
Expand Down
8 changes: 1 addition & 7 deletions rad/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,6 @@ pub mod fromx {
mod tests {
use std::convert::TryFrom;

use tokio;

use serde_cbor::Value;
use witnet_data_structures::{
chain::RADFilter,
Expand Down Expand Up @@ -1985,11 +1983,7 @@ mod tests {
});
}
Err(e) => {
println!(
"Encountered error for proxy {:?}: {}",
transport,
e.to_string()
);
println!("Encountered error for proxy {:?}: {}", transport, e);
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions rad/src/types/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ impl Operable for RadonBoolean {
match call {
(RadonOpCodes::Identity, None) => identity(RadonTypes::from(self.clone())),
(RadonOpCodes::BooleanNegate, None) => Ok(boolean_operators::negate(self).into()),
(RadonOpCodes::BooleanAsString, None) => boolean_operators::to_string(self.clone())
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::BooleanAsString, None) => {
boolean_operators::to_string(self.clone()).map(RadonTypes::from)
}
(op_code, args) => Err(RadError::UnsupportedOperator {
input_type: RADON_BOOLEAN_TYPE_NAME.to_string(),
operator: op_code.to_string(),
Expand Down
12 changes: 6 additions & 6 deletions rad/src/types/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,12 @@ impl Operable for RadonBytes {
match call {
// Identity
(RadonOpCodes::Identity, None) => identity(RadonTypes::from(self.clone())),
(RadonOpCodes::BytesAsString, None) => bytes_operators::to_string(self)
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::BytesHash, Some(args)) => bytes_operators::hash(self, args.as_slice())
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::BytesAsString, None) => {
bytes_operators::to_string(self).map(RadonTypes::from)
}
(RadonOpCodes::BytesHash, Some(args)) => {
bytes_operators::hash(self, args.as_slice()).map(RadonTypes::from)
}
// Unsupported / unimplemented
(op_code, args) => Err(RadError::UnsupportedOperator {
input_type: RADON_BYTES_TYPE_NAME.to_string(),
Expand Down
6 changes: 3 additions & 3 deletions rad/src/types/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ impl Operable for RadonFloat {
(RadonOpCodes::FloatAbsolute, None) => {
Ok(RadonTypes::from(float_operators::absolute(self)))
}
(RadonOpCodes::FloatAsString, None) => float_operators::to_string(self.clone())
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::FloatAsString, None) => {
float_operators::to_string(self.clone()).map(RadonTypes::from)
}
(RadonOpCodes::FloatCeiling, None) => {
Ok(RadonTypes::from(float_operators::ceiling(self)))
}
Expand Down
24 changes: 12 additions & 12 deletions rad/src/types/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ impl Operable for RadonInteger {
match call {
// Identity
(RadonOpCodes::Identity, None) => identity(RadonTypes::from(self.clone())),
(RadonOpCodes::IntegerAbsolute, None) => integer_operators::absolute(self)
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::IntegerAsFloat, None) => integer_operators::to_float(self.clone())
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::IntegerAsString, None) => integer_operators::to_string(self.clone())
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::IntegerAbsolute, None) => {
integer_operators::absolute(self).map(RadonTypes::from)
}
(RadonOpCodes::IntegerAsFloat, None) => {
integer_operators::to_float(self.clone()).map(RadonTypes::from)
}
(RadonOpCodes::IntegerAsString, None) => {
integer_operators::to_string(self.clone()).map(RadonTypes::from)
}
(RadonOpCodes::IntegerGreaterThan, Some(args)) => {
integer_operators::greater_than(self, args).map(Into::into)
}
Expand All @@ -123,9 +123,9 @@ impl Operable for RadonInteger {
(RadonOpCodes::IntegerMultiply, Some(args)) => {
integer_operators::multiply(self, args.as_slice()).map(Into::into)
}
(RadonOpCodes::IntegerNegate, None) => integer_operators::negate(self)
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::IntegerNegate, None) => {
integer_operators::negate(self).map(RadonTypes::from)
}
(RadonOpCodes::IntegerPower, Some(args)) => {
integer_operators::power(self, args.as_slice()).map(Into::into)
}
Expand Down
32 changes: 15 additions & 17 deletions rad/src/types/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,24 @@ impl Operable for RadonString {
} else {
string_operators::legacy::as_float_before_wip0024(self)
}
.map(RadonTypes::from)
.map_err(Into::into),
.map(RadonTypes::from),
(RadonOpCodes::StringAsInteger, args) => if wip0024 {
string_operators::as_integer(self, args)
} else {
string_operators::legacy::as_integer_before_wip0024(self)
}
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::StringAsBoolean, None) => string_operators::to_bool(self)
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::StringParseJSONArray, None) => string_operators::parse_json_array(self)
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::StringParseJSONMap, None) => string_operators::parse_json_map(self)
.map(RadonTypes::from)
.map_err(Into::into),
.map(RadonTypes::from),
(RadonOpCodes::StringAsBoolean, None) => {
string_operators::to_bool(self).map(RadonTypes::from)
}
(RadonOpCodes::StringParseJSONArray, None) => {
string_operators::parse_json_array(self).map(RadonTypes::from)
}
(RadonOpCodes::StringParseJSONMap, None) => {
string_operators::parse_json_map(self).map(RadonTypes::from)
}
(RadonOpCodes::StringMatch, Some(args)) => {
string_operators::string_match(self, args.as_slice()).map(RadonTypes::from)
string_operators::string_match(self, args.as_slice())
}
(RadonOpCodes::StringLength, None) => {
Ok(RadonTypes::from(string_operators::length(self)))
Expand All @@ -140,9 +138,9 @@ impl Operable for RadonString {
(RadonOpCodes::StringToUpperCase, None) => {
Ok(RadonTypes::from(string_operators::to_uppercase(self)))
}
(RadonOpCodes::StringParseXMLMap, None) => string_operators::parse_xml_map(self)
.map(RadonTypes::from)
.map_err(Into::into),
(RadonOpCodes::StringParseXMLMap, None) => {
string_operators::parse_xml_map(self).map(RadonTypes::from)
}
(op_code, args) => Err(RadError::UnsupportedOperator {
input_type: RADON_STRING_TYPE_NAME.to_string(),
operator: op_code.to_string(),
Expand Down
9 changes: 4 additions & 5 deletions validations/benches/reppoe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,10 @@ fn be<I>(
}

fn staggered() -> impl Iterator<Item = u32> {
iter::repeat(10000)
.take(50)
.chain(iter::repeat(1000).take(50))
.chain(iter::repeat(100).take(50))
.chain(iter::repeat(10).take(50))
iter::repeat_n(10000, 50)
.chain(iter::repeat_n(1000, 50))
.chain(iter::repeat_n(100, 50))
.chain(iter::repeat_n(10, 50))
}

fn no_cache_empty_rep_eng_1w(b: &mut Bencher) {
Expand Down
8 changes: 4 additions & 4 deletions wallet/src/actors/worker/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1067,15 +1067,15 @@ impl Worker {
(true, false)
} else if block_beacon.checkpoint == 3048961
&& block_beacon.hash_prev_block
== witnet_data_structures::chain::Hash::from(Vec::from(
== witnet_data_structures::chain::Hash::from(
hex::decode("f83b42c391bbc2084651c3258af6f6830574e405c146ebe0989990c1071acf54")
.unwrap(),
))
)
&& last_sync.hash_prev_block
== witnet_data_structures::chain::Hash::from(Vec::from(
== witnet_data_structures::chain::Hash::from(
hex::decode("1a36ef15698405b5f9ea3b42efcf7469a4b4572a7826f7c9855835c0adf233cd")
.unwrap(),
))
)
{
log::warn!("Dealing with special V1_7 → V1_8 synchronization case");

Expand Down