diff --git a/.github/workflows/casper-node.yml b/.github/workflows/casper-node.yml index 3464f59c1c..282ffc6ce4 100644 --- a/.github/workflows/casper-node.yml +++ b/.github/workflows/casper-node.yml @@ -187,7 +187,7 @@ jobs: run: make build-test-artifacts CARGO_FLAGS=--release - name: archive smart contracts - run: tar -czf smart-contracts.tar.gz resources/local/chainspec.toml target/wasm32-unknown-unknown/release/*.wasm + run: tar -czf smart-contracts.tar.gz resources/local/chainspec.toml target/wasm32v1-none/release/*.wasm - name: upload smart contracts uses: actions/upload-artifact@v4 diff --git a/EVM.md b/EVM.md index 0e631987d5..e890f709ab 100644 --- a/EVM.md +++ b/EVM.md @@ -1207,4 +1207,4 @@ cargo build -p casper-sidecar [eip-7702]: https://eips.ethereum.org/EIPS/eip-7702 [eip-7840]: https://eips.ethereum.org/EIPS/eip-7840 [execution-apis]: https://ethereum.github.io/execution-apis/ -[geth-pubsub]: https://geth.ethereum.org/docs/interacting-with-geth/rpc/pubsub +[geth-pubsub]: https://geth.ethereum.org/docs/interacting-with-geth/rpc/pubsub \ No newline at end of file diff --git a/Makefile b/Makefile index fb5df047d1..d53771d24e 100644 --- a/Makefile +++ b/Makefile @@ -3,13 +3,11 @@ CARGO = $(or $(shell which cargo), $(HOME)/.cargo/bin/cargo) RUSTUP = $(or $(shell which rustup), $(HOME)/.cargo/bin/rustup) CARGO_AUDIT = $(or $(shell which cargo-audit), $(HOME)/.cargo/bin/cargo-audit) -PINNED_NIGHTLY := $(shell cat smart_contracts/rust-toolchain) PINNED_STABLE := $(shell sed -nr 's/channel *= *\"(.*)\"/\1/p' rust-toolchain.toml) CARGO_AUDIT_VERSION := 0.22.1 WASM_STRIP_VERSION := $(shell wasm-strip --version) CARGO_OPTS := --locked -CARGO_PINNED_NIGHTLY := $(CARGO) +$(PINNED_NIGHTLY) $(CARGO_OPTS) CARGO := $(CARGO) $(CARGO_OPTS) DISABLE_LOGGING = RUST_LOG=MatchesNothing @@ -21,19 +19,22 @@ CLIENT_CONTRACTS = $(shell find ./smart_contracts/contracts/client -mindepth 1 - EVM_CONTRACTS = $(shell find ./smart_contracts/evm_contracts -mindepth 1 -maxdepth 1 -name '*.sol' -exec basename {} .sol \;) CARGO_HOME_REMAP = $(if $(CARGO_HOME),$(CARGO_HOME),$(HOME)/.cargo) RUSTC_FLAGS = "--remap-path-prefix=$(CARGO_HOME_REMAP)=/home/cargo --remap-path-prefix=$$PWD=/dir" -WASM_RUSTC_FLAGS = "--remap-path-prefix=$(CARGO_HOME_REMAP)=/home/cargo --remap-path-prefix=$$PWD=/dir -C target-cpu=mvp -C target-feature=-bulk-memory" +# panic=abort is set explicitly here (rather than via a [profile] in smart_contracts/contract's +# own Cargo.toml) because workspace member manifests can't declare profiles; only the workspace +# root's Cargo.toml can. +WASM_RUSTC_FLAGS = "--remap-path-prefix=$(CARGO_HOME_REMAP)=/home/cargo --remap-path-prefix=$$PWD=/dir -C link-arg=--import-undefined -C panic=abort" CARGO_TEST_PROFILE_ENV ?= -CONTRACT_TARGET_DIR = target/wasm32-unknown-unknown/release +CONTRACT_TARGET_DIR = target/wasm32v1-none/release EVM_CONTRACT_TARGET_DIR = target/evm-contracts build-contract-rs/%: - cd smart_contracts/contracts && RUSTFLAGS=$(WASM_RUSTC_FLAGS) $(CARGO) build --verbose --release -Z build-std=std,core,alloc,panic_abort $(filter-out --release, $(CARGO_FLAGS)) --package $* + cd smart_contracts/contracts && RUSTFLAGS=$(WASM_RUSTC_FLAGS) $(CARGO) build --verbose --release $(filter-out --release, $(CARGO_FLAGS)) --package $* build-vm2-contract-rs/%: CMAKE_POLICY_VERSION_MINIMUM=3.5 $(CARGO) build -p cargo-casper --bin cargo-casper RUSTFLAGS=$(RUSTC_FLAGS) $(CURDIR)/target/debug/cargo-casper build-schema --package $* - cd smart_contracts/contracts/vm2 && RUSTFLAGS=$(WASM_RUSTC_FLAGS) $(CARGO) build --verbose --release -Z build-std=std,core,alloc,panic_abort $(filter-out --release, $(CARGO_FLAGS)) --package $* + cd smart_contracts/contracts/vm2 && RUSTFLAGS=$(WASM_RUSTC_FLAGS) $(CARGO) build --verbose --release $(filter-out --release, $(CARGO_FLAGS)) --package $* .PHONY: build-vm2-contracts-rs build-vm2-contracts-rs: $(patsubst %, build-vm2-contract-rs/%, $(VM2_CONTRACTS)) @@ -134,11 +135,11 @@ check-testing-features: .PHONY: check-format check-format: - $(CARGO_PINNED_NIGHTLY) fmt --all -- --check + $(CARGO) fmt --all -- --check .PHONY: format format: - $(CARGO_PINNED_NIGHTLY) fmt --all + $(CARGO) fmt --all lint-contracts-rs: cd smart_contracts/contracts && $(CARGO) clippy $(patsubst %, -p %, $(ALL_CONTRACTS)) -- -A renamed_and_removed_lints @@ -178,8 +179,8 @@ audit: audit-rs .PHONY: doc doc: - RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--cfg docsrs" $(CARGO_PINNED_NIGHTLY) doc --all-features $(CARGO_FLAGS) --no-deps - cd smart_contracts/contract && RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--cfg docsrs" $(CARGO_PINNED_NIGHTLY) doc --all-features $(CARGO_FLAGS) --no-deps + RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--cfg docsrs" $(RUSTUP) run nightly $(CARGO) doc --all-features $(CARGO_FLAGS) --no-deps + cd smart_contracts/contract && RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--cfg docsrs" $(RUSTUP) run nightly $(CARGO) doc --all-features $(CARGO_FLAGS) --no-deps .PHONY: check-rs check: \ @@ -223,12 +224,11 @@ setup-cargo-packagers: .PHONY: setup-rs setup-rs: $(RUSTUP) update - $(RUSTUP) toolchain install $(PINNED_STABLE) $(PINNED_NIGHTLY) - $(RUSTUP) target add --toolchain $(PINNED_STABLE) wasm32-unknown-unknown - $(RUSTUP) target add --toolchain $(PINNED_NIGHTLY) wasm32-unknown-unknown - $(RUSTUP) component add --toolchain $(PINNED_NIGHTLY) rustfmt clippy-preview + $(RUSTUP) toolchain install $(PINNED_STABLE) nightly + $(RUSTUP) target add --toolchain $(PINNED_STABLE) wasm32v1-none wasm32-unknown-unknown + $(RUSTUP) component add --toolchain $(PINNED_STABLE) rustfmt clippy-preview $(RUSTUP) component add --toolchain $(PINNED_STABLE) clippy-preview - $(RUSTUP) component add rust-src --toolchain $(PINNED_NIGHTLY) + $(RUSTUP) component add rust-src --toolchain $(PINNED_STABLE) $(CARGO_AUDIT) --version 2>/dev/null | grep -q ' $(CARGO_AUDIT_VERSION)$$' || \ $(CARGO) install cargo-audit --version '=$(CARGO_AUDIT_VERSION)' diff --git a/build_wasm_package.sh b/build_wasm_package.sh index b1437556c4..35f54090fa 100755 --- a/build_wasm_package.sh +++ b/build_wasm_package.sh @@ -21,7 +21,7 @@ export RUN_DIR=$(dirname $(abspath $0)) NODE_CONFIG_FILE="$RUN_DIR/node/Cargo.toml" # have to be sed instead of grep -oP to work in alpine docker image export WASM_PACKAGE_VERSION="$(grep ^version $NODE_CONFIG_FILE | sed -e s'/.*= "//' | sed -e s'/".*//')" -export CL_WASM_DIR="$RUN_DIR/target/wasm32-unknown-unknown/release" +export CL_WASM_DIR="$RUN_DIR/target/wasm32v1-none/release" export CL_OUTPUT_S3_DIR="$RUN_DIR/s3_artifacts/${WASM_PACKAGE_VERSION}" export CL_WASM_PACKAGE="$CL_OUTPUT_S3_DIR/casper-contracts.tar.gz" export CL_S3_BUCKET='casperlabs-cicd-artifacts' diff --git a/cargo_casper/src/cli/build.rs b/cargo_casper/src/cli/build.rs index bca029a1d4..1dfc03e181 100644 --- a/cargo_casper/src/cli/build.rs +++ b/cargo_casper/src/cli/build.rs @@ -10,7 +10,7 @@ pub fn build_impl( output_dir: Option, embed_schema: bool, ) -> Result<(), anyhow::Error> { - // Build the contract package targetting wasm32-unknown-unknown without + // Build the contract package targetting wasm32v1-none without // extra feature flags - this is the production contract wasm file. // // Optionally (but by default) create an entrypoint in the wasm that will have @@ -31,10 +31,7 @@ pub fn build_impl( None, vec![("__CARGO_CASPER_INJECT_SCHEMA_MARKER", &contract_schema)], ) - .dispatch( - "wasm32-unknown-unknown", - ["casper-contract-sdk/__embed_schema"], - ) + .dispatch("wasm32v1-none", ["casper-contract-sdk/__embed_schema"]) .context("Failed to compile user wasm")? .get_artifact_by_extension("wasm") .context("Build artifacts for contract wasm didn't include a wasm file")?; @@ -53,7 +50,7 @@ pub fn build_impl( // Compile and move to specified output directory eprintln!("🔨 Step 2: Building contract..."); CompileJob::new(package_name, None, vec![]) - .dispatch("wasm32-unknown-unknown", Option::::None) + .dispatch("wasm32v1-none", Option::::None) .context("Failed to compile user wasm")? .get_artifact_by_extension("wasm") .context("Failed extracting build artifacts to directory")? diff --git a/ci/nctl_upgrade_stage.sh b/ci/nctl_upgrade_stage.sh index b9c533ea29..5c8c66e2ea 100755 --- a/ci/nctl_upgrade_stage.sh +++ b/ci/nctl_upgrade_stage.sh @@ -27,7 +27,7 @@ function clean_up() { # DIRECTORIES ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." >/dev/null 2>&1 && pwd)" BIN_BUILD_DIR="$ROOT_DIR/target/release" -WASM_BUILD_DIR="$ROOT_DIR/target/wasm32-unknown-unknown/release" +WASM_BUILD_DIR="$ROOT_DIR/target/wasm32v1-none/release" CONFIG_DIR="$ROOT_DIR/resources/local" TEMP_STAGE_DIR='/tmp/nctl_upgrade_stage' diff --git a/execution_engine/src/bin/run_wasm.rs b/execution_engine/src/bin/run_wasm.rs index d92e7105ff..86da12cb68 100644 --- a/execution_engine/src/bin/run_wasm.rs +++ b/execution_engine/src/bin/run_wasm.rs @@ -60,7 +60,7 @@ fn run_wasm( "Not enough arguments supplied" ); let mut vec = Vec::new(); - for (input_arg, func_arg) in cli_args.args.iter().zip(params.into_iter()) { + for (input_arg, func_arg) in cli_args.args.iter().zip(params) { let value = match func_arg { casper_wasmi::ValueType::I32 => { casper_wasmi::RuntimeValue::I32(input_arg.parse().unwrap()) diff --git a/execution_engine/src/lib.rs b/execution_engine/src/lib.rs index 3bc2dbc234..15c35b3e53 100644 --- a/execution_engine/src/lib.rs +++ b/execution_engine/src/lib.rs @@ -12,7 +12,7 @@ trivial_numeric_casts, unused_qualifications )] -#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] pub mod engine_state; pub mod execution; diff --git a/execution_engine/src/runtime/mod.rs b/execution_engine/src/runtime/mod.rs index a07fe8cf27..ea0c07f6dd 100644 --- a/execution_engine/src/runtime/mod.rs +++ b/execution_engine/src/runtime/mod.rs @@ -4199,7 +4199,7 @@ where } // Remove group if it is not referenced by at least one entry_point in active versions. - for (_version, contract_hash) in contract_package.versions().iter() { + for contract_hash in contract_package.versions().values() { let entry_points = { self.context .get_casper_vm_v1_entry_point(Key::contract_entity_key( diff --git a/execution_engine_testing/test_support/src/utils.rs b/execution_engine_testing/test_support/src/utils.rs index 9b06cba531..24475ad5fc 100644 --- a/execution_engine_testing/test_support/src/utils.rs +++ b/execution_engine_testing/test_support/src/utils.rs @@ -32,11 +32,11 @@ static RUST_WORKSPACE_PATH: Lazy = Lazy::new(|| { path.to_path_buf() }); // The location of compiled Wasm files if compiled from the Rust sources within the casper-node -// repo, i.e. 'casper-node/target/wasm32-unknown-unknown/release/'. +// repo, i.e. 'casper-node/target/wasm32v1-none/release/'. static RUST_WORKSPACE_WASM_PATH: Lazy = Lazy::new(|| { let path = RUST_WORKSPACE_PATH .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release"); assert!( path.exists() || RUST_TOOL_WASM_PATH.exists(), @@ -54,14 +54,12 @@ static RUST_TOOL_WASM_PATH: Lazy = Lazy::new(|| { }); // The location of compiled Wasm files if compiled from the Rust sources within the casper-node // repo where `CARGO_TARGET_DIR` is set, i.e. -// '/wasm32-unknown-unknown/release/'. +// '/wasm32v1-none/release/'. static MAYBE_CARGO_TARGET_DIR_WASM_PATH: Lazy> = Lazy::new(|| { let maybe_target = std::env::var("CARGO_TARGET_DIR").ok(); - maybe_target.as_ref().map(|path| { - Path::new(path) - .join("wasm32-unknown-unknown") - .join("release") - }) + maybe_target + .as_ref() + .map(|path| Path::new(path).join("wasm32v1-none").join("release")) }); static WASM_PATHS: Lazy> = Lazy::new(get_compiled_wasm_paths); diff --git a/execution_engine_testing/tests/src/test/counter_factory.rs b/execution_engine_testing/tests/src/test/counter_factory.rs index 3689ecbb2a..9221027bd7 100644 --- a/execution_engine_testing/tests/src/test/counter_factory.rs +++ b/execution_engine_testing/tests/src/test/counter_factory.rs @@ -58,7 +58,7 @@ fn should_not_call_undefined_entrypoints_on_factory() { assert!( matches!(&no_such_method_2, Error::Exec(ExecError::TemplateMethod(function_name)) if function_name == INCREASE_ENTRY_POINT), "{:?}", - &no_such_method_2 + no_such_method_2 ); // Can't call abstract entry point "decrease" on the factory. @@ -78,7 +78,7 @@ fn should_not_call_undefined_entrypoints_on_factory() { assert!( matches!(&no_such_method_3, Error::Exec(ExecError::TemplateMethod(function_name)) if function_name == DECREASE_ENTRY_POINT), "{:?}", - &no_such_method_3 + no_such_method_3 ); } diff --git a/execution_engine_testing/tests/src/test/explorer/faucet.rs b/execution_engine_testing/tests/src/test/explorer/faucet.rs index fac9d27488..f48adcd434 100644 --- a/execution_engine_testing/tests/src/test/explorer/faucet.rs +++ b/execution_engine_testing/tests/src/test/explorer/faucet.rs @@ -663,14 +663,14 @@ fn faucet_costs() { // This test will fail if execution costs vary. The expected costs should not be updated // without understanding why the cost has changed. If the costs do change, it should be // reflected in the "Costs by Entry Point" section of the faucet crate's README.md. - const EXPECTED_FAUCET_INSTALL_COST: u64 = 118_807_845_390; + const EXPECTED_FAUCET_INSTALL_COST: u64 = 111_710_366_947; const EXPECTED_FAUCET_INSTALL_COST_ALT: u64 = 149_230_872_143; - const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 79_790_440; + const EXPECTED_FAUCET_SET_VARIABLES_COST: u64 = 78_044_800; - const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_652_954_573; + const EXPECTED_FAUCET_CALL_BY_INSTALLER_COST: u64 = 2_651_525_838; - const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_558_820_996; + const EXPECTED_FAUCET_CALL_BY_USER_COST: u64 = 2_557_179_771; let installer_account = AccountHash::new([1u8; 32]); let user_account: AccountHash = AccountHash::new([2u8; 32]); diff --git a/execution_engine_testing/tests/src/test/wasmless_transfer.rs b/execution_engine_testing/tests/src/test/wasmless_transfer.rs index 502b03abf0..d2b739a804 100644 --- a/execution_engine_testing/tests/src/test/wasmless_transfer.rs +++ b/execution_engine_testing/tests/src/test/wasmless_transfer.rs @@ -506,7 +506,7 @@ fn invalid_transfer_wasmless(invalid_wasmless_transfer: InvalidWasmlessTransfer) let account_1_closing_balance = builder.get_purse_balance(account_1_purse); assert_eq!( - format!("{}", &expected_error), + format!("{}", expected_error), format!("{}", error), "expected_error: {} actual error: {}", expected_error, diff --git a/executor/wasm/tests/integration.rs b/executor/wasm/tests/integration.rs index 1afaa9f567..06c2f5db9f 100644 --- a/executor/wasm/tests/integration.rs +++ b/executor/wasm/tests/integration.rs @@ -74,7 +74,7 @@ static RUST_WORKSPACE_PATH: Lazy = Lazy::new(|| { static RUST_WORKSPACE_WASM_PATH: Lazy = Lazy::new(|| { let path = RUST_WORKSPACE_PATH .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release"); assert!( path.exists() || RUST_TOOL_WASM_PATH.exists(), diff --git a/node/src/components/binary_port.rs b/node/src/components/binary_port.rs index f3f90a9fc0..26f1cda825 100644 --- a/node/src/components/binary_port.rs +++ b/node/src/components/binary_port.rs @@ -1357,7 +1357,7 @@ where .try_accept_transaction(transaction) .await .map_or_else( - |err| BinaryResponse::new_error(err.into()), + |err| BinaryResponse::new_error((*err).into()), |()| BinaryResponse::new_empty(), ) } diff --git a/node/src/components/block_accumulator/error.rs b/node/src/components/block_accumulator/error.rs index de09081e6a..2acbd6a95e 100644 --- a/node/src/components/block_accumulator/error.rs +++ b/node/src/components/block_accumulator/error.rs @@ -1,5 +1,4 @@ use thiserror::Error; -use tracing::error; use casper_types::{crypto, BlockHash, BlockValidationError, EraId}; diff --git a/node/src/components/block_accumulator/tests.rs b/node/src/components/block_accumulator/tests.rs index b13baf6b6b..714c349f67 100644 --- a/node/src/components/block_accumulator/tests.rs +++ b/node/src/components/block_accumulator/tests.rs @@ -1416,10 +1416,10 @@ fn accumulator_purge() { // Change the timestamps to old ones so that all blocks would normally // get purged. let last_progress = time_before_insertion.saturating_sub(purge_interval * 10); - for (_, acceptor) in block_accumulator.block_acceptors.iter_mut() { + for acceptor in block_accumulator.block_acceptors.values_mut() { acceptor.set_last_progress(last_progress); } - for (_, timestamps) in block_accumulator.peer_block_timestamps.iter_mut() { + for timestamps in block_accumulator.peer_block_timestamps.values_mut() { for (_, timestamp) in timestamps.iter_mut() { *timestamp = last_progress; } @@ -1544,10 +1544,10 @@ fn accumulator_purge() { // Change the timestamps to old ones so that all blocks would normally // get purged. let last_progress = time_before_insertion.saturating_sub(purge_interval * 10); - for (_, acceptor) in block_accumulator.block_acceptors.iter_mut() { + for acceptor in block_accumulator.block_acceptors.values_mut() { acceptor.set_last_progress(last_progress); } - for (_, timestamps) in block_accumulator.peer_block_timestamps.iter_mut() { + for timestamps in block_accumulator.peer_block_timestamps.values_mut() { for (_, timestamp) in timestamps.iter_mut() { *timestamp = last_progress; } diff --git a/node/src/components/block_synchronizer/global_state_synchronizer.rs b/node/src/components/block_synchronizer/global_state_synchronizer.rs index d46efa762d..e8c3a5898b 100644 --- a/node/src/components/block_synchronizer/global_state_synchronizer.rs +++ b/node/src/components/block_synchronizer/global_state_synchronizer.rs @@ -540,8 +540,8 @@ impl GlobalStateSynchronizer { self.tries_awaiting_children = still_incomplete; let mut effects: Effects = ready_tries - .into_iter() - .flat_map(|(_, trie_awaiting)| { + .into_values() + .flat_map(|trie_awaiting| { let trie_raw = trie_awaiting.into_trie_raw(); let request = PutTrieRequest::new(trie_raw.clone()); effect_builder diff --git a/node/src/components/consensus/highway_core/highway_testing.rs b/node/src/components/consensus/highway_core/highway_testing.rs index 9452e87477..83eceb538e 100644 --- a/node/src/components/consensus/highway_core/highway_testing.rs +++ b/node/src/components/consensus/highway_core/highway_testing.rs @@ -1140,7 +1140,6 @@ mod test_harness { v.finalized_values().cloned().collect::>(), v.messages_produced() .filter(|&hwm| hwm.is_new_unit()) - .cloned() .count(), ) }) diff --git a/node/src/components/consensus/protocols/zug/des_testing.rs b/node/src/components/consensus/protocols/zug/des_testing.rs index e638eb1de6..9425ae1eb2 100644 --- a/node/src/components/consensus/protocols/zug/des_testing.rs +++ b/node/src/components/consensus/protocols/zug/des_testing.rs @@ -1112,7 +1112,6 @@ mod test_harness { v.finalized_values().cloned().collect::>(), v.messages_produced() .filter(|&zm| zm.is_signed_gossip_message() || zm.is_proposal()) - .cloned() .count(), ) }) diff --git a/node/src/components/contract_runtime/rewards.rs b/node/src/components/contract_runtime/rewards.rs index a8cd4a1f8b..6eaa48b408 100644 --- a/node/src/components/contract_runtime/rewards.rs +++ b/node/src/components/contract_runtime/rewards.rs @@ -450,10 +450,7 @@ pub(crate) async fn fetch_data_and_calculate_rewards_for_era actual_total_seigniorage.low_u128(), expected_total_seigniorage.low_u128(), ); - let gauge_value = match Ratio::to_f64(&seigniorage_target_fraction) { - Some(v) => v, - None => f64::NAN, - }; + let gauge_value = Ratio::to_f64(&seigniorage_target_fraction).unwrap_or(f64::NAN); metrics.seigniorage_target_fraction.set(gauge_value) } diff --git a/node/src/components/contract_runtime/tests.rs b/node/src/components/contract_runtime/tests.rs index c735305d0b..cc72fdc588 100644 --- a/node/src/components/contract_runtime/tests.rs +++ b/node/src/components/contract_runtime/tests.rs @@ -637,7 +637,7 @@ fn valid_wasm_txn( let contract_file = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join(format!("{name}.wasm")); let module_bytes = Bytes::from(std::fs::read(contract_file).expect("cannot read module bytes")); diff --git a/node/src/components/diagnostics_port/command.rs b/node/src/components/diagnostics_port/command.rs index d482157beb..2da294f767 100644 --- a/node/src/components/diagnostics_port/command.rs +++ b/node/src/components/diagnostics_port/command.rs @@ -147,7 +147,7 @@ impl Command { pub(super) fn from_line(line: &str) -> Result { let mut parts = vec!["casper-diagnostics-port".to_owned()]; parts.extend(shlex::split(line).ok_or(Error::ShlexFailure)?); - Ok(Self::from_iter_safe(parts.into_iter())?) + Ok(Self::from_iter_safe(parts)?) } } diff --git a/node/src/components/fetcher/error.rs b/node/src/components/fetcher/error.rs index e548d03c89..ed2dd99c7b 100644 --- a/node/src/components/fetcher/error.rs +++ b/node/src/components/fetcher/error.rs @@ -1,7 +1,6 @@ use datasize::DataSize; use serde::Serialize; use thiserror::Error; -use tracing::error; use crate::{components::fetcher::FetchItem, types::NodeId}; diff --git a/node/src/components/storage/error.rs b/node/src/components/storage/error.rs index d5787e42e7..07c7300ebb 100644 --- a/node/src/components/storage/error.rs +++ b/node/src/components/storage/error.rs @@ -2,7 +2,6 @@ use std::{fmt::Debug, io, path::PathBuf}; use casper_binary_port::RecordId; use thiserror::Error; -use tracing::error; use casper_types::{ bytesrepr, crypto, BlockBody, BlockHash, BlockHeader, BlockValidationError, DeployHash, Digest, diff --git a/node/src/components/transaction_acceptor.rs b/node/src/components/transaction_acceptor.rs index 4097d34c8d..d8f2680ccd 100644 --- a/node/src/components/transaction_acceptor.rs +++ b/node/src/components/transaction_acceptor.rs @@ -733,7 +733,7 @@ impl TransactionAcceptor { // Only deploys need their payment code checked. let payment_identifier = if let Transaction::Deploy(deploy) = &event_metadata.transaction { if let Err(error) = deploy_payment_is_valid(deploy.payment(), &block_header) { - return self.reject_transaction(effect_builder, *event_metadata, error); + return self.reject_transaction(effect_builder, *event_metadata, *error); } deploy.payment().identifier() } else { @@ -1627,33 +1627,32 @@ fn is_authorized_entity( } // `allow` can be removed once https://github.com/casper-network/casper-node/issues/3063 is fixed. -#[allow(clippy::result_large_err)] fn deploy_payment_is_valid( payment: &ExecutableDeployItem, block_header: &BlockHeader, -) -> Result<(), Error> { +) -> Result<(), Box> { match payment { ExecutableDeployItem::Transfer { .. } => { - return Err(Error::parameter_failure( + return Err(Box::new(Error::parameter_failure( block_header, DeployParameterFailure::InvalidPaymentVariant.into(), - )); + ))); } ExecutableDeployItem::ModuleBytes { module_bytes, args } => { // module bytes being empty implies the payment executable is standard payment. if module_bytes.is_empty() { if let Some(value) = args.get(ARG_AMOUNT) { if value.to_t::().is_err() { - return Err(Error::parameter_failure( + return Err(Box::new(Error::parameter_failure( block_header, DeployParameterFailure::FailedToParsePaymentAmount.into(), - )); + ))); } } else { - return Err(Error::parameter_failure( + return Err(Box::new(Error::parameter_failure( block_header, DeployParameterFailure::MissingPaymentAmount.into(), - )); + ))); } } } diff --git a/node/src/components/transaction_acceptor/tests.rs b/node/src/components/transaction_acceptor/tests.rs index a447d5cdac..e547248b22 100644 --- a/node/src/components/transaction_acceptor/tests.rs +++ b/node/src/components/transaction_acceptor/tests.rs @@ -1556,7 +1556,7 @@ fn inject_balance_check_for_peer( async fn run_transaction_acceptor_without_timeout( test_scenario: TestScenario, -) -> Result<(), super::Error> { +) -> Result<(), Box> { let _ = logging::init(); let rng = &mut TestRng::new(); @@ -1918,9 +1918,10 @@ async fn run_transaction_acceptor_without_timeout( } } - txn_receiver.await.unwrap() + txn_receiver.await.unwrap().map_err(Box::new) } +#[allow(clippy::result_large_err)] async fn run_transaction_acceptor(test_scenario: TestScenario) -> Result<(), super::Error> { time::timeout( TIMEOUT, @@ -1928,6 +1929,7 @@ async fn run_transaction_acceptor(test_scenario: TestScenario) -> Result<(), sup ) .await .unwrap() + .map_err(|b_e| *b_e) } #[tokio::test] diff --git a/node/src/effect.rs b/node/src/effect.rs index 54b6b28557..92bf4251d1 100644 --- a/node/src/effect.rs +++ b/node/src/effect.rs @@ -856,7 +856,7 @@ impl EffectBuilder { pub(crate) async fn try_accept_transaction( self, transaction: Transaction, - ) -> Result<(), transaction_acceptor::Error> + ) -> Result<(), Box> where REv: From, { @@ -868,6 +868,7 @@ impl EffectBuilder { QueueKind::Api, ) .await + .map_err(Box::new) } /// Announces that a transaction not previously stored has now been accepted and stored. diff --git a/node/src/lib.rs b/node/src/lib.rs index 723014ce4e..7b752abb0f 100644 --- a/node/src/lib.rs +++ b/node/src/lib.rs @@ -6,7 +6,7 @@ //! ## Application structure //! //! While the [`main`](fn.main.html) function is the central entrypoint for the node application, -//! its core event loop is found inside the [reactor](reactor/index.html). +//! its core event loop is found inside the [reactor]. #![doc(html_root_url = "https://docs.rs/casper-node/2.2.0")] #![doc( diff --git a/node/src/reactor/main_reactor/keep_up.rs b/node/src/reactor/main_reactor/keep_up.rs index 8acca57b8b..361ab4e801 100644 --- a/node/src/reactor/main_reactor/keep_up.rs +++ b/node/src/reactor/main_reactor/keep_up.rs @@ -437,11 +437,9 @@ impl MainReactor { "KeepUp: historical sync back is awaiting response".to_string(), self.control_logic_default_delay.into(), ), - LeapState::Received { - best_available, - from_peers: _, - .. - } => self.sync_back_leap_received(effect_builder, *best_available), + LeapState::Received { best_available, .. } => { + self.sync_back_leap_received(effect_builder, *best_available) + } LeapState::Failed { error, .. } => { self.sync_back_leap_failed(effect_builder, rng, parent_hash, error) } diff --git a/node/src/reactor/main_reactor/tests/rewards.rs b/node/src/reactor/main_reactor/tests/rewards.rs index cae59643d6..b7f392c629 100644 --- a/node/src/reactor/main_reactor/tests/rewards.rs +++ b/node/src/reactor/main_reactor/tests/rewards.rs @@ -682,8 +682,8 @@ async fn run_rewards_network_scenario( .iter() .fold(U512::zero(), |acc, reward| U512::from(*reward.1) + acc), Rewards::V2(v2_rewards) => v2_rewards - .iter() - .flat_map(|(_key, amounts)| amounts) + .values() + .flatten() .fold(U512::zero(), |acc, reward| *reward + acc), }; let recomputed_total_rewards: U512 = rewards diff --git a/node/src/reactor/main_reactor/tests/transactions.rs b/node/src/reactor/main_reactor/tests/transactions.rs index 9d718c6deb..ecf28a86cf 100644 --- a/node/src/reactor/main_reactor/tests/transactions.rs +++ b/node/src/reactor/main_reactor/tests/transactions.rs @@ -61,7 +61,7 @@ pub(crate) static CHARLIE_PUBLIC_KEY: Lazy = // The amount of gas it takes to execute the generated do_nothing.wasm. // Passing this around as a constant is brittle and should be replaced // with a more sustainable solution in the future. -const DO_NOTHING_WASM_EXECUTION_GAS: u64 = 116445_u64; +const DO_NOTHING_WASM_EXECUTION_GAS: u64 = 117180_u64; pub(crate) const MIN_GAS_PRICE: u8 = 1; const CHAIN_NAME: &str = "single-transaction-test-net"; @@ -3474,7 +3474,7 @@ async fn should_burn_fee_refund_unconsumed_custom_payment() { let contract_file = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join("ee_601_regression.wasm"); let module_bytes = Bytes::from(std::fs::read(contract_file).expect("cannot read module bytes")); @@ -3574,7 +3574,7 @@ async fn should_allow_norefund_nofee_custom_payment() { let contract_file = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join("ee_601_regression.wasm"); let module_bytes = Bytes::from(std::fs::read(contract_file).expect("cannot read module bytes")); @@ -4287,7 +4287,7 @@ fn valid_wasm_txn(initiator: Arc, pricing_mode: PricingMode) -> Trans let contract_file = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join("do_nothing.wasm"); let module_bytes = Bytes::from(std::fs::read(contract_file).expect("cannot read module bytes")); @@ -5031,7 +5031,7 @@ async fn insufficient_funds_transfer_from_purse() { let purse_create_contract = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join("transfer_main_purse_to_new_purse.wasm"); let module_bytes = @@ -5155,7 +5155,7 @@ async fn charge_when_session_code_succeeds() { let contract = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join("transfer_purse_to_account.wasm"); let module_bytes = Bytes::from(std::fs::read(contract).expect("cannot read module bytes")); @@ -5226,7 +5226,7 @@ async fn charge_when_session_code_fails_with_user_error() { let revert_contract = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join("revert.wasm"); let module_bytes = @@ -5294,7 +5294,7 @@ async fn charge_when_session_code_runs_out_of_gas() { let revert_contract = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join("endless_loop.wasm"); let module_bytes = @@ -5368,7 +5368,7 @@ async fn successful_purse_to_purse_transfer() { let purse_create_contract = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join("transfer_main_purse_to_new_purse.wasm"); let module_bytes = @@ -5471,7 +5471,7 @@ async fn successful_purse_to_account_transfer() { let purse_create_contract = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join("transfer_main_purse_to_new_purse.wasm"); let module_bytes = @@ -5958,7 +5958,7 @@ async fn out_of_gas_txn_does_not_produce_effects() { let revert_contract = RESOURCES_PATH .join("..") .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release") .join("endless_loop_with_effects.wasm"); let module_bytes = @@ -6216,7 +6216,7 @@ async fn gh_5058_regression_custom_payment_with_deploy_variant_works() { .parent() .unwrap() .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release"); let payment_amount = U512::from(2_500_000_000u64); @@ -6289,7 +6289,7 @@ async fn should_penalize_failed_custom_payment() { .parent() .unwrap() .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release"); let payment_amount = U512::from(1_000_000u64); @@ -6369,7 +6369,7 @@ async fn gh_5082_install_upgrade_should_allow_adding_new_version() { .parent() .unwrap() .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release"); let txn_1 = { @@ -6460,7 +6460,7 @@ async fn should_allow_custom_payment() { .parent() .unwrap() .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release"); let payment_amount = U512::from(2_500_000_000u64); @@ -6692,7 +6692,7 @@ async fn run_sizing_scenario(sizing_scenario: SizingScenario) { .parent() .unwrap() .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release"); let (payment_1, session_1) = match sizing_scenario { @@ -6916,7 +6916,7 @@ async fn should_assign_deploy_to_largest_lane_by_payment_amount_only_in_payment_ .parent() .unwrap() .join("target") - .join("wasm32-unknown-unknown") + .join("wasm32v1-none") .join("release"); let mut wasm_lanes = fixture diff --git a/node/src/types/appendable_block.rs b/node/src/types/appendable_block.rs index 88acc59e3e..d328d6f2e3 100644 --- a/node/src/types/appendable_block.rs +++ b/node/src/types/appendable_block.rs @@ -6,7 +6,6 @@ use std::{ use datasize::DataSize; use itertools::Itertools; use thiserror::Error; -use tracing::error; use casper_types::{ Approval, Gas, PublicKey, RewardedSignatures, Timestamp, TransactionConfig, TransactionHash, diff --git a/node/src/types/block/approvals_hashes.rs b/node/src/types/block/approvals_hashes.rs index 58ed9f523d..ca5e39c4c6 100644 --- a/node/src/types/block/approvals_hashes.rs +++ b/node/src/types/block/approvals_hashes.rs @@ -6,7 +6,6 @@ use std::{ use datasize::DataSize; use serde::{Deserialize, Serialize}; use thiserror::Error; -use tracing::error; use casper_types::{ bytesrepr::{self, FromBytes, ToBytes}, diff --git a/node/src/types/block/meta_block/merge_mismatch_error.rs b/node/src/types/block/meta_block/merge_mismatch_error.rs index a2de312222..2660d60318 100644 --- a/node/src/types/block/meta_block/merge_mismatch_error.rs +++ b/node/src/types/block/meta_block/merge_mismatch_error.rs @@ -1,5 +1,4 @@ use thiserror::Error; -use tracing::error; #[derive(Error, Debug)] pub(crate) enum MergeMismatchError { diff --git a/node/src/types/sync_leap.rs b/node/src/types/sync_leap.rs index c66d20a327..81b988f061 100644 --- a/node/src/types/sync_leap.rs +++ b/node/src/types/sync_leap.rs @@ -9,7 +9,6 @@ use itertools::Itertools; use num_rational::Ratio; use serde::{Deserialize, Serialize}; use thiserror::Error; -use tracing::error; use casper_types::{ crypto, BlockHash, BlockHeader, BlockHeaderWithSignatures, @@ -1520,7 +1519,6 @@ mod tests { .block_headers_with_signatures .iter() .take(2) - .cloned() .map(|block_header_with_signatures| block_header_with_signatures.block_header().clone()) .collect(); diff --git a/node/src/utils.rs b/node/src/utils.rs index f33eb41a8d..2a2f8f641c 100644 --- a/node/src/utils.rs +++ b/node/src/utils.rs @@ -36,7 +36,9 @@ use once_cell::sync::Lazy; use prometheus::{self, Histogram, HistogramOpts, Registry}; use serde::Serialize; use thiserror::Error; -use tracing::{error, warn}; +#[cfg(test)] +use tracing::error; +use tracing::warn; use crate::types::NodeId; pub(crate) use block_signatures::{check_sufficient_block_signatures, BlockSignatureError}; diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f706767681..e9dae42a39 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,2 @@ [toolchain] -channel = "1.91.0" -components = ["rust-analyzer"] +channel = "1.98.0" \ No newline at end of file diff --git a/rustfmt.toml b/rustfmt.toml index b16fb7d514..3a26366d4d 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,4 +1 @@ -wrap_comments = true -comment_width = 100 -imports_granularity = "Crate" edition = "2021" diff --git a/smart_contracts/contract/CHANGELOG.md b/smart_contracts/contract/CHANGELOG.md index 366e14313b..de93c9d51e 100644 --- a/smart_contracts/contract/CHANGELOG.md +++ b/smart_contracts/contract/CHANGELOG.md @@ -9,7 +9,13 @@ All notable changes to this project will be documented in this file. The format [comment]: <> (Fixed: any bug fixes) [comment]: <> (Security: in case of vulnerabilities) +## Unreleased +### Changed +* Smart-contract Wasm builds in this workspace now target `wasm32v1-none` instead of `wasm32-unknown-unknown`. `smart_contracts/contracts/.cargo/config.toml` sets `target = "wasm32v1-none"` and replaces the old `-C target-feature=-bulk-memory` rustflag with `-C link-arg=--import-undefined`; all other flags were dropped since `wasm32v1-none` enforces the Wasm MVP feature set on its own. The repo-root `rust-toolchain.toml` and `smart_contracts/rust-toolchain` were bumped accordingly, moving this workspace off its previously pinned dated nightly onto the `1.98.0` stable channel. +* `wasm32v1-none` and `-C link-arg=--import-undefined` require a Rust toolchain no older than `nightly-2025-08-03`. This workspace now builds with `1.98.0` stable, which postdates that requirement, but third-party contracts built against this crate's API on their own nightly toolchain must bump to at least `nightly-2025-08-03` (or a later toolchain) to keep building. + +## 5.1.1 ## 4.0.0 diff --git a/smart_contracts/contract/Cargo.toml b/smart_contracts/contract/Cargo.toml index 618ab90884..9aa9b8f4d4 100644 --- a/smart_contracts/contract/Cargo.toml +++ b/smart_contracts/contract/Cargo.toml @@ -25,4 +25,4 @@ std = [] [package.metadata.docs.rs] all-features = true -rustdoc-args = ["--cfg", "docsrs"] +rustdoc-args = ["--cfg", "docsrs"] \ No newline at end of file diff --git a/smart_contracts/contract/src/lib.rs b/smart_contracts/contract/src/lib.rs index 1ce525aa4c..c7b05f19f2 100644 --- a/smart_contracts/contract/src/lib.rs +++ b/smart_contracts/contract/src/lib.rs @@ -47,10 +47,6 @@ #![cfg_attr(not(test), no_std)] #![cfg_attr(all(not(test), feature = "no-std-helpers"), allow(internal_features))] -#![cfg_attr( - all(not(test), feature = "no-std-helpers"), - feature(alloc_error_handler, core_intrinsics, lang_items) -)] #![doc(html_root_url = "https://docs.rs/casper-contract/5.1.1")] #![doc( html_favicon_url = "https://raw.githubusercontent.com/casper-network/casper-node/blob/dev/images/Casper_Logo_Favicon_48.png", diff --git a/smart_contracts/contract/src/no_std_handlers.rs b/smart_contracts/contract/src/no_std_handlers.rs index 1798593b92..7e084ff92c 100644 --- a/smart_contracts/contract/src/no_std_handlers.rs +++ b/smart_contracts/contract/src/no_std_handlers.rs @@ -5,15 +5,17 @@ pub fn panic(_info: &core::panic::PanicInfo) -> ! { #[cfg(feature = "test-support")] crate::contract_api::runtime::print(&alloc::format!("{_info}")); - core::intrinsics::abort(); + abort() } -/// An out-of-memory allocation error handler for use in a `no_std` environment which simply aborts -/// the process. -#[alloc_error_handler] -pub fn oom(_: core::alloc::Layout) -> ! { - core::intrinsics::abort(); +#[cfg(target_arch = "wasm32")] +fn abort() -> ! { + core::arch::wasm32::unreachable() } -#[lang = "eh_personality"] -extern "C" fn eh_personality() {} +#[cfg(not(target_arch = "wasm32"))] +fn abort() -> ! { + loop { + core::hint::spin_loop() + } +} diff --git a/smart_contracts/contracts/.cargo/config.toml b/smart_contracts/contracts/.cargo/config.toml index c1f383b025..6e10d52eb9 100644 --- a/smart_contracts/contracts/.cargo/config.toml +++ b/smart_contracts/contracts/.cargo/config.toml @@ -1,3 +1,3 @@ [build] -target = "wasm32-unknown-unknown" -rustflags = ["-C", "target-feature=-bulk-memory"] +target = "wasm32v1-none" +rustflags = ["-C", "link-arg=--import-undefined"] diff --git a/smart_contracts/contracts/SRE/create-test-node-01/Cargo.toml b/smart_contracts/contracts/SRE/create-test-node-01/Cargo.toml index 63239304e0..5aa595570e 100644 --- a/smart_contracts/contracts/SRE/create-test-node-01/Cargo.toml +++ b/smart_contracts/contracts/SRE/create-test-node-01/Cargo.toml @@ -4,12 +4,8 @@ version = "0.1.0" authors = ["Henry Till "] edition = "2021" -[[bin]] -name = "create_test_node_01" -path = "src/main.rs" -bench = false -doctest = false -test = false +[lib] +crate-type = ["cdylib", "rlib"] [dependencies] create-test-node-shared = { path = "../create-test-node-shared" } diff --git a/smart_contracts/contracts/SRE/create-test-node-01/src/main.rs b/smart_contracts/contracts/SRE/create-test-node-01/src/lib.rs similarity index 100% rename from smart_contracts/contracts/SRE/create-test-node-01/src/main.rs rename to smart_contracts/contracts/SRE/create-test-node-01/src/lib.rs diff --git a/smart_contracts/contracts/SRE/create-test-node-02/Cargo.toml b/smart_contracts/contracts/SRE/create-test-node-02/Cargo.toml index f05ce96db3..577c1f21c2 100644 --- a/smart_contracts/contracts/SRE/create-test-node-02/Cargo.toml +++ b/smart_contracts/contracts/SRE/create-test-node-02/Cargo.toml @@ -4,12 +4,8 @@ version = "0.1.0" authors = ["Henry Till "] edition = "2021" -[[bin]] -name = "create_test_node_02" -path = "src/main.rs" -bench = false -doctest = false -test = false +[lib] +crate-type = ["cdylib", "rlib"] [dependencies] create-test-node-shared = { path = "../create-test-node-shared" } diff --git a/smart_contracts/contracts/SRE/create-test-node-02/src/main.rs b/smart_contracts/contracts/SRE/create-test-node-02/src/lib.rs similarity index 100% rename from smart_contracts/contracts/SRE/create-test-node-02/src/main.rs rename to smart_contracts/contracts/SRE/create-test-node-02/src/lib.rs diff --git a/smart_contracts/contracts/SRE/create-test-node-03/Cargo.toml b/smart_contracts/contracts/SRE/create-test-node-03/Cargo.toml index 5ab2c6f65d..54a03a6b96 100644 --- a/smart_contracts/contracts/SRE/create-test-node-03/Cargo.toml +++ b/smart_contracts/contracts/SRE/create-test-node-03/Cargo.toml @@ -4,12 +4,8 @@ version = "0.1.0" authors = ["Henry Till "] edition = "2021" -[[bin]] -name = "create_test_node_03" -path = "src/main.rs" -bench = false -doctest = false -test = false +[lib] +crate-type = ["cdylib", "rlib"] [dependencies] create-test-node-shared = { path = "../create-test-node-shared" } diff --git a/smart_contracts/contracts/SRE/create-test-node-03/src/main.rs b/smart_contracts/contracts/SRE/create-test-node-03/src/lib.rs similarity index 100% rename from smart_contracts/contracts/SRE/create-test-node-03/src/main.rs rename to smart_contracts/contracts/SRE/create-test-node-03/src/lib.rs diff --git a/smart_contracts/contracts/SRE/create-test-node-shared/Cargo.toml b/smart_contracts/contracts/SRE/create-test-node-shared/Cargo.toml index 3fb74f4393..dca0a91429 100644 --- a/smart_contracts/contracts/SRE/create-test-node-shared/Cargo.toml +++ b/smart_contracts/contracts/SRE/create-test-node-shared/Cargo.toml @@ -6,5 +6,5 @@ edition = "2021" [dependencies] base16 = { version = "0.2.1", default-features = false } -casper-contract = { path = "../../../contract" } +casper-contract = { path = "../../../contract", features = ["no-std-helpers"] } casper-types = { path = "../../../../types" } diff --git a/smart_contracts/contracts/nctl/nctl-dictionary/src/main.rs b/smart_contracts/contracts/nctl/nctl-dictionary/src/main.rs index 5ce10de485..2a4ff63b16 100644 --- a/smart_contracts/contracts/nctl/nctl-dictionary/src/main.rs +++ b/smart_contracts/contracts/nctl/nctl-dictionary/src/main.rs @@ -2,7 +2,7 @@ #![no_main] #[cfg(not(target_arch = "wasm32"))] -compile_error!("target arch should be wasm32: compile with '--target wasm32-unknown-unknown'"); +compile_error!("target arch should be wasm32: compile with '--target wasm32v1-none'"); // We need to explicitly import the std alloc crate and `alloc::string::String` as we're in a // `no_std` environment. diff --git a/smart_contracts/contracts/test/ee-966-regression/src/main.rs b/smart_contracts/contracts/test/ee-966-regression/src/main.rs index efffe3a0da..9a75c6953d 100644 --- a/smart_contracts/contracts/test/ee-966-regression/src/main.rs +++ b/smart_contracts/contracts/test/ee-966-regression/src/main.rs @@ -1,7 +1,6 @@ #![no_std] #![no_main] #![allow(internal_features)] -#![feature(lang_items)] extern crate core; @@ -61,9 +60,6 @@ pub fn panic(_info: &::core::panic::PanicInfo) -> ! { revert(ApiError::OutOfMemory) } -#[lang = "eh_personality"] -extern "C" fn eh_personality() {} - #[no_mangle] pub extern "C" fn call() { let initial_memory_pages = memory_size(); diff --git a/smart_contracts/contracts/test/key-putter/src/main.rs b/smart_contracts/contracts/test/key-putter/src/main.rs index eca797a7cf..72b026b3cf 100644 --- a/smart_contracts/contracts/test/key-putter/src/main.rs +++ b/smart_contracts/contracts/test/key-putter/src/main.rs @@ -2,7 +2,7 @@ #![no_main] #[cfg(not(target_arch = "wasm32"))] -compile_error!("target arch should be wasm32: compile with '--target wasm32-unknown-unknown'"); +compile_error!("target arch should be wasm32: compile with '--target wasm32v1-none'"); // This code imports necessary aspects of external crates that we will use in our contract code. extern crate alloc; diff --git a/smart_contracts/contracts/tutorial/counter-installer/src/main.rs b/smart_contracts/contracts/tutorial/counter-installer/src/main.rs index 952fc2cb72..f39dda2880 100644 --- a/smart_contracts/contracts/tutorial/counter-installer/src/main.rs +++ b/smart_contracts/contracts/tutorial/counter-installer/src/main.rs @@ -2,7 +2,7 @@ #![no_main] #[cfg(not(target_arch = "wasm32"))] -compile_error!("target arch should be wasm32: compile with '--target wasm32-unknown-unknown'"); +compile_error!("target arch should be wasm32: compile with '--target wasm32v1-none'"); extern crate alloc; diff --git a/smart_contracts/contracts/tutorial/increment-counter/src/main.rs b/smart_contracts/contracts/tutorial/increment-counter/src/main.rs index befcf7d46a..1c3026255a 100644 --- a/smart_contracts/contracts/tutorial/increment-counter/src/main.rs +++ b/smart_contracts/contracts/tutorial/increment-counter/src/main.rs @@ -2,7 +2,7 @@ #![no_main] #[cfg(not(target_arch = "wasm32"))] -compile_error!("target arch should be wasm32: compile with '--target wasm32-unknown-unknown'"); +compile_error!("target arch should be wasm32: compile with '--target wasm32v1-none'"); extern crate alloc; diff --git a/smart_contracts/macros/src/lib.rs b/smart_contracts/macros/src/lib.rs index 547695b1e5..e7d618b334 100644 --- a/smart_contracts/macros/src/lib.rs +++ b/smart_contracts/macros/src/lib.rs @@ -532,10 +532,6 @@ fn generate_impl_for_contract( let mut instance: #struct_name = casper_contract_sdk::casper::read_state().unwrap(); let _ret = instance.#func_name(#(args.#arg_names,)*); } - } else if method_attribute.constructor { - quote! { - let _ret = <#struct_name>::#func_name(#(args.#arg_names,)*); - } } else { quote! { let _ret = <#struct_name>::#func_name(#(args.#arg_names,)*); diff --git a/smart_contracts/rust-toolchain b/smart_contracts/rust-toolchain index a733a6e85d..783fda8643 100644 --- a/smart_contracts/rust-toolchain +++ b/smart_contracts/rust-toolchain @@ -1 +1 @@ -nightly-2025-08-28 +1.98.0 diff --git a/smart_contracts/sdk/src/collections/iterable_map.rs b/smart_contracts/sdk/src/collections/iterable_map.rs index ee785c2457..d963355580 100644 --- a/smart_contracts/sdk/src/collections/iterable_map.rs +++ b/smart_contracts/sdk/src/collections/iterable_map.rs @@ -292,20 +292,16 @@ where let prefix = self.create_prefix_from_ptr(&bucket_ptr); let keyspace = Keyspace::Context(&prefix); - if let Some(entry) = self.get_entry(keyspace) { - // Existing value, check if the keys match - if entry.key == *key && entry.value.is_some() { - // We have found a slot where this key lives, return it - return Some((bucket_ptr, entry)); - } else { - // We found a slot for this key hash, but either the keys mismatch, - // or it's vacant, so we need to probe further. - bucket_ptr.index += 1; - continue; - } + let entry = self.get_entry(keyspace)?; + // Existing value, check if the keys match + if entry.key == *key && entry.value.is_some() { + // We have found a slot where this key lives, return it + return Some((bucket_ptr, entry)); } else { - // We've reached empty address space, so the slot doesn't actually exist. - return None; + // We found a slot for this key hash, but either the keys mismatch, + // or it's vacant, so we need to probe further. + bucket_ptr.index += 1; + continue; } } } diff --git a/smart_contracts/sdk/src/collections/iterable_set.rs b/smart_contracts/sdk/src/collections/iterable_set.rs index 0f2ced6461..890d62dc89 100644 --- a/smart_contracts/sdk/src/collections/iterable_set.rs +++ b/smart_contracts/sdk/src/collections/iterable_set.rs @@ -163,7 +163,7 @@ mod tests { assert!(set.contains(&val2)); let mut collected: Vec<_> = set.iter().collect(); - collected.sort_by(|a, b| a.field1.cmp(&b.field1)); + collected.sort_by_key(|a| a.field1); assert_eq!(collected, vec![val1, val2]); }) .unwrap(); diff --git a/smart_contracts/sdk_codegen/src/lib.rs b/smart_contracts/sdk_codegen/src/lib.rs index 51c34afa1b..4a78dadd7b 100644 --- a/smart_contracts/sdk_codegen/src/lib.rs +++ b/smart_contracts/sdk_codegen/src/lib.rs @@ -100,7 +100,7 @@ impl Codegen { if !self.schema.definitions.has_definition(state) { panic!( "Missing state definition. Expected to find a definition for {}.", - &state + state ) }; } @@ -434,9 +434,10 @@ impl Codegen { .line("}"); } Some(Specialized::Option { some }) => { - let some_type = self.type_mapping.get(&some).unwrap_or_else(|| { - panic!("Missing type mapping for {}", &some) - }); + let some_type = self + .type_mapping + .get(&some) + .unwrap_or_else(|| panic!("Missing type mapping for {}", some)); let impl_block = scope .new_impl(&enum_name) @@ -508,7 +509,7 @@ impl Codegen { if entry_point.flags.contains(EntryPointFlags::CONSTRUCTOR) { func.ret(Type::new(format!( "Result<{}, casper_contract_sdk::types::CallError>", - &struct_name + struct_name ))) .generic("C") .bound("C", "casper_contract_sdk::Contract"); @@ -531,7 +532,7 @@ impl Codegen { func.line("let value = 0; // TODO: Transferring values"); let input_struct_name = - format!("{}_{}", slugify_type(&self.schema.name), &entry_point.name); + format!("{}_{}", slugify_type(&self.schema.name), entry_point.name); if entry_point.arguments.is_empty() { func.line(format!(r#"let call_data = {input_struct_name};"#)); @@ -552,7 +553,7 @@ impl Codegen { func.line(format!( r#"let result = {struct_name} {{ address: create_result.contract_address }};"#, - struct_name = &struct_name + struct_name = struct_name )); func.line("Ok(result)"); continue; @@ -563,7 +564,7 @@ impl Codegen { for entry_point in &self.schema.entry_points { // Generate arg structure similar to what casper-contract-macros is doing - let struct_name = format!("{}_{}", &self.schema.name, &entry_point.name); + let struct_name = format!("{}_{}", self.schema.name, entry_point.name); let input_struct = scope.new_struct(&struct_name); for trait_name in DEFAULT_DERIVED_TRAITS { @@ -574,7 +575,7 @@ impl Codegen { let mapped_type = self.type_mapping.get(&argument.decl).unwrap_or_else(|| { panic!( "Missing type mapping for {} when generating input arg {}", - argument.decl, &struct_name + argument.decl, struct_name ) }); input_struct.push_field(Field::new(&argument.name, Type::new(mapped_type))); diff --git a/storage/CHANGELOG.md b/storage/CHANGELOG.md index 1ea8760e07..8f96aeee5a 100644 --- a/storage/CHANGELOG.md +++ b/storage/CHANGELOG.md @@ -9,6 +9,13 @@ All notable changes to this project will be documented in this file. The format [comment]: <> (Fixed: any bug fixes) [comment]: <> (Security: in case of vulnerabilities) +## Unreleased + +### Changed + +* Disk-Based Block Store Caching. `LmdbBlockStore` (`storage/src/block_store/lmdb/lmdb_block_store.rs`) persists its `block_height_index`, `switch_block_era_id_index`, and `transaction_hash_index` lookups as dedicated LMDB tables -- `block_height_index_db`, `switch_block_era_id_index_db`, and `transaction_hash_index_db` -- directly on `LmdbBlockStore`, instead of rebuilding them as in-memory `BTreeMap`s +* `MAX_DB_COUNT` was raised from `17` to `20` to accommodate the three new named databases + ## 5.0.0 ### Added diff --git a/storage/src/block_store/types/approvals_hashes.rs b/storage/src/block_store/types/approvals_hashes.rs index 3398dfcf7f..414bb46931 100644 --- a/storage/src/block_store/types/approvals_hashes.rs +++ b/storage/src/block_store/types/approvals_hashes.rs @@ -6,7 +6,6 @@ use std::{ use datasize::DataSize; use serde::{Deserialize, Serialize}; use thiserror::Error; -use tracing::error; use casper_types::{ bytesrepr::{self, FromBytes, ToBytes}, diff --git a/storage/src/data_access_layer/auction.rs b/storage/src/data_access_layer/auction.rs index b61145307a..1facfc78dc 100644 --- a/storage/src/data_access_layer/auction.rs +++ b/storage/src/data_access_layer/auction.rs @@ -2,7 +2,6 @@ use std::collections::BTreeSet; use serde::Serialize; use thiserror::Error; -use tracing::error; use casper_types::{ account::AccountHash, diff --git a/storage/src/data_access_layer/balance.rs b/storage/src/data_access_layer/balance.rs index 650c92b309..c8900add81 100644 --- a/storage/src/data_access_layer/balance.rs +++ b/storage/src/data_access_layer/balance.rs @@ -152,12 +152,10 @@ impl BalanceIdentifier { } } BalanceIdentifier::Entity(entity_addr) => { - match tc.runtime_footprint_by_entity_addr(*entity_addr) { - Ok(entity) => entity - .main_purse() - .ok_or(TrackingCopyError::Authorization)?, - Err(tce) => return Err(tce), - } + let entity = tc.runtime_footprint_by_entity_addr(*entity_addr)?; + entity + .main_purse() + .ok_or(TrackingCopyError::Authorization)? } BalanceIdentifier::Refund => { self.get_system_purse(tc, HANDLE_PAYMENT, REFUND_PURSE_KEY)? diff --git a/storage/src/global_state/state/lmdb.rs b/storage/src/global_state/state/lmdb.rs index bec6ee4366..acc90a5a7b 100644 --- a/storage/src/global_state/state/lmdb.rs +++ b/storage/src/global_state/state/lmdb.rs @@ -212,10 +212,8 @@ impl StateReader for LmdbGlobalStateView { ); let mut ret = Vec::new(); for result in keys_iter { - match result { - Ok(key) => ret.push(key), - Err(error) => return Err(error), - } + let key = result?; + ret.push(key) } txn.commit()?; Ok(ret) @@ -541,9 +539,7 @@ pub fn make_temporary_global_state( mod tests { use casper_types::{account::AccountHash, execution::TransformKindV2, CLValue, Digest}; - use crate::global_state::state::{ - scratch::tests::TestPair, CommitProvider as _, StateProvider as _, - }; + use crate::global_state::state::scratch::tests::TestPair; use super::*; diff --git a/storage/src/global_state/state/scratch.rs b/storage/src/global_state/state/scratch.rs index 86edef81ac..b2480e2311 100644 --- a/storage/src/global_state/state/scratch.rs +++ b/storage/src/global_state/state/scratch.rs @@ -341,16 +341,12 @@ impl StateReader for ScratchGlobalStateView { prefix, ); for result in keys_iter { - match result { - Ok(key) => { - // If the key is pruned then we won't return it. If the key is already cached, - // then it would have been picked up by the code above so we don't add it again - // to avoid duplicates. - if !cache.pruned.contains(&key) && !cache.cached_values.contains_key(&key) { - ret.push(key); - } - } - Err(error) => return Err(error), + let key = result?; + // If the key is pruned then we won't return it. If the key is already cached, + // then it would have been picked up by the code above so we don't add it again + // to avoid duplicates. + if !cache.pruned.contains(&key) && !cache.cached_values.contains_key(&key) { + ret.push(key); } } txn.commit()?; diff --git a/storage/src/global_state/trie/mod.rs b/storage/src/global_state/trie/mod.rs index 8acefc32f6..6a58e7c5c2 100644 --- a/storage/src/global_state/trie/mod.rs +++ b/storage/src/global_state/trie/mod.rs @@ -176,6 +176,7 @@ impl ToBytes for PointerBlock { } } +#[allow(dropping_copy_types)] impl FromBytes for PointerBlock { fn from_bytes(mut bytes: &[u8]) -> Result<(Self, &[u8]), bytesrepr::Error> { let pointer_block_array = { diff --git a/storage/src/global_state/trie_store/operations/tests/write.rs b/storage/src/global_state/trie_store/operations/tests/write.rs index 5ccf917ed4..b674f7db54 100644 --- a/storage/src/global_state/trie_store/operations/tests/write.rs +++ b/storage/src/global_state/trie_store/operations/tests/write.rs @@ -165,7 +165,7 @@ mod partial_tries { write_environment, writable_store, current_root, - &[leaf.to_owned()], + std::slice::from_ref(leaf), )?; assert_eq!(1, results.len()); match results[0] { diff --git a/storage/src/lib.rs b/storage/src/lib.rs index 4faaefb7f5..d8eb6f1970 100644 --- a/storage/src/lib.rs +++ b/storage/src/lib.rs @@ -5,7 +5,7 @@ html_favicon_url = "https://raw.githubusercontent.com/casper-network/casper-node/master/images/CasperLabs_Logo_Favicon_RGB_50px.png", html_logo_url = "https://raw.githubusercontent.com/casper-network/casper-node/master/images/CasperLabs_Logo_Symbol_RGB.png" )] -#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] #![warn(missing_docs)] /// Address generator logic. diff --git a/storage/src/system/transfer.rs b/storage/src/system/transfer.rs index 06d3d2fd28..1480e1ab5e 100644 --- a/storage/src/system/transfer.rs +++ b/storage/src/system/transfer.rs @@ -520,28 +520,27 @@ impl TransferRuntimeArgsBuilder { where R: StateReader, { - let (to, target) = match self - .resolve_transfer_target_mode(protocol_version, Rc::clone(&tracking_copy))? - { - TransferTargetMode::ExistingAccount { - main_purse: purse_uref, - target_account_hash: target_account, - } => (Some(target_account), purse_uref), - TransferTargetMode::ExistingEvmAccount { - main_purse: purse_uref, - .. - } => (None, purse_uref), - TransferTargetMode::PurseExists { - target_account_hash, - purse_uref, - } => (target_account_hash, purse_uref), - TransferTargetMode::CreateAccount(_) | TransferTargetMode::CreateEvmAccount(_) => { - // Method "build()" is called after `resolve_transfer_target_mode` is first called - // and handled by creating a new account. Calling `resolve_transfer_target_mode` - // for the second time should never return `CreateAccount` variant. - return Err(TransferError::InvalidOperation); - } - }; + let (to, target) = + match self.resolve_transfer_target_mode(protocol_version, Rc::clone(&tracking_copy))? { + TransferTargetMode::ExistingAccount { + main_purse: purse_uref, + target_account_hash: target_account, + } => (Some(target_account), purse_uref), + TransferTargetMode::ExistingEvmAccount { + main_purse: purse_uref, + .. + } => (None, purse_uref), + TransferTargetMode::PurseExists { + target_account_hash, + purse_uref, + } => (target_account_hash, purse_uref), + TransferTargetMode::CreateAccount(_) | TransferTargetMode::CreateEvmAccount(_) => { + // Method "build()" is called after `resolve_transfer_target_mode` is first called + // and handled by creating a new account. Calling `resolve_transfer_target_mode` + // for the second time should never return `CreateAccount` variant. + return Err(TransferError::InvalidOperation); + } + }; let source = self.resolve_source_uref(from, Rc::clone(&tracking_copy))?; diff --git a/storage/src/tracking_copy/mod.rs b/storage/src/tracking_copy/mod.rs index c7be3cfe9e..b221552dd9 100644 --- a/storage/src/tracking_copy/mod.rs +++ b/storage/src/tracking_copy/mod.rs @@ -19,7 +19,6 @@ use std::{ use linked_hash_map::LinkedHashMap; use thiserror::Error; -use tracing::error; use crate::{ global_state::{ diff --git a/types/src/lib.rs b/types/src/lib.rs index 5d42e17d07..aaa41dac1f 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -15,7 +15,7 @@ html_favicon_url = "https://raw.githubusercontent.com/casper-network/casper-node/blob/dev/images/Casper_Logo_Favicon_48.png", html_logo_url = "https://raw.githubusercontent.com/casper-network/casper-node/blob/dev/images/Casper_Logo_Favicon.png" )] -#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] #[cfg_attr(not(test), macro_use)] extern crate alloc; diff --git a/types/src/system/caller.rs b/types/src/system/caller.rs index 122dd07911..33b8e75a50 100644 --- a/types/src/system/caller.rs +++ b/types/src/system/caller.rs @@ -167,7 +167,7 @@ impl Caller { Caller::Initiator { account_hash } } - /// Creates a [`'Caller::Entity`]. This represents a call into a contract with + /// Creates a [`Caller::Entity`]. This represents a call into a contract with /// `EntryPointType::Called`. pub fn entity(package_hash: PackageHash, entity_addr: EntityAddr) -> Self { Caller::Entity { diff --git a/types/src/system/caller/call_stack_elements.rs b/types/src/system/caller/call_stack_elements.rs index be9fc8cbe6..3ee5e5eee3 100644 --- a/types/src/system/caller/call_stack_elements.rs +++ b/types/src/system/caller/call_stack_elements.rs @@ -55,7 +55,7 @@ impl CallStackElement { CallStackElement::Session { account_hash } } - /// Creates a [`'CallStackElement::StoredContract`]. This represents a call into a contract with + /// Creates a [`CallStackElement::StoredContract`]. This represents a call into a contract with /// `EntryPointType::Contract`. pub fn stored_contract( contract_package_hash: ContractPackageHash, @@ -67,7 +67,7 @@ impl CallStackElement { } } - /// Creates a [`'CallStackElement::StoredSession`]. This represents a call into a contract with + /// Creates a [`CallStackElement::StoredSession`]. This represents a call into a contract with /// `EntryPointType::Session`. pub fn stored_session( account_hash: AccountHash, diff --git a/types/src/transaction/deploy/deploy_category.rs b/types/src/transaction/deploy/deploy_category.rs index ef59d40afc..a4f04da57c 100644 --- a/types/src/transaction/deploy/deploy_category.rs +++ b/types/src/transaction/deploy/deploy_category.rs @@ -7,7 +7,7 @@ use datasize::DataSize; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; -/// The category of a [`Transaction`]. +/// The category of a [`Deploy`]. #[deprecated( note = "DeployCategory is scheduled for removal in the next casper-types major version" )] diff --git a/types/src/uint.rs b/types/src/uint.rs index 26741c1f20..ce7c31890c 100644 --- a/types/src/uint.rs +++ b/types/src/uint.rs @@ -32,7 +32,16 @@ use crate::bytesrepr::{self, Error, FromBytes, ToBytes, U8_SERIALIZED_LENGTH}; clippy::range_plus_one, clippy::transmute_ptr_to_ptr, clippy::reversed_empty_ranges, - clippy::manual_div_ceil + clippy::manual_div_ceil, + // `construct_uint!` expands to code using the deprecated `iN::max_value()` associated + // functions instead of the `MAX` associated constant, and to a macro-generated trailing + // semicolon in expression position; both are internal to the `uint` crate's macro and + // outside our control. `semicolon_in_expressions_from_non_local_macros` doesn't exist on + // stable, so `unknown_lints` is needed there; on nightly (e.g. `make doc`) it silences the + // real lint, which fires even outside of rustdoc, so this can't be gated on `cfg(docsrs)`. + unknown_lints, + semicolon_in_expressions_from_non_local_macros, + deprecated )] mod macro_code { #[cfg(feature = "datasize")] diff --git a/utils/casper-tool/casper-tool.py b/utils/casper-tool/casper-tool.py index 78b52d7a80..5c633696cd 100755 --- a/utils/casper-tool/casper-tool.py +++ b/utils/casper-tool/casper-tool.py @@ -13,7 +13,7 @@ #: Relative directory to be appended to basedir in case WASM dir is not specified. -DEFAULT_WASM_SUBDIR = ["target", "wasm32-unknown-unknown", "release"] +DEFAULT_WASM_SUBDIR = ["target", "wasm32v1-none", "release"] #: The port the node is reachable on. diff --git a/utils/global-state-update-gen/src/decode.rs b/utils/global-state-update-gen/src/decode.rs index 49433465c7..6fc447b141 100644 --- a/utils/global-state-update-gen/src/decode.rs +++ b/utils/global-state-update-gen/src/decode.rs @@ -41,7 +41,7 @@ pub(crate) fn decode_file(matches: &ArgMatches<'_>) { let config: GlobalStateUpdateConfig = toml::from_str(&contents).unwrap(); let update_data: GlobalStateUpdate = config.try_into().unwrap(); - println!("validators = {:#?}", &update_data.validators); + println!("validators = {:#?}", update_data.validators); let entries: BTreeMap<_, _> = update_data .entries .iter()