Skip to content

Commit

Permalink
chore(cargo): adapt codebase to latest Rust (1.81)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommytrg committed Sep 16, 2024
1 parent d996f0e commit b348fa4
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 27 deletions.
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions data_structures/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ workspace = ".."

[features]
rocksdb-backend = ["witnet_storage/rocksdb-backend"]
with-serde = ["rocksdb-backend"]

[dependencies]
bls-signatures-rs = "0.1.0"
Expand Down
23 changes: 9 additions & 14 deletions data_structures/src/chain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1490,7 +1490,7 @@ pub struct DataRequestOutput {
/// The minimum percentage of non-error reveals required to consider this data request as
/// "resolved" instead of as "error".
/// This field must be >50 and <100.
/// >50 because simple majority
/// \ >50 because simple majority
/// <100 because a 100% consensus encourages to commit a RadError for free
pub min_consensus_percentage: u32,
/// The amount of nanowits that each witness must collateralize in order to claim eligibility of
Expand Down Expand Up @@ -2576,9 +2576,9 @@ impl TransactionsPool {
/// Returns an error if:
/// * The transaction is of an invalid type (mint or tally)
/// * The commit transaction has the same data request pointer and pkh as
/// an existing transaction, but different hash.
/// an existing transaction, but different hash.
/// * The reveal transaction has the same data request pointer and pkh as
/// an existing transaction, but different hash.
/// an existing transaction, but different hash.
pub fn contains(&self, transaction: &Transaction) -> Result<bool, TransactionError> {
let tx_hash = transaction.hash();

Expand Down Expand Up @@ -4555,22 +4555,17 @@ impl EpochConstants {
.filter(|&x| x <= Epoch::MAX as Epoch)
.map(i64::from)
.and_then(|x| x.checked_add(self.checkpoint_zero_timestamp))
.ok_or(EpochCalculationError::Overflow);

let epoch_timestamp = match epoch_timestamp {
Ok(timestamp) => timestamp,
Err(error) => {
return Err(error);
}
};
.ok_or(EpochCalculationError::Overflow)?;

let mut in_v2 = false;
let timestamp = if epoch_timestamp >= self.checkpoint_zero_timestamp_v2 {
in_v2 = true;

let epochs_pre_v2 = ((self.checkpoint_zero_timestamp_v2
- self.checkpoint_zero_timestamp)
/ self.checkpoints_period as i64) as u32;
let epochs_pre_v2: u32 = u32::try_from(
(self.checkpoint_zero_timestamp_v2 - self.checkpoint_zero_timestamp)
/ i64::from(self.checkpoints_period),
)
.map_err(|_| EpochCalculationError::Overflow)?;

self.checkpoint_zero_timestamp_v2
+ i64::from((epoch - epochs_pre_v2) * Epoch::from(self.checkpoints_period_v2))
Expand Down
2 changes: 1 addition & 1 deletion data_structures/src/wit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ pub trait PrecisionLoss: Copy {

impl PrecisionLoss for u64 {
fn lose_precision(self, digits: u8) -> u64 {
self / 10_u64.pow(digits as u32)
self / 10_u64.pow(u32::from(digits))
}
}

Expand Down
5 changes: 2 additions & 3 deletions net/src/client/tcp/actors/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,9 @@ impl Handler<Request> for JsonRpcClient {
res.unwrap_or(Err(Error::RequestTimedOut(timeout.as_millis())))
})
.map(|res, act, ctx| {
res.map(|res| {
res.inspect(|_| {
// Backoff time is reset to default
act.reset_backoff_time();
res
act.reset_backoff_time()
})
.map_err(|err| {
log::error!("JSONRPC Request error: {:?}", err);
Expand Down
2 changes: 1 addition & 1 deletion partial_struct/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
//! ## Features
//!
//! * `Option<T>` inside the original structs are NOT handled. The generated
//! struct will be wrapped in an extra `Option` like `Option<Option<T>>`
//! struct will be wrapped in an extra `Option` like `Option<Option<T>>`
//! * You can add derives to the generated struct:
//! ```rust
//! use partial_struct::PartialStruct;
Expand Down
5 changes: 1 addition & 4 deletions storage/src/backends/hashmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,7 @@ impl<'a, 'b> Iterator for DBIterator<'a, 'b> {
.data
.iter()
.skip(skip)
.map(|x| {
skip += 1;
x
})
.inspect(|_| skip += 1)
.filter_map(|(k, v)| {
if k.starts_with(self.prefix.as_ref()) {
Some((k.clone(), v.clone()))
Expand Down

0 comments on commit b348fa4

Please sign in to comment.