From d2d9cdad592d9d0e654d4048a887f21ac958c8f5 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Thu, 7 Dec 2023 15:46:00 +0300 Subject: [PATCH 01/14] chore: support rust 1.76 --- common/numerated/src/interval.rs | 8 ++++---- examples/constructor/src/builder.rs | 2 -- examples/fungible-token/src/wasm.rs | 4 ++-- examples/node/src/wasm.rs | 4 ++-- gcli/tests/common/mod.rs | 8 +------- gclient/src/api/listener/mod.rs | 1 - gclient/src/api/storage/mod.rs | 2 -- gclient/src/lib.rs | 2 +- gsdk/src/storage.rs | 3 +-- gsdk/src/testing/node.rs | 4 ++-- pallets/gear/src/manager/mod.rs | 1 - runtime/vara/src/lib.rs | 5 ++--- rust-toolchain.toml | 2 +- scripts/src/clippy.sh | 7 +++---- utils/gear-replay-cli/src/lib.rs | 2 +- utils/runtime-fuzzer/src/runtime/mod.rs | 2 +- utils/validator-checks/src/blocks_production.rs | 2 +- utils/validator-checks/src/result.rs | 2 +- utils/wasm-gen/src/tests.rs | 2 +- 19 files changed, 24 insertions(+), 39 deletions(-) diff --git a/common/numerated/src/interval.rs b/common/numerated/src/interval.rs index 8a5d7a20dd7..a817e354882 100644 --- a/common/numerated/src/interval.rs +++ b/common/numerated/src/interval.rs @@ -441,7 +441,7 @@ mod tests { #[test] fn size() { assert_eq!(Interval::::try_from(11..111).unwrap().size(), Some(100),); - assert_eq!(Interval::::try_from(..1).unwrap().size(), Some(1),); + assert_eq!(Interval::::from(..1).size(), Some(1),); assert_eq!(Interval::::from(..=1).size(), Some(2)); assert_eq!(Interval::::from(1..).size(), Some(255)); assert_eq!(Interval::::from(0..).size(), None); @@ -452,7 +452,7 @@ mod tests { Interval::::try_from(11..111).unwrap().raw_size(), Some(100), ); - assert_eq!(Interval::::try_from(..1).unwrap().raw_size(), Some(1),); + assert_eq!(Interval::::from(..1).raw_size(), Some(1),); assert_eq!(Interval::::from(..=1).raw_size(), Some(2)); assert_eq!(Interval::::from(1..).raw_size(), Some(255)); assert_eq!(Interval::::from(0..).raw_size(), None); @@ -460,7 +460,7 @@ mod tests { assert_eq!(Interval::::try_from(1..1).unwrap().raw_size(), Some(0)); assert_eq!(Interval::::try_from(-1..99).unwrap().size(), Some(-28)); // corresponds to 100 numeration - assert_eq!(Interval::::try_from(..1).unwrap().size(), Some(1)); // corresponds to 129 numeration + assert_eq!(Interval::::from(..1).size(), Some(1)); // corresponds to 129 numeration assert_eq!(Interval::::from(..=1).size(), Some(2)); // corresponds to 130 numeration assert_eq!(Interval::::from(1..).size(), Some(-1)); // corresponds to 127 numeration assert_eq!(Interval::::from(0..).size(), Some(0)); // corresponds to 128 numeration @@ -471,7 +471,7 @@ mod tests { Interval::::try_from(-1..99).unwrap().raw_size(), Some(100) ); - assert_eq!(Interval::::try_from(..1).unwrap().raw_size(), Some(129)); + assert_eq!(Interval::::from(..1).raw_size(), Some(129)); assert_eq!(Interval::::from(..=1).raw_size(), Some(130)); assert_eq!(Interval::::from(1..).raw_size(), Some(127)); assert_eq!(Interval::::from(0..).raw_size(), Some(128)); diff --git a/examples/constructor/src/builder.rs b/examples/constructor/src/builder.rs index a11b94f0640..8d8dff7c6e5 100644 --- a/examples/constructor/src/builder.rs +++ b/examples/constructor/src/builder.rs @@ -46,8 +46,6 @@ impl Calls { self } - // TODO #3452: remove this on next rust update - #[allow(clippy::useless_conversion)] pub fn add_from_iter(mut self, calls: impl Iterator) -> Self { self.0.extend(calls.into_iter()); self diff --git a/examples/fungible-token/src/wasm.rs b/examples/fungible-token/src/wasm.rs index 9840581aeab..1d90cd7dba4 100644 --- a/examples/fungible-token/src/wasm.rs +++ b/examples/fungible-token/src/wasm.rs @@ -170,10 +170,10 @@ extern "C" fn state() { decimals, } = state; - let balances = balances.into_iter().map(|(k, v)| (k, v)).collect(); + let balances = balances.into_iter().collect(); let allowances = allowances .into_iter() - .map(|(id, allowance)| (id, allowance.into_iter().map(|(k, v)| (k, v)).collect())) + .map(|(id, allowance)| (id, allowance.into_iter().collect())) .collect(); let payload = IoFungibleToken { name, diff --git a/examples/node/src/wasm.rs b/examples/node/src/wasm.rs index 83c9acefa07..a5d014f0807 100644 --- a/examples/node/src/wasm.rs +++ b/examples/node/src/wasm.rs @@ -143,7 +143,7 @@ fn process(request: Request) -> Reply { transition.query_list = state().sub_nodes.iter().cloned().collect(); let first_sub_node = *transition .query_list - .get(0) + .first() .expect("Checked above that sub_nodes is not empty; qed"); transition.last_sent_message_id = msg::send(first_sub_node, request, 0).unwrap(); @@ -176,7 +176,7 @@ fn process(request: Request) -> Reply { if let TransitionState::Ready = transition.state { let first_sub_node = *transition .query_list - .get(0) + .first() .expect("Checked above that sub_nodes is not empty; qed"); transition.query_index = 0; diff --git a/gcli/tests/common/mod.rs b/gcli/tests/common/mod.rs index 78494bb3d1b..cd3dee9147d 100644 --- a/gcli/tests/common/mod.rs +++ b/gcli/tests/common/mod.rs @@ -17,11 +17,7 @@ // along with this program. If not, see . //! Common utils for integration tests -pub use self::{ - args::Args, - result::{Error, Result}, - traits::{Convert, NodeExec}, -}; +pub use self::{args::Args, result::Result, traits::NodeExec}; use gear_core::ids::{CodeId, ProgramId}; use gsdk::{ ext::{sp_core::crypto::Ss58Codec, sp_runtime::AccountId32}, @@ -39,8 +35,6 @@ mod result; pub mod traits; mod prelude { - pub use scale_info::scale::Encode; - pub const ALICE_SS58_ADDRESS: &str = "kGkLEU3e3XXkJp2WK4eNpVmSab5xUNL9QtmLPh8QfCL2EgotW"; } diff --git a/gclient/src/api/listener/mod.rs b/gclient/src/api/listener/mod.rs index 4faf3c3b515..0e489c1ecfd 100644 --- a/gclient/src/api/listener/mod.rs +++ b/gclient/src/api/listener/mod.rs @@ -21,7 +21,6 @@ mod subscription; pub use gsdk::metadata::{gear::Event as GearEvent, Event}; pub use iterator::*; -pub use subscription::*; use crate::{Error, Result}; use async_trait::async_trait; diff --git a/gclient/src/api/storage/mod.rs b/gclient/src/api/storage/mod.rs index 52efb1e3ea2..7cd05ec9495 100644 --- a/gclient/src/api/storage/mod.rs +++ b/gclient/src/api/storage/mod.rs @@ -19,8 +19,6 @@ pub(crate) mod account_id; mod block; -pub use block::*; - use super::{GearApi, Result}; use crate::Error; use account_id::IntoAccountId32; diff --git a/gclient/src/lib.rs b/gclient/src/lib.rs index 1a09bd621a8..bde9c37149b 100644 --- a/gclient/src/lib.rs +++ b/gclient/src/lib.rs @@ -135,7 +135,7 @@ mod api; mod utils; mod ws; -pub use api::{calls::*, error::*, listener::*, GearApi}; +pub use api::{error::*, listener::*, GearApi}; pub use gsdk::metadata::errors; pub use utils::*; pub use ws::WSAddress; diff --git a/gsdk/src/storage.rs b/gsdk/src/storage.rs index 5642a050db0..c3b7b14d3f6 100644 --- a/gsdk/src/storage.rs +++ b/gsdk/src/storage.rs @@ -360,8 +360,7 @@ impl Api { ], ); - let data: Option<(UserStoredMessage, Interval)> = self.fetch_storage(&addr).await.ok(); - Ok(data.map(|(m, i)| (m, i))) + Ok(self.fetch_storage(&addr).await.ok()) } /// Get all mailbox messages or for the provided `address`. diff --git a/gsdk/src/testing/node.rs b/gsdk/src/testing/node.rs index 6dcade77aaf..ff5e9467314 100644 --- a/gsdk/src/testing/node.rs +++ b/gsdk/src/testing/node.rs @@ -70,7 +70,7 @@ impl Node { pub fn wait_for_log_record(&mut self, log: &str) -> Result { let stderr = self.process.stderr.as_mut(); let reader = BufReader::new(stderr.ok_or(Error::EmptyStderr)?); - for line in reader.lines().flatten() { + for line in reader.lines().map_while(|result| result.ok()) { if line.contains(log) { return Ok(line); } @@ -83,7 +83,7 @@ impl Node { pub fn print_logs(&mut self) { let stderr = self.process.stderr.as_mut(); let reader = BufReader::new(stderr.expect("Unable to get stderr")); - for line in reader.lines().flatten() { + for line in reader.lines().map_while(|result| result.ok()) { println!("{line}"); } } diff --git a/pallets/gear/src/manager/mod.rs b/pallets/gear/src/manager/mod.rs index 4973d70a7f6..84ee9b1bff8 100644 --- a/pallets/gear/src/manager/mod.rs +++ b/pallets/gear/src/manager/mod.rs @@ -49,7 +49,6 @@ mod journal; mod task; use gear_core_errors::{ReplyCode, SignalCode}; -pub use journal::*; pub use task::*; use crate::{ diff --git a/runtime/vara/src/lib.rs b/runtime/vara/src/lib.rs index 784f3a7b435..c1e3f2458f9 100644 --- a/runtime/vara/src/lib.rs +++ b/runtime/vara/src/lib.rs @@ -266,8 +266,7 @@ impl pallet_babe::Config for Runtime { type WeightInfo = (); type MaxAuthorities = MaxAuthorities; - type KeyOwnerProof = - >::Proof; + type KeyOwnerProof = sp_session::MembershipProof; type EquivocationReportSystem = pallet_babe::EquivocationReportSystem; } @@ -278,7 +277,7 @@ impl pallet_grandpa::Config for Runtime { type WeightInfo = (); type MaxAuthorities = MaxAuthorities; type MaxSetIdSessionEntries = MaxSetIdSessionEntries; - type KeyOwnerProof = >::Proof; + type KeyOwnerProof = sp_session::MembershipProof; type EquivocationReportSystem = pallet_grandpa::EquivocationReportSystem; } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index a7adebc0c1e..90810b8b6e8 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2023-09-05" +channel = "nightly-2023-12-07" components = [ "llvm-tools" ] targets = [ "wasm32-unknown-unknown" ] profile = "default" diff --git a/scripts/src/clippy.sh b/scripts/src/clippy.sh index 0133a609d66..b70925273ea 100755 --- a/scripts/src/clippy.sh +++ b/scripts/src/clippy.sh @@ -20,14 +20,13 @@ EOF } gear_clippy() { - # TODO #3452: remove `-A clippy::needless_pass_by_ref_mut` on next rust update EXCLUDE_PACKAGES="--exclude vara-runtime --exclude runtime-fuzzer --exclude runtime-fuzzer-fuzz" INCLUDE_PACKAGES="-p vara-runtime -p runtime-fuzzer -p runtime-fuzzer-fuzz" - __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy --workspace "$@" $EXCLUDE_PACKAGES -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut - __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy $INCLUDE_PACKAGES --all-features -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut + __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy --workspace "$@" $EXCLUDE_PACKAGES -- --no-deps -D warnings + __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy $INCLUDE_PACKAGES --all-features -- --no-deps -D warnings } examples_clippy() { - __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy -p "demo-*" -p test-syscalls --no-default-features "$@" -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut + __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy -p "demo-*" -p test-syscalls --no-default-features "$@" -- --no-deps -D warnings } diff --git a/utils/gear-replay-cli/src/lib.rs b/utils/gear-replay-cli/src/lib.rs index 1f54a00d61f..a4cc4b125ff 100644 --- a/utils/gear-replay-cli/src/lib.rs +++ b/utils/gear-replay-cli/src/lib.rs @@ -103,7 +103,7 @@ pub async fn run() -> sc_cli::Result<()> { true => VARA_SS58_PREFIX, false => GEAR_SS58_PREFIX, }; - sp_core::crypto::set_default_ss58_version(ss58_prefix.try_into().unwrap()); + sp_core::crypto::set_default_ss58_version(ss58_prefix.into()); match &options.command { Command::ReplayBlock(cmd) => { diff --git a/utils/runtime-fuzzer/src/runtime/mod.rs b/utils/runtime-fuzzer/src/runtime/mod.rs index cebf312c3a7..21365af3f34 100644 --- a/utils/runtime-fuzzer/src/runtime/mod.rs +++ b/utils/runtime-fuzzer/src/runtime/mod.rs @@ -31,7 +31,7 @@ use vara_runtime::{ }; pub use account::{account, alice}; -pub use block::{default_gas_limit, run_to_block, run_to_next_block}; +pub use block::{default_gas_limit, run_to_next_block}; pub use mailbox::get_mailbox_messages; mod account; diff --git a/utils/validator-checks/src/blocks_production.rs b/utils/validator-checks/src/blocks_production.rs index 3a251fc95b9..7635df4cb08 100644 --- a/utils/validator-checks/src/blocks_production.rs +++ b/utils/validator-checks/src/blocks_production.rs @@ -35,7 +35,7 @@ impl BlocksProduction { } let logs = &block.header().digest.logs; - if let Some(DigestItem::PreRuntime(engine, bytes)) = logs.get(0) { + if let Some(DigestItem::PreRuntime(engine, bytes)) = logs.first() { if *engine == BABE_ENGINE_ID { if let Some(author) = BabePreDigest::decode(&mut bytes.as_ref()) .ok() diff --git a/utils/validator-checks/src/result.rs b/utils/validator-checks/src/result.rs index feb286d403c..fe91997c943 100644 --- a/utils/validator-checks/src/result.rs +++ b/utils/validator-checks/src/result.rs @@ -15,7 +15,7 @@ pub enum Error { EnvLogger(#[from] log::SetLoggerError), /// Decoding ss58 address failed. #[error(transparent)] - PublicError(#[from] gsdk::ext::sp_core::crypto::PublicError), + PublicKey(#[from] gsdk::ext::sp_core::crypto::PublicError), /// Blocks production validation failed. #[error("Some validators didn't produce blocks.")] BlocksProduction, diff --git a/utils/wasm-gen/src/tests.rs b/utils/wasm-gen/src/tests.rs index 8db5c816e40..b8f7163b571 100644 --- a/utils/wasm-gen/src/tests.rs +++ b/utils/wasm-gen/src/tests.rs @@ -184,7 +184,7 @@ fn injecting_addresses_works() { .entries(); let first_addr_offset = entries - .get(0) + .first() .and_then(|segment| segment.offset().as_ref()) .map(|expr| &expr.code()[0]) .expect("checked"); From 6605cfaf4107ff16fd9d7d493a77539aa52deb92 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Fri, 8 Dec 2023 14:11:46 +0300 Subject: [PATCH 02/14] small fix --- gstd/src/async_runtime/signals.rs | 2 +- gstd/src/msg/async.rs | 2 +- sandbox/host/src/sandbox/wasmer_backend.rs | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/gstd/src/async_runtime/signals.rs b/gstd/src/async_runtime/signals.rs index 7d8b3e979b8..5b4e946be63 100644 --- a/gstd/src/async_runtime/signals.rs +++ b/gstd/src/async_runtime/signals.rs @@ -89,7 +89,7 @@ impl WakeSignals { self.signals.contains_key(&reply_to) } - pub fn poll(&mut self, reply_to: MessageId, cx: &Context<'_>) -> ReplyPoll { + pub fn poll(&mut self, reply_to: MessageId, cx: &mut Context<'_>) -> ReplyPoll { match self.signals.remove(&reply_to) { None => ReplyPoll::None, Some(mut signal @ WakeSignal { payload: None, .. }) => { diff --git a/gstd/src/msg/async.rs b/gstd/src/msg/async.rs index 140f0635844..9cda3082b6e 100644 --- a/gstd/src/msg/async.rs +++ b/gstd/src/msg/async.rs @@ -32,7 +32,7 @@ use core::{ use futures::future::FusedFuture; use scale_info::scale::Decode; -fn poll(waiting_reply_to: MessageId, cx: &Context<'_>, f: F) -> Poll> +fn poll(waiting_reply_to: MessageId, cx: &mut Context<'_>, f: F) -> Poll> where F: Fn(Vec) -> Result, { diff --git a/sandbox/host/src/sandbox/wasmer_backend.rs b/sandbox/host/src/sandbox/wasmer_backend.rs index a0bd58cff3d..a0fb1a730b0 100644 --- a/sandbox/host/src/sandbox/wasmer_backend.rs +++ b/sandbox/host/src/sandbox/wasmer_backend.rs @@ -533,7 +533,6 @@ impl MemoryWrapper { /// See `[memory_as_slice]`. In addition to those requirements, since a mutable reference is /// returned it must be ensured that only one mutable and no shared references to memory /// exists at the same time. - #[allow(clippy::needless_pass_by_ref_mut)] unsafe fn memory_as_slice_mut(memory: &mut sandbox_wasmer::Memory) -> &mut [u8] { let ptr = memory.data_ptr(); From aa1f8c8360fb3553ea47b4048b449924e6681798 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Sat, 9 Dec 2023 11:38:20 +0300 Subject: [PATCH 03/14] update version --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 90810b8b6e8..25341243646 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2023-12-07" +channel = "nightly-2023-12-09" components = [ "llvm-tools" ] targets = [ "wasm32-unknown-unknown" ] profile = "default" From ad341b88269062911337209b4ab101ea41b5dec3 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Sat, 9 Dec 2023 12:10:04 +0300 Subject: [PATCH 04/14] fix clippy --- pallets/gear-voucher/src/benchmarking.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pallets/gear-voucher/src/benchmarking.rs b/pallets/gear-voucher/src/benchmarking.rs index 38aac81bf34..edcb8e004f6 100644 --- a/pallets/gear-voucher/src/benchmarking.rs +++ b/pallets/gear-voucher/src/benchmarking.rs @@ -36,7 +36,7 @@ benchmarks! { issue { let issuer = benchmarking::account::("caller", 0, 0); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &issuer, 100_000_000_000_000_u128.unique_saturated_into() ); From a571f9a9c98c88fdb6bce32058f515b7b32c6466 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Sat, 9 Dec 2023 13:06:30 +0300 Subject: [PATCH 05/14] [skip-ci] fix new lints --- pallets/gear/src/benchmarking/mod.rs | 22 +++++++++---------- pallets/gear/src/benchmarking/tasks.rs | 21 ++++++++++++------ .../benchmarking/tests/syscalls_integrity.rs | 14 ++++++------ pallets/gear/src/runtime_api.rs | 2 +- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/pallets/gear/src/benchmarking/mod.rs b/pallets/gear/src/benchmarking/mod.rs index b911e5bcc97..3e7c98a910e 100644 --- a/pallets/gear/src/benchmarking/mod.rs +++ b/pallets/gear/src/benchmarking/mod.rs @@ -465,9 +465,9 @@ benchmarks! { claim_value { let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); let program_id = benchmarking::account::("program", 0, 100); - CurrencyOf::::deposit_creating(&program_id, 100_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&program_id, 100_000_000_000_000_u128.unique_saturated_into()); let code = benchmarking::generate_wasm2(16.into()).unwrap(); benchmarking::set_program::, _>(ProgramId::from_origin(program_id.clone().into_origin()), code, 1.into()); let original_message_id = MessageId::from_origin(benchmarking::account::("message", 0, 100).into_origin()); @@ -497,7 +497,7 @@ benchmarks! { pay_program_rent { let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); let minimum_balance = CurrencyOf::::minimum_balance(); let code = benchmarking::generate_wasm2(16.into()).unwrap(); let salt = vec![]; @@ -518,7 +518,7 @@ benchmarks! { resume_session_init { let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); let code = benchmarking::generate_wasm2(16.into()).unwrap(); let salt = vec![]; let program_id = ProgramId::generate_from_user(CodeId::generate(&code), &salt); @@ -543,7 +543,7 @@ benchmarks! { resume_session_push { let c in 0 .. 16 * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u32; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); let code = benchmarking::generate_wasm2(16.into()).unwrap(); let salt = vec![]; let program_id = ProgramId::generate_from_user(CodeId::generate(&code), &salt); @@ -579,7 +579,7 @@ benchmarks! { resume_session_commit { let c in 0 .. (MAX_PAGES - 1) * (WASM_PAGE_SIZE / GEAR_PAGE_SIZE) as u32; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 400_000_000_000_000u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, 400_000_000_000_000u128.unique_saturated_into()); let code = benchmarking::generate_wasm2(0.into()).unwrap(); let salt = vec![]; let program_id = ProgramId::generate_from_user(CodeId::generate(&code), &salt); @@ -693,7 +693,7 @@ benchmarks! { send_message { let p in 0 .. MAX_PAYLOAD_LEN; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); let minimum_balance = CurrencyOf::::minimum_balance(); let program_id = ProgramId::from_origin(benchmarking::account::("program", 0, 100).into_origin()); let code = benchmarking::generate_wasm2(16.into()).unwrap(); @@ -709,10 +709,10 @@ benchmarks! { send_reply { let p in 0 .. MAX_PAYLOAD_LEN; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); let minimum_balance = CurrencyOf::::minimum_balance(); let program_id = benchmarking::account::("program", 0, 100); - CurrencyOf::::deposit_creating(&program_id, 100_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&program_id, 100_000_000_000_000_u128.unique_saturated_into()); let code = benchmarking::generate_wasm2(16.into()).unwrap(); benchmarking::set_program::, _>(ProgramId::from_origin(program_id.clone().into_origin()), code, 1.into()); let original_message_id = MessageId::from_origin(benchmarking::account::("message", 0, 100).into_origin()); @@ -743,7 +743,7 @@ benchmarks! { let q in 1 .. MAX_PAGES; let q = q as u16; let caller: T::AccountId = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, (1u128 << 60).unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, (1u128 << 60).unique_saturated_into()); let code = benchmarking::generate_wasm(q.into()).unwrap(); let salt = vec![255u8; 32]; }: { @@ -758,7 +758,7 @@ benchmarks! { let q in 0 .. MAX_PAGES; let q = q as u16; let caller: T::AccountId = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, (1_u128 << 60).unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, (1_u128 << 60).unique_saturated_into()); let code = benchmarking::generate_wasm2(q.into()).unwrap(); let salt = vec![255u8; 32]; }: { diff --git a/pallets/gear/src/benchmarking/tasks.rs b/pallets/gear/src/benchmarking/tasks.rs index a7987fb9412..8b4fe594c8d 100644 --- a/pallets/gear/src/benchmarking/tasks.rs +++ b/pallets/gear/src/benchmarking/tasks.rs @@ -25,7 +25,8 @@ where use demo_delayed_sender::WASM_BINARY; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); init_block::(None); @@ -51,7 +52,8 @@ where T::AccountId: Origin, { let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 400_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 400_000_000_000_000u128.unique_saturated_into()); init_block::(None); @@ -105,7 +107,8 @@ where T::AccountId: Origin, { let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); let code = benchmarking::generate_wasm2(16.into()).unwrap(); let salt = vec![]; let program_id = ProgramId::generate_from_user(CodeId::generate(&code), &salt); @@ -144,7 +147,8 @@ where use demo_reserve_gas::{InitAction, WASM_BINARY}; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); init_block::(None); @@ -211,7 +215,8 @@ where use demo_constructor::{Call, Calls, Scheme, WASM_BINARY}; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); init_block::(None); @@ -267,7 +272,8 @@ where use demo_waiter::{Command, WaitSubcommand, WASM_BINARY}; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); init_block::(None); @@ -317,7 +323,8 @@ where use demo_waiter::{Command, WaitSubcommand, WASM_BINARY}; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); init_block::(None); diff --git a/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs b/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs index f5a8bca4b8e..103a2830b01 100644 --- a/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs +++ b/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs @@ -51,7 +51,7 @@ where utils::init_logger(); let origin = benchmarking::account::("origin", 0, 0); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &origin, 100_000_000_000_000_000_u128.unique_saturated_into(), ); @@ -204,7 +204,7 @@ where { run_tester::(|tester_pid, _| { let default_account = utils::default_account(); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &default_account, 100_000_000_000_000_u128.unique_saturated_into(), ); @@ -394,7 +394,7 @@ where let wasm_module = alloc_free_test_wasm::(); let default_account = utils::default_account(); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &default_account, 100_000_000_000_000_u128.unique_saturated_into(), ); @@ -486,7 +486,7 @@ where { run_tester::(|_, _| { let message_sender = benchmarking::account::("some_user", 0, 0); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &message_sender, 50_000_000_000_000_u128.unique_saturated_into(), ); @@ -1011,7 +1011,7 @@ where // Deploy program with valid code hash let child_deployer = benchmarking::account::("child_deployer", 0, 0); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &child_deployer, 100_000_000_000_000_u128.unique_saturated_into(), ); @@ -1028,7 +1028,7 @@ where // Set default code-hash for create program calls let default_account = utils::default_account(); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &default_account, 100_000_000_000_000_u128.unique_saturated_into(), ); @@ -1089,7 +1089,7 @@ where // Manually reset the storage Gear::::reset(); - CurrencyOf::::slash( + let _ = CurrencyOf::::slash( &Id::from_origin(tester_pid.into_origin()), CurrencyOf::::free_balance(&Id::from_origin(tester_pid.into_origin())), ); diff --git a/pallets/gear/src/runtime_api.rs b/pallets/gear/src/runtime_api.rs index 8885c6d44ff..552a5904c44 100644 --- a/pallets/gear/src/runtime_api.rs +++ b/pallets/gear/src/runtime_api.rs @@ -62,7 +62,7 @@ where let max_balance: BalanceOf = ::GasMultiplier::get() .gas_to_value(initial_gas) + value.unique_saturated_into(); - CurrencyOf::::deposit_creating(&account, max_balance.saturating_sub(balance)); + let _ = CurrencyOf::::deposit_creating(&account, max_balance.saturating_sub(balance)); let who = frame_support::dispatch::RawOrigin::Signed(account); let value: BalanceOf = value.unique_saturated_into(); From bf474e9f5abe03b7cb01864b166ff2cdf9be0a53 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Tue, 12 Dec 2023 19:49:05 +0300 Subject: [PATCH 06/14] rm this file --- rustc-ice-2023-12-12T16_30_42-94085.txt | 94 ------------------------- 1 file changed, 94 deletions(-) delete mode 100644 rustc-ice-2023-12-12T16_30_42-94085.txt diff --git a/rustc-ice-2023-12-12T16_30_42-94085.txt b/rustc-ice-2023-12-12T16_30_42-94085.txt deleted file mode 100644 index d6dae2804cd..00000000000 --- a/rustc-ice-2023-12-12T16_30_42-94085.txt +++ /dev/null @@ -1,94 +0,0 @@ -thread 'rustc' panicked at compiler/rustc_infer/src/infer/at.rs:453:17: -`> as std::future::IntoFuture>` has escaping bound vars, so it cannot be wrapped in a dummy binder. -stack backtrace: - 0: 0x7f2206572da1 - std::backtrace_rs::backtrace::libunwind::trace::hccf3cfe599d26745 - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/std/src/../../backtrace/src/backtrace/libunwind.rs:104:5 - 1: 0x7f2206572da1 - std::backtrace_rs::backtrace::trace_unsynchronized::haa7af8d2b4cbb771 - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/std/src/../../backtrace/src/backtrace/mod.rs:66:5 - 2: 0x7f2206572da1 - std::backtrace::Backtrace::create::hb61fb03ca000ac0e - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/std/src/backtrace.rs:332:13 - 3: 0x7f2206572cf0 - std::backtrace::Backtrace::force_capture::ha2642a8c0082a0f7 - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/std/src/backtrace.rs:313:9 - 4: 0x7f22092f3b7c - std[63a706e8f787616a]::panicking::update_hook::>::{closure#0} - 5: 0x7f220658e618 - as core::ops::function::Fn>::call::h1fb6d1c1593aee78 - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/alloc/src/boxed.rs:2029:9 - 6: 0x7f220658e618 - std::panicking::rust_panic_with_hook::h71d389cf21201b59 - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/std/src/panicking.rs:783:13 - 7: 0x7f220658e36e - std::panicking::begin_panic_handler::{{closure}}::h655372ff562611b4 - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/std/src/panicking.rs:657:13 - 8: 0x7f220658b926 - std::sys_common::backtrace::__rust_end_short_backtrace::h0e91de37c406f2fe - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/std/src/sys_common/backtrace.rs:171:18 - 9: 0x7f220658e0d2 - rust_begin_unwind - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/std/src/panicking.rs:645:5 - 10: 0x7f22065dab65 - core::panicking::panic_fmt::h0290566811e2a53e - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/core/src/panicking.rs:72:14 - 11: 0x7f220aa62f3a - ::match_impl - 12: 0x7f220aa1850b - ::assemble_candidates_from_impls - 13: 0x7f220acfb7aa - ::candidate_from_obligation_no_cache - 14: 0x7f22080a3c7f - ::candidate_from_obligation - 15: 0x7f22080bb325 - ::evaluate_trait_predicate_recursively::{closure#0}::{closure#1} - 16: 0x7f220b008bc0 - ::evaluate_trait_predicate_recursively - 17: 0x7f220b344a85 - ::evaluation_probe::<::evaluate_root_obligation::{closure#0}> - 18: 0x7f220a7f0c9d - rustc_traits[60cf1104940f583f]::evaluate_obligation::evaluate_obligation - 19: 0x7f220a7f0660 - rustc_query_impl[f5ccc45571579d05]::plumbing::__rust_begin_short_backtrace::> - 20: 0x7f220a7edef0 - rustc_query_system[27562f837937fef4]::query::plumbing::try_execute_query::>, rustc_middle[3cd0fd8fa7010d83]::query::erase::Erased<[u8; 2usize]>>, false, false, false>, rustc_query_impl[f5ccc45571579d05]::plumbing::QueryCtxt, true> - 21: 0x7f220a7ed012 - rustc_query_impl[f5ccc45571579d05]::query_impl::evaluate_obligation::get_query_incr::__rust_end_short_backtrace - 22: 0x7f22076beffa - ::evaluate_obligation_no_overflow - 23: 0x7f2208dd8e47 - ::predicate_must_hold_modulo_regions - 24: 0x5593212c7208 - clippy_lints[277303205d454b3]::methods::unnecessary_to_owned::can_change_type - 25: 0x5593212cf8e5 - ::check_expr - 26: 0x7f22096985f0 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr::{closure#0} - 27: 0x7f2209698478 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr - 28: 0x7f220969886e - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr::{closure#0} - 29: 0x7f2209698478 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr - 30: 0x7f220969880e - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr::{closure#0} - 31: 0x7f2209698478 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr - 32: 0x7f22096988df - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr::{closure#0} - 33: 0x7f2209698478 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr - 34: 0x7f220969880e - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr::{closure#0} - 35: 0x7f2209698478 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr - 36: 0x7f22096988df - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr::{closure#0} - 37: 0x7f2209698478 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr - 38: 0x7f2209699700 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_block - 39: 0x7f2209698c48 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr::{closure#0} - 40: 0x7f2209698478 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr - 41: 0x7f2209696e4a - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_nested_body - 42: 0x7f2209698fe4 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_fn - 43: 0x7f2209698c2d - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr::{closure#0} - 44: 0x7f2209698478 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr - 45: 0x7f2209699700 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_block - 46: 0x7f2209698c48 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr::{closure#0} - 47: 0x7f2209698478 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_expr - 48: 0x7f2209696e4a - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_nested_body - 49: 0x7f2209698fe4 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_fn - 50: 0x7f2209697695 - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_item - 51: 0x7f220969931a - as rustc_hir[2bc89bd1d481614d]::intravisit::Visitor>::visit_mod - 52: 0x7f220af91a69 - rustc_lint[83a746896f00c08a]::late::check_crate::{closure#0} - 53: 0x7f220af91cba - rustc_lint[83a746896f00c08a]::late::check_crate - 54: 0x7f220aea4a91 - rustc_interface[3a1e345ecc972694]::passes::analysis - 55: 0x7f220aea3a9d - rustc_query_impl[f5ccc45571579d05]::plumbing::__rust_begin_short_backtrace::> - 56: 0x7f220b583fcb - rustc_query_system[27562f837937fef4]::query::plumbing::try_execute_query::>, false, false, false>, rustc_query_impl[f5ccc45571579d05]::plumbing::QueryCtxt, true> - 57: 0x7f220b583c74 - rustc_query_impl[f5ccc45571579d05]::query_impl::analysis::get_query_incr::__rust_end_short_backtrace - 58: 0x7f220b5f5597 - rustc_interface[3a1e345ecc972694]::interface::run_compiler::, rustc_driver_impl[98adf24451642c5c]::run_compiler::{closure#0}>::{closure#0} - 59: 0x7f220b598cdf - std[63a706e8f787616a]::sys_common::backtrace::__rust_begin_short_backtrace::, rustc_driver_impl[98adf24451642c5c]::run_compiler::{closure#0}>::{closure#0}, core[10fc8ff5d1438c73]::result::Result<(), rustc_span[bebb6495ac98f822]::ErrorGuaranteed>>::{closure#0}, core[10fc8ff5d1438c73]::result::Result<(), rustc_span[bebb6495ac98f822]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[10fc8ff5d1438c73]::result::Result<(), rustc_span[bebb6495ac98f822]::ErrorGuaranteed>> - 60: 0x7f220b598b09 - <::spawn_unchecked_, rustc_driver_impl[98adf24451642c5c]::run_compiler::{closure#0}>::{closure#0}, core[10fc8ff5d1438c73]::result::Result<(), rustc_span[bebb6495ac98f822]::ErrorGuaranteed>>::{closure#0}, core[10fc8ff5d1438c73]::result::Result<(), rustc_span[bebb6495ac98f822]::ErrorGuaranteed>>::{closure#0}::{closure#0}, core[10fc8ff5d1438c73]::result::Result<(), rustc_span[bebb6495ac98f822]::ErrorGuaranteed>>::{closure#1} as core[10fc8ff5d1438c73]::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} - 61: 0x7f22065984a5 - as core::ops::function::FnOnce>::call_once::h393c2ea0d143c635 - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/alloc/src/boxed.rs:2015:9 - 62: 0x7f22065984a5 - as core::ops::function::FnOnce>::call_once::h9fe7ff8f459c008e - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/alloc/src/boxed.rs:2015:9 - 63: 0x7f22065984a5 - std::sys::unix::thread::Thread::new::thread_start::h83837285baf7b768 - at /rustc/f967532a47eb728ada44473a5c4c2eca1a45fe30/library/std/src/sys/unix/thread.rs:108:17 - 64: 0x7f2206094ac3 - start_thread - at ./nptl/pthread_create.c:442:8 - 65: 0x7f2206126660 - clone3 - at ./misc/../sysdeps/unix/sysv/linux/x86_64/clone3.S:81 - 66: 0x0 - - - -rustc version: 1.76.0-nightly (f967532a4 2023-12-08) -platform: x86_64-unknown-linux-gnu - -query stack during panic: -#0 [evaluate_obligation] evaluating trait selection obligation `gclient::api::calls::::upload_program_bytes::{opaque#0}: core::future::into_future::IntoFuture` -#1 [analysis] running analysis passes on this crate -end of query stack From e1a04984d6a2c7d5e76e37595c84c9b4613fbd38 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Thu, 25 Jan 2024 09:18:04 +0300 Subject: [PATCH 07/14] try nightly-2024-01-25 --- rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 0a4a3bae84c..083e594e40c 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "nightly-2023-12-30" +channel = "nightly-2024-01-25" components = [ "llvm-tools" ] targets = [ "wasm32-unknown-unknown" ] profile = "default" From bbc73fec4c3ceec3c96c8afd2966b245d24da3a7 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:07:37 +0300 Subject: [PATCH 08/14] fix errors after merge --- common/src/gas_provider/property_tests/mod.rs | 4 ++-- examples/calc-hash/over-blocks/src/wasm.rs | 4 ++-- examples/constructor/src/wasm.rs | 2 +- examples/init-wait/src/wasm.rs | 4 ++-- examples/new-meta/src/wasm.rs | 4 ++-- examples/reserve-gas/src/wasm.rs | 4 ++-- examples/signal-entry/src/wasm.rs | 4 ++-- examples/state-rollback/src/wasm.rs | 5 ++-- examples/wait/src/wasm.rs | 3 ++- examples/waiter/src/wasm.rs | 23 +++++++++++++------ gstd/tests/debug.rs | 11 +++++---- pallets/gear-voucher/src/benchmarking.rs | 6 ++--- pallets/gear/src/benchmarking/mod.rs | 10 ++++---- pallets/gear/src/benchmarking/tasks.rs | 15 ++++++++---- .../benchmarking/tests/syscalls_integrity.rs | 17 ++++++++------ pallets/gear/src/mock.rs | 2 +- pallets/gear/src/runtime_api.rs | 5 +++- pallets/gear/src/tests.rs | 2 +- sandbox/host/src/sandbox.rs | 2 ++ scripts/src/clippy.sh | 7 +++--- 20 files changed, 80 insertions(+), 54 deletions(-) diff --git a/common/src/gas_provider/property_tests/mod.rs b/common/src/gas_provider/property_tests/mod.rs index 314852c3cf6..e6782739b97 100644 --- a/common/src/gas_provider/property_tests/mod.rs +++ b/common/src/gas_provider/property_tests/mod.rs @@ -94,7 +94,7 @@ type Balance = u64; type Funds = u128; std::thread_local! { - static TOTAL_ISSUANCE: RefCell> = RefCell::new(None); + static TOTAL_ISSUANCE: RefCell> = const { RefCell::new(None) }; } #[derive(Debug, PartialEq, Eq)] @@ -177,7 +177,7 @@ impl From for GasNodeId { } std::thread_local! { - static GAS_TREE_NODES: RefCell> = RefCell::new(BTreeMap::new()); + static GAS_TREE_NODES: RefCell> = const { RefCell::new(BTreeMap::new()) }; } struct GasTreeNodesWrap; diff --git a/examples/calc-hash/over-blocks/src/wasm.rs b/examples/calc-hash/over-blocks/src/wasm.rs index 2cdc19f8526..f4b5319ec71 100644 --- a/examples/calc-hash/over-blocks/src/wasm.rs +++ b/examples/calc-hash/over-blocks/src/wasm.rs @@ -1,5 +1,5 @@ use crate::Method; -use gstd::{exec, msg}; +use gstd::{exec, msg, prelude::*}; use types::Package; #[no_mangle] @@ -11,7 +11,7 @@ extern "C" fn init() { extern "C" fn handle() { let threshold = unsafe { state::THRESHOLD.expect("Threshold has not been set.") }; let method = msg::load::().expect("Invalid contract method."); - let registry = unsafe { &mut state::REGISTRY }; + let registry = unsafe { &mut *ptr::addr_of_mut!(state::REGISTRY) }; match method { Method::Start { expected, id, src } => { diff --git a/examples/constructor/src/wasm.rs b/examples/constructor/src/wasm.rs index 3848d0516ef..6377f1bd13b 100644 --- a/examples/constructor/src/wasm.rs +++ b/examples/constructor/src/wasm.rs @@ -7,7 +7,7 @@ static mut SCHEME: Option = None; fn process_fn<'a>(f: impl Fn(&'a Scheme) -> Option<&'a Vec>) { let scheme = unsafe { SCHEME.as_ref() }.expect("Should be set before access"); let calls = f(scheme) - .map(Clone::clone) + .cloned() .unwrap_or_else(|| msg::load().expect("Failed to load payload")); let mut res = None; diff --git a/examples/init-wait/src/wasm.rs b/examples/init-wait/src/wasm.rs index 103b86a62d3..e309ec2b4c0 100644 --- a/examples/init-wait/src/wasm.rs +++ b/examples/init-wait/src/wasm.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gstd::{collections::BTreeMap, exec, msg, MessageId}; +use gstd::{collections::BTreeMap, exec, msg, prelude::*, MessageId}; #[derive(PartialEq, Debug)] enum State { @@ -40,7 +40,7 @@ extern "C" fn handle() { #[no_mangle] extern "C" fn init() { - let state = unsafe { &mut STATE }; + let state = unsafe { &mut *ptr::addr_of_mut!(STATE) }; match state { State::NotInited => { for k in 0..20 { diff --git a/examples/new-meta/src/wasm.rs b/examples/new-meta/src/wasm.rs index 906aaee1b44..11e0ee60708 100644 --- a/examples/new-meta/src/wasm.rs +++ b/examples/new-meta/src/wasm.rs @@ -24,10 +24,10 @@ extern "C" fn init() { extern "C" fn handle() { let message_in: MessageIn = msg::load().unwrap(); - let res = unsafe { &WALLETS } + let res = unsafe { &*ptr::addr_of!(WALLETS) } .iter() .find(|w| w.id.decimal == message_in.id.decimal) - .map(Clone::clone); + .cloned(); let message_out = MessageOut { res }; diff --git a/examples/reserve-gas/src/wasm.rs b/examples/reserve-gas/src/wasm.rs index 0d87110b198..17abc8b1a3a 100644 --- a/examples/reserve-gas/src/wasm.rs +++ b/examples/reserve-gas/src/wasm.rs @@ -62,7 +62,7 @@ extern "C" fn init() { ) }; } - InitAction::Wait => match unsafe { &WAKE_STATE } { + InitAction::Wait => match unsafe { &*ptr::addr_of!(WAKE_STATE) } { WakeState::Initial => { let _reservation = ReservationId::reserve(50_000, 10); // to find message to reply to in test @@ -152,7 +152,7 @@ extern "C" fn handle() { } } HandleAction::ConsumeReservationsFromList => { - let reservations = unsafe { mem::take(&mut RESERVATIONS) }; + let reservations = unsafe { mem::take(&mut *ptr::addr_of_mut!(RESERVATIONS)) }; for reservation_id in reservations { msg::send_from_reservation( reservation_id, diff --git a/examples/signal-entry/src/wasm.rs b/examples/signal-entry/src/wasm.rs index 8fb46cf5f3c..fbbf82f1478 100644 --- a/examples/signal-entry/src/wasm.rs +++ b/examples/signal-entry/src/wasm.rs @@ -49,7 +49,7 @@ extern "C" fn init() { #[no_mangle] extern "C" fn handle() { unsafe { HANDLE_MSG = Some(msg::id()) }; - let do_panic = unsafe { &mut DO_PANIC }; + let do_panic = unsafe { &mut *ptr::addr_of_mut!(DO_PANIC) }; let action: HandleAction = msg::load().unwrap(); match action { @@ -234,7 +234,7 @@ extern "C" fn handle() { #[no_mangle] extern "C" fn handle_signal() { - match unsafe { &HANDLE_SIGNAL_STATE } { + match unsafe { &*ptr::addr_of!(HANDLE_SIGNAL_STATE) } { HandleSignalState::Normal => { msg::send(unsafe { INITIATOR }, b"handle_signal", 0).unwrap(); let signal_code = msg::signal_code() diff --git a/examples/state-rollback/src/wasm.rs b/examples/state-rollback/src/wasm.rs index eb6096d83ab..5bcb46510e9 100644 --- a/examples/state-rollback/src/wasm.rs +++ b/examples/state-rollback/src/wasm.rs @@ -25,7 +25,8 @@ extern "C" fn handle() { let payload = msg::load_bytes().expect("Failed to load payload"); // Previous value - msg::send(msg::source(), unsafe { &PAYLOAD }, 0).expect("Failed to send message"); + msg::send(msg::source(), unsafe { &*ptr::addr_of!(PAYLOAD) }, 0) + .expect("Failed to send message"); let is_panic = payload == b"panic"; let is_leave = payload == b"leave"; @@ -34,7 +35,7 @@ extern "C" fn handle() { unsafe { PAYLOAD = Some(payload) }; // Newly set value - msg::reply(unsafe { &PAYLOAD }, 0).expect("Failed to send reply"); + msg::reply(unsafe { &*ptr::addr_of!(PAYLOAD) }, 0).expect("Failed to send reply"); // Stop execution with panic. is_panic.then(|| panic!()); diff --git a/examples/wait/src/wasm.rs b/examples/wait/src/wasm.rs index e6b4c70eafc..3506aef51f6 100644 --- a/examples/wait/src/wasm.rs +++ b/examples/wait/src/wasm.rs @@ -19,6 +19,7 @@ // for panic/oom handlers extern crate gstd; +use core::ptr; use gcore::{exec, msg, MessageId}; static mut STATE: u32 = 0; @@ -27,7 +28,7 @@ static mut MSG_ID_2: MessageId = MessageId::zero(); #[no_mangle] extern "C" fn handle() { - let state = unsafe { &mut STATE }; + let state = unsafe { &mut *ptr::addr_of_mut!(STATE) }; gstd::debug!("{state}"); match *state { diff --git a/examples/waiter/src/wasm.rs b/examples/waiter/src/wasm.rs index f92987b6f1f..03161230643 100644 --- a/examples/waiter/src/wasm.rs +++ b/examples/waiter/src/wasm.rs @@ -23,7 +23,7 @@ use crate::{ use core::ops::{Deref, DerefMut}; use futures::future; use gstd::{ - exec, format, msg, + exec, format, msg, ptr, sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}, }; @@ -117,21 +117,24 @@ async fn main() { }; let lock_guard = lock.await; process_mx_lock_continuation( - unsafe { &mut MUTEX_LOCK_GUARD }, + unsafe { &mut *ptr::addr_of_mut!(MUTEX_LOCK_GUARD) }, lock_guard, continuation, ) .await; } Command::MxLockStaticAccess(subcommand) => { - process_lock_static_access_subcommand_mut(unsafe { &mut MUTEX_LOCK_GUARD }, subcommand); + process_lock_static_access_subcommand_mut( + unsafe { &mut *ptr::addr_of_mut!(MUTEX_LOCK_GUARD) }, + subcommand, + ); } Command::RwLock(lock_type, continuation) => { match lock_type { RwLockType::Read => { let lock_guard = unsafe { RW_LOCK.read().await }; process_rw_lock_continuation( - unsafe { &mut R_LOCK_GUARD }, + unsafe { &mut *ptr::addr_of_mut!(R_LOCK_GUARD) }, lock_guard, continuation, ) @@ -140,7 +143,7 @@ async fn main() { RwLockType::Write => { let lock_guard = unsafe { RW_LOCK.write().await }; process_rw_lock_continuation( - unsafe { &mut W_LOCK_GUARD }, + unsafe { &mut *ptr::addr_of_mut!(W_LOCK_GUARD) }, lock_guard, continuation, ) @@ -150,10 +153,16 @@ async fn main() { } Command::RwLockStaticAccess(lock_type, subcommand) => match lock_type { RwLockType::Read => { - process_lock_static_access_subcommand(unsafe { &mut R_LOCK_GUARD }, subcommand); + process_lock_static_access_subcommand( + unsafe { &mut *ptr::addr_of_mut!(R_LOCK_GUARD) }, + subcommand, + ); } RwLockType::Write => { - process_lock_static_access_subcommand_mut(unsafe { &mut W_LOCK_GUARD }, subcommand); + process_lock_static_access_subcommand_mut( + unsafe { &mut *ptr::addr_of_mut!(W_LOCK_GUARD) }, + subcommand, + ); } }, } diff --git a/gstd/tests/debug.rs b/gstd/tests/debug.rs index 1d786ec4355..4a02eeebac2 100644 --- a/gstd/tests/debug.rs +++ b/gstd/tests/debug.rs @@ -17,17 +17,20 @@ fn test_debug() { let value = 42; debug!("{value}"); - assert_eq!(unsafe { &DEBUG_MSG }, b"42"); + assert_eq!(unsafe { &*ptr::addr_of!(DEBUG_MSG) }, b"42"); debug!("Formatted: value = {value}"); - assert_eq!(unsafe { &DEBUG_MSG }, b"Formatted: value = 42"); + assert_eq!( + unsafe { &*ptr::addr_of!(DEBUG_MSG) }, + b"Formatted: value = 42" + ); debug!("String literal"); - assert_eq!(unsafe { &DEBUG_MSG }, b"String literal"); + assert_eq!(unsafe { &*ptr::addr_of!(DEBUG_MSG) }, b"String literal"); crate::dbg!(value); assert_eq!( - unsafe { &DEBUG_MSG }, + unsafe { &*ptr::addr_of!(DEBUG_MSG) }, b"[gstd/tests/debug.rs:28:5] value = 42" ); } diff --git a/pallets/gear-voucher/src/benchmarking.rs b/pallets/gear-voucher/src/benchmarking.rs index b803b6ff906..77a8246cb8e 100644 --- a/pallets/gear-voucher/src/benchmarking.rs +++ b/pallets/gear-voucher/src/benchmarking.rs @@ -35,7 +35,7 @@ benchmarks! { issue { // Origin account. let origin = benchmarking::account::("origin", 0, 0); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &origin, 100_000_000_000_000_u128.unique_saturated_into() ); @@ -72,7 +72,7 @@ benchmarks! { revoke { // Origin account. let origin = benchmarking::account::("origin", 0, 0); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &origin, 100_000_000_000_000_u128.unique_saturated_into() ); @@ -102,7 +102,7 @@ benchmarks! { update { // Origin account. let origin = benchmarking::account::("origin", 0, 0); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &origin, 100_000_000_000_000_u128.unique_saturated_into() ); diff --git a/pallets/gear/src/benchmarking/mod.rs b/pallets/gear/src/benchmarking/mod.rs index 5ab9ebfc892..89b614a5b7b 100644 --- a/pallets/gear/src/benchmarking/mod.rs +++ b/pallets/gear/src/benchmarking/mod.rs @@ -423,9 +423,9 @@ benchmarks! { claim_value { let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); let program_id = benchmarking::account::("program", 0, 100); - CurrencyOf::::deposit_creating(&program_id, 100_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&program_id, 100_000_000_000_000_u128.unique_saturated_into()); let code = benchmarking::generate_wasm(16.into()).unwrap(); benchmarking::set_program::, _>(program_id.clone().cast(), code, 1.into()); let original_message_id = benchmarking::account::("message", 0, 100).cast(); @@ -527,7 +527,7 @@ benchmarks! { send_message { let p in 0 .. MAX_PAYLOAD_LEN; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); let minimum_balance = CurrencyOf::::minimum_balance(); let program_id = benchmarking::account::("program", 0, 100).cast(); let code = benchmarking::generate_wasm(16.into()).unwrap(); @@ -543,10 +543,10 @@ benchmarks! { send_reply { let p in 0 .. MAX_PAYLOAD_LEN; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&caller, 100_000_000_000_000_u128.unique_saturated_into()); let minimum_balance = CurrencyOf::::minimum_balance(); let program_id = benchmarking::account::("program", 0, 100); - CurrencyOf::::deposit_creating(&program_id, 100_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating(&program_id, 100_000_000_000_000_u128.unique_saturated_into()); let code = benchmarking::generate_wasm(16.into()).unwrap(); benchmarking::set_program::, _>(program_id.clone().cast(), code, 1.into()); let original_message_id = benchmarking::account::("message", 0, 100).cast(); diff --git a/pallets/gear/src/benchmarking/tasks.rs b/pallets/gear/src/benchmarking/tasks.rs index 0107a1409d0..c94c6f1de48 100644 --- a/pallets/gear/src/benchmarking/tasks.rs +++ b/pallets/gear/src/benchmarking/tasks.rs @@ -25,7 +25,8 @@ where use demo_delayed_sender::WASM_BINARY; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); init_block::(None); @@ -53,7 +54,8 @@ where use demo_reserve_gas::{InitAction, WASM_BINARY}; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); init_block::(None); @@ -120,7 +122,8 @@ where use demo_constructor::{Call, Calls, Scheme, WASM_BINARY}; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); init_block::(None); @@ -176,7 +179,8 @@ where use demo_waiter::{Command, WaitSubcommand, WASM_BINARY}; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); init_block::(None); @@ -226,7 +230,8 @@ where use demo_waiter::{Command, WaitSubcommand, WASM_BINARY}; let caller = benchmarking::account("caller", 0, 0); - CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); + let _ = + CurrencyOf::::deposit_creating(&caller, 200_000_000_000_000u128.unique_saturated_into()); init_block::(None); diff --git a/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs b/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs index ae128871788..b7be7a58668 100644 --- a/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs +++ b/pallets/gear/src/benchmarking/tests/syscalls_integrity.rs @@ -50,7 +50,7 @@ where utils::init_logger(); let origin = benchmarking::account::("origin", 0, 0); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &origin, 100_000_000_000_000_000_u128.unique_saturated_into(), ); @@ -145,7 +145,10 @@ where utils::init_logger(); let origin = benchmarking::account::("origin", 0, 0); - CurrencyOf::::deposit_creating(&origin, 5_000_000_000_000_000_u128.unique_saturated_into()); + let _ = CurrencyOf::::deposit_creating( + &origin, + 5_000_000_000_000_000_u128.unique_saturated_into(), + ); let salt = b"signal_stack_limit_exceeded_works salt"; @@ -440,7 +443,7 @@ where let wasm_module = alloc_free_test_wasm::(); let default_account = utils::default_account(); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &default_account, 100_000_000_000_000_u128.unique_saturated_into(), ); @@ -532,7 +535,7 @@ where { run_tester::(|_, _| { let message_sender = benchmarking::account::("some_user", 0, 0); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &message_sender, 50_000_000_000_000_u128.unique_saturated_into(), ); @@ -1057,7 +1060,7 @@ where // Deploy program with valid code hash let child_deployer = benchmarking::account::("child_deployer", 0, 0); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &child_deployer, 100_000_000_000_000_u128.unique_saturated_into(), ); @@ -1074,7 +1077,7 @@ where // Set default code-hash for create program calls let default_account = utils::default_account(); - CurrencyOf::::deposit_creating( + let _ = CurrencyOf::::deposit_creating( &default_account, 100_000_000_000_000_u128.unique_saturated_into(), ); @@ -1135,7 +1138,7 @@ where // Manually reset the storage Gear::::reset(); - CurrencyOf::::slash( + let _ = CurrencyOf::::slash( &tester_pid.cast(), CurrencyOf::::free_balance(&tester_pid.cast()), ); diff --git a/pallets/gear/src/mock.rs b/pallets/gear/src/mock.rs index b2e88593176..b56e1ac1919 100644 --- a/pallets/gear/src/mock.rs +++ b/pallets/gear/src/mock.rs @@ -113,7 +113,7 @@ parameter_types! { } thread_local! { - static SCHEDULE: RefCell>> = RefCell::new(None); + static SCHEDULE: RefCell>> = const { RefCell::new(None) }; } #[derive(Debug)] diff --git a/pallets/gear/src/runtime_api.rs b/pallets/gear/src/runtime_api.rs index bf6615310f3..4403ba7c724 100644 --- a/pallets/gear/src/runtime_api.rs +++ b/pallets/gear/src/runtime_api.rs @@ -71,7 +71,10 @@ where .saturating_add(value_for_gas) .saturating_add(value); - CurrencyOf::::deposit_creating(&origin, required_balance.saturating_sub(origin_balance)); + let _ = CurrencyOf::::deposit_creating( + &origin, + required_balance.saturating_sub(origin_balance), + ); let who = frame_support::dispatch::RawOrigin::Signed(origin); diff --git a/pallets/gear/src/tests.rs b/pallets/gear/src/tests.rs index 35c16f74bed..63bdaeb78c0 100644 --- a/pallets/gear/src/tests.rs +++ b/pallets/gear/src/tests.rs @@ -14825,7 +14825,7 @@ mod utils { let mut found_status: Option = None; System::events().iter().for_each(|e| { if let MockRuntimeEvent::Gear(Event::MessagesDispatched { statuses, .. }) = &e.event { - found_status = statuses.get(&message_id).map(Clone::clone); + found_status = statuses.get(&message_id).cloned(); } }); diff --git a/sandbox/host/src/sandbox.rs b/sandbox/host/src/sandbox.rs index 72958d47e49..b2d2fdd41ba 100644 --- a/sandbox/host/src/sandbox.rs +++ b/sandbox/host/src/sandbox.rs @@ -538,6 +538,7 @@ impl Store
{ /// /// Returns `Err` If `instance_idx` isn't a valid index of an instance or /// instance is already torndown. + #[allow(clippy::useless_asref)] pub fn instance(&self, instance_idx: u32) -> Result>> { self.instances .get(instance_idx as usize) @@ -553,6 +554,7 @@ impl Store
{ /// /// Returns `Err` If `instance_idx` isn't a valid index of an instance or /// instance is already torndown. + #[allow(clippy::useless_asref)] pub fn dispatch_thunk(&self, instance_idx: u32) -> Result
{ self.instances .get(instance_idx as usize) diff --git a/scripts/src/clippy.sh b/scripts/src/clippy.sh index 5a381a2c3c8..b70925273ea 100755 --- a/scripts/src/clippy.sh +++ b/scripts/src/clippy.sh @@ -20,14 +20,13 @@ EOF } gear_clippy() { - # TODO #3452: remove `-A clippy::needless_pass_by_ref_mut`, `-A clippy::assertions_on_constants` on next rust update EXCLUDE_PACKAGES="--exclude vara-runtime --exclude runtime-fuzzer --exclude runtime-fuzzer-fuzz" INCLUDE_PACKAGES="-p vara-runtime -p runtime-fuzzer -p runtime-fuzzer-fuzz" - __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy --workspace "$@" $EXCLUDE_PACKAGES -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut -A clippy::assertions_on_constants - __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy $INCLUDE_PACKAGES --all-features -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut -A clippy::assertions_on_constants + __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy --workspace "$@" $EXCLUDE_PACKAGES -- --no-deps -D warnings + __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy $INCLUDE_PACKAGES --all-features -- --no-deps -D warnings } examples_clippy() { - __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy -p "demo-*" -p test-syscalls --no-default-features "$@" -- --no-deps -D warnings -A clippy::needless_pass_by_ref_mut -A clippy::assertions_on_constants + __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy -p "demo-*" -p test-syscalls --no-default-features "$@" -- --no-deps -D warnings } From 00f0ac0a7aa06ac5e7ad60f008bb77442a65d2ba Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Thu, 25 Jan 2024 11:34:27 +0300 Subject: [PATCH 09/14] fix wasm builder --- utils/wasm-builder/src/cargo_toolchain.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/wasm-builder/src/cargo_toolchain.rs b/utils/wasm-builder/src/cargo_toolchain.rs index 5fc6ab8fccb..9ed62ff3f5b 100644 --- a/utils/wasm-builder/src/cargo_toolchain.rs +++ b/utils/wasm-builder/src/cargo_toolchain.rs @@ -36,7 +36,7 @@ pub(crate) struct Toolchain(String); impl Toolchain { /// This is a version of nightly toolchain, tested on our CI. - const PINNED_NIGHTLY_TOOLCHAIN: &'static str = "nightly-2023-09-05"; + const PINNED_NIGHTLY_TOOLCHAIN: &'static str = "nightly-2024-01-25"; /// Returns `Toolchain` representing the recommended nightly version. pub fn recommended_nightly() -> Self { From 93ab5a8084646e1762526435e8eaa3337e6ee353 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:11:14 +0300 Subject: [PATCH 10/14] fix gstd tests --- gstd/tests/debug.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gstd/tests/debug.rs b/gstd/tests/debug.rs index 4a02eeebac2..333e24bae12 100644 --- a/gstd/tests/debug.rs +++ b/gstd/tests/debug.rs @@ -31,6 +31,6 @@ fn test_debug() { crate::dbg!(value); assert_eq!( unsafe { &*ptr::addr_of!(DEBUG_MSG) }, - b"[gstd/tests/debug.rs:28:5] value = 42" + b"[gstd/tests/debug.rs:31:5] value = 42" ); } From 7fc9671ef7eff8b1781a13d0fc80762099a1f145 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Thu, 25 Jan 2024 12:44:52 +0300 Subject: [PATCH 11/14] fix fuzzer test --- utils/runtime-fuzzer/src/gear_calls.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/runtime-fuzzer/src/gear_calls.rs b/utils/runtime-fuzzer/src/gear_calls.rs index 7cefd33d5b6..20998a3af19 100644 --- a/utils/runtime-fuzzer/src/gear_calls.rs +++ b/utils/runtime-fuzzer/src/gear_calls.rs @@ -55,7 +55,7 @@ const MAX_SALT_SIZE: usize = 512; const _: () = assert!(MAX_SALT_SIZE <= gear_core::message::MAX_PAYLOAD_SIZE); const ID_SIZE: usize = mem::size_of::(); -const GAS_AND_VALUE_SIZE: usize = mem::size_of::<(u64, u128)>(); +const GAS_AND_VALUE_SIZE: usize = mem::size_of::() + mem::size_of::(); /// Used to make sure that generators will not exceed `Unstructured` size as it's used not only /// to generate things like wasm code or message payload but also to generate some auxiliary From 26c1919bdbe9fa1686cc356267e39586cb216f3b Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Thu, 1 Feb 2024 17:20:34 +0300 Subject: [PATCH 12/14] remove ptr::addr_of --- examples/calc-hash/over-blocks/src/wasm.rs | 4 ++-- examples/init-wait/src/wasm.rs | 4 ++-- examples/new-meta/src/wasm.rs | 2 +- examples/reserve-gas/src/wasm.rs | 4 ++-- examples/signal-entry/src/wasm.rs | 4 ++-- examples/state-rollback/src/wasm.rs | 5 ++--- examples/wait/src/wasm.rs | 3 +-- examples/waiter/src/wasm.rs | 23 +++++++--------------- scripts/src/clippy.sh | 2 +- 9 files changed, 20 insertions(+), 31 deletions(-) diff --git a/examples/calc-hash/over-blocks/src/wasm.rs b/examples/calc-hash/over-blocks/src/wasm.rs index feb9e55d04c..8285343e4f8 100644 --- a/examples/calc-hash/over-blocks/src/wasm.rs +++ b/examples/calc-hash/over-blocks/src/wasm.rs @@ -1,5 +1,5 @@ use crate::Method; -use gstd::{exec, msg, prelude::*}; +use gstd::{exec, msg}; use types::Package; #[no_mangle] @@ -11,7 +11,7 @@ extern "C" fn init() { extern "C" fn handle() { let threshold = unsafe { state::THRESHOLD.expect("Threshold has not been set.") }; let method = msg::load::().expect("Invalid program method."); - let registry = unsafe { &mut *ptr::addr_of_mut!(state::REGISTRY) }; + let registry = unsafe { &mut state::REGISTRY }; match method { Method::Start { expected, id, src } => { diff --git a/examples/init-wait/src/wasm.rs b/examples/init-wait/src/wasm.rs index e309ec2b4c0..103b86a62d3 100644 --- a/examples/init-wait/src/wasm.rs +++ b/examples/init-wait/src/wasm.rs @@ -16,7 +16,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -use gstd::{collections::BTreeMap, exec, msg, prelude::*, MessageId}; +use gstd::{collections::BTreeMap, exec, msg, MessageId}; #[derive(PartialEq, Debug)] enum State { @@ -40,7 +40,7 @@ extern "C" fn handle() { #[no_mangle] extern "C" fn init() { - let state = unsafe { &mut *ptr::addr_of_mut!(STATE) }; + let state = unsafe { &mut STATE }; match state { State::NotInited => { for k in 0..20 { diff --git a/examples/new-meta/src/wasm.rs b/examples/new-meta/src/wasm.rs index 11e0ee60708..ff62c7830a0 100644 --- a/examples/new-meta/src/wasm.rs +++ b/examples/new-meta/src/wasm.rs @@ -24,7 +24,7 @@ extern "C" fn init() { extern "C" fn handle() { let message_in: MessageIn = msg::load().unwrap(); - let res = unsafe { &*ptr::addr_of!(WALLETS) } + let res = unsafe { &WALLETS } .iter() .find(|w| w.id.decimal == message_in.id.decimal) .cloned(); diff --git a/examples/reserve-gas/src/wasm.rs b/examples/reserve-gas/src/wasm.rs index 17abc8b1a3a..0d87110b198 100644 --- a/examples/reserve-gas/src/wasm.rs +++ b/examples/reserve-gas/src/wasm.rs @@ -62,7 +62,7 @@ extern "C" fn init() { ) }; } - InitAction::Wait => match unsafe { &*ptr::addr_of!(WAKE_STATE) } { + InitAction::Wait => match unsafe { &WAKE_STATE } { WakeState::Initial => { let _reservation = ReservationId::reserve(50_000, 10); // to find message to reply to in test @@ -152,7 +152,7 @@ extern "C" fn handle() { } } HandleAction::ConsumeReservationsFromList => { - let reservations = unsafe { mem::take(&mut *ptr::addr_of_mut!(RESERVATIONS)) }; + let reservations = unsafe { mem::take(&mut RESERVATIONS) }; for reservation_id in reservations { msg::send_from_reservation( reservation_id, diff --git a/examples/signal-entry/src/wasm.rs b/examples/signal-entry/src/wasm.rs index fbbf82f1478..8fb46cf5f3c 100644 --- a/examples/signal-entry/src/wasm.rs +++ b/examples/signal-entry/src/wasm.rs @@ -49,7 +49,7 @@ extern "C" fn init() { #[no_mangle] extern "C" fn handle() { unsafe { HANDLE_MSG = Some(msg::id()) }; - let do_panic = unsafe { &mut *ptr::addr_of_mut!(DO_PANIC) }; + let do_panic = unsafe { &mut DO_PANIC }; let action: HandleAction = msg::load().unwrap(); match action { @@ -234,7 +234,7 @@ extern "C" fn handle() { #[no_mangle] extern "C" fn handle_signal() { - match unsafe { &*ptr::addr_of!(HANDLE_SIGNAL_STATE) } { + match unsafe { &HANDLE_SIGNAL_STATE } { HandleSignalState::Normal => { msg::send(unsafe { INITIATOR }, b"handle_signal", 0).unwrap(); let signal_code = msg::signal_code() diff --git a/examples/state-rollback/src/wasm.rs b/examples/state-rollback/src/wasm.rs index 5bcb46510e9..eb6096d83ab 100644 --- a/examples/state-rollback/src/wasm.rs +++ b/examples/state-rollback/src/wasm.rs @@ -25,8 +25,7 @@ extern "C" fn handle() { let payload = msg::load_bytes().expect("Failed to load payload"); // Previous value - msg::send(msg::source(), unsafe { &*ptr::addr_of!(PAYLOAD) }, 0) - .expect("Failed to send message"); + msg::send(msg::source(), unsafe { &PAYLOAD }, 0).expect("Failed to send message"); let is_panic = payload == b"panic"; let is_leave = payload == b"leave"; @@ -35,7 +34,7 @@ extern "C" fn handle() { unsafe { PAYLOAD = Some(payload) }; // Newly set value - msg::reply(unsafe { &*ptr::addr_of!(PAYLOAD) }, 0).expect("Failed to send reply"); + msg::reply(unsafe { &PAYLOAD }, 0).expect("Failed to send reply"); // Stop execution with panic. is_panic.then(|| panic!()); diff --git a/examples/wait/src/wasm.rs b/examples/wait/src/wasm.rs index 3506aef51f6..e6b4c70eafc 100644 --- a/examples/wait/src/wasm.rs +++ b/examples/wait/src/wasm.rs @@ -19,7 +19,6 @@ // for panic/oom handlers extern crate gstd; -use core::ptr; use gcore::{exec, msg, MessageId}; static mut STATE: u32 = 0; @@ -28,7 +27,7 @@ static mut MSG_ID_2: MessageId = MessageId::zero(); #[no_mangle] extern "C" fn handle() { - let state = unsafe { &mut *ptr::addr_of_mut!(STATE) }; + let state = unsafe { &mut STATE }; gstd::debug!("{state}"); match *state { diff --git a/examples/waiter/src/wasm.rs b/examples/waiter/src/wasm.rs index 03161230643..f92987b6f1f 100644 --- a/examples/waiter/src/wasm.rs +++ b/examples/waiter/src/wasm.rs @@ -23,7 +23,7 @@ use crate::{ use core::ops::{Deref, DerefMut}; use futures::future; use gstd::{ - exec, format, msg, ptr, + exec, format, msg, sync::{Mutex, MutexGuard, RwLock, RwLockReadGuard, RwLockWriteGuard}, }; @@ -117,24 +117,21 @@ async fn main() { }; let lock_guard = lock.await; process_mx_lock_continuation( - unsafe { &mut *ptr::addr_of_mut!(MUTEX_LOCK_GUARD) }, + unsafe { &mut MUTEX_LOCK_GUARD }, lock_guard, continuation, ) .await; } Command::MxLockStaticAccess(subcommand) => { - process_lock_static_access_subcommand_mut( - unsafe { &mut *ptr::addr_of_mut!(MUTEX_LOCK_GUARD) }, - subcommand, - ); + process_lock_static_access_subcommand_mut(unsafe { &mut MUTEX_LOCK_GUARD }, subcommand); } Command::RwLock(lock_type, continuation) => { match lock_type { RwLockType::Read => { let lock_guard = unsafe { RW_LOCK.read().await }; process_rw_lock_continuation( - unsafe { &mut *ptr::addr_of_mut!(R_LOCK_GUARD) }, + unsafe { &mut R_LOCK_GUARD }, lock_guard, continuation, ) @@ -143,7 +140,7 @@ async fn main() { RwLockType::Write => { let lock_guard = unsafe { RW_LOCK.write().await }; process_rw_lock_continuation( - unsafe { &mut *ptr::addr_of_mut!(W_LOCK_GUARD) }, + unsafe { &mut W_LOCK_GUARD }, lock_guard, continuation, ) @@ -153,16 +150,10 @@ async fn main() { } Command::RwLockStaticAccess(lock_type, subcommand) => match lock_type { RwLockType::Read => { - process_lock_static_access_subcommand( - unsafe { &mut *ptr::addr_of_mut!(R_LOCK_GUARD) }, - subcommand, - ); + process_lock_static_access_subcommand(unsafe { &mut R_LOCK_GUARD }, subcommand); } RwLockType::Write => { - process_lock_static_access_subcommand_mut( - unsafe { &mut *ptr::addr_of_mut!(W_LOCK_GUARD) }, - subcommand, - ); + process_lock_static_access_subcommand_mut(unsafe { &mut W_LOCK_GUARD }, subcommand); } }, } diff --git a/scripts/src/clippy.sh b/scripts/src/clippy.sh index b70925273ea..9f33610254d 100755 --- a/scripts/src/clippy.sh +++ b/scripts/src/clippy.sh @@ -28,5 +28,5 @@ gear_clippy() { } examples_clippy() { - __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy -p "demo-*" -p test-syscalls --no-default-features "$@" -- --no-deps -D warnings + __GEAR_WASM_BUILDER_NO_BUILD=1 SKIP_WASM_BUILD=1 SKIP_VARA_RUNTIME_WASM_BUILD=1 cargo clippy -p "demo-*" -p test-syscalls --no-default-features "$@" -- --no-deps -D warnings -A static_mut_ref } From e42c08ecc27dd055e1209bd13ed931b665506084 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Fri, 2 Feb 2024 15:20:18 +0300 Subject: [PATCH 13/14] remove gear_calls.rs after merge... --- utils/runtime-fuzzer/src/gear_calls.rs | 459 ------------------------- 1 file changed, 459 deletions(-) delete mode 100644 utils/runtime-fuzzer/src/gear_calls.rs diff --git a/utils/runtime-fuzzer/src/gear_calls.rs b/utils/runtime-fuzzer/src/gear_calls.rs deleted file mode 100644 index 20998a3af19..00000000000 --- a/utils/runtime-fuzzer/src/gear_calls.rs +++ /dev/null @@ -1,459 +0,0 @@ -// This file is part of Gear. - -// Copyright (C) 2021-2024 Gear Technologies Inc. -// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0 - -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -//! [`GearCalls`] implementation. -//! -//! [`GearCalls`]'s purpose is to lazy evaluate [`GearCall`]s using provided [`Config`] -//! (see the [`GearCalls`] docs for the more detailed information about usage). -//! -//! [`Config`] is basically a set of [`ExtrinsicGenerator`]s, each of them is capable of -//! generating one particular extrinsic's parameters, for example - [`UploadProgramGenerator`] -//! or [`SendMessageGenerator`]. -//! -//! Some of the extrinsics require access to the mailbox messages, such as `SendReply` -//! and `ClaimValue` ones. This access is provided by the [`MailboxProvider`] trait -//! which must be implemented by the callling side and passed into generators which require it. - -use crate::{GearCall, SendMessageArgs, UploadProgramArgs}; -use arbitrary::{Error, Result, Unstructured}; -use gear_call_gen::{ClaimValueArgs, SendReplyArgs}; -use gear_core::ids::{CodeId, MessageId, ProgramId}; -use gear_utils::NonEmpty; -use gear_wasm_gen::{ - ActorKind, EntryPointsSet, InvocableSyscall, PtrParamAllowedValues, RegularParamType, - StandardGearWasmConfigsBundle, SyscallName, SyscallsInjectionTypes, SyscallsParamsConfig, -}; -use std::mem; - -/// Maximum payload size for the fuzzer - 1 KiB. -/// -/// TODO: #3442 -const MAX_PAYLOAD_SIZE: usize = 1024; -const _: () = assert!(MAX_PAYLOAD_SIZE <= gear_core::message::MAX_PAYLOAD_SIZE); - -/// Maximum salt size for the fuzzer - 512 bytes. -/// -/// There's no need in large salts as we have only 35 extrinsics -/// for one run. Also small salt will make overall size of the -/// corpus smaller. -const MAX_SALT_SIZE: usize = 512; -const _: () = assert!(MAX_SALT_SIZE <= gear_core::message::MAX_PAYLOAD_SIZE); - -const ID_SIZE: usize = mem::size_of::(); -const GAS_AND_VALUE_SIZE: usize = mem::size_of::() + mem::size_of::(); - -/// Used to make sure that generators will not exceed `Unstructured` size as it's used not only -/// to generate things like wasm code or message payload but also to generate some auxiliary -/// data, for example index in some vec. -const AUXILIARY_SIZE: usize = 512; - -/// This trait provides ability for [`ExtrinsicGenerator`]s to fetch messages -/// from mailbox, for example [`UploadProgramGenerator`] and -/// [`ClaimValueGenerator`] use it. -pub(crate) trait MailboxProvider { - fn fetch_messages(&self) -> Vec; -} - -/// Struct that's used by `GearCalls` to store some data available only in the -/// middle of calls generation such as uploaded program ids. -/// -/// ### Note -/// This struct shouldn't be used directly, as it should be updated and read -/// only by the `GearCalls`. -pub(crate) struct TempData { - existing_addresses: Vec, -} - -/// The struct for generating gear extrinsics. -/// -/// # Usage -/// -/// `Iterator` is implemented for this struct, so for -/// generating gear calls you need to iterate over [`GearCalls`]. -pub(crate) struct GearCalls<'a> { - unstructured: Unstructured<'a>, - intermediate_data: TempData, - - generators: Vec, - - current_generator: usize, - current_extrinsic: usize, -} - -impl<'a> GearCalls<'a> { - pub(crate) fn new( - data: &'a [u8], - generators: ExtrinsicGeneratorSet, - existing_users: Vec, - ) -> Result> { - if data.len() < generators.unstructured_size_hint() { - return Err(Error::NotEnoughData); - } - - Ok(GearCalls { - unstructured: Unstructured::new(data), - intermediate_data: TempData { - existing_addresses: existing_users, - }, - current_generator: 0, - current_extrinsic: 0, - generators: generators.0, - }) - } -} - -impl Iterator for GearCalls<'_> { - type Item = Result; - - fn next(&mut self) -> Option> { - loop { - if self.current_generator == self.generators.len() { - return None; - } - - let generator = &self.generators[self.current_generator].generator; - let call = generator.generate(&mut self.intermediate_data, &mut self.unstructured); - - self.current_extrinsic += 1; - if self.current_extrinsic == self.generators[self.current_generator].amount { - self.current_extrinsic = 0; - self.current_generator += 1; - } - - return match call { - Ok(Some(call)) => Some(Ok(call)), - Ok(None) => continue, - Err(err) => Some(Err(err)), - }; - } - } -} - -/// Extrinsic generators that will be used inside [`GearCalls`] to generate all the calls needed. -pub(crate) struct ExtrinsicGeneratorSet(Vec); - -impl ExtrinsicGeneratorSet { - pub(crate) fn new(generators: Vec) -> ExtrinsicGeneratorSet { - ExtrinsicGeneratorSet(generators) - } - - pub(crate) fn unstructured_size_hint(&self) -> usize { - self.0 - .iter() - .map(|generator| generator.amount * generator.generator.unstructured_size_hint()) - .sum() - } -} - -/// [`ExtrinsicGenerator`] that should be invoked [`RepeatedGenerator::amount`](`amount`) times -/// by the [`GearCalls`] to generate [`RepeatedGenerator::amount`](`amount`) extrinsics. -pub(crate) struct RepeatedGenerator { - pub amount: usize, - pub generator: ExtrinsicGenerator, -} - -impl RepeatedGenerator { - pub fn new(amount: usize, generator: ExtrinsicGenerator) -> RepeatedGenerator { - RepeatedGenerator { amount, generator } - } -} - -/// Enum containing all the possible concrete extrinsic generators. -pub(crate) enum ExtrinsicGenerator { - UploadProgram(UploadProgramGenerator), - SendMessage(SendMessageGenerator), - SendReply(SendReplyGenerator), - ClaimValue(ClaimValueGenerator), -} - -impl ExtrinsicGenerator { - pub(crate) fn generate( - &self, - intermediate_data: &mut TempData, - unstructured: &mut Unstructured, - ) -> Result> { - match self { - Self::UploadProgram(g) => g.generate(intermediate_data, unstructured), - Self::SendMessage(g) => g.generate(intermediate_data, unstructured), - Self::SendReply(g) => g.generate(unstructured), - Self::ClaimValue(g) => g.generate(unstructured), - } - } - - pub(crate) const fn unstructured_size_hint(&self) -> usize { - match self { - Self::UploadProgram(g) => g.unstructured_size_hint(), - Self::SendMessage(g) => g.unstructured_size_hint(), - Self::SendReply(g) => g.unstructured_size_hint(), - Self::ClaimValue(g) => g.unstructured_size_hint(), - } - } -} - -/// Extrinsic generator that's capable of generating `UploadProgram` calls. -pub(crate) struct UploadProgramGenerator { - pub gas: u64, - pub value: u128, - pub test_input_id: String, -} - -impl UploadProgramGenerator { - fn generate( - &self, - intermediate_data: &mut TempData, - unstructured: &mut Unstructured, - ) -> Result> { - log::trace!("New gear-wasm generation"); - log::trace!("Random data before wasm gen {}", unstructured.len()); - - let code = gear_wasm_gen::generate_gear_program_code( - unstructured, - config( - &intermediate_data.existing_addresses, - Some(format!( - "Generated program from corpus - {}", - &self.test_input_id - )), - ), - )?; - log::trace!("Random data after wasm gen {}", unstructured.len()); - log::trace!("Code length {:?}", code.len()); - - let salt = arbitrary_salt(unstructured)?; - log::trace!("Random data after salt gen {}", unstructured.len()); - log::trace!("Salt length {:?}", salt.len()); - - let payload = arbitrary_payload(unstructured)?; - log::trace!( - "Random data after payload (upload_program) gen {}", - unstructured.len() - ); - log::trace!("Payload (upload_program) length {:?}", payload.len()); - - let program_id = ProgramId::generate_from_user(CodeId::generate(&code), &salt); - - log::trace!("Generated code for program id - {program_id}"); - - intermediate_data.existing_addresses.push(program_id); - - Ok(Some( - UploadProgramArgs((code, salt, payload, self.gas, self.value)).into(), - )) - } - - const fn unstructured_size_hint(&self) -> usize { - // Max code size - 25 KiB. - const MAX_CODE_SIZE: usize = 25 * 1024; - - MAX_CODE_SIZE + MAX_SALT_SIZE + MAX_PAYLOAD_SIZE + GAS_AND_VALUE_SIZE + AUXILIARY_SIZE - } -} - -impl From for ExtrinsicGenerator { - fn from(g: UploadProgramGenerator) -> ExtrinsicGenerator { - ExtrinsicGenerator::UploadProgram(g) - } -} - -/// Extrinsic generator that's capable of generating `SendMessage` calls. -pub(crate) struct SendMessageGenerator { - pub gas: u64, - pub value: u128, -} - -impl SendMessageGenerator { - fn generate( - &self, - intermediate_data: &TempData, - unstructured: &mut Unstructured, - ) -> Result> { - let program_id = unstructured - .choose(&intermediate_data.existing_addresses) - .copied()?; - let payload = arbitrary_payload(unstructured)?; - log::trace!( - "Random data after payload (send_message) gen {}", - unstructured.len() - ); - log::trace!("Payload (send_message) length {:?}", payload.len()); - - Ok(Some( - SendMessageArgs((program_id, payload, self.gas, self.value)).into(), - )) - } - - const fn unstructured_size_hint(&self) -> usize { - ID_SIZE + MAX_PAYLOAD_SIZE + GAS_AND_VALUE_SIZE + AUXILIARY_SIZE - } -} - -impl From for ExtrinsicGenerator { - fn from(g: SendMessageGenerator) -> ExtrinsicGenerator { - ExtrinsicGenerator::SendMessage(g) - } -} - -/// Extrinsic generator that's capable of generating `SendReply` calls. -pub(crate) struct SendReplyGenerator { - pub mailbox_provider: Box, - - pub gas: u64, - pub value: u128, -} - -impl SendReplyGenerator { - fn generate(&self, unstructured: &mut Unstructured) -> Result> { - log::trace!( - "Random data before payload (send_reply) gen {}", - unstructured.len() - ); - let message_id = - arbitrary_message_id_from_mailbox(unstructured, self.mailbox_provider.as_ref())?; - - Ok(match message_id { - None => None, - Some(message_id) => { - let payload = arbitrary_payload(unstructured)?; - log::trace!( - "Random data after payload (send_reply) gen {}", - unstructured.len() - ); - log::trace!("Payload (send_reply) length {:?}", payload.len()); - - Some(SendReplyArgs((message_id, payload, self.gas, self.value)).into()) - } - }) - } - - const fn unstructured_size_hint(&self) -> usize { - ID_SIZE + MAX_PAYLOAD_SIZE + GAS_AND_VALUE_SIZE + AUXILIARY_SIZE - } -} - -impl From for ExtrinsicGenerator { - fn from(g: SendReplyGenerator) -> ExtrinsicGenerator { - ExtrinsicGenerator::SendReply(g) - } -} - -/// Extrinsic generator that's capable of generating `ClaimValue` calls. -pub(crate) struct ClaimValueGenerator { - pub mailbox_provider: Box, -} - -impl ClaimValueGenerator { - fn generate(&self, unstructured: &mut Unstructured) -> Result> { - log::trace!("Generating claim_value call"); - let message_id = - arbitrary_message_id_from_mailbox(unstructured, self.mailbox_provider.as_ref())?; - Ok(message_id.map(|msg_id| ClaimValueArgs(msg_id).into())) - } - - const fn unstructured_size_hint(&self) -> usize { - ID_SIZE + AUXILIARY_SIZE - } -} - -impl From for ExtrinsicGenerator { - fn from(g: ClaimValueGenerator) -> ExtrinsicGenerator { - ExtrinsicGenerator::ClaimValue(g) - } -} - -fn arbitrary_message_id_from_mailbox( - u: &mut Unstructured, - mailbox_provider: &dyn MailboxProvider, -) -> Result> { - let messages = mailbox_provider.fetch_messages(); - - if messages.is_empty() { - log::trace!("Mailbox is empty."); - Ok(None) - } else { - log::trace!("Mailbox is not empty, len = {}", messages.len()); - u.choose(&messages).cloned().map(Some) - } -} - -fn arbitrary_salt(u: &mut Unstructured) -> Result> { - arbitrary_limited_bytes(u, MAX_SALT_SIZE) -} - -fn arbitrary_payload(u: &mut Unstructured) -> Result> { - arbitrary_limited_bytes(u, MAX_PAYLOAD_SIZE) -} - -fn arbitrary_limited_bytes(u: &mut Unstructured, limit: usize) -> Result> { - let arb_size = u.int_in_range(0..=limit)?; - u.bytes(arb_size).map(|bytes| bytes.to_vec()) -} - -fn config(programs: &[ProgramId], log_info: Option) -> StandardGearWasmConfigsBundle { - let initial_pages = 2; - let mut injection_types = SyscallsInjectionTypes::all_once(); - injection_types.set_multiple( - [ - (SyscallName::Leave, 0..=0), - (SyscallName::Panic, 0..=0), - (SyscallName::OomPanic, 0..=0), - (SyscallName::EnvVars, 0..=0), - (SyscallName::Send, 10..=15), - (SyscallName::Exit, 0..=1), - (SyscallName::Alloc, 3..=6), - (SyscallName::Free, 3..=6), - ] - .map(|(syscall, range)| (InvocableSyscall::Loose(syscall), range)) - .into_iter(), - ); - - let mut params_config = SyscallsParamsConfig::new() - .with_default_regular_config() - .with_rule(RegularParamType::Alloc, (10..=20).into()) - .with_rule( - RegularParamType::Free, - (initial_pages..=initial_pages + 35).into(), - ) - .with_ptr_rule(PtrParamAllowedValues::Value(0..=0)); - - let actor_kind = NonEmpty::collect( - programs - .iter() - .copied() - .filter_map(|pid| (pid != ProgramId::default()).then_some(pid.into())), - ) - .map(ActorKind::ExistingAddresses) - .unwrap_or(ActorKind::Source); - - log::trace!("Messages destination config: {:?}", actor_kind); - - params_config = params_config - .with_ptr_rule(PtrParamAllowedValues::ActorId(actor_kind.clone())) - .with_ptr_rule(PtrParamAllowedValues::ActorIdWithValue { - actor_kind: actor_kind.clone(), - range: 0..=0, - }); - - StandardGearWasmConfigsBundle { - entry_points_set: EntryPointsSet::InitHandleHandleReply, - injection_types, - log_info, - params_config, - initial_pages: initial_pages as u32, - ..Default::default() - } -} From 9a9a1577f98aec61a8858bb5271d21919ce5e059 Mon Sep 17 00:00:00 2001 From: StackOverflowExcept1on <109800286+StackOverflowExcept1on@users.noreply.github.com> Date: Fri, 2 Feb 2024 15:29:31 +0300 Subject: [PATCH 14/14] some fixes --- gstd/tests/debug.rs | 14 ++++++-------- utils/gring/src/keystore.rs | 2 +- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/gstd/tests/debug.rs b/gstd/tests/debug.rs index 333e24bae12..4664d50fdf5 100644 --- a/gstd/tests/debug.rs +++ b/gstd/tests/debug.rs @@ -13,24 +13,22 @@ mod sys { } #[test] +#[allow(static_mut_ref)] fn test_debug() { let value = 42; debug!("{value}"); - assert_eq!(unsafe { &*ptr::addr_of!(DEBUG_MSG) }, b"42"); + assert_eq!(unsafe { &DEBUG_MSG }, b"42"); debug!("Formatted: value = {value}"); - assert_eq!( - unsafe { &*ptr::addr_of!(DEBUG_MSG) }, - b"Formatted: value = 42" - ); + assert_eq!(unsafe { &DEBUG_MSG }, b"Formatted: value = 42"); debug!("String literal"); - assert_eq!(unsafe { &*ptr::addr_of!(DEBUG_MSG) }, b"String literal"); + assert_eq!(unsafe { &DEBUG_MSG }, b"String literal"); crate::dbg!(value); assert_eq!( - unsafe { &*ptr::addr_of!(DEBUG_MSG) }, - b"[gstd/tests/debug.rs:31:5] value = 42" + unsafe { &DEBUG_MSG }, + b"[gstd/tests/debug.rs:29:5] value = 42" ); } diff --git a/utils/gring/src/keystore.rs b/utils/gring/src/keystore.rs index b027d944a6f..adf62ca111c 100644 --- a/utils/gring/src/keystore.rs +++ b/utils/gring/src/keystore.rs @@ -190,7 +190,7 @@ impl Encoding { /// Check if is encoding with scrypt. pub fn is_scrypt(&self) -> bool { - self.ty.get(0) == Some(&"scrypt".into()) + self.ty.first() == Some(&"scrypt".into()) } /// Check if the cipher is xsalsa20-poly1305.