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

Upgrade rust toolchain #3522

Draft
wants to merge 14 commits into
base: master
Choose a base branch
from
Draft
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 consensus/src/aggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ impl<V: StepVote> Aggregator<V> {

self.votes
.get(&(msg_step, *vote))
.map_or(false, |(_, cluster)| cluster.contains_key(signer))
.is_some_and(|(_, cluster)| cluster.contains_key(signer))
}

pub fn collect_vote(
Expand Down
1 change: 0 additions & 1 deletion consensus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#![deny(unused_crate_dependencies)]
#![deny(unused_extern_crates)]
#![feature(lazy_cell)]

pub mod commons;
pub mod consensus;
Expand Down
3 changes: 1 addition & 2 deletions consensus/src/quorum/verifiers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ pub async fn verify_step_votes(

let (quorum_result, voters) =
verify_votes(header, step, vote, sv, committee)
.map_err(|e|
.inspect_err(|e|
{
error!( "invalid {:?}, vote = {:?}, round = {}, iter = {}, seed = {}, sv = {:?}, err = {}",
step,
Expand All @@ -77,7 +77,6 @@ pub async fn verify_step_votes(
sv,
e
);
e
}
)?;

Expand Down
2 changes: 1 addition & 1 deletion consensus/src/user/provisioners.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ impl<'a> CommitteeGenerator<'a> {
fn from_provisioners(
provisioners: &'a Provisioners,
round: u64,
exclusion: &Vec<PublicKeyBytes>,
exclusion: &[PublicKeyBytes],
) -> Self {
let eligibles = provisioners
.eligibles(round)
Expand Down
4 changes: 2 additions & 2 deletions contracts/charlie/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ all: wasm clippy

wasm: ## Generate the optimized WASM for the contract given
@RUSTFLAGS="$(RUSTFLAGS) --remap-path-prefix $(HOME)= -C link-args=-zstack-size=65536" \
cargo build \
cargo +dusk build \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you changed to use dusk compiler?
It should work with standard compiler

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new toolchain can't compile piecrust-uplink anymore because of changes made to the panic handler in rust 1.81.0.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, should we first update piecurst?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can.
We don't need to do that right now if all the contracts use the dusk toolchain, but if we do decide to do that, then the dusk toolchain, too, will need to be updated.

--release \
--color=always \
-Z build-std=core,alloc \
Expand All @@ -11,7 +11,7 @@ wasm: ## Generate the optimized WASM for the contract given
test:

clippy:
@cargo clippy -Z build-std=core,alloc --release --target wasm32-unknown-unknown -- -D warnings
@cargo +dusk clippy -Z build-std=core,alloc --release --target wasm32-unknown-unknown -- -D warnings

doc:

Expand Down
4 changes: 2 additions & 2 deletions contracts/stake/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ wasm: ## Generate the optimized WASM for the contract given
--target wasm32-unknown-unknown

clippy: ## Run clippy
@cargo clippy --all-features --release -- -D warnings
@cargo clippy -Z build-std=core,alloc --release --target wasm32-unknown-unknown -- -D warnings
@cargo +dusk clippy --all-features --release -- -D warnings
@cargo +dusk clippy -Z build-std=core,alloc --release --target wasm32-unknown-unknown -- -D warnings

doc: ## Run doc gen
@cargo doc --release
Expand Down
4 changes: 2 additions & 2 deletions contracts/transfer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ wasm: ## Build the WASM files
--target wasm64-unknown-unknown

clippy: ## Run clippy
@cargo clippy --all-features --release -- -D warnings
@cargo clippy -Z build-std=core,alloc --release --target wasm32-unknown-unknown -- -D warnings
@cargo +dusk clippy --all-features --release -- -D warnings
@cargo +dusk clippy -Z build-std=core,alloc --release --target wasm32-unknown-unknown -- -D warnings

doc: ## Run doc gen
@cargo doc --release
Expand Down
6 changes: 3 additions & 3 deletions core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ pub enum Error {
PhoenixCircuit(String),
/// The transaction circuit prover wasn't found or couldn't be created.
PhoenixProver(String),
/// Dusk-bytes InvalidData error
/// Dusk-bytes `InvalidData` error
InvalidData,
/// Dusk-bytes BadLength error
/// Dusk-bytes `BadLength` error
BadLength(usize, usize),
/// Dusk-bytes InvalidChar error
/// Dusk-bytes `InvalidChar` error
InvalidChar(char, usize),
/// Rkyv serialization.
Rkyv(String),
Expand Down
2 changes: 2 additions & 0 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#![deny(rustdoc::broken_intra_doc_links)]
#![deny(clippy::pedantic)]
#![allow(clippy::module_name_repetitions)]
#![allow(clippy::used_underscore_binding)]
#![allow(stable_features)]
#![feature(const_fn_floating_point_arithmetic)]
#![cfg_attr(not(target_family = "wasm"), deny(unused_crate_dependencies))]
#![deny(unused_extern_crates)]
Expand Down
10 changes: 6 additions & 4 deletions node-data/src/ledger/faults.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,10 +354,12 @@ impl Slash {
return Ok(None);
}
};
let provisioner = (*provisioner.inner()).try_into().map_err(|e| {
error!("Unable to generate provisioners from IterationInfo: {e:?}");
e
})?;
let provisioner =
(*provisioner.inner()).try_into().inspect_err(|e| {
error!(
"Unable to generate provisioners from IterationInfo: {e:?}"
);
})?;
Ok(Some(Self {
provisioner,
r#type: slash,
Expand Down
5 changes: 3 additions & 2 deletions node/src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ impl Archive {
let path = base_path.as_ref().join(ARCHIVE_FOLDER_NAME);

// Recursively create the archive folder if it doesn't exist already
fs::create_dir_all(&path)
.expect("creating directory in {path} should not fail");
fs::create_dir_all(&path).unwrap_or_else(|_| {
panic!("creating directory in {path:?} should not fail")
});
path
}

Expand Down
12 changes: 7 additions & 5 deletions node/src/archive/moonlight.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ impl Archive {
Arc::new(
OptimisticTransactionDB::open_cf_descriptors(
&rocksdb_opts,
path,
&path,
cfs,
)
.expect("should be a valid database in {path}"),
.unwrap_or_else(|_| {
panic!("should be a valid database in {path:?}")
}),
)
}

Expand Down Expand Up @@ -650,7 +652,7 @@ mod util {
tx.block_height()
})
.ok()
.map_or(false, |idx| {
.is_some_and(|idx| {
outflows[idx].origin() == inflow_tx.origin()
})
})
Expand All @@ -676,7 +678,7 @@ mod util {
// Remove all transactions that are above the to_block
while moonlight_tx
.last()
.map_or(false, |tx| tx.block_height() > to_block)
.is_some_and(|tx| tx.block_height() > to_block)
{
moonlight_tx.pop();
}
Expand Down Expand Up @@ -709,7 +711,7 @@ mod util {
}

/// Find lower bound for MoonlightTx.
fn lower_bound(moonlight_tx: &Vec<EventIdentifier>, target: u64) -> usize {
fn lower_bound(moonlight_tx: &[EventIdentifier], target: u64) -> usize {
let mut left = 0;
let mut right = moonlight_tx.len();

Expand Down
2 changes: 1 addition & 1 deletion node/src/archive/transformer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ fn record_flows(
address_outflow_mappings: &mut Vec<(AccountPublicKey, EventIdentifier)>,
memo_mappings: &mut Vec<(Vec<u8>, EventIdentifier)>,
tx_ident: EventIdentifier,
group: &Vec<ContractEvent>,
group: &[ContractEvent],
) -> bool {
// Helper to handle inflow mappings without pushing duplicates
let mut handle_inflow = |key: AccountPublicKey| {
Expand Down
5 changes: 1 addition & 4 deletions node/src/chain/fsm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -384,10 +384,7 @@ impl<N: Network, DB: database::DB, VM: vm::VMExecution> SimpleFSM<N, DB, VM> {
// candidate) we try to fetch the candidate from the DB
let res = db.read().await.view(|t| t.candidate(&candidate));

match res {
Ok(b) => b,
Err(_) => None,
}
res.unwrap_or_default()
} else {
// INFO: we currently ignore Quorum messages from the past
None
Expand Down
1 change: 0 additions & 1 deletion node/src/chain/fsm/outofsync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ const SYNC_TIMEOUT: Duration = Duration::from_secs(5);
/// network efficiently, ensuring that blocks are processed in the correct
/// order and that network requests are managed effectively to minimize
/// redundant data and processing.

pub(super) struct OutOfSyncImpl<
DB: database::DB,
VM: vm::VMExecution,
Expand Down
6 changes: 1 addition & 5 deletions node/src/chain/header_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ use node_data::ledger::{Fault, InvalidFault, Seed, Signature};
use node_data::message::payload::{RatificationResult, Vote};
use node_data::message::{ConsensusHeader, BLOCK_HEADER_VERSION};
use node_data::{get_current_timestamp, ledger, StepName};
use thiserror::Error;
use tokio::sync::RwLock;
use tracing::{debug, error};

Expand All @@ -42,9 +41,6 @@ const MARGIN_TIMESTAMP: u64 = 3;

// TODO: Use thiserror instead of anyhow

#[derive(Debug, Error)]
enum HeaderVerificationErr {}

/// An implementation of the all validation checks of a candidate block header
/// according to current context
pub(crate) struct Validator<'a, DB: database::DB> {
Expand All @@ -69,7 +65,7 @@ impl<'a, DB: database::DB> Validator<'a, DB> {
/// Executes check points to make sure a candidate header is fully valid
///
/// * `disable_winner_att_check` - disables the check of the winning
/// attestation
/// attestation
///
/// Returns a tuple containing:
/// - the number of Previous Non-Attested Iterations (PNI)
Expand Down
1 change: 0 additions & 1 deletion node/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub trait DB: Send + Sync + 'static {
}

/// Implements both read-write and read-only transactions to DB.

pub trait Ledger {
/// Read-write transactions
/// Returns disk footprint of the committed transaction
Expand Down
20 changes: 11 additions & 9 deletions node/src/database/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,12 @@ impl DB for Backend {
rocksdb: Arc::new(
OptimisticTransactionDB::open_cf_descriptors(
&blocks_cf_opts,
path,
&path,
cfs,
)
.expect("should be a valid database in {path}"),
.unwrap_or_else(|_| {
panic!("should be a valid database in {path:?}")
}),
),
}
}
Expand Down Expand Up @@ -300,7 +302,7 @@ pub struct DBTransaction<'db, DB: DBAccess> {
metadata_cf: &'db ColumnFamily,
}

impl<'db, DB: DBAccess> Ledger for DBTransaction<'db, DB> {
impl<DB: DBAccess> Ledger for DBTransaction<'_, DB> {
fn store_block(
&mut self,
header: &Header,
Expand Down Expand Up @@ -606,7 +608,7 @@ impl<'db, DB: DBAccess> Ledger for DBTransaction<'db, DB> {
}

/// Implementation of the `Candidate` trait for `DBTransaction<'db, DB>`.
impl<'db, DB: DBAccess> ConsensusStorage for DBTransaction<'db, DB> {
impl<DB: DBAccess> ConsensusStorage for DBTransaction<'_, DB> {
/// Stores a candidate block in the database.
///
/// # Arguments
Expand Down Expand Up @@ -822,7 +824,7 @@ impl<'db, DB: DBAccess> ConsensusStorage for DBTransaction<'db, DB> {
}
}

impl<'db, DB: DBAccess> Persist for DBTransaction<'db, DB> {
impl<DB: DBAccess> Persist for DBTransaction<'_, DB> {
/// Deletes all items from both CF_LEDGER and CF_CANDIDATES column families
fn clear_database(&mut self) -> Result<()> {
// Create an iterator over the column family CF_LEDGER
Expand Down Expand Up @@ -855,7 +857,7 @@ impl<'db, DB: DBAccess> Persist for DBTransaction<'db, DB> {
}
}

impl<'db, DB: DBAccess> Mempool for DBTransaction<'db, DB> {
impl<DB: DBAccess> Mempool for DBTransaction<'_, DB> {
fn store_mempool_tx(
&mut self,
tx: &Transaction,
Expand Down Expand Up @@ -1127,7 +1129,7 @@ impl<DB: DBAccess> Iterator for MemPoolFeeIterator<'_, DB> {
}
}

impl<'db, DB: DBAccess> std::fmt::Debug for DBTransaction<'db, DB> {
impl<DB: DBAccess> std::fmt::Debug for DBTransaction<'_, DB> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// Print ledger blocks
let iter = self.inner.iterator_cf(self.ledger_cf, IteratorMode::Start);
Expand Down Expand Up @@ -1168,7 +1170,7 @@ impl<'db, DB: DBAccess> std::fmt::Debug for DBTransaction<'db, DB> {
}
}

impl<'db, DB: DBAccess> Metadata for DBTransaction<'db, DB> {
impl<DB: DBAccess> Metadata for DBTransaction<'_, DB> {
fn op_write<T: AsRef<[u8]>>(&mut self, key: &[u8], value: T) -> Result<()> {
self.put_cf(self.metadata_cf, key, value)?;
Ok(())
Expand All @@ -1179,7 +1181,7 @@ impl<'db, DB: DBAccess> Metadata for DBTransaction<'db, DB> {
}
}

impl<'db, DB: DBAccess> DBTransaction<'db, DB> {
impl<DB: DBAccess> DBTransaction<'_, DB> {
/// A thin wrapper around inner.put_cf that calculates a db transaction
/// disk footprint
fn put_cf<K: AsRef<[u8]>, V: AsRef<[u8]>>(
Expand Down
1 change: 0 additions & 1 deletion node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#![deny(unused_crate_dependencies)]
#![deny(unused_extern_crates)]
#![feature(lazy_cell)]

#[cfg(feature = "archive")]
pub mod archive;
Expand Down
2 changes: 1 addition & 1 deletion node/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl<const N: usize> Kadcast<N> {

async fn send_with_metrics(
&self,
bytes: &Vec<u8>,
bytes: &[u8],
recv_addr: Vec<SocketAddr>,
) {
if !recv_addr.is_empty() {
Expand Down
1 change: 0 additions & 1 deletion rusk-recovery/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

#![deny(unused_crate_dependencies)]
#![deny(unused_extern_crates)]
#![feature(lazy_cell)]

#[cfg(feature = "keys")]
pub mod keys;
Expand Down
2 changes: 1 addition & 1 deletion rusk-wallet/src/bin/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,7 @@ fn status_emoji(status: bool) -> String {
}
}

impl<'a> Display for ProfileSelect<'a> {
impl Display for ProfileSelect<'_> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ProfileSelect::Index(index, profile) => write!(
Expand Down
8 changes: 4 additions & 4 deletions rusk-wallet/src/bin/io/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ pub(crate) fn request_token_amt(
) -> Result<Dusk, Error> {
let min = MIN_CONVERTIBLE;

request_token(action, min, balance, None).map_err(Error::from)
request_token(action, min, balance, None)
}

/// Request amount of tokens that can be 0
Expand All @@ -261,7 +261,7 @@ pub(crate) fn request_optional_token_amt(
) -> Result<Dusk, Error> {
let min = Dusk::from(0);

request_token(action, min, balance, None).map_err(Error::from)
request_token(action, min, balance, None)
}

/// Request amount of tokens that can't be lower than the `min` argument and
Expand All @@ -270,7 +270,7 @@ pub(crate) fn request_stake_token_amt(
balance: Dusk,
min: Dusk,
) -> Result<Dusk, Error> {
request_token("stake", min, balance, None).map_err(Error::from)
request_token("stake", min, balance, None)
}

/// Request gas limit
Expand Down Expand Up @@ -372,7 +372,7 @@ pub(crate) fn request_address(
pub(crate) fn request_contract_code() -> anyhow::Result<PathBuf> {
let validator = |path_str: &str| {
let path = PathBuf::from(path_str);
if path.extension().map_or(false, |ext| ext == "wasm") {
if path.extension().is_some_and(|ext| ext == "wasm") {
Ok(Validation::Valid)
} else {
Ok(Validation::Invalid("Not a valid directory".into()))
Expand Down
Loading
Loading