From eb25725d5e695428ba99c643b76c12ab14e00b1f Mon Sep 17 00:00:00 2001 From: renauter Date: Fri, 24 Nov 2023 13:47:02 -0300 Subject: [PATCH 01/25] upgrade to polkadot 0.9.43 --- substrate-node/Cargo.toml | 132 +++++++++++++++--------------- substrate-node/runtime/Cargo.toml | 2 +- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/substrate-node/Cargo.toml b/substrate-node/Cargo.toml index ca0599f98..45247f26d 100644 --- a/substrate-node/Cargo.toml +++ b/substrate-node/Cargo.toml @@ -60,73 +60,73 @@ tfchain-support = { path = "support", default-features = false } tfchain-runtime = { path = "runtime", default-features = false } # Benchmarking (with default disabled) -frame-system-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} +frame-system-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} # Substrate (with default disabled) -frame-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -frame-benchmarking-cli = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -frame-executive = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -frame-support = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -frame-system = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -frame-system-rpc-runtime-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -frame-try-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-authorship = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-balances = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-collective = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-grandpa = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-membership = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-scheduler = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-session-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-timestamp = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-transaction-payment = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-transaction-payment-rpc = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-transaction-payment-rpc-runtime-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -pallet-utility = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-block-builder = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-consensus-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-inherents = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-io = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-offchain = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-std = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-transaction-pool = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-version = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-storage = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -try-runtime-cli = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-keystore = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} -sp-staking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"} +frame-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +frame-benchmarking-cli = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +frame-executive = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +frame-support = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +frame-system = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +frame-system-rpc-runtime-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +frame-try-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-authorship = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-balances = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-collective = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-grandpa = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-membership = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-scheduler = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-session-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-timestamp = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-transaction-payment = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-transaction-payment-rpc = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-transaction-payment-rpc-runtime-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +pallet-utility = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-block-builder = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-consensus-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-inherents = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-io = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-offchain = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-std = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-transaction-pool = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-version = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-storage = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +try-runtime-cli = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-keystore = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +sp-staking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} # Client-only (with default enabled) -polkadot-cli = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.42"} -polkadot-primitives = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.42"} -polkadot-service = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.42"} -sc-basic-authorship = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-chain-spec = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-cli = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-client-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-consensus = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-consensus-aura = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-executor = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-consensus-grandpa = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-keystore = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-network = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-rpc = { git = "https://github.com/paritytech/substrate.git", "branch" = "polkadot-v0.9.42" } -sc-rpc-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-service = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-sysinfo = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-telemetry = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-tracing = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-transaction-pool = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sc-transaction-pool-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sp-blockchain = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sp-consensus = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sp-keyring = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -sp-timestamp = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -substrate-build-script-utils = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -substrate-frame-rpc-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} -substrate-prometheus-endpoint = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42"} +polkadot-cli = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43"} +polkadot-primitives = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43"} +polkadot-service = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43"} +sc-basic-authorship = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-chain-spec = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-cli = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-client-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-consensus = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-consensus-aura = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-executor = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-consensus-grandpa = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-keystore = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-network = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-rpc = { git = "https://github.com/paritytech/substrate.git", "branch" = "polkadot-v0.9.43" } +sc-rpc-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-service = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-sysinfo = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-telemetry = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-tracing = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-transaction-pool = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sc-transaction-pool-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sp-blockchain = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sp-consensus = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sp-keyring = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +sp-timestamp = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +substrate-build-script-utils = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +substrate-frame-rpc-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +substrate-prometheus-endpoint = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} diff --git a/substrate-node/runtime/Cargo.toml b/substrate-node/runtime/Cargo.toml index 095b6318e..05206d0ea 100644 --- a/substrate-node/runtime/Cargo.toml +++ b/substrate-node/runtime/Cargo.toml @@ -14,7 +14,7 @@ version.workspace = true targets = ["x86_64-unknown-linux-gnu"] [build-dependencies] -substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" } +substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } [dependencies] smallvec.workspace = true From fb8a23ebc37b4182a2974efc6bd1c93f785b8bf3 Mon Sep 17 00:00:00 2001 From: renauter Date: Fri, 24 Nov 2023 13:48:24 -0300 Subject: [PATCH 02/25] update rust-toolchain to 1.70.0 --- substrate-node/rust-toolchain.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate-node/rust-toolchain.toml b/substrate-node/rust-toolchain.toml index aa33e4ae2..1405ae81a 100644 --- a/substrate-node/rust-toolchain.toml +++ b/substrate-node/rust-toolchain.toml @@ -1,5 +1,5 @@ [toolchain] -channel = "1.69.0" +channel = "1.70.0" components = [ "cargo", "clippy", From aeac5f8fa24ae80afc7fc2e48da673be17a2c501 Mon Sep 17 00:00:00 2001 From: renauter Date: Fri, 24 Nov 2023 13:49:12 -0300 Subject: [PATCH 03/25] update node sevices.rs --- substrate-node/node/Cargo.toml | 1 + substrate-node/node/src/service.rs | 14 +++++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/substrate-node/node/Cargo.toml b/substrate-node/node/Cargo.toml index 45d2af21e..4fb2d5fd9 100644 --- a/substrate-node/node/Cargo.toml +++ b/substrate-node/node/Cargo.toml @@ -28,6 +28,7 @@ serde_json.workspace = true sc-cli.workspace = true sp-core.workspace = true sc-executor.workspace = true +sc-network.workspace = true sc-service.workspace = true sc-telemetry.workspace = true sc-keystore.workspace = true diff --git a/substrate-node/node/src/service.rs b/substrate-node/node/src/service.rs index b6320aaa0..05117164a 100644 --- a/substrate-node/node/src/service.rs +++ b/substrate-node/node/src/service.rs @@ -156,7 +156,7 @@ pub fn new_partial( } /// Builds a new service for a full client. -pub fn new_full(mut config: Configuration) -> Result { +pub fn new_full(config: Configuration) -> Result { let sc_service::PartialComponents { client, backend, @@ -168,6 +168,8 @@ pub fn new_full(mut config: Configuration) -> Result other: (block_import, grandpa_link, mut telemetry), } = new_partial(&config)?; + let mut net_config = sc_network::config::FullNetworkConfiguration::new(&config.network); + let grandpa_protocol_name = sc_consensus_grandpa::protocol_standard_name( &client .block_hash(0) @@ -176,13 +178,10 @@ pub fn new_full(mut config: Configuration) -> Result .expect("Genesis block exists; qed"), &config.chain_spec, ); + net_config.add_notification_protocol(sc_consensus_grandpa::grandpa_peers_set_config( + grandpa_protocol_name.clone(), + )); - config - .network - .extra_sets - .push(sc_consensus_grandpa::grandpa_peers_set_config( - grandpa_protocol_name.clone(), - )); let warp_sync = Arc::new(sc_consensus_grandpa::warp_proof::NetworkProvider::new( backend.clone(), grandpa_link.shared_authority_set().clone(), @@ -192,6 +191,7 @@ pub fn new_full(mut config: Configuration) -> Result let (network, system_rpc_tx, tx_handler_controller, network_starter, sync) = sc_service::build_network(sc_service::BuildNetworkParams { config: &config, + net_config, client: client.clone(), transaction_pool: transaction_pool.clone(), spawn_handle: task_manager.spawn_handle(), From 8ad030261f46f0bd7977930a88a078b8f66525f2 Mon Sep 17 00:00:00 2001 From: renauter Date: Fri, 24 Nov 2023 18:04:46 -0300 Subject: [PATCH 04/25] update try-runtime feature --- .../src/migrations/v10.rs | 2 +- .../src/migrations/v11.rs | 4 +- .../src/migrations/v6.rs | 4 +- .../src/migrations/v8.rs | 4 +- .../src/migrations/v9.rs | 2 +- .../pallet-tfgrid/src/migrations/v10.rs | 4 +- .../pallet-tfgrid/src/migrations/v11.rs | 4 +- .../pallet-tfgrid/src/migrations/v12.rs | 4 +- .../pallet-tfgrid/src/migrations/v13.rs | 4 +- .../pallet-tfgrid/src/migrations/v14.rs | 4 +- .../pallet-tfgrid/src/migrations/v15.rs | 4 +- .../pallet-tfgrid/src/migrations/v17.rs | 4 +- .../pallet-tft-bridge/src/migrations/v2.rs | 66 ++++++++++--------- .../tfgrid_v15_smart_contract_v8.rs | 4 +- 14 files changed, 60 insertions(+), 54 deletions(-) diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs index ca180d44d..c130c03e2 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs @@ -16,7 +16,7 @@ impl OnRuntimeUpgrade for ReworkBillingLoopInsertion { } #[cfg(feature = "try-runtime")] - fn post_upgrade(_: Vec) -> Result<(), &'static str> { + fn post_upgrade(_: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V10); diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs index 4ea467536..52a5840e3 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs @@ -23,7 +23,7 @@ pub type ContractLock = StorageMap< pub struct ExtendContractLock(PhantomData); impl OnRuntimeUpgrade for ExtendContractLock { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { debug!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V10); @@ -41,7 +41,7 @@ impl OnRuntimeUpgrade for ExtendContractLock { } #[cfg(feature = "try-runtime")] - fn post_upgrade(_: Vec) -> Result<(), &'static str> { + fn post_upgrade(_: Vec) -> Result<(), sp_runtime::TryRuntimeError> { debug!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V11); diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v6.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v6.rs index 7d6df417f..70e3702a6 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v6.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v6.rs @@ -11,7 +11,7 @@ pub struct ContractMigrationV5(PhantomData); impl OnRuntimeUpgrade for ContractMigrationV5 { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V5); @@ -30,7 +30,7 @@ impl OnRuntimeUpgrade for ContractMigrationV5 { } #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_contracts_count: Vec) -> Result<(), &'static str> { + fn post_upgrade(pre_contracts_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V6); diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v8.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v8.rs index 9c2214474..ccdcf8912 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v8.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v8.rs @@ -15,7 +15,7 @@ pub struct FixTwinLockedBalances(PhantomData); impl OnRuntimeUpgrade for FixTwinLockedBalances { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { debug!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V6); @@ -33,7 +33,7 @@ impl OnRuntimeUpgrade for FixTwinLockedBalances { } #[cfg(feature = "try-runtime")] - fn post_upgrade(_: Vec) -> Result<(), &'static str> { + fn post_upgrade(_: Vec) -> Result<(), sp_runtime::TryRuntimeError> { debug!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V8); diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs index d420af067..c7314a930 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs @@ -24,7 +24,7 @@ impl OnRuntimeUpgrade for CleanStorageState { } #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() == types::StorageVersion::V8 || PalletVersion::::get() == types::StorageVersion::V9); diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v10.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v10.rs index 7863413e3..f6953ca7d 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v10.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v10.rs @@ -11,7 +11,7 @@ pub struct FixFarmNodeIndexMap(PhantomData); impl OnRuntimeUpgrade for FixFarmNodeIndexMap { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V9Struct); @@ -35,7 +35,7 @@ impl OnRuntimeUpgrade for FixFarmNodeIndexMap { } #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_nodes_count: Vec) -> Result<(), &'static str> { + fn post_upgrade(pre_nodes_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V10Struct); diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v11.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v11.rs index 2d0848e7c..b86ad25ac 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v11.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v11.rs @@ -12,7 +12,7 @@ pub struct FixFarmingPolicy(PhantomData); impl OnRuntimeUpgrade for FixFarmingPolicy { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V10Struct); @@ -36,7 +36,7 @@ impl OnRuntimeUpgrade for FixFarmingPolicy { } #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_farms_count: Vec) -> Result<(), &'static str> { + fn post_upgrade(pre_farms_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V11Struct); diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v12.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v12.rs index cbf9abd29..29bbcff13 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v12.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v12.rs @@ -35,7 +35,7 @@ pub struct InputValidation(PhantomData); impl OnRuntimeUpgrade for InputValidation { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V11Struct); @@ -59,7 +59,7 @@ impl OnRuntimeUpgrade for InputValidation { } #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_nodes_count: Vec) -> Result<(), &'static str> { + fn post_upgrade(pre_nodes_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V12Struct); diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v13.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v13.rs index fe35d1fe9..a7c790b88 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v13.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v13.rs @@ -18,7 +18,7 @@ pub struct FixPublicIP(PhantomData); impl OnRuntimeUpgrade for FixPublicIP { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() <= types::StorageVersion::V12Struct); @@ -42,7 +42,7 @@ impl OnRuntimeUpgrade for FixPublicIP { } #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_nodes_count: Vec) -> Result<(), &'static str> { + fn post_upgrade(pre_nodes_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V13Struct); diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs index 3ab9d9a53..79bec6c75 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs @@ -12,7 +12,7 @@ pub struct FixFarmingPoliciesMap(PhantomData); impl OnRuntimeUpgrade for FixFarmingPoliciesMap { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V13Struct); @@ -36,7 +36,7 @@ impl OnRuntimeUpgrade for FixFarmingPoliciesMap { } #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_policies_count: Vec) -> Result<(), &'static str> { + fn post_upgrade(pre_policies_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V14Struct); diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs index 341523adf..e4417f31f 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs @@ -12,7 +12,7 @@ pub struct MigrateTwinsV15(PhantomData); impl OnRuntimeUpgrade for MigrateTwinsV15 { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V14Struct); @@ -36,7 +36,7 @@ impl OnRuntimeUpgrade for MigrateTwinsV15 { } #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_twins_count: Vec) -> Result<(), &'static str> { + fn post_upgrade(pre_twins_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V15Struct); diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs index 7b21c5e62..55543aeb3 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs @@ -14,7 +14,7 @@ pub struct FixFarmPublicIps(PhantomData); impl OnRuntimeUpgrade for FixFarmPublicIps { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V16Struct); @@ -38,7 +38,7 @@ impl OnRuntimeUpgrade for FixFarmPublicIps { } #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_farms_count: Vec) -> Result<(), &'static str> { + fn post_upgrade(pre_farms_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); assert!(PalletVersion::::get() >= types::StorageVersion::V17Struct); diff --git a/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs b/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs index bceb91343..74e87d3b4 100644 --- a/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs +++ b/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs @@ -10,7 +10,7 @@ pub struct MigrateBurnTransactionsV2(PhantomData); impl OnRuntimeUpgrade for MigrateBurnTransactionsV2 { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); if PalletVersion::::get() != types::StorageVersion::V1 { return Ok(Vec::::new()); @@ -44,12 +44,15 @@ impl OnRuntimeUpgrade for MigrateBurnTransactionsV2 { } #[cfg(feature = "try-runtime")] - fn post_upgrade(_pre_burn_transactions_count: Vec) -> Result<(), &'static str> { + fn post_upgrade( + _pre_burn_transactions_count: Vec, + ) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); if PalletVersion::::get() != types::StorageVersion::V2 { return Ok(()); } - let burn_transactions_count: u64 = migrations::types::v2::BurnTransactions::::iter().count() as u64; + let burn_transactions_count: u64 = + migrations::types::v2::BurnTransactions::::iter().count() as u64; info!( "🔎 MigrateBurnTransactionsV2 post migration: Number of existing burn transactions {:?}", burn_transactions_count @@ -71,11 +74,14 @@ pub fn migrate_burn_transactions() -> frame_support::weights::Weight let mut read_writes = 0; - migrations::types::v2::BurnTransactions::::translate::, _>( - |k, burn_transaction| { - debug!("migrated burn transaction: {:?}", k); + migrations::types::v2::BurnTransactions::::translate::< + super::types::v1::BurnTransaction, + _, + >(|k, burn_transaction| { + debug!("migrated burn transaction: {:?}", k); - let new_burn_transaction = migrations::types::v2::BurnTransaction:: { + let new_burn_transaction = + migrations::types::v2::BurnTransaction:: { block: burn_transaction.block, amount: burn_transaction.amount, source: None, @@ -84,29 +90,29 @@ pub fn migrate_burn_transactions() -> frame_support::weights::Weight sequence_number: burn_transaction.sequence_number, }; - read_writes += 1; - Some(new_burn_transaction) - }, - ); - - migrations::types::v2::ExecutedBurnTransactions::::translate::, _>( - |k, executed_burn_transaction| { - debug!("migrated executed burn transaction: {:?}", k); - - let new_executed_burn_transaction = - migrations::types::v2::BurnTransaction:: { - block: executed_burn_transaction.block, - amount: executed_burn_transaction.amount, - source: None, - target: executed_burn_transaction.target, - signatures: executed_burn_transaction.signatures, - sequence_number: executed_burn_transaction.sequence_number, - }; - - read_writes += 1; - Some(new_executed_burn_transaction) - }, - ); + read_writes += 1; + Some(new_burn_transaction) + }); + + migrations::types::v2::ExecutedBurnTransactions::::translate::< + super::types::v1::BurnTransaction, + _, + >(|k, executed_burn_transaction| { + debug!("migrated executed burn transaction: {:?}", k); + + let new_executed_burn_transaction = + migrations::types::v2::BurnTransaction:: { + block: executed_burn_transaction.block, + amount: executed_burn_transaction.amount, + source: None, + target: executed_burn_transaction.target, + signatures: executed_burn_transaction.signatures, + sequence_number: executed_burn_transaction.sequence_number, + }; + + read_writes += 1; + Some(new_executed_burn_transaction) + }); // Update pallet storage version PalletVersion::::set(types::StorageVersion::V2); diff --git a/substrate-node/runtime/src/migrations/tfgrid_v15_smart_contract_v8.rs b/substrate-node/runtime/src/migrations/tfgrid_v15_smart_contract_v8.rs index aa208cdcf..61098abf8 100644 --- a/substrate-node/runtime/src/migrations/tfgrid_v15_smart_contract_v8.rs +++ b/substrate-node/runtime/src/migrations/tfgrid_v15_smart_contract_v8.rs @@ -34,7 +34,7 @@ pub struct Migrate(PhantomData); impl OnRuntimeUpgrade for Migrate { #[cfg(feature = "try-runtime")] - fn pre_upgrade() -> Result, &'static str> { + fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!( "current pallet version: {:?}", pallet_tfgrid::PalletVersion::::get() @@ -92,7 +92,7 @@ impl OnRuntimeUpgrade for Migrate { } #[cfg(feature = "try-runtime")] - fn post_upgrade(pre_twins_count: Vec) -> Result<(), &'static str> { + fn post_upgrade(pre_twins_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!( "current pallet version: {:?}", pallet_tfgrid::PalletVersion::::get() From e238adb48aba111698c844afe7415af52b57a05a Mon Sep 17 00:00:00 2001 From: renauter Date: Sat, 25 Nov 2023 14:09:33 -0300 Subject: [PATCH 05/25] update integration tests --- substrate-node/tests/TfChainClient.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substrate-node/tests/TfChainClient.py b/substrate-node/tests/TfChainClient.py index 1b205ae2c..4b918c047 100644 --- a/substrate-node/tests/TfChainClient.py +++ b/substrate-node/tests/TfChainClient.py @@ -116,8 +116,8 @@ def propose_council_motion(self, substrate, who, call): for event in response.triggered_events: if event.value["event_id"] == "Proposed": - proposal_hash = event.value["event"]["attributes"]["proposal_hash"] - proposal_index = event.value["event"]["attributes"]["proposal_index"] + proposal_hash = event.value["event"]["attributes"][2] + proposal_index = event.value["event"]["attributes"][1] return proposal_hash, proposal_index From da6757516a237265a9a0c89041b0a674df702917 Mon Sep 17 00:00:00 2001 From: renauter Date: Sat, 25 Nov 2023 16:51:52 -0300 Subject: [PATCH 06/25] prefer returning TryRuntimeError in pre_upgrade() post_upgrade() --- .../src/migrations/v10.rs | 7 +++- .../src/migrations/v11.rs | 34 +++++++++++++------ .../src/migrations/v6.rs | 19 +++++++---- .../src/migrations/v8.rs | 12 +++++-- .../src/migrations/v9.rs | 8 ++++- .../pallet-tfgrid/src/migrations/v10.rs | 19 +++++++---- .../pallet-tfgrid/src/migrations/v11.rs | 19 +++++++---- .../pallet-tfgrid/src/migrations/v12.rs | 19 +++++++---- .../pallet-tfgrid/src/migrations/v13.rs | 19 +++++++---- .../pallet-tfgrid/src/migrations/v14.rs | 19 +++++++---- .../pallet-tfgrid/src/migrations/v15.rs | 19 +++++++---- .../pallet-tfgrid/src/migrations/v17.rs | 19 +++++++---- .../pallet-tft-bridge/src/migrations/v2.rs | 17 ++++++---- .../tfgrid_v15_smart_contract_v8.rs | 19 ++++++----- 14 files changed, 172 insertions(+), 77 deletions(-) diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs index c130c03e2..fa255505b 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v10.rs @@ -5,6 +5,8 @@ use sp_core::Get; use sp_runtime::Saturating; use sp_std::{marker::PhantomData, vec}; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use sp_std::vec::Vec; @@ -18,7 +20,10 @@ impl OnRuntimeUpgrade for ReworkBillingLoopInsertion { #[cfg(feature = "try-runtime")] fn post_upgrade(_: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V10); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V10, + DispatchError::Other("Unexpected pallet version") + ); super::v9::check_contracts_to_bill_at::(); diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs index 52a5840e3..3346a4e9d 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v11.rs @@ -8,6 +8,8 @@ use sp_core::Get; use sp_runtime::traits::Zero; use sp_std::marker::PhantomData; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use sp_std::{vec, vec::Vec}; @@ -25,7 +27,10 @@ impl OnRuntimeUpgrade for ExtendContractLock { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { debug!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V10); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V10, + DispatchError::Other("Unexpected pallet version") + ); debug!("👥 Smart Contract pallet to V11 passes PRE migrate checks ✅",); Ok(vec![]) @@ -43,16 +48,12 @@ impl OnRuntimeUpgrade for ExtendContractLock { #[cfg(feature = "try-runtime")] fn post_upgrade(_: Vec) -> Result<(), sp_runtime::TryRuntimeError> { debug!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V11); - - check_contract_lock_v11::(); - - debug!( - "👥 Smart Contract pallet to {:?} passes POST migrate checks ✅", - PalletVersion::::get() + ensure!( + PalletVersion::::get() >= types::StorageVersion::V11, + DispatchError::Other("Unexpected pallet version") ); - Ok(()) + check_contract_lock_v11::() } } @@ -86,7 +87,8 @@ pub fn migrate_to_version_11() -> frame_support::weights::Weight { T::DbWeight::get().reads_writes(r, w) } -pub fn check_contract_lock_v11() { +#[cfg(feature = "try-runtime")] +pub fn check_contract_lock_v11() -> Result<(), sp_runtime::TryRuntimeError> { debug!( "🔎 Smart Contract pallet {:?} checking ContractLock storage map START", PalletVersion::::get() @@ -112,7 +114,10 @@ pub fn check_contract_lock_v11() { ); } else { // Ensure new field is set to zero - assert_eq!(contract_lock.extra_amount_locked, BalanceOf::::zero()); + ensure!( + contract_lock.extra_amount_locked == BalanceOf::::zero(), + DispatchError::Other("Unexpected lock amount") + ); } } @@ -120,4 +125,11 @@ pub fn check_contract_lock_v11() { "🏁 Smart Contract pallet {:?} checking ContractLock storage map END", PalletVersion::::get() ); + + debug!( + "👥 Smart Contract pallet to {:?} passes POST migrate checks ✅", + PalletVersion::::get() + ); + + Ok(()) } diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v6.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v6.rs index 70e3702a6..34010b446 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v6.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v6.rs @@ -4,6 +4,8 @@ use log::{debug, info}; use sp_core::Get; use sp_std::{marker::PhantomData, vec::Vec}; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use parity_scale_codec::{Decode, Encode}; @@ -13,7 +15,10 @@ impl OnRuntimeUpgrade for ContractMigrationV5 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V5); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V5, + DispatchError::Other("Unexpected pallet version") + ); let contracts_count: u64 = ContractsToBillAt::::iter().count() as u64; log::info!( @@ -32,15 +37,17 @@ impl OnRuntimeUpgrade for ContractMigrationV5 { #[cfg(feature = "try-runtime")] fn post_upgrade(pre_contracts_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V6); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V6, + DispatchError::Other("Unexpected pallet version") + ); // Check number of Contracts against pre-check result let pre_contracts_count: u64 = Decode::decode(&mut pre_contracts_count.as_slice()) .expect("the state parameter should be something that was generated by pre_upgrade"); - assert_eq!( - ContractsToBillAt::::iter().count() as u64, - pre_contracts_count, - "Number of Contracts migrated does not match" + ensure!( + ContractsToBillAt::::iter().count() as u64 == pre_contracts_count, + DispatchError::Other("Number of Contracts migrated does not match") ); info!( diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v8.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v8.rs index ccdcf8912..4fcb53bf3 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v8.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v8.rs @@ -8,6 +8,8 @@ use sp_core::Get; use sp_runtime::traits::{CheckedSub, SaturatedConversion}; use sp_std::{collections::btree_map::BTreeMap, marker::PhantomData}; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use sp_std::{vec, vec::Vec}; @@ -17,7 +19,10 @@ impl OnRuntimeUpgrade for FixTwinLockedBalances { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { debug!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V6); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V6, + DispatchError::Other("Unexpected pallet version") + ); debug!("👥 Smart Contract pallet to V8 passes PRE migrate checks ✅",); Ok(vec![]) @@ -35,7 +40,10 @@ impl OnRuntimeUpgrade for FixTwinLockedBalances { #[cfg(feature = "try-runtime")] fn post_upgrade(_: Vec) -> Result<(), sp_runtime::TryRuntimeError> { debug!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V8); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V8, + DispatchError::Other("Unexpected pallet version") + ); debug!( "👥 Smart Contract pallet to {:?} passes POST migrate checks ✅", diff --git a/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs b/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs index c7314a930..abc3ca0eb 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/migrations/v9.rs @@ -6,6 +6,9 @@ use scale_info::prelude::string::String; use sp_core::Get; use sp_std::{marker::PhantomData, vec, vec::Vec}; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; + pub struct CleanStorageState(PhantomData); impl OnRuntimeUpgrade for CleanStorageState { @@ -26,7 +29,10 @@ impl OnRuntimeUpgrade for CleanStorageState { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() == types::StorageVersion::V8 || PalletVersion::::get() == types::StorageVersion::V9); + ensure!( + PalletVersion::::get() == types::StorageVersion::V8 || PalletVersion::::get() == types::StorageVersion::V9, + DispatchError::Other("Unexpected pallet version") + ); check_pallet_smart_contract::(); diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v10.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v10.rs index f6953ca7d..8e772f748 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v10.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v10.rs @@ -4,6 +4,8 @@ use log::{debug, info}; use sp_std::{collections::btree_map::BTreeMap, marker::PhantomData}; use sp_std::{vec, vec::Vec}; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use parity_scale_codec::{Decode, Encode}; @@ -13,7 +15,10 @@ impl OnRuntimeUpgrade for FixFarmNodeIndexMap { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V9Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V9Struct, + DispatchError::Other("Unexpected pallet version") + ); let nodes_count: u64 = Nodes::::iter().count() as u64; log::info!( @@ -37,15 +42,17 @@ impl OnRuntimeUpgrade for FixFarmNodeIndexMap { #[cfg(feature = "try-runtime")] fn post_upgrade(pre_nodes_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V10Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V10Struct, + DispatchError::Other("Unexpected pallet version") + ); // Check number of nodes against pre-check result let pre_nodes_count: u64 = Decode::decode(&mut pre_nodes_count.as_slice()) .expect("the state parameter should be something that was generated by pre_upgrade"); - assert_eq!( - Nodes::::iter().count() as u64, - pre_nodes_count, - "Number of nodes migrated does not match" + ensure!( + Nodes::::iter().count() as u64 == pre_nodes_count, + DispatchError::Other("Number of nodes migrated does not match") ); info!( diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v11.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v11.rs index b86ad25ac..a6bb51408 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v11.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v11.rs @@ -3,6 +3,8 @@ use frame_support::{traits::Get, traits::OnRuntimeUpgrade, weights::Weight}; use log::{debug, info}; use sp_std::marker::PhantomData; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use parity_scale_codec::{Decode, Encode}; #[cfg(feature = "try-runtime")] @@ -14,7 +16,10 @@ impl OnRuntimeUpgrade for FixFarmingPolicy { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V10Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V10Struct, + DispatchError::Other("Unexpected pallet version") + ); let farms_count: u64 = Farms::::iter().count() as u64; log::info!( @@ -38,15 +43,17 @@ impl OnRuntimeUpgrade for FixFarmingPolicy { #[cfg(feature = "try-runtime")] fn post_upgrade(pre_farms_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V11Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V11Struct, + DispatchError::Other("Unexpected pallet version") + ); // Check number of farms against pre-check result let pre_farms_count: u64 = Decode::decode(&mut pre_farms_count.as_slice()) .expect("the state parameter should be something that was generated by pre_upgrade"); - assert_eq!( - Farms::::iter().count() as u64, - pre_farms_count, - "Number of farms migrated does not match" + ensure!( + Farms::::iter().count() as u64 == pre_farms_count, + DispatchError::Other("Number of farms migrated does not match") ); info!( diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v12.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v12.rs index 29bbcff13..be66a58ae 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v12.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v12.rs @@ -6,6 +6,8 @@ use frame_support::{ use log::{debug, info}; use sp_std::marker::PhantomData; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use parity_scale_codec::{Decode, Encode}; #[cfg(feature = "try-runtime")] @@ -37,7 +39,10 @@ impl OnRuntimeUpgrade for InputValidation { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V11Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V11Struct, + DispatchError::Other("Unexpected pallet version") + ); let nodes_count: u64 = Nodes::::iter().count() as u64; log::info!( @@ -61,15 +66,17 @@ impl OnRuntimeUpgrade for InputValidation { #[cfg(feature = "try-runtime")] fn post_upgrade(pre_nodes_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V12Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V12Struct, + DispatchError::Other("Unexpected pallet version") + ); // Check number of nodes against pre-check result let pre_nodes_count: u64 = Decode::decode(&mut pre_nodes_count.as_slice()) .expect("the state parameter should be something that was generated by pre_upgrade"); - assert_eq!( - Nodes::::iter().count() as u64, - pre_nodes_count, - "Number of nodes migrated does not match" + ensure!( + Nodes::::iter().count() as u64 == pre_nodes_count, + DispatchError::Other("Number of nodes migrated does not match") ); info!( diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v13.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v13.rs index a7c790b88..8b70e9588 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v13.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v13.rs @@ -9,6 +9,8 @@ use tfchain_support::{ types::{Farm, Node, PublicIP, IP4}, }; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use parity_scale_codec::{Decode, Encode}; #[cfg(feature = "try-runtime")] @@ -20,7 +22,10 @@ impl OnRuntimeUpgrade for FixPublicIP { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() <= types::StorageVersion::V12Struct); + ensure!( + PalletVersion::::get() <= types::StorageVersion::V12Struct, + DispatchError::Other("Unexpected pallet version") + ); let nodes_count: u64 = Nodes::::iter().count() as u64; log::info!( @@ -44,15 +49,17 @@ impl OnRuntimeUpgrade for FixPublicIP { #[cfg(feature = "try-runtime")] fn post_upgrade(pre_nodes_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V13Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V13Struct, + DispatchError::Other("Unexpected pallet version") + ); // Check number of nodes against pre-check result let pre_nodes_count: u64 = Decode::decode(&mut pre_nodes_count.as_slice()) .expect("the state parameter should be something that was generated by pre_upgrade"); - assert_eq!( - Nodes::::iter().count() as u64, - pre_nodes_count, - "Number of nodes migrated does not match" + ensure!( + Nodes::::iter().count() as u64 == pre_nodes_count, + DispatchError::Other("Number of nodes migrated does not match") ); info!( diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs index 79bec6c75..967c9ce73 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs @@ -3,6 +3,8 @@ use frame_support::{traits::Get, traits::OnRuntimeUpgrade, weights::Weight}; use log::{debug, info}; use sp_std::marker::PhantomData; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use parity_scale_codec::{Decode, Encode}; #[cfg(feature = "try-runtime")] @@ -14,7 +16,10 @@ impl OnRuntimeUpgrade for FixFarmingPoliciesMap { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V13Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V13Struct, + DispatchError::Other("Unexpected pallet version") + ); let policies_count: u64 = FarmingPoliciesMap::::iter().count() as u64; info!( @@ -38,15 +43,17 @@ impl OnRuntimeUpgrade for FixFarmingPoliciesMap { #[cfg(feature = "try-runtime")] fn post_upgrade(pre_policies_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V14Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V14Struct, + DispatchError::Other("Unexpected pallet version") + ); // Check number of farming policies against pre-check result let pre_policies_count: u64 = Decode::decode(&mut pre_policies_count.as_slice()) .expect("the state parameter should be something that was generated by pre_upgrade"); - assert_eq!( - FarmingPoliciesMap::::iter().count() as u64, - pre_policies_count, - "Number of farming policies migrated does not match" + ensure!( + FarmingPoliciesMap::::iter().count() as u64 == pre_policies_count, + DispatchError::Other("Number of farming policies migrated does not match") ); info!( diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs index e4417f31f..637160796 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v15.rs @@ -3,6 +3,8 @@ use frame_support::{traits::Get, traits::OnRuntimeUpgrade, weights::Weight}; use log::{debug, info}; use sp_std::marker::PhantomData; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use parity_scale_codec::Decode; #[cfg(feature = "try-runtime")] @@ -14,7 +16,10 @@ impl OnRuntimeUpgrade for MigrateTwinsV15 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V14Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V14Struct, + DispatchError::Other("Unexpected pallet version") + ); let twins_count: u64 = Twins::::iter().count() as u64; log::info!( @@ -38,15 +43,17 @@ impl OnRuntimeUpgrade for MigrateTwinsV15 { #[cfg(feature = "try-runtime")] fn post_upgrade(pre_twins_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V15Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V15Struct, + DispatchError::Other("Unexpected pallet version") + ); // Check number of twins against pre-check result let pre_twins_count: u64 = Decode::decode(&mut pre_twins_count.as_slice()) .expect("the state parameter should be something that was generated by pre_upgrade"); - assert_eq!( - Twins::::iter().count() as u64, - pre_twins_count, - "Number of twins migrated does not match" + ensure!( + Twins::::iter().count() as u64 == pre_twins_count, + DispatchError::Other("Number of twins migrated does not match") ); info!( diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs index 55543aeb3..3e95841c8 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v17.rs @@ -7,6 +7,8 @@ use sp_runtime::{BoundedVec, Saturating}; use sp_std::{marker::PhantomData, vec::Vec}; use tfchain_support::types::{PublicIP, IP4}; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use parity_scale_codec::{Decode, Encode}; @@ -16,7 +18,10 @@ impl OnRuntimeUpgrade for FixFarmPublicIps { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V16Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V16Struct, + DispatchError::Other("Unexpected pallet version") + ); let farms_count: u64 = Farms::::iter().count() as u64; info!( @@ -40,15 +45,17 @@ impl OnRuntimeUpgrade for FixFarmPublicIps { #[cfg(feature = "try-runtime")] fn post_upgrade(pre_farms_count: Vec) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - assert!(PalletVersion::::get() >= types::StorageVersion::V17Struct); + ensure!( + PalletVersion::::get() >= types::StorageVersion::V17Struct, + DispatchError::Other("Unexpected pallet version") + ); // Check number of farms against pre-check result let pre_farms_count: u64 = Decode::decode(&mut pre_farms_count.as_slice()) .expect("the state parameter should be something that was generated by pre_upgrade"); - assert_eq!( - Farms::::iter().count() as u64, - pre_farms_count, - "Number of farms migrated does not match" + ensure!( + Farms::::iter().count() as u64 == pre_farms_count, + DispatchError::Other("Number of farms migrated does not match") ); info!( diff --git a/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs b/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs index 74e87d3b4..53075edd9 100644 --- a/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs +++ b/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs @@ -3,6 +3,8 @@ use frame_support::log::{debug, info}; use frame_support::{traits::Get, traits::OnRuntimeUpgrade, weights::Weight}; use sp_std::marker::PhantomData; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use sp_std::vec::Vec; @@ -12,9 +14,10 @@ impl OnRuntimeUpgrade for MigrateBurnTransactionsV2 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - if PalletVersion::::get() != types::StorageVersion::V1 { - return Ok(Vec::::new()); - }; + ensure!( + PalletVersion::::get() == types::StorageVersion::V1, + DispatchError::Other("Unexpected pallet version") + ); let burn_transactions_count: u64 = migrations::types::v1::BurnTransactions::::iter().count() as u64; @@ -48,9 +51,11 @@ impl OnRuntimeUpgrade for MigrateBurnTransactionsV2 { _pre_burn_transactions_count: Vec, ) -> Result<(), sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - if PalletVersion::::get() != types::StorageVersion::V2 { - return Ok(()); - } + ensure!( + PalletVersion::::get() == types::StorageVersion::V2, + DispatchError::Other("Unexpected pallet version") + ); + let burn_transactions_count: u64 = migrations::types::v2::BurnTransactions::::iter().count() as u64; info!( diff --git a/substrate-node/runtime/src/migrations/tfgrid_v15_smart_contract_v8.rs b/substrate-node/runtime/src/migrations/tfgrid_v15_smart_contract_v8.rs index 61098abf8..df07f5f5a 100644 --- a/substrate-node/runtime/src/migrations/tfgrid_v15_smart_contract_v8.rs +++ b/substrate-node/runtime/src/migrations/tfgrid_v15_smart_contract_v8.rs @@ -15,6 +15,8 @@ use frame_support::{ use log::{debug, info}; use sp_std::{collections::btree_map::BTreeMap, marker::PhantomData}; +#[cfg(feature = "try-runtime")] +use frame_support::{dispatch::DispatchError, ensure}; #[cfg(feature = "try-runtime")] use parity_scale_codec::Decode; #[cfg(feature = "try-runtime")] @@ -39,9 +41,10 @@ impl OnRuntimeUpgrade for Migrate { "current pallet version: {:?}", pallet_tfgrid::PalletVersion::::get() ); - assert!( + ensure!( pallet_tfgrid::PalletVersion::::get() - >= pallet_tfgrid::types::StorageVersion::V14Struct + >= pallet_tfgrid::types::StorageVersion::V14Struct, + DispatchError::Other("Unexpected pallet version") ); let twins_count: u64 = pallet_tfgrid::Twins::::iter().count() as u64; @@ -97,18 +100,18 @@ impl OnRuntimeUpgrade for Migrate { "current pallet version: {:?}", pallet_tfgrid::PalletVersion::::get() ); - assert!( + ensure!( pallet_tfgrid::PalletVersion::::get() - >= pallet_tfgrid::types::StorageVersion::V15Struct + >= pallet_tfgrid::types::StorageVersion::V15Struct, + DispatchError::Other("Unexpected pallet version") ); // Check number of twins against pre-check result let pre_twins_count: u64 = Decode::decode(&mut pre_twins_count.as_slice()) .expect("the state parameter should be something that was generated by pre_upgrade"); - assert_eq!( - pallet_tfgrid::Twins::::iter().count() as u64, - pre_twins_count, - "Number of twins migrated does not match" + ensure!( + pallet_tfgrid::Twins::::iter().count() as u64 == pre_twins_count, + DispatchError::Other("Number of twins migrated does not match") ); info!( From d4dd71f3ad12a303c7329edffbe6f1d95babb2c3 Mon Sep 17 00:00:00 2001 From: renauter Date: Sat, 25 Nov 2023 23:16:42 -0300 Subject: [PATCH 07/25] fix outdated CLI options --- substrate-node/tests/SubstrateNetwork.py | 28 ++++++++++-------------- substrate-node/tests/TfChainClient.py | 4 ++-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/substrate-node/tests/SubstrateNetwork.py b/substrate-node/tests/SubstrateNetwork.py index 1daaf828d..80da5d14a 100644 --- a/substrate-node/tests/SubstrateNetwork.py +++ b/substrate-node/tests/SubstrateNetwork.py @@ -15,7 +15,7 @@ SUBSTRATE_NODE_DIR = dirname(os.getcwd()) TFCHAIN_EXE = join(SUBSTRATE_NODE_DIR, "target", "release", "tfchain") -RE_NODE_STARTED = re.compile("Running JSON-RPC WS server") +RE_NODE_STARTED = re.compile("Running JSON-RPC server") RE_FIRST_BLOCK = re.compile("Prepared block for proposing at") TIMEOUT_STARTUP_IN_SECONDS = 600 @@ -78,7 +78,7 @@ def execute_command(cmd: list, log_file: str | None = None): return p, fd -def run_node(log_file: str, base_path: str, predefined_account: str, port: int, ws_port: int, rpc_port: int, node_key: str | None = None, bootnodes: str | None = None): +def run_node(log_file: str, base_path: str, predefined_account: str, port: int, rpc_port: int, node_key: str | None = None, bootnodes: str | None = None): logging.info("Starting node with logfile %s", log_file) if not isfile(TFCHAIN_EXE): @@ -90,9 +90,8 @@ def run_node(log_file: str, base_path: str, predefined_account: str, port: int, "--chain", "local", f"--{predefined_account.lower()}", "--port", f"{port}", - "--ws-port", f"{ws_port}", "--rpc-port", f"{rpc_port}", - "--telemetry-url", "wss://telemetry.polkadot.io/submit/ 0", + "--no-telemetry", "--validator", "--rpc-methods", "Unsafe", "--rpc-cors", "all" @@ -108,7 +107,7 @@ def run_node(log_file: str, base_path: str, predefined_account: str, port: int, return execute_command(cmd, log_file) -def run_single_node(log_file: str, base_path: str, port: int, ws_port: int, rpc_port: int, node_key: str | None = None, bootnodes: str | None = None): +def run_single_node(log_file: str, base_path: str, port: int, rpc_port: int, node_key: str | None = None, bootnodes: str | None = None): logging.info("Starting node with logfile %s", log_file) if not isfile(TFCHAIN_EXE): @@ -117,10 +116,9 @@ def run_single_node(log_file: str, base_path: str, port: int, ws_port: int, rpc_ cmd = [TFCHAIN_EXE, "--dev", - "--ws-external", + "--rpc-external", "--base-path", f"{base_path}", "--port", f"{port}", - "--ws-port", f"{ws_port}", "--rpc-port", f"{rpc_port}", "--validator", "--rpc-methods", "Unsafe", @@ -153,34 +151,32 @@ def setup_multi_node_network(self, log_name: str = "", amt: int = 1): rmtree(output_dir_network, ignore_errors=True) port = 30333 - ws_port = 9944 - rpc_port = 9933 + rpc_port = 9944 if amt == 1: log_file_alice = join(output_dir_network, "node_alice.log") - self._nodes["alice"] = run_single_node(log_file_alice, "/tmp/alice", port, ws_port, rpc_port) + self._nodes["alice"] = run_single_node(log_file_alice, "/tmp/alice", port, rpc_port) wait_till_node_ready(log_file_alice) - setup_offchain_workers(ws_port, "Alice") + setup_offchain_workers(rpc_port, "Alice") wait_till_first_block(log_file_alice) else: log_file_alice = join(output_dir_network, "node_alice.log") - self._nodes["alice"] = run_node(log_file_alice, "/tmp/alice", "alice", port, ws_port, + self._nodes["alice"] = run_node(log_file_alice, "/tmp/alice", "alice", port, rpc_port, node_key="0000000000000000000000000000000000000000000000000000000000000001") wait_till_node_ready(log_file_alice) - setup_offchain_workers(ws_port, "Alice") + setup_offchain_workers(rpc_port, "Alice") log_file = "" for x in range(1, amt): port += 1 - ws_port += 1 rpc_port += 1 name = list(PREDEFINED_KEYS.keys())[x].lower() log_file = join(output_dir_network, f"node_{name}.log") - self._nodes[name] = run_node(log_file, f"/tmp/{name}", name, port, ws_port, rpc_port, node_key=None, + self._nodes[name] = run_node(log_file, f"/tmp/{name}", name, port, rpc_port, node_key=None, bootnodes="/ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp") wait_till_node_ready(log_file) - setup_offchain_workers(ws_port, "Bob") + setup_offchain_workers(rpc_port, "Bob") wait_till_first_block(log_file_alice) diff --git a/substrate-node/tests/TfChainClient.py b/substrate-node/tests/TfChainClient.py index 4b918c047..1b205ae2c 100644 --- a/substrate-node/tests/TfChainClient.py +++ b/substrate-node/tests/TfChainClient.py @@ -116,8 +116,8 @@ def propose_council_motion(self, substrate, who, call): for event in response.triggered_events: if event.value["event_id"] == "Proposed": - proposal_hash = event.value["event"]["attributes"][2] - proposal_index = event.value["event"]["attributes"][1] + proposal_hash = event.value["event"]["attributes"]["proposal_hash"] + proposal_index = event.value["event"]["attributes"]["proposal_index"] return proposal_hash, proposal_index From dd1dc755e0c70dd83ff97b953310570b84817b36 Mon Sep 17 00:00:00 2001 From: renauter Date: Sat, 25 Nov 2023 23:17:36 -0300 Subject: [PATCH 08/25] fix outdated CLI options (continuation) --- clients/tfchain-client-go/readme.md | 101 +++++++++--------- docs/development/README.md | 26 ++--- docs/development/fork-off-substrate.md | 28 ++--- docs/development/local_multinode.md | 35 +++--- docs/misc/creating_validator.md | 78 +++++++------- .../.devcontainer/devcontainer.json | 21 ++-- .../substrate-node/templates/deployment.yaml | 14 +-- .../substrate-node/templates/service.yaml | 4 - .../charts/substrate-node/values.yaml | 6 +- 9 files changed, 153 insertions(+), 160 deletions(-) diff --git a/clients/tfchain-client-go/readme.md b/clients/tfchain-client-go/readme.md index b449ae9bc..190c55ef4 100644 --- a/clients/tfchain-client-go/readme.md +++ b/clients/tfchain-client-go/readme.md @@ -2,83 +2,84 @@ # **TFchain go client** -- This library is a go implementation of a client for the TFChain. -- Internally, our own [fork](https://github.com/threefoldtech/go-substrate-rpc-client) of is used to make substrate rpc calls. -- Used in multiple repos like [zos](https://github.com/threefoldtech/zos), [rmb-go](https://github.com/threefoldtech/rmb_go), and [terraform-provider-grid](https://github.com/threefoldtech/terraform-provider-grid). +* This library is a go implementation of a client for the TFChain. +* Internally, our own [fork](https://github.com/threefoldtech/go-substrate-rpc-client) of is used to make substrate rpc calls. +* Used in multiple repos like [zos](https://github.com/threefoldtech/zos), [rmb-go](https://github.com/threefoldtech/rmb_go), and [terraform-provider-grid](https://github.com/threefoldtech/terraform-provider-grid). ## **Usage** To make substrate calls: -- First, start a substrate connection against the desired url for the chain: +* First, start a substrate connection against the desired url for the chain: - ```go - manager := NewManager("wss://tfchain.grid.tf/ws") - substrateConnection, err := manager.Substrate() - ``` + ```go + manager := NewManager("wss://tfchain.grid.tf/ws") + substrateConnection, err := manager.Substrate() + ``` + +* These are the urls for different chain networks: -- These are the urls for different chain networks: - - - devnet: - - testnet: - - qanet: - - mainnet: + * devnet: + * testnet: + * qanet: + * mainnet: -- It is the user's responsibility to close the connection. +* It is the user's responsibility to close the connection. - ```go - defer substrateConnection.Close() - ``` + ```go + defer substrateConnection.Close() + ``` -- Then, a user could use the provided api calls to communicate with the chain. like: +* Then, a user could use the provided api calls to communicate with the chain. like: - ```go - contractID, err := substrateConnection.CreateNodeContract(identity, nodeID, body, hash, publicIPsCount, solutionProviderID) - ``` + ```go + contractID, err := substrateConnection.CreateNodeContract(identity, nodeID, body, hash, publicIPsCount, solutionProviderID) + ``` -- Also, if a connection is closed for some reason like timing out, internally, it is reopened if nothing blocks. -- All provided api calls are found under the Substrate struct. +* Also, if a connection is closed for some reason like timing out, internally, it is reopened if nothing blocks. + +* All provided api calls are found under the Substrate struct. ## **Run tests** - To run the tests, you could either run it against a local docker image of the TFChain, or against devnet +To run the tests, you could either run it against a local docker image of the TFChain, or against devnet -- ### **Run against local docker image** +* ### **Run against local docker image** - To run tests against a local docker image of tfchain, you need to set CI environment variable to anything actually. + To run tests against a local docker image of tfchain, you need to set CI environment variable to anything actually. - ```bash - docker run -d -p 9944:9944 threefolddev/tfchain:2.2.0-rc8 --dev --ws-external - sleep 3 - export CI="true" - go test . -v - ``` + ```bash + docker run -d -p 9944:9944 threefolddev/tfchain:2.2.0-rc8 --dev --rpc-external + sleep 3 + export CI="true" + go test . -v + ``` -- ### **Run against devnet** +* ### **Run against devnet** - ```bash - unset CI - go test . -v - ``` + ```bash + unset CI + go test . -v + ``` ### **Test Coverage** -- 30.6% of statements +* 30.6% of statements ## **Workflows** -- ### **Test** - - - This workflow runs all tests found in the root directory against a local docker image of the [TFChain](https://github.com/threefoldtech/tfchain) found [here](https://hub.docker.com/r/threefolddev/tfchain). +* ### **Test** -- ### **Lint** + * This workflow runs all tests found in the root directory against a local docker image of the [TFChain](https://github.com/threefoldtech/tfchain) found [here](https://hub.docker.com/r/threefolddev/tfchain). - - This workflow ensures linting, so make sure to run these commands without any errors before pushing code: +* ### **Lint** - ```bash - golangci-lint run - ``` + * This workflow ensures linting, so make sure to run these commands without any errors before pushing code: - ```bash - gofmt -d -l . - ``` + ```bash + golangci-lint run + ``` + + ```bash + gofmt -d -l . + ``` diff --git a/docs/development/README.md b/docs/development/README.md index aa721798b..1883d6db1 100644 --- a/docs/development/README.md +++ b/docs/development/README.md @@ -26,14 +26,16 @@ cargo build ``` ## Run a dev node + A dev node is a single-node network that runs on your local machine. It is useful for testing and debugging purposes. To run a dev node, you need to do the following: ```sh cd tfchain/substrate-node cargo build -./target/debug/tfchain --dev --ws-external --pruning archive +./target/debug/tfchain --dev --rpc-external --pruning archive ``` + This will run the node in default development mode. This flag sets `--chain=dev`, `--force-authoring`, `--rpc-cors=all`, `--alice`, and `--tmp` flags, unless explicitly overridden. ## Run multiple local nodes @@ -45,11 +47,12 @@ If you want to run tfchain in a multi node network (more than one node), see [lo You can use the Polkadot JS Apps ui to connect to your dev node. You can access the web interface at https://polkadot.js.org/apps/ and change the settings to use a local node with the address `ws://127.0.0.1:9944`. This will allow you to interact with your dev node and perform basic operations. -- Use the Polkadot JS Apps to interact with your nodes. You can access the web interface at https://polkadot.js.org/apps/ and change the settings to use a local node or a remote node with the appropriate address. -- Use the `Accounts` tab to manage your accounts and balances. You can create new accounts, import existing accounts, transfer tokens, and view your transaction history. -- Use the `Explorer` tab to view the network status and activity. You can see the latest blocks, events, validators, and peers. -- Use the `Chain State` tab to query the state of the network. You can select a module and a storage item and see its value at any given block. -- Use the `Extrinsics` tab to submit extrinsics to the network. You can select an account, a module, and a function and provide any required parameters. + +* Use the Polkadot JS Apps to interact with your nodes. You can access the web interface at https://polkadot.js.org/apps/ and change the settings to use a local node or a remote node with the appropriate address. +* Use the `Accounts` tab to manage your accounts and balances. You can create new accounts, import existing accounts, transfer tokens, and view your transaction history. +* Use the `Explorer` tab to view the network status and activity. You can see the latest blocks, events, validators, and peers. +* Use the `Chain State` tab to query the state of the network. You can select a module and a storage item and see its value at any given block. +* Use the `Extrinsics` tab to submit extrinsics to the network. You can select an account, a module, and a function and provide any required parameters. ## Create an account @@ -79,19 +82,18 @@ A pallet is a modular component that defines some logic and functionality for th To learn about pallet development, you can start by checking these resources: -- Get start by reading The substrate [Build application logic tutorials](https://docs.substrate.io/tutorials/build-application-logic/). these tutorials focus on how you can customize the runtime using pallets, creating a custom pallet using macros, adding it to the runtime, and testing its functionality. - -- Check the [the Substrate collectibles workshop](https://docs.substrate.io/tutorials/collectibles-workshop/runtime-and-pallets/). This is an interactive, hands-on, and self-paced workshop that introduces the basic steps for building a blockchain-based application using Substrate. +* Get start by reading The substrate [Build application logic tutorials](https://docs.substrate.io/tutorials/build-application-logic/). these tutorials focus on how you can customize the runtime using pallets, creating a custom pallet using macros, adding it to the runtime, and testing its functionality. -- Explore other existing pallets on the [Substrate GitHub repository](https://github.com/paritytech/substrate/tree/master/frame) and learn from their code. You can see how different pallets implement different features and patterns, such as storage, events, errors, hooks, traits, weights, origins, calls, etc. +* Check the [the Substrate collectibles workshop](https://docs.substrate.io/tutorials/collectibles-workshop/runtime-and-pallets/). This is an interactive, hands-on, and self-paced workshop that introduces the basic steps for building a blockchain-based application using Substrate. +* Explore other existing pallets on the [Substrate GitHub repository](https://github.com/paritytech/substrate/tree/master/frame) and learn from their code. You can see how different pallets implement different features and patterns, such as storage, events, errors, hooks, traits, weights, origins, calls, etc. ## Writing tests for pallets Every pallet should have all functionality tested, you can write unit tests and integration tests for a pallet: -- Unit tests: check this [guide](https://docs.substrate.io/reference/how-to-guides/testing/) -- Integration tests: see this [document](../../substrate-node/tests/readme.md) +* Unit tests: check this [guide](https://docs.substrate.io/reference/how-to-guides/testing/) +* Integration tests: see this [document](../../substrate-node/tests/readme.md) ## Upgrading Substrate version diff --git a/docs/development/fork-off-substrate.md b/docs/development/fork-off-substrate.md index 382942c95..3937fbee8 100644 --- a/docs/development/fork-off-substrate.md +++ b/docs/development/fork-off-substrate.md @@ -5,51 +5,53 @@ The fork-off-substrate tool is a handy tool that allows you to download and run In this guide, we will show you how to use the tool to create a local fork of the TFchain network. ### Prerequisites + Before you start, you need to have the following items: -- The executable binary and the runtime WASM blob of the target blockchain. You can either compile them from the source code of the blockchain project, or copy them from a trusted node that runs the blockchain. For TFchain, you can find the source code [here](https://github.com/threefoldtech/tfchain) and the instructions on how to compile it [here](https://github.com/threefoldtech/tfchain/tree/development/docs/development). Find the Wasm binary file in the target directory. The file name should be `tfchain_runtime.compact.wasm` and the file path should be something like this: +* The executable binary and the runtime WASM blob of the target blockchain. You can either compile them from the source code of the blockchain project, or copy them from a trusted node that runs the blockchain. For TFchain, you can find the source code [here](https://github.com/threefoldtech/tfchain) and the instructions on how to compile it [here](https://github.com/threefoldtech/tfchain/tree/development/docs/development). Find the Wasm binary file in the target directory. The file name should be `tfchain_runtime.compact.wasm` and the file path should be something like this: ```bash ./substrate-node/target/debug/wbuild/tfchain-runtime/tfchain_runtime.compact.wasm ``` ### Steps -- Install the `fork-off-substrate` tool dependencies on your computer, go to `tfchain` directory then follow these steps: + +* Install the `fork-off-substrate` tool dependencies on your computer, go to `tfchain` directory then follow these steps: ```bash cd ./tools/fork-off-substrate npm i ``` -- Create a folder called data inside the top folder (fork-off-substrate). +* Create a folder called data inside the top folder (fork-off-substrate). ```bash mkdir data ``` -- Copy the executable/binary of your substrate based node inside the data folder and rename it to `binary` +* Copy the executable/binary of your substrate based node inside the data folder and rename it to `binary` ```bash cp ../../substrate-node/target/debug/tfchain ./data/binary ``` -- Copy the runtime WASM blob of your substrate based blockchain to the data folder and rename it to `runtime.wasm`. +* Copy the runtime WASM blob of your substrate based blockchain to the data folder and rename it to `runtime.wasm`. ```bash cp ../../substrate-node/target/debug/wbuild/tfchain-runtime/tfchain_runtime.compact.wasm ./data/runtime.wasm ``` -- Run a full node for your blockchain locally (Recommended but should be fully synced) or have an external endpoint handy (but should be running with `--rpc-methods Unsafe` flag) +* Run a full node for your blockchain locally (Recommended but should be fully synced) or have an external endpoint handy (but should be running with `--rpc-methods Unsafe` flag) ```bash - ../../substrate-node/target/debug/tfchain --chain ../../substrate-node/chainspecs/dev/chainSpecRaw.json --ws-external --rpc-methods Unsafe + ../../substrate-node/target/debug/tfchain --chain ../../substrate-node/chainspecs/dev/chainSpecRaw.json --rpc-external --rpc-methods Unsafe ``` -- Run the script +* Run the script - - If using a local node, simply run the script using + * If using a local node, simply run the script using ```bash npm start ``` - - If you are using an external/non-default endpoint, you need to provide it to the script via the HTTP_RPC_ENDPOINT environment variable + * If you are using an external/non-default endpoint, you need to provide it to the script via the HTTP\_RPC\_ENDPOINT environment variable ```bash HTTP_RPC_ENDPOINT=https:// npm start ``` -- You should have the genesis file for the forked chain inside the data folder. It will be called `fork.json`. -- You can now run a new chain using this genesis file +* You should have the genesis file for the forked chain inside the data folder. It will be called `fork.json`. +* You can now run a new chain using this genesis file ```bash ./data/binary --chain ./data/fork.json --alice ``` -for more information about this tool, you can read this [blog post](https://mudit.blog/fork-substrate-blockchain/). \ No newline at end of file +for more information about this tool, you can read this [blog post](https://mudit.blog/fork-substrate-blockchain/). diff --git a/docs/development/local_multinode.md b/docs/development/local_multinode.md index 43f2eb528..82cd5b21e 100644 --- a/docs/development/local_multinode.md +++ b/docs/development/local_multinode.md @@ -9,7 +9,8 @@ cd substrate-node cargo build ``` -you can +you can + ## Start the network In a terminal window execute the following command: @@ -20,8 +21,7 @@ In a terminal window execute the following command: --chain local \ --alice \ --port 30333 \ - --ws-port 9945 \ - --rpc-port 9933 \ + --rpc-port 9945 \ --node-key 0000000000000000000000000000000000000000000000000000000000000001 \ --validator ``` @@ -36,8 +36,7 @@ In a second terminal window executing the following command: --chain local \ --bob \ --port 30334 \ - --ws-port 9946 \ - --rpc-port 9934 \ + --rpc-port 9946 \ --telemetry-url "wss://telemetry.polkadot.io/submit/ 0" \ --validator \ --bootnodes /ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp @@ -73,25 +72,23 @@ Verify that you see lines similar to the following in the terminal where you sta In these lines, you can see the following information about your blockchain: -- The second node identity was discovered on the network (12D3KooWBCbmQovz78Hq7MzPxdx9d1gZzXMsn6HtWj29bW51YUKB). -- The node has a one peer (1 peers). -- The nodes have produced some blocks (best: #3 (0x0c55…d51b)). -- The blocks are being finalized (finalized #1 (0xf086…9847)). +* The second node identity was discovered on the network (12D3KooWBCbmQovz78Hq7MzPxdx9d1gZzXMsn6HtWj29bW51YUKB). +* The node has a one peer (1 peers). +* The nodes have produced some blocks (best: #3 (0x0c55…d51b)). +* The blocks are being finalized (finalized #1 (0xf086…9847)). ## Review the command-line options Before moving on, have a look at how the following options are used to start the node. -- --base-path Specifies the directory for storing all of the data related to this chain. -- --chain local Specifies the chain specification to use. Valid predefined chain specifications include local, development, and staging. -- --alice Adds the predefined keys for the alice account to the node's keystore. With this setting, the alice account is used for block production and finalization. -- --port 30333 Specifies the port to listen on for peer-to-peer (p2p) traffic. Because this tutorial uses two nodes running on the same physical computer to simulate a network, you must explicitly specify a different port for at least one account. -- --ws-port 9945 Specifies the port to listen on for incoming WebSocket traffic. The default port is 9944. This tutorial uses a custom web socket port number (9945). -- --rpc-port 9933 Specifies the port to listen on for incoming RPC traffic. The default port is 9933. -- --node-key Specifies the Ed25519 secret key to use for libp2p networking. You should only use this option for development and testing. -- --telemetry-url Specifies where to send telemetry data. For this tutorial, you can send telemetry data to a server hosted by Parity that is available for anyone to use. -- --validator Specifies that this node participates in block production and finalization for the network. - +* \--base-path Specifies the directory for storing all of the data related to this chain. +* \--chain local Specifies the chain specification to use. Valid predefined chain specifications include local, development, and staging. +* \--alice Adds the predefined keys for the alice account to the node's keystore. With this setting, the alice account is used for block production and finalization. +* \--port 30333 Specifies the port to listen on for peer-to-peer (p2p) traffic. Because this tutorial uses two nodes running on the same physical computer to simulate a network, you must explicitly specify a different port for at least one account. +* \--rpc-port 9945 Specifies the port to listen on for incoming RPC traffic. The default port is 9944. +* \--node-key Specifies the Ed25519 secret key to use for libp2p networking. You should only use this option for development and testing. +* \--telemetry-url Specifies where to send telemetry data. For this tutorial, you can send telemetry data to a server hosted by Parity that is available for anyone to use. +* \--validator Specifies that this node participates in block production and finalization for the network. ## What next diff --git a/docs/misc/creating_validator.md b/docs/misc/creating_validator.md index 78a9b963e..97d43e24d 100644 --- a/docs/misc/creating_validator.md +++ b/docs/misc/creating_validator.md @@ -10,9 +10,9 @@ The transactions weights in TFchain were benchmarked on standard hardware. It is Standard Hardware For the full details of the standard hardware please see here. -- CPU - Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz -- Storage - A NVMe solid state drive. Should be reasonably sized to deal with blockchain growth. Starting around 80GB - 160GB will be okay for the first six months of TFchain, but will need to be re-evaluated every six months. -- Memory - 64GB ECC. +* CPU - Intel(R) Core(TM) i7-7700K CPU @ 4.20GHz +* Storage - A NVMe solid state drive. Should be reasonably sized to deal with blockchain growth. Starting around 80GB - 160GB will be okay for the first six months of TFchain, but will need to be re-evaluated every six months. +* Memory - 64GB ECC. The specs posted above are by no means the minimum specs that you could use when running a validator, however you should be aware that if you are using less you may need to toggle some extra optimizations in order to be equal to other validators that are running the standard. @@ -101,9 +101,9 @@ You can now start synchronising chain data. Bootnodes examples: -- Devnet bootnode: `/ip4/185.206.122.7/tcp/30333/p2p/12D3KooWLcMLBg9itjQL1EXsAqkJFPhqESHqJKY7CBKmhhhL8fdp` -- Testnet bootnode: `/ip4/51.68.204.40/tcp/30333/p2p/12D3KooWHe8Wbn6dDbyxXietaXSRTZJfykPRgrkJDjXh9xZ4383k` -- Mainnet bootnode: `/ip4/185.206.122.83/tcp/30333/p2p/12D3KooWLtsdtQHswnXkLRH7e8vZJHktsh7gfuL5PoADV51JJ6wY` +* Devnet bootnode: `/ip4/185.206.122.7/tcp/30333/p2p/12D3KooWLcMLBg9itjQL1EXsAqkJFPhqESHqJKY7CBKmhhhL8fdp` +* Testnet bootnode: `/ip4/51.68.204.40/tcp/30333/p2p/12D3KooWHe8Wbn6dDbyxXietaXSRTZJfykPRgrkJDjXh9xZ4383k` +* Mainnet bootnode: `/ip4/185.206.122.83/tcp/30333/p2p/12D3KooWLtsdtQHswnXkLRH7e8vZJHktsh7gfuL5PoADV51JJ6wY` You can begin syncing your node by running the following command: @@ -147,16 +147,16 @@ If you are interested in determining how much longer you have to go, your server ## Create a Validator object -- dev: -- test: -- main: +* dev: +* test: +* main: Open polkadot js link in the browser based on the network you want to validate on. -- Browse to `accounts` and click `Add Account`, create an account and name it `VALIDATOR_ACCOUNT`. Take note of the mnemonic. - This account will be your account that manages the Validator and manages your council membership (voting). Make sure to send some TFT to this account. -- (Optional) Create another account and name it `ANYNAME_STASH`. This account will be your stash account. -- Create one more account and call it `VALIDATOR_NODE_ACCOUNT`, this account will be used to participate in consensus. +* Browse to `accounts` and click `Add Account`, create an account and name it `VALIDATOR_ACCOUNT`. Take note of the mnemonic. + This account will be your account that manages the Validator and manages your council membership (voting). Make sure to send some TFT to this account. +* (Optional) Create another account and name it `ANYNAME_STASH`. This account will be your stash account. +* Create one more account and call it `VALIDATOR_NODE_ACCOUNT`, this account will be used to participate in consensus. You now should have 3 accounts. @@ -180,11 +180,11 @@ This call needs to be signed with your account (`VALIDATOR_ACCOUNT`) that manage Information needed: -- validator_node_account: Account ID generated from previous step (`VALIDATOR_NODE_ACCOUNT`) -- stash_account: Stash account, can be your `VALIDATOR_ACCOUNT` -- description: Reason why I want to become a validator -- tfconnectid: Your Threefold connect name -- info: link to webpage or linked in profile +* validator\_node\_account: Account ID generated from previous step (`VALIDATOR_NODE_ACCOUNT`) +* stash\_account: Stash account, can be your `VALIDATOR_ACCOUNT` +* description: Reason why I want to become a validator +* tfconnectid: Your Threefold connect name +* info: link to webpage or linked in profile If all information is filled in correctly. Click on `Submit transaction` and sign. If all goes well, the Council will approve your request. @@ -204,7 +204,7 @@ Transfer some balance to this account (you can see the address in the polkadot U Restart tfchain with: ```sh -./target/release/tfchain ...otherArgs --ws-external --rpc-methods Unsafe --rpc-external --telemetry-url 'wss://shard1.telemetry.tfchain.grid.tf/submit 1' +./target/release/tfchain ...otherArgs --rpc-external --rpc-methods Unsafe --telemetry-url 'wss://shard1.telemetry.tfchain.grid.tf/submit 1' ``` #### Using polkodatjs @@ -220,7 +220,7 @@ yarn yarn start ``` -Browse to and connect to the new node over its public ip. Make sure to specify the port, like: ws://YOUR_MACHINE_PUBLIC_IP:9944 +Browse to and connect to the new node over its public ip. Make sure to specify the port, like: ws://YOUR\_MACHINE\_PUBLIC\_IP:9944 First insert the types: Go to `Settings` -> `Developer` -> Copy paste output of following [file](https://raw.githubusercontent.com/threefoldtech/tfchain_client_js/master/types.json) @@ -240,14 +240,12 @@ Go to `Extrinsics` -> `session` -> `setKeys` -> (make sure to use the created no input: -``` -keys: the key from rotate keys ouput -proofs: 0 -``` + keys: the key from rotate keys ouput + proofs: 0 Now we can start the node in Validator mode: -Restart tfchain and remove flags: `--ws-external --rpc-methods Unsafe --rpc-external` and replace that with `--validator` +Restart tfchain and remove flags: `--rpc-external --rpc-methods Unsafe` and replace that with `--validator` Your node is now running in validator mode. Next up you need to manually activate the validator. @@ -265,22 +263,20 @@ Select `ActivateValidatorNode` and click Submit Transaction. Example systemd file: -``` -[Unit] -Description=TFchain service -After=network.target -StartLimitIntervalSec=0 - -[Service] -Type=simple -Restart=always -RestartSec=1 -User=user -ExecStart=/home/user/tfchain/substrate-node/target/release/tfchain --chain /home/user/tfchain/substrate-node/chainspecs/dev/chainSpec.json --pruning=archive --bootnodes /ip4/185.206.122.7/tcp/30333/p2p/12D3KooWLcMLBg9itjQL1EXsAqkJFPhqESHqJKY7CBKmhhhL8fdp --validator --telemetry-url 'wss://shard1.telemetry.tfchain.grid.tf/submit 1' - -[Install] -WantedBy=multi-user.target -``` + [Unit] + Description=TFchain service + After=network.target + StartLimitIntervalSec=0 + + [Service] + Type=simple + Restart=always + RestartSec=1 + User=user + ExecStart=/home/user/tfchain/substrate-node/target/release/tfchain --chain /home/user/tfchain/substrate-node/chainspecs/dev/chainSpec.json --pruning=archive --bootnodes /ip4/185.206.122.7/tcp/30333/p2p/12D3KooWLcMLBg9itjQL1EXsAqkJFPhqESHqJKY7CBKmhhhL8fdp --validator --telemetry-url 'wss://shard1.telemetry.tfchain.grid.tf/submit 1' + + [Install] + WantedBy=multi-user.target Replace `user` by your username. diff --git a/substrate-node/.devcontainer/devcontainer.json b/substrate-node/.devcontainer/devcontainer.json index 9452e0ade..3dc8a239a 100644 --- a/substrate-node/.devcontainer/devcontainer.json +++ b/substrate-node/.devcontainer/devcontainer.json @@ -14,12 +14,19 @@ 3000, 9944 ], - "preCreateCommand": ["cargo build", "cargo check"], - "postStartCommand": "./target/debug/node-template --dev --ws-external", + "preCreateCommand": [ + "cargo build", + "cargo check" + ], + "postStartCommand": "./target/debug/node-template --dev --rpc-external", "menuActions": [ - {"id": "polkadotjs", - "label": "Open PolkadotJS Apps", - "type": "external-preview", - "args": ["https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F/$HOST/wss"]} + { + "id": "polkadotjs", + "label": "Open PolkadotJS Apps", + "type": "external-preview", + "args": [ + "https://polkadot.js.org/apps/?rpc=wss%3A%2F%2F/$HOST/wss" + ] + } ] -} +} \ No newline at end of file diff --git a/substrate-node/charts/substrate-node/templates/deployment.yaml b/substrate-node/charts/substrate-node/templates/deployment.yaml index a4ba61e16..de6a2111e 100644 --- a/substrate-node/charts/substrate-node/templates/deployment.yaml +++ b/substrate-node/charts/substrate-node/templates/deployment.yaml @@ -38,24 +38,19 @@ spec: - name: rpc containerPort: {{ .Values.rpc_port }} protocol: TCP - - name: ws - containerPort: {{ .Values.ws_port }} - protocol: TCP env: - name: SUBSTRATE_NAME value: {{ .Values.name }} - name: SUBSTRATE_PORT value: {{ .Values.port | quote }} - - name: SUBSTRATE_WS_PORT - value: {{ .Values.ws_port | quote }} - name: SUBSTRATE_RPC_PORT value: {{ .Values.rpc_port | quote }} - name: SUBSTRATE_BOOT_NODE value: {{ .Values.boot_node }} - name: CHAINSPEC value: {{ .Values.chainspec }} - - name: WS_MAX_CONNECTIONS - value: {{ .Values.ws_max_connections | quote }} + - name: RPC_MAX_CONNECTIONS + value: {{ .Values.rpc_max_connections | quote }} - name: SUBSTRATE_RPC_METHODS value: {{ .Values.rpc_methods }} args: [ @@ -66,7 +61,6 @@ spec: "--keystore-path=/keystore", "--chain=$(CHAINSPEC)", "--port", "$(SUBSTRATE_PORT)", - "--ws-port", "$(SUBSTRATE_WS_PORT)", "--rpc-port", "$(SUBSTRATE_RPC_PORT)", {{ if .Values.boot_node }} "--bootnodes", "$(SUBSTRATE_BOOT_NODE)", @@ -76,9 +70,9 @@ spec: "--validator", "--pruning", "archive", {{ else }} - "--ws-external", + "--rpc-external", {{ end }} - "--ws-max-connections", "$(WS_MAX_CONNECTIONS)", + "--rpc-max-connections", "$(RPC_MAX_CONNECTIONS)", {{ if .Values.telemetry_url }} "--telemetry-url", {{ .Values.telemetry_url | quote }}, {{ end }} diff --git a/substrate-node/charts/substrate-node/templates/service.yaml b/substrate-node/charts/substrate-node/templates/service.yaml index f2b1c6a95..b817b8c8c 100644 --- a/substrate-node/charts/substrate-node/templates/service.yaml +++ b/substrate-node/charts/substrate-node/templates/service.yaml @@ -8,10 +8,6 @@ metadata: spec: type: {{ .Values.service.type }} ports: - - port: 80 - targetPort: {{ .Values.ws_port }} - protocol: TCP - name: ws - port: {{ .Values.port }} protocol: TCP name: http diff --git a/substrate-node/charts/substrate-node/values.yaml b/substrate-node/charts/substrate-node/values.yaml index 114ead932..4ef36de3b 100644 --- a/substrate-node/charts/substrate-node/values.yaml +++ b/substrate-node/charts/substrate-node/values.yaml @@ -43,15 +43,13 @@ name: 'tfchainnode01' port: 30333 -ws_port: 9944 - -rpc_port: 9933 +rpc_port: 9944 is_validator: true chainspec: '/etc/chainspecs/dev/chainSpecRaw.json' -ws_max_connections: 1048576 +rpc_max_connections: 1048576 #rpc_methods: "Unsafe" From 67da2473d6bf737000088b02ee9222ff1ba7b910 Mon Sep 17 00:00:00 2001 From: renauter Date: Sun, 26 Nov 2023 19:39:49 -0300 Subject: [PATCH 09/25] fix codacy --- substrate-node/tests/SubstrateNetwork.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/substrate-node/tests/SubstrateNetwork.py b/substrate-node/tests/SubstrateNetwork.py index 80da5d14a..9fbc8670b 100644 --- a/substrate-node/tests/SubstrateNetwork.py +++ b/substrate-node/tests/SubstrateNetwork.py @@ -13,6 +13,7 @@ SUBSTRATE_NODE_DIR = dirname(os.getcwd()) +TMP_DIR = "\tmp" TFCHAIN_EXE = join(SUBSTRATE_NODE_DIR, "target", "release", "tfchain") RE_NODE_STARTED = re.compile("Running JSON-RPC server") @@ -151,17 +152,17 @@ def setup_multi_node_network(self, log_name: str = "", amt: int = 1): rmtree(output_dir_network, ignore_errors=True) port = 30333 - rpc_port = 9944 + rpc_port = 994 if amt == 1: log_file_alice = join(output_dir_network, "node_alice.log") - self._nodes["alice"] = run_single_node(log_file_alice, "/tmp/alice", port, rpc_port) + self._nodes["alice"] = run_single_node(log_file_alice, f"{TMP_DIR}/alice", port, rpc_port) wait_till_node_ready(log_file_alice) setup_offchain_workers(rpc_port, "Alice") wait_till_first_block(log_file_alice) else: log_file_alice = join(output_dir_network, "node_alice.log") - self._nodes["alice"] = run_node(log_file_alice, "/tmp/alice", "alice", port, + self._nodes["alice"] = run_node(log_file_alice, f"{TMP_DIR}/alice", "alice", port, rpc_port, node_key="0000000000000000000000000000000000000000000000000000000000000001") wait_till_node_ready(log_file_alice) setup_offchain_workers(rpc_port, "Alice") @@ -173,7 +174,7 @@ def setup_multi_node_network(self, log_name: str = "", amt: int = 1): rpc_port += 1 name = list(PREDEFINED_KEYS.keys())[x].lower() log_file = join(output_dir_network, f"node_{name}.log") - self._nodes[name] = run_node(log_file, f"/tmp/{name}", name, port, rpc_port, node_key=None, + self._nodes[name] = run_node(log_file, f"{TMP_DIR}/{name}", name, port, rpc_port, node_key=None, bootnodes="/ip4/127.0.0.1/tcp/30333/p2p/12D3KooWEyoppNCUx8Yx66oV9fJnriXwCcXwDDUA2kj6vnc6iDEp") wait_till_node_ready(log_file) setup_offchain_workers(rpc_port, "Bob") From 85031442dbefad2203b8160ca0b93d5ac8f6da8d Mon Sep 17 00:00:00 2001 From: renauter Date: Mon, 27 Nov 2023 00:19:18 -0300 Subject: [PATCH 10/25] fix integration tests --- substrate-node/tests/SubstrateNetwork.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate-node/tests/SubstrateNetwork.py b/substrate-node/tests/SubstrateNetwork.py index 9fbc8670b..d6b8794bc 100644 --- a/substrate-node/tests/SubstrateNetwork.py +++ b/substrate-node/tests/SubstrateNetwork.py @@ -152,7 +152,7 @@ def setup_multi_node_network(self, log_name: str = "", amt: int = 1): rmtree(output_dir_network, ignore_errors=True) port = 30333 - rpc_port = 994 + rpc_port = 9944 if amt == 1: log_file_alice = join(output_dir_network, "node_alice.log") From 79d7d8670c92e7422f959b58c5bf2b71e2a7292f Mon Sep 17 00:00:00 2001 From: renauter Date: Mon, 27 Nov 2023 00:58:53 -0300 Subject: [PATCH 11/25] upgrade to polkadot 1.0.0 --- substrate-node/Cargo.toml | 132 +++++++++++++++--------------- substrate-node/runtime/Cargo.toml | 2 +- 2 files changed, 67 insertions(+), 67 deletions(-) diff --git a/substrate-node/Cargo.toml b/substrate-node/Cargo.toml index 45247f26d..fa48fdca1 100644 --- a/substrate-node/Cargo.toml +++ b/substrate-node/Cargo.toml @@ -60,73 +60,73 @@ tfchain-support = { path = "support", default-features = false } tfchain-runtime = { path = "runtime", default-features = false } # Benchmarking (with default disabled) -frame-system-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +frame-system-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} # Substrate (with default disabled) -frame-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -frame-benchmarking-cli = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -frame-executive = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -frame-support = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -frame-system = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -frame-system-rpc-runtime-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -frame-try-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-authorship = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-balances = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-collective = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-grandpa = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-membership = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-scheduler = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-session-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-timestamp = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-transaction-payment = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-transaction-payment-rpc = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-transaction-payment-rpc-runtime-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -pallet-utility = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-block-builder = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-consensus-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-inherents = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-io = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-offchain = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-std = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-transaction-pool = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-version = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-storage = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -try-runtime-cli = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-keystore = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} -sp-staking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.43"} +frame-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +frame-benchmarking-cli = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +frame-executive = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +frame-support = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +frame-system = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +frame-system-rpc-runtime-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +frame-try-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-authorship = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-balances = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-collective = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-grandpa = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-membership = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-scheduler = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-session-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-timestamp = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-transaction-payment = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-transaction-payment-rpc = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-transaction-payment-rpc-runtime-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +pallet-utility = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-api = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-block-builder = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-consensus-aura = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-core = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-inherents = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-io = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-offchain = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-runtime = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-std = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-transaction-pool = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-version = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-storage = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +try-runtime-cli = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-keystore = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} +sp-staking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0"} # Client-only (with default enabled) -polkadot-cli = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43"} -polkadot-primitives = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43"} -polkadot-service = {git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.43"} -sc-basic-authorship = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-chain-spec = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-cli = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-client-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-consensus = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-consensus-aura = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-executor = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-consensus-grandpa = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-keystore = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-network = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-rpc = { git = "https://github.com/paritytech/substrate.git", "branch" = "polkadot-v0.9.43" } -sc-rpc-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-service = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-sysinfo = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-telemetry = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-tracing = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-transaction-pool = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sc-transaction-pool-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sp-blockchain = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sp-consensus = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sp-keyring = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -sp-timestamp = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -substrate-build-script-utils = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -substrate-frame-rpc-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} -substrate-prometheus-endpoint = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43"} +polkadot-cli = {git = "https://github.com/paritytech/polkadot", branch = "release-v1.0.0"} +polkadot-primitives = {git = "https://github.com/paritytech/polkadot", branch = "release-v1.0.0"} +polkadot-service = {git = "https://github.com/paritytech/polkadot", branch = "release-v1.0.0"} +sc-basic-authorship = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-chain-spec = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-cli = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-client-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-consensus = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-consensus-aura = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-executor = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-consensus-grandpa = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-keystore = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-network = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-rpc = { git = "https://github.com/paritytech/substrate.git", "branch" = "polkadot-v1.0.0" } +sc-rpc-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-service = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-sysinfo = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-telemetry = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-tracing = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-transaction-pool = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-transaction-pool-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sp-blockchain = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sp-consensus = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sp-keyring = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sp-timestamp = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +substrate-build-script-utils = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +substrate-frame-rpc-system = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +substrate-prometheus-endpoint = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} diff --git a/substrate-node/runtime/Cargo.toml b/substrate-node/runtime/Cargo.toml index 05206d0ea..9c2b11fec 100644 --- a/substrate-node/runtime/Cargo.toml +++ b/substrate-node/runtime/Cargo.toml @@ -14,7 +14,7 @@ version.workspace = true targets = ["x86_64-unknown-linux-gnu"] [build-dependencies] -substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" } +substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" } [dependencies] smallvec.workspace = true From 5d485960ef631d56884f73e452e8b835601fb84a Mon Sep 17 00:00:00 2001 From: renauter Date: Mon, 27 Nov 2023 01:01:23 -0300 Subject: [PATCH 12/25] upgrade parity-scale-codec --- substrate-node/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate-node/Cargo.toml b/substrate-node/Cargo.toml index fa48fdca1..9328401e4 100644 --- a/substrate-node/Cargo.toml +++ b/substrate-node/Cargo.toml @@ -24,7 +24,7 @@ resolver = "2" base58 = {version = "0.2.0", default-features = false} bitflags = {version = "1.3.2", default-features = false} clap = "4.0.9" -parity-scale-codec = { version = "3.2.2", default-features = false } +parity-scale-codec = { version = "3.6.1", default-features = false } env_logger = "0.10.0" futures = {version = "0.3.21", default-features = false} hex = {version = "0.4.0", default-features = false} From a663505c7d016b91dd0bd7cefd37d21ae995f7b0 Mon Sep 17 00:00:00 2001 From: renauter Date: Mon, 27 Nov 2023 21:43:29 -0300 Subject: [PATCH 13/25] update node --- substrate-node/Cargo.toml | 1 + substrate-node/node/Cargo.toml | 1 + .../{command_helper.rs => benchmarking.rs} | 108 +++++++++++------- substrate-node/node/src/chain_spec.rs | 14 ++- substrate-node/node/src/cli.rs | 1 + substrate-node/node/src/command.rs | 66 ++++++----- substrate-node/node/src/main.rs | 4 +- substrate-node/node/src/rpc.rs | 4 +- substrate-node/node/src/service.rs | 35 ++++-- 9 files changed, 146 insertions(+), 88 deletions(-) rename substrate-node/node/src/{command_helper.rs => benchmarking.rs} (59%) diff --git a/substrate-node/Cargo.toml b/substrate-node/Cargo.toml index 9328401e4..a0caf5172 100644 --- a/substrate-node/Cargo.toml +++ b/substrate-node/Cargo.toml @@ -123,6 +123,7 @@ sc-telemetry = {git = "https://github.com/paritytech/substrate", branch = "polka sc-tracing = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} sc-transaction-pool = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} sc-transaction-pool-api = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} +sc-offchain = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" } sp-blockchain = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} sp-consensus = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} sp-keyring = {git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0"} diff --git a/substrate-node/node/Cargo.toml b/substrate-node/node/Cargo.toml index 4fb2d5fd9..b759c1045 100644 --- a/substrate-node/node/Cargo.toml +++ b/substrate-node/node/Cargo.toml @@ -34,6 +34,7 @@ sc-telemetry.workspace = true sc-keystore.workspace = true sc-transaction-pool.workspace = true sc-transaction-pool-api.workspace = true +sc-offchain.workspace = true sc-consensus-aura.workspace = true sp-consensus-aura.workspace = true sp-consensus.workspace = true diff --git a/substrate-node/node/src/command_helper.rs b/substrate-node/node/src/benchmarking.rs similarity index 59% rename from substrate-node/node/src/command_helper.rs rename to substrate-node/node/src/benchmarking.rs index de991eaf2..06f55b394 100644 --- a/substrate-node/node/src/command_helper.rs +++ b/substrate-node/node/src/benchmarking.rs @@ -1,53 +1,41 @@ -// This file is part of Substrate. - -// Copyright (C) 2022 Parity Technologies (UK) Ltd. -// 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 . - -//! Contains code to setup the command invocations in [`super::command`] which would -//! otherwise bloat that module. +//! Setup code for [`super::command`] which would otherwise bloat that module. +//! +//! Should only be used for benchmarking as it may break in other contexts. use crate::service::FullClient; -use runtime::SystemCall; +use runtime::{AccountId, Balance, BalancesCall, SystemCall}; use sc_cli::Result; use sc_client_api::BlockBackend; use sp_core::{Encode, Pair}; -use sp_inherents::InherentData; +use sp_inherents::{InherentData, InherentDataProvider}; use sp_keyring::Sr25519Keyring; use sp_runtime::{OpaqueExtrinsic, SaturatedConversion}; -use std::sync::Arc; use tfchain_runtime as runtime; +use std::{sync::Arc, time::Duration}; + /// Generates extrinsics for the `benchmark overhead` command. /// /// Note: Should only be used for benchmarking. -pub struct BenchmarkExtrinsicBuilder { +pub struct RemarkBuilder { client: Arc, } -impl BenchmarkExtrinsicBuilder { +impl RemarkBuilder { /// Creates a new [`Self`] from the given client. pub fn new(client: Arc) -> Self { Self { client } } } -impl frame_benchmarking_cli::ExtrinsicBuilder for BenchmarkExtrinsicBuilder { +impl frame_benchmarking_cli::ExtrinsicBuilder for RemarkBuilder { + fn pallet(&self) -> &str { + "system" + } + fn extrinsic(&self) -> &str { - todo!() + "remark" } fn build(&self, nonce: u32) -> std::result::Result { @@ -62,9 +50,52 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for BenchmarkExtrinsicBuilder { Ok(extrinsic) } +} + +/// Generates `Balances::TransferKeepAlive` extrinsics for the benchmarks. +/// +/// Note: Should only be used for benchmarking. +pub struct TransferKeepAliveBuilder { + client: Arc, + dest: AccountId, + value: Balance, +} + +impl TransferKeepAliveBuilder { + /// Creates a new [`Self`] from the given client. + pub fn new(client: Arc, dest: AccountId, value: Balance) -> Self { + Self { + client, + dest, + value, + } + } +} +impl frame_benchmarking_cli::ExtrinsicBuilder for TransferKeepAliveBuilder { fn pallet(&self) -> &str { - todo!() + "balances" + } + + fn extrinsic(&self) -> &str { + "transfer_keep_alive" + } + + fn build(&self, nonce: u32) -> std::result::Result { + let acc = Sr25519Keyring::Bob.pair(); + let extrinsic: OpaqueExtrinsic = create_benchmark_extrinsic( + self.client.as_ref(), + acc, + BalancesCall::transfer_keep_alive { + dest: self.dest.clone().into(), + value: self.value, + } + .into(), + nonce, + ) + .into(); + + Ok(extrinsic) } } @@ -120,10 +151,10 @@ pub fn create_benchmark_extrinsic( let signature = raw_payload.using_encoded(|e| sender.sign(e)); runtime::UncheckedExtrinsic::new_signed( - call.clone(), + call, sp_runtime::AccountId32::from(sender.public()).into(), - runtime::Signature::Sr25519(signature.clone()), - extra.clone(), + runtime::Signature::Sr25519(signature), + extra, ) } @@ -131,12 +162,11 @@ pub fn create_benchmark_extrinsic( /// /// Note: Should only be used for benchmarking. pub fn inherent_benchmark_data() -> Result { - // TODO, see if we can fix this later - // let mut inherent_data = InherentData::new(); - // let d = Duration::from_millis(0); - // let timestamp = sp_timestamp::InherentDataProvider::new(d.into()); - // timestamp - // .provide_inherent_data(&mut inherent_data) - // .map_err(|e| format!("creating inherent data: {:?}", e))?; - Ok(InherentData::new()) + let mut inherent_data = InherentData::new(); + let d = Duration::from_millis(0); + let timestamp = sp_timestamp::InherentDataProvider::new(d.into()); + + futures::executor::block_on(timestamp.provide_inherent_data(&mut inherent_data)) + .map_err(|e| format!("creating inherent data: {:?}", e))?; + Ok(inherent_data) } diff --git a/substrate-node/node/src/chain_spec.rs b/substrate-node/node/src/chain_spec.rs index d5c827ce2..50b809e22 100644 --- a/substrate-node/node/src/chain_spec.rs +++ b/substrate-node/node/src/chain_spec.rs @@ -6,8 +6,8 @@ use sp_runtime::traits::{IdentifyAccount, Verify}; use std::convert::TryInto; use tfchain_runtime::opaque::SessionKeys; use tfchain_runtime::{ - AccountId, AuraConfig, BalancesConfig, CouncilConfig, CouncilMembershipConfig, GenesisConfig, - GrandpaConfig, SessionConfig, Signature, SmartContractModuleConfig, SystemConfig, + AccountId, AuraConfig, BalancesConfig, CouncilConfig, CouncilMembershipConfig, GrandpaConfig, + RuntimeGenesisConfig, SessionConfig, Signature, SmartContractModuleConfig, SystemConfig, TFTBridgeModuleConfig, TFTPriceModuleConfig, TfgridModuleConfig, ValidatorSetConfig, WASM_BINARY, }; @@ -16,7 +16,7 @@ use tfchain_runtime::{ // const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/"; /// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type. -pub type ChainSpec = sc_service::GenericChainSpec; +pub type ChainSpec = sc_service::GenericChainSpec; /// Generate a crypto pair from seed. pub fn get_from_seed(seed: &str) -> ::Public { @@ -303,12 +303,12 @@ fn testnet_genesis( max_tft_price: u32, billing_frequency: u64, council_members: Vec, -) -> GenesisConfig { - GenesisConfig { +) -> RuntimeGenesisConfig { + RuntimeGenesisConfig { system: SystemConfig { // Add Wasm runtime to storage. code: wasm_binary.to_vec(), - // changes_trie_config: Default::default(), + ..Default::default() }, balances: BalancesConfig { // Configure endowed accounts with initial balance of 1 << 60. @@ -342,6 +342,7 @@ fn testnet_genesis( }, grandpa: GrandpaConfig { authorities: vec![], + ..Default::default() }, tfgrid_module: TfgridModuleConfig { su_price_value: 50000, @@ -388,6 +389,7 @@ fn testnet_genesis( }, smart_contract_module: SmartContractModuleConfig { billing_frequency: billing_frequency, + _data: std::marker::PhantomData, }, } } diff --git a/substrate-node/node/src/cli.rs b/substrate-node/node/src/cli.rs index 5d8513a1f..965bf3533 100644 --- a/substrate-node/node/src/cli.rs +++ b/substrate-node/node/src/cli.rs @@ -10,6 +10,7 @@ pub struct Cli { } #[derive(Debug, clap::Subcommand)] +#[allow(clippy::large_enum_variant)] pub enum Subcommand { /// Key management cli utilities #[clap(subcommand)] diff --git a/substrate-node/node/src/command.rs b/substrate-node/node/src/command.rs index 86c53e4f5..fb3bd365b 100644 --- a/substrate-node/node/src/command.rs +++ b/substrate-node/node/src/command.rs @@ -1,13 +1,14 @@ use crate::{ + benchmarking::{inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder}, chain_spec, cli::{Cli, Subcommand}, - command_helper::{inherent_benchmark_data, BenchmarkExtrinsicBuilder}, service, }; -use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE}; -use sc_cli::{ChainSpec, RuntimeVersion, SubstrateCli}; +use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE}; +use sc_cli::SubstrateCli; use sc_service::PartialComponents; -use tfchain_runtime::Block; +use sp_keyring::Sr25519Keyring; +use tfchain_runtime::{Block, EXISTENTIAL_DEPOSIT}; impl SubstrateCli for Cli { fn impl_name() -> String { @@ -44,10 +45,6 @@ impl SubstrateCli for Cli { )?), }) } - - fn native_runtime_version(_: &Box) -> &'static RuntimeVersion { - &tfchain_runtime::VERSION - } } /// Parse and run command line arguments @@ -142,7 +139,7 @@ pub fn run() -> sc_cli::Result<()> { ); } - cmd.run::(config) + cmd.run::(config) } BenchmarkCmd::Block(cmd) => { let PartialComponents { client, .. } = service::new_partial(&config)?; @@ -165,7 +162,7 @@ pub fn run() -> sc_cli::Result<()> { } BenchmarkCmd::Overhead(cmd) => { let PartialComponents { client, .. } = service::new_partial(&config)?; - let ext_builder = BenchmarkExtrinsicBuilder::new(client.clone()); + let ext_builder = RemarkBuilder::new(client.clone()); cmd.run( config, @@ -175,12 +172,23 @@ pub fn run() -> sc_cli::Result<()> { &ext_builder, ) } + BenchmarkCmd::Extrinsic(cmd) => { + let PartialComponents { client, .. } = service::new_partial(&config)?; + // Register the *Remark* and *TKA* builders. + let ext_factory = ExtrinsicFactory(vec![ + Box::new(RemarkBuilder::new(client.clone())), + Box::new(TransferKeepAliveBuilder::new( + client.clone(), + Sr25519Keyring::Alice.to_account_id(), + EXISTENTIAL_DEPOSIT, + )), + ]); + + cmd.run(client, inherent_benchmark_data()?, Vec::new(), &ext_factory) + } BenchmarkCmd::Machine(cmd) => { cmd.run(&config, SUBSTRATE_REFERENCE_HARDWARE.clone()) } - BenchmarkCmd::Extrinsic(_cmd) => { - todo!() - } } }) } @@ -192,22 +200,22 @@ pub fn run() -> sc_cli::Result<()> { let runner = cli.create_runner(cmd)?; runner.async_run(|config| { - // we don't need any of the components of new_partial, just a runtime, or a task - // manager to do `async_run`. - let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry); - let task_manager = - sc_service::TaskManager::new(config.tokio_handle.clone(), registry) - .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; - let info_provider = timestamp_with_aura_info(6000); - - Ok(( - cmd.run::::ExtendHostFunctions, - >, _>(Some(info_provider)), - task_manager, - )) - }) + // we don't need any of the components of new_partial, just a runtime, or a task + // manager to do `async_run`. + let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry); + let task_manager = + sc_service::TaskManager::new(config.tokio_handle.clone(), registry) + .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?; + let info_provider = timestamp_with_aura_info(6000); + + Ok(( + cmd.run::::ExtendHostFunctions, + >, _>(Some(info_provider)), + task_manager, + )) + }) } #[cfg(not(feature = "try-runtime"))] Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \ diff --git a/substrate-node/node/src/main.rs b/substrate-node/node/src/main.rs index 5d5bd2d90..33c3195e0 100644 --- a/substrate-node/node/src/main.rs +++ b/substrate-node/node/src/main.rs @@ -4,11 +4,11 @@ mod chain_spec; #[macro_use] mod service; +mod benchmarking; mod cli; mod command; mod rpc; -mod command_helper; fn main() -> sc_cli::Result<()> { - command::run() + command::run() } diff --git a/substrate-node/node/src/rpc.rs b/substrate-node/node/src/rpc.rs index d02be6a23..d26b0d2cd 100644 --- a/substrate-node/node/src/rpc.rs +++ b/substrate-node/node/src/rpc.rs @@ -14,7 +14,7 @@ use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; use sp_block_builder::BlockBuilder; use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata}; -use tfchain_runtime::{opaque::Block, AccountId, Balance, Index}; +use tfchain_runtime::{opaque::Block, AccountId, Balance, Nonce}; /// Full client dependencies. pub struct FullDeps { @@ -34,7 +34,7 @@ where C: ProvideRuntimeApi, C: HeaderBackend + HeaderMetadata + 'static, C: Send + Sync + 'static, - C::Api: substrate_frame_rpc_system::AccountNonceApi, + C::Api: substrate_frame_rpc_system::AccountNonceApi, C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, C::Api: BlockBuilder, P: TransactionPool + 'static, diff --git a/substrate-node/node/src/service.rs b/substrate-node/node/src/service.rs index 05117164a..4a93bef6f 100644 --- a/substrate-node/node/src/service.rs +++ b/substrate-node/node/src/service.rs @@ -1,11 +1,13 @@ //! Service and ServiceFactory implementation. Specialized wrapper over substrate service. -use sc_client_api::BlockBackend; +use futures::FutureExt; +use sc_client_api::{Backend, BlockBackend}; use sc_consensus_aura::{ImportQueueParams, SlotProportion, StartAuraParams}; use sc_consensus_grandpa::SharedVoterState; pub use sc_executor::NativeElseWasmExecutor; use sc_service::{error::Error as ServiceError, Configuration, TaskManager, WarpSyncParams}; use sc_telemetry::{Telemetry, TelemetryWorker}; +use sc_transaction_pool_api::OffchainTransactionPoolFactory; use sp_consensus_aura::sr25519::AuthorityPair as AuraPair; use std::{sync::Arc, time::Duration}; use tfchain_runtime::{self, opaque::Block, RuntimeApi}; @@ -35,6 +37,7 @@ pub type FullClient = type FullBackend = sc_service::TFullBackend; type FullSelectChain = sc_consensus::LongestChain; +#[allow(clippy::type_complexity)] pub fn new_partial( config: &Configuration, ) -> Result< @@ -68,8 +71,7 @@ pub fn new_partial( }) .transpose()?; - let executor = sc_service::new_native_or_wasm_executor(&config); - + let executor = sc_service::new_native_or_wasm_executor(config); let (client, backend, keystore_container, task_manager) = sc_service::new_full_parts::( &config, @@ -97,7 +99,7 @@ pub fn new_partial( let (grandpa_block_import, grandpa_link) = sc_consensus_grandpa::block_import( client.clone(), - &(client.clone() as Arc<_>), + &client, select_chain.clone(), telemetry.as_ref().map(|x| x.handle()), )?; @@ -201,11 +203,23 @@ pub fn new_full(config: Configuration) -> Result { })?; if config.offchain_worker.enabled { - sc_service::build_offchain_workers( - &config, - task_manager.spawn_handle(), - client.clone(), - network.clone(), + task_manager.spawn_handle().spawn( + "offchain-workers-runner", + "offchain-worker", + sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions { + runtime_api_provider: client.clone(), + is_validator: config.role.is_authority(), + keystore: Some(keystore_container.keystore()), + offchain_db: backend.offchain_storage(), + transaction_pool: Some(OffchainTransactionPoolFactory::new( + transaction_pool.clone(), + )), + network_provider: network.clone(), + enable_http_requests: true, + custom_extensions: |_| vec![], + }) + .run(client.clone(), task_manager.spawn_handle()) + .boxed(), ); } @@ -265,7 +279,7 @@ pub fn new_full(config: Configuration) -> Result { let proposer_factory = sc_basic_authorship::ProposerFactory::new( task_manager.spawn_handle(), client.clone(), - transaction_pool, + transaction_pool.clone(), prometheus_registry.as_ref(), telemetry.as_ref().map(|x| x.handle()), ); @@ -344,6 +358,7 @@ pub fn new_full(config: Configuration) -> Result { prometheus_registry, shared_voter_state: SharedVoterState::empty(), telemetry: telemetry.as_ref().map(|x| x.handle()), + offchain_tx_pool_factory: OffchainTransactionPoolFactory::new(transaction_pool), }; // the GRANDPA voter task is considered infallible, i.e. From a10d86143d10ab5a795f71c3a82c562cfa337100 Mon Sep 17 00:00:00 2001 From: renauter Date: Mon, 27 Nov 2023 21:44:15 -0300 Subject: [PATCH 14/25] update runtime --- substrate-node/runtime/src/lib.rs | 42 ++++++++++++++++++------------- 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/substrate-node/runtime/src/lib.rs b/substrate-node/runtime/src/lib.rs index 679bd3c86..4f8f6be3b 100644 --- a/substrate-node/runtime/src/lib.rs +++ b/substrate-node/runtime/src/lib.rs @@ -35,7 +35,10 @@ use tfchain_support::{ // A few exports that help ease life for downstream crates. pub use frame_support::{ construct_runtime, parameter_types, - traits::{ConstU8, EitherOfDiverse, FindAuthor, KeyOwnerProofSystem, PrivilegeCmp, Randomness}, + traits::{ + ConstBool, ConstU8, EitherOfDiverse, FindAuthor, KeyOwnerProofSystem, PrivilegeCmp, + Randomness, + }, weights::{ constants::{ BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_REF_TIME_PER_SECOND, @@ -100,7 +103,7 @@ pub type AccountIndex = u32; pub type Balance = u128; /// Index of a transaction in the chain. -pub type Index = u32; +pub type Nonce = u32; /// A hash of some data used by the chain. pub type Hash = sp_core::H256; @@ -143,6 +146,7 @@ pub fn session_keys(aura: AuraId, grandpa: GrandpaId) -> SessionKeys { /// Constant values used within the runtime. pub mod constants; +#[sp_version::runtime_version] pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("substrate-threefold"), impl_name: create_runtime_str!("substrate-threefold"), @@ -188,6 +192,8 @@ parameter_types! { impl frame_system::Config for Runtime { /// The basic call filter to use in dispatchable. type BaseCallFilter = frame_support::traits::Everything; + /// The block type for the runtime. + type Block = Block; /// Block & extrinsics weights: base values and limits. type BlockWeights = BlockWeights; /// The maximum length of a block (in bytes). @@ -198,16 +204,12 @@ impl frame_system::Config for Runtime { type RuntimeCall = RuntimeCall; /// The lookup mechanism to get account ID from whatever is passed in dispatchers. type Lookup = AccountIdLookup; - /// The index type for storing how many extrinsics an account has signed. - type Index = Index; - /// The index type for blocks. - type BlockNumber = BlockNumber; + /// The type for storing how many extrinsics an account has signed. + type Nonce = Nonce; /// The type for hashing blocks and tries. type Hash = Hash; /// The hashing algorithm used. type Hashing = BlakeTwo256; - /// The header type. - type Header = generic::Header; /// The ubiquitous event type. type RuntimeEvent = RuntimeEvent; /// The ubiquitous origin type. @@ -246,6 +248,7 @@ impl pallet_aura::Config for Runtime { type AuthorityId = AuraId; type DisabledValidators = (); type MaxAuthorities = MaxAuthorities; + type AllowMultipleBlocksPerSlot = ConstBool; } impl pallet_grandpa::Config for Runtime { @@ -271,8 +274,11 @@ impl pallet_timestamp::Config for Runtime { type WeightInfo = (); } +/// Existential deposit. +pub const EXISTENTIAL_DEPOSIT: u128 = 500; + parameter_types! { - pub const ExistentialDeposit: u128 = 500; + pub const ExistentialDeposit: u128 = EXISTENTIAL_DEPOSIT; pub const MaxLocks: u32 = 50; pub const MaxReserves: u32 = 50; } @@ -291,7 +297,7 @@ impl pallet_balances::Config for Runtime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type FreezeIdentifier = (); type MaxFreezes = (); - type HoldIdentifier = (); + type RuntimeHoldReason = (); type MaxHolds = (); } @@ -514,7 +520,7 @@ where call: RuntimeCall, public: ::Signer, account: AccountId, - index: Index, + index: Nonce, ) -> Option<( RuntimeCall, ::SignaturePayload, @@ -690,10 +696,7 @@ impl pallet_utility::Config for Runtime { // Create the runtime by composing the FRAME pallets that were previously configured. construct_runtime!( - pub enum Runtime where - Block = Block, - NodeBlock = opaque::Block, - UncheckedExtrinsic = UncheckedExtrinsic + pub enum Runtime { // System support System: frame_system = 0, @@ -770,7 +773,10 @@ pub type Executive = frame_executive::Executive< // All migrations executed on runtime upgrade as a nested tuple of types implementing // `OnRuntimeUpgrade`. -type Migrations = (pallet_tfgrid::migrations::v17::FixFarmPublicIps, pallet_tft_bridge::migrations::v2::MigrateBurnTransactionsV2); +type Migrations = ( + pallet_tfgrid::migrations::v17::FixFarmPublicIps, + pallet_tft_bridge::migrations::v2::MigrateBurnTransactionsV2, +); // follows Substrate's non destructive way of eliminating otherwise required // repetion: https://github.com/paritytech/substrate/pull/10592 @@ -919,8 +925,8 @@ impl_runtime_apis! { } } - impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { - fn account_nonce(account: AccountId) -> Index { + impl frame_system_rpc_runtime_api::AccountNonceApi for Runtime { + fn account_nonce(account: AccountId) -> Nonce { System::account_nonce(account) } } From 50e224ee534ffd7aa9a53c4979921877fe1e3425 Mon Sep 17 00:00:00 2001 From: renauter Date: Mon, 27 Nov 2023 21:46:33 -0300 Subject: [PATCH 15/25] update pallets --- .../pallets/pallet-burning/src/lib.rs | 4 +- substrate-node/pallets/pallet-dao/src/dao.rs | 5 +- substrate-node/pallets/pallet-dao/src/lib.rs | 6 +- .../pallet-smart-contract/src/billing.rs | 9 ++- .../pallets/pallet-smart-contract/src/lib.rs | 18 ++---- .../pallets/pallet-tfgrid/src/benchmarking.rs | 6 +- .../pallets/pallet-tfgrid/src/farm.rs | 3 +- .../pallets/pallet-tfgrid/src/lib.rs | 60 +++++-------------- .../pallet-tfgrid/src/migrations/v14.rs | 3 +- .../pallets/pallet-tfgrid/src/pricing.rs | 13 ++-- .../pallets/pallet-tft-bridge/src/lib.rs | 36 ++++------- .../pallet-tft-bridge/src/migrations/types.rs | 10 ++-- .../pallet-tft-bridge/src/migrations/v2.rs | 17 ++++-- .../pallet-tft-bridge/src/tft_bridge.rs | 6 +- .../pallets/pallet-tft-price/src/lib.rs | 20 ++----- .../pallets/pallet-tft-price/src/tft_price.rs | 11 ++-- .../pallets/pallet-validator/src/lib.rs | 12 +--- .../substrate-validator-set/src/lib.rs | 22 +++---- 18 files changed, 100 insertions(+), 161 deletions(-) diff --git a/substrate-node/pallets/pallet-burning/src/lib.rs b/substrate-node/pallets/pallet-burning/src/lib.rs index f957d94fc..2d63e18c4 100644 --- a/substrate-node/pallets/pallet-burning/src/lib.rs +++ b/substrate-node/pallets/pallet-burning/src/lib.rs @@ -51,7 +51,7 @@ pub mod pallet { #[pallet::event] #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { - BurnTransactionCreated(T::AccountId, BalanceOf, T::BlockNumber, Vec), + BurnTransactionCreated(T::AccountId, BalanceOf, BlockNumberFor, Vec), } #[pallet::error] @@ -62,7 +62,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn burns)] pub type Burns = - StorageValue<_, Vec, T::BlockNumber>>, OptionQuery>; + StorageValue<_, Vec, BlockNumberFor>>, OptionQuery>; #[pallet::call] impl Pallet { diff --git a/substrate-node/pallets/pallet-dao/src/dao.rs b/substrate-node/pallets/pallet-dao/src/dao.rs index 569ee1303..2a04497c4 100644 --- a/substrate-node/pallets/pallet-dao/src/dao.rs +++ b/substrate-node/pallets/pallet-dao/src/dao.rs @@ -14,6 +14,7 @@ use frame_support::{ traits::Get, weights::Weight, }; +use frame_system::pallet_prelude::BlockNumberFor; use pallet_tfgrid::pallet::{InterfaceOf, LocationOf, SerialNumberOf, TfgridNode}; use sp_runtime::traits::{Dispatchable, Hash}; use sp_std::prelude::*; @@ -29,7 +30,7 @@ impl Pallet { action: Box<::Proposal>, description: Vec, link: Vec, - duration: Option, + duration: Option>, ) -> DispatchResultWithPostInfo { Self::is_council_member(who.clone())?; @@ -43,7 +44,7 @@ impl Pallet { let mut end = now + T::MotionDuration::get(); if let Some(motion_duration) = duration { ensure!( - motion_duration < T::BlockNumber::from(constants::time::DAYS * 30), + motion_duration < BlockNumberFor::::from(constants::time::DAYS * 30), Error::::InvalidProposalDuration ); end = now + motion_duration; diff --git a/substrate-node/pallets/pallet-dao/src/lib.rs b/substrate-node/pallets/pallet-dao/src/lib.rs index 622d3c618..e87a2a036 100644 --- a/substrate-node/pallets/pallet-dao/src/lib.rs +++ b/substrate-node/pallets/pallet-dao/src/lib.rs @@ -57,7 +57,7 @@ pub mod pallet { + GetDispatchInfo; /// The time-out for council motions. - type MotionDuration: Get; + type MotionDuration: Get>; /// The minimum amount of vetos to dissaprove a proposal type MinVetos: Get; @@ -100,7 +100,7 @@ pub mod pallet { _, Identity, T::Hash, - proposal::DaoVotes, + proposal::DaoVotes, T::AccountId>, OptionQuery, >; @@ -189,7 +189,7 @@ pub mod pallet { action: Box<::Proposal>, description: Vec, link: Vec, - duration: Option, + duration: Option>, ) -> DispatchResultWithPostInfo { let who = ensure_signed(origin)?; Self::_propose(who, threshold, action, description, link, duration) diff --git a/substrate-node/pallets/pallet-smart-contract/src/billing.rs b/substrate-node/pallets/pallet-smart-contract/src/billing.rs index 5e31716dc..8f5b8ff22 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/billing.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/billing.rs @@ -4,7 +4,10 @@ use frame_support::{ ensure, traits::{Currency, ExistenceRequirement, LockableCurrency, OnUnbalanced, WithdrawReasons}, }; -use frame_system::offchain::{SendSignedTransaction, SignMessage, Signer}; +use frame_system::{ + offchain::{SendSignedTransaction, SignMessage, Signer}, + pallet_prelude::BlockNumberFor, +}; use sp_core::Get; use sp_runtime::{ traits::{CheckedAdd, CheckedSub, Convert, Zero}, @@ -13,7 +16,7 @@ use sp_runtime::{ use sp_std::vec::Vec; impl Pallet { - pub fn bill_conttracts_for_block(block_number: T::BlockNumber) { + pub fn bill_conttracts_for_block(block_number: BlockNumberFor) { // Let offchain worker check if there are contracts on // billing loop at current index and try to bill them let index = Self::get_billing_loop_index_from_block_number(block_number); @@ -619,7 +622,7 @@ impl Pallet { // Billing index is block number % (mod) Billing Frequency // So index belongs to [0; billing_frequency - 1] range - pub fn get_billing_loop_index_from_block_number(block_number: T::BlockNumber) -> u64 { + pub fn get_billing_loop_index_from_block_number(block_number: BlockNumberFor) -> u64 { block_number.saturated_into::() % BillingFrequency::::get() } diff --git a/substrate-node/pallets/pallet-smart-contract/src/lib.rs b/substrate-node/pallets/pallet-smart-contract/src/lib.rs index 9b8fea12e..09726b04b 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/lib.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/lib.rs @@ -389,22 +389,14 @@ pub mod pallet { } #[pallet::genesis_config] - pub struct GenesisConfig { + #[derive(frame_support::DefaultNoBound)] + pub struct GenesisConfig { pub billing_frequency: u64, - } - - // The default value for the genesis config type. - #[cfg(feature = "std")] - impl Default for GenesisConfig { - fn default() -> Self { - Self { - billing_frequency: 600, - } - } + pub _data: PhantomData, } #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { + impl BuildGenesisConfig for GenesisConfig { fn build(&self) { BillingFrequency::::put(self.billing_frequency); } @@ -670,7 +662,7 @@ pub mod pallet { weight_used } - fn offchain_worker(block_number: T::BlockNumber) { + fn offchain_worker(block_number: BlockNumberFor) { Self::bill_conttracts_for_block(block_number); } } diff --git a/substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs b/substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs index ba6c73d82..17e5800b6 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs @@ -497,7 +497,7 @@ benchmarks! { let nu = 10; let ipv4 = 8; let minimal_uptime = 9999; - let policy_end = T::BlockNumber::max_value(); + let policy_end = BlockNumberFor::max_value(); let immutable = true; let default = true; let node_certification = NodeCertification::Diy; @@ -680,7 +680,7 @@ benchmarks! { let power = Power::Down; }: _(RawOrigin::Signed(caller), power) verify { - let power_state = PowerState::Down(T::BlockNumber::from(1 as u32)); + let power_state = PowerState::Down(BlockNumberFor::from(1 as u32)); let node_power = TfgridModule::::node_power_state(node_id); assert_eq!(node_power.state, power_state); assert_last_event::(Event::PowerStateChanged { @@ -812,7 +812,7 @@ fn _create_farming_policy() { let nu = 10; let ipv4 = 8; let minimal_uptime = 9999; - let policy_end = T::BlockNumber::max_value(); + let policy_end = BlockNumberFor::max_value(); let immutable = true; let default = true; let node_certification = NodeCertification::Diy; diff --git a/substrate-node/pallets/pallet-tfgrid/src/farm.rs b/substrate-node/pallets/pallet-tfgrid/src/farm.rs index c92f85172..d4f72a9d6 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/farm.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/farm.rs @@ -6,6 +6,7 @@ use frame_support::{ traits::Get, BoundedVec, RuntimeDebug, }; +use frame_system::pallet_prelude::BlockNumberFor; use parity_scale_codec::{Decode, Encode, MaxEncodedLen}; use scale_info::TypeInfo; use sp_std::{marker::PhantomData, vec, vec::Vec}; @@ -269,7 +270,7 @@ impl Pallet { let now = frame_system::Pallet::::block_number(); // Policy end is expressed in number of blocks - if farming_policy.policy_end != T::BlockNumber::from(0 as u32) + if farming_policy.policy_end != BlockNumberFor::::from(0 as u32) && now >= farming_policy.policy_created + farming_policy.policy_end { return Err(DispatchErrorWithPostInfo::from( diff --git a/substrate-node/pallets/pallet-tfgrid/src/lib.rs b/substrate-node/pallets/pallet-tfgrid/src/lib.rs index 0c17d14f9..2888d5e14 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/lib.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/lib.rs @@ -201,7 +201,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn farming_policies_map)] pub type FarmingPoliciesMap = - StorageMap<_, Blake2_128Concat, u32, types::FarmingPolicy, ValueQuery>; + StorageMap<_, Blake2_128Concat, u32, types::FarmingPolicy>, ValueQuery>; // Concrete type for location pub type TermsAndConditionsOf = ::TermsAndConditions; @@ -259,7 +259,7 @@ pub mod pallet { _, Blake2_128Concat, u32, - tfchain_support::types::NodePower, + tfchain_support::types::NodePower>, ValueQuery, >; @@ -412,14 +412,14 @@ pub mod pallet { PricingPolicyStored(types::PricingPolicy), // CertificationCodeStored(types::CertificationCodes), - FarmingPolicyStored(types::FarmingPolicy), + FarmingPolicyStored(types::FarmingPolicy>), FarmPayoutV2AddressRegistered(u32, Vec), FarmMarkedAsDedicated(u32), ConnectionPriceSet(u32), NodeCertificationSet(u32, NodeCertification), NodeCertifierAdded(T::AccountId), NodeCertifierRemoved(T::AccountId), - FarmingPolicyUpdated(types::FarmingPolicy), + FarmingPolicyUpdated(types::FarmingPolicy>), FarmingPolicySet(u32, Option), FarmCertificationSet(u32, FarmCertification), @@ -434,7 +434,7 @@ pub mod pallet { PowerStateChanged { farm_id: u32, node_id: u32, - power_state: PowerState, + power_state: PowerState>, }, } @@ -572,6 +572,7 @@ pub mod pallet { } #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub su_price_value: u32, pub su_price_unit: u32, @@ -599,41 +600,8 @@ pub mod pallet { pub connection_price: u32, } - // The default value for the genesis config type. - #[cfg(feature = "std")] - impl Default for GenesisConfig { - fn default() -> Self { - Self { - su_price_value: Default::default(), - su_price_unit: Default::default(), - nu_price_value: Default::default(), - nu_price_unit: Default::default(), - ipu_price_value: Default::default(), - ipu_price_unit: Default::default(), - cu_price_value: Default::default(), - cu_price_unit: Default::default(), - domain_name_price_value: Default::default(), - unique_name_price_value: Default::default(), - foundation_account: None, - sales_account: None, - discount_for_dedication_nodes: Default::default(), - farming_policy_diy_cu: Default::default(), - farming_policy_diy_nu: Default::default(), - farming_policy_diy_su: Default::default(), - farming_policy_diy_ipu: Default::default(), - farming_policy_diy_minimal_uptime: Default::default(), - farming_policy_certified_cu: Default::default(), - farming_policy_certified_nu: Default::default(), - farming_policy_certified_su: Default::default(), - farming_policy_certified_ipu: Default::default(), - farming_policy_certified_minimal_uptime: Default::default(), - connection_price: Default::default(), - } - } - } - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { + impl BuildGenesisConfig for GenesisConfig { fn build(&self) { let su = types::Policy { value: self.su_price_value, @@ -701,8 +669,8 @@ pub mod pallet { nu: self.farming_policy_diy_nu, ipv4: self.farming_policy_diy_ipu, minimal_uptime: self.farming_policy_diy_minimal_uptime, - policy_created: T::BlockNumber::from(0 as u32), - policy_end: T::BlockNumber::from(0 as u32), + policy_created: BlockNumberFor::::from(0 as u32), + policy_end: BlockNumberFor::::from(0 as u32), immutable: false, default: true, node_certification: NodeCertification::Diy, @@ -723,8 +691,8 @@ pub mod pallet { nu: self.farming_policy_certified_nu, ipv4: self.farming_policy_certified_ipu, minimal_uptime: self.farming_policy_certified_minimal_uptime, - policy_created: T::BlockNumber::from(0 as u32), - policy_end: T::BlockNumber::from(0 as u32), + policy_created: BlockNumberFor::::from(0 as u32), + policy_end: BlockNumberFor::::from(0 as u32), immutable: false, default: true, node_certification: NodeCertification::Certified, @@ -1069,7 +1037,7 @@ pub mod pallet { nu: u32, ipv4: u32, minimal_uptime: u16, - policy_end: T::BlockNumber, + policy_end: BlockNumberFor, immutable: bool, default: bool, node_certification: NodeCertification, @@ -1172,7 +1140,7 @@ pub mod pallet { nu: u32, ipv4: u32, minimal_uptime: u16, - policy_end: T::BlockNumber, + policy_end: BlockNumberFor, default: bool, node_certification: NodeCertification, farm_certification: FarmCertification, @@ -1266,4 +1234,4 @@ pub mod pallet { // #[pallet::call_index(39)] // #[pallet::weight(::WeightInfo::set_node_gpu_status())] } -} \ No newline at end of file +} diff --git a/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs b/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs index 967c9ce73..68dd5c6ba 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/migrations/v14.rs @@ -1,5 +1,6 @@ use crate::{types::FarmingPolicy, *}; use frame_support::{traits::Get, traits::OnRuntimeUpgrade, weights::Weight}; +use frame_system::pallet_prelude::BlockNumberFor; use log::{debug, info}; use sp_std::marker::PhantomData; @@ -69,7 +70,7 @@ pub fn fix_farming_policies_map_migration_() -> frame_support::weight info!(" >>> Migrating farming policies storage..."); let mut read_writes = 0; - FarmingPoliciesMap::::translate::, _>(|k, fp| { + FarmingPoliciesMap::::translate::>, _>(|k, fp| { debug!("Farming policy #{:?}: start migrating", k); debug!(" id was: {:?}", fp.id); let mut new_farming_policy = fp.clone(); diff --git a/substrate-node/pallets/pallet-tfgrid/src/pricing.rs b/substrate-node/pallets/pallet-tfgrid/src/pricing.rs index eb00645eb..9441bbcaf 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/pricing.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/pricing.rs @@ -4,6 +4,7 @@ use frame_support::{ ensure, sp_runtime::SaturatedConversion, }; +use frame_system::pallet_prelude::BlockNumberFor; use sp_std::vec::Vec; use tfchain_support::types::{FarmCertification, NodeCertification}; @@ -108,7 +109,7 @@ impl Pallet { nu: u32, ipv4: u32, minimal_uptime: u16, - policy_end: T::BlockNumber, + policy_end: BlockNumberFor, immutable: bool, default: bool, node_certification: NodeCertification, @@ -152,7 +153,7 @@ impl Pallet { nu: u32, ipv4: u32, minimal_uptime: u16, - policy_end: T::BlockNumber, + policy_end: BlockNumberFor, default: bool, node_certification: NodeCertification, farm_certification: FarmCertification, @@ -190,7 +191,7 @@ impl Pallet { pub fn get_farming_policy( node: &TfgridNode, - ) -> Result, DispatchErrorWithPostInfo> { + ) -> Result>, DispatchErrorWithPostInfo> { let mut farm = Farms::::get(node.farm_id).ok_or(Error::::FarmNotExists)?; // If there is a farming policy defined on the @@ -260,7 +261,7 @@ impl Pallet { // policy which certifications best fit the current // node and farm certifications, considering that in all // cases a default policy would be preferable - let mut policies: Vec> = + let mut policies: Vec>> = FarmingPoliciesMap::::iter().map(|p| p.1).collect(); policies.sort(); @@ -290,8 +291,8 @@ impl Pallet { // Set the default farming policy as the last best certified // farming policy amoung all the default farming policies fn get_default_farming_policy( - ) -> Result, DispatchErrorWithPostInfo> { - let mut policies: Vec> = + ) -> Result>, DispatchErrorWithPostInfo> { + let mut policies: Vec>> = FarmingPoliciesMap::::iter().map(|p| p.1).collect(); policies.sort(); diff --git a/substrate-node/pallets/pallet-tft-bridge/src/lib.rs b/substrate-node/pallets/pallet-tft-bridge/src/lib.rs index 410c5d0a8..077928233 100644 --- a/substrate-node/pallets/pallet-tft-bridge/src/lib.rs +++ b/substrate-node/pallets/pallet-tft-bridge/src/lib.rs @@ -61,7 +61,7 @@ pub mod pallet { _, Blake2_128Concat, Vec, - MintTransaction, + MintTransaction>, OptionQuery, >; @@ -71,7 +71,7 @@ pub mod pallet { _, Blake2_128Concat, Vec, - MintTransaction, + MintTransaction>, OptionQuery, >; @@ -81,7 +81,7 @@ pub mod pallet { _, Blake2_128Concat, u64, - BurnTransaction, + BurnTransaction>, OptionQuery, >; @@ -91,19 +91,19 @@ pub mod pallet { _, Blake2_128Concat, u64, - BurnTransaction, + BurnTransaction>, OptionQuery, >; #[pallet::storage] #[pallet::getter(fn refund_transactions)] pub type RefundTransactions = - StorageMap<_, Blake2_128Concat, Vec, RefundTransaction, ValueQuery>; + StorageMap<_, Blake2_128Concat, Vec, RefundTransaction>, ValueQuery>; #[pallet::storage] #[pallet::getter(fn executed_refund_transactions)] pub type ExecutedRefundTransactions = - StorageMap<_, Blake2_128Concat, Vec, RefundTransaction, ValueQuery>; + StorageMap<_, Blake2_128Concat, Vec, RefundTransaction>, ValueQuery>; #[pallet::storage] #[pallet::getter(fn burn_transaction_id)] @@ -147,20 +147,20 @@ pub mod pallet { // Minting events MintTransactionProposed(Vec, T::AccountId, u64), MintTransactionVoted(Vec), - MintCompleted(MintTransaction), + MintCompleted(MintTransaction>), MintTransactionExpired(Vec, u64, T::AccountId), // Burn events BurnTransactionCreated(u64, T::AccountId, Vec, u64), BurnTransactionProposed(u64, Vec, u64), BurnTransactionSignatureAdded(u64, StellarSignature), BurnTransactionReady(u64), - BurnTransactionProcessed(BurnTransaction), + BurnTransactionProcessed(BurnTransaction>), BurnTransactionExpired(u64, Option, Vec, u64), // Refund events RefundTransactionCreated(Vec, Vec, u64), RefundTransactionsignatureAdded(Vec, StellarSignature), RefundTransactionReady(Vec), - RefundTransactionProcessed(RefundTransaction), + RefundTransactionProcessed(RefundTransaction>), RefundTransactionExpired(Vec, Vec, u64), } @@ -190,6 +190,7 @@ pub mod pallet { } #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub validator_accounts: Option>, pub fee_account: Option, @@ -197,21 +198,8 @@ pub mod pallet { pub deposit_fee: u64, } - // The default value for the genesis config type. - #[cfg(feature = "std")] - impl Default for GenesisConfig { - fn default() -> Self { - Self { - validator_accounts: None, - fee_account: None, - withdraw_fee: Default::default(), - deposit_fee: Default::default(), - } - } - } - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { + impl BuildGenesisConfig for GenesisConfig { fn build(&self) { if let Some(validator_accounts) = &self.validator_accounts { Validators::::put(validator_accounts); @@ -227,7 +215,7 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { - fn on_finalize(block: T::BlockNumber) { + fn on_finalize(block: BlockNumberFor) { let current_block_u64: u64 = block.saturated_into::(); for (tx_id, mut tx) in BurnTransactions::::iter() { diff --git a/substrate-node/pallets/pallet-tft-bridge/src/migrations/types.rs b/substrate-node/pallets/pallet-tft-bridge/src/migrations/types.rs index ad24ae41b..11ae84552 100644 --- a/substrate-node/pallets/pallet-tft-bridge/src/migrations/types.rs +++ b/substrate-node/pallets/pallet-tft-bridge/src/migrations/types.rs @@ -1,5 +1,6 @@ pub mod v1 { use frame_support::{pallet_prelude::ValueQuery, storage_alias, Blake2_128Concat}; + use frame_system::pallet_prelude::BlockNumberFor; use parity_scale_codec::{Decode, Encode}; use scale_info::{prelude::vec::Vec, TypeInfo}; @@ -19,7 +20,7 @@ pub mod v1 { Pallet, Blake2_128Concat, u64, - BurnTransaction<::BlockNumber>, + BurnTransaction>, ValueQuery, >; @@ -28,13 +29,14 @@ pub mod v1 { Pallet, Blake2_128Concat, u64, - BurnTransaction<::BlockNumber>, + BurnTransaction>, ValueQuery, >; } pub mod v2 { use frame_support::{pallet_prelude::OptionQuery, storage_alias, Blake2_128Concat}; + use frame_system::pallet_prelude::BlockNumberFor; use parity_scale_codec::{Decode, Encode}; use scale_info::{prelude::vec::Vec, TypeInfo}; @@ -55,7 +57,7 @@ pub mod v2 { Pallet, Blake2_128Concat, u64, - BurnTransaction<::AccountId, ::BlockNumber>, + BurnTransaction<::AccountId, BlockNumberFor>, OptionQuery, >; @@ -64,7 +66,7 @@ pub mod v2 { Pallet, Blake2_128Concat, u64, - BurnTransaction<::AccountId, ::BlockNumber>, + BurnTransaction<::AccountId, BlockNumberFor>, OptionQuery, >; } diff --git a/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs b/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs index 53075edd9..28cd2598c 100644 --- a/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs +++ b/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs @@ -1,6 +1,11 @@ use crate::*; -use frame_support::log::{debug, info}; -use frame_support::{traits::Get, traits::OnRuntimeUpgrade, weights::Weight}; +use frame_support::{ + log::{debug, info}, + traits::Get, + traits::OnRuntimeUpgrade, + weights::Weight, +}; +use frame_system::pallet_prelude::BlockNumberFor; use sp_std::marker::PhantomData; #[cfg(feature = "try-runtime")] @@ -80,13 +85,13 @@ pub fn migrate_burn_transactions() -> frame_support::weights::Weight let mut read_writes = 0; migrations::types::v2::BurnTransactions::::translate::< - super::types::v1::BurnTransaction, + super::types::v1::BurnTransaction>, _, >(|k, burn_transaction| { debug!("migrated burn transaction: {:?}", k); let new_burn_transaction = - migrations::types::v2::BurnTransaction:: { + migrations::types::v2::BurnTransaction::> { block: burn_transaction.block, amount: burn_transaction.amount, source: None, @@ -100,13 +105,13 @@ pub fn migrate_burn_transactions() -> frame_support::weights::Weight }); migrations::types::v2::ExecutedBurnTransactions::::translate::< - super::types::v1::BurnTransaction, + super::types::v1::BurnTransaction>, _, >(|k, executed_burn_transaction| { debug!("migrated executed burn transaction: {:?}", k); let new_executed_burn_transaction = - migrations::types::v2::BurnTransaction:: { + migrations::types::v2::BurnTransaction::> { block: executed_burn_transaction.block, amount: executed_burn_transaction.amount, source: None, diff --git a/substrate-node/pallets/pallet-tft-bridge/src/tft_bridge.rs b/substrate-node/pallets/pallet-tft-bridge/src/tft_bridge.rs index 5b74b3a49..775f27832 100644 --- a/substrate-node/pallets/pallet-tft-bridge/src/tft_bridge.rs +++ b/substrate-node/pallets/pallet-tft-bridge/src/tft_bridge.rs @@ -5,7 +5,7 @@ use frame_support::{ pallet_prelude::DispatchResultWithPostInfo, traits::{Currency, ExistenceRequirement, OnUnbalanced, WithdrawReasons}, }; -use frame_system as system; +use frame_system::pallet_prelude::BlockNumberFor; use sp_runtime::SaturatedConversion; use sp_std::prelude::*; use substrate_stellar_sdk as stellar; @@ -13,7 +13,7 @@ use substrate_stellar_sdk as stellar; impl Pallet { pub fn mint_tft( tx_id: Vec, - mut tx: MintTransaction, + mut tx: MintTransaction>, ) -> DispatchResultWithPostInfo { let deposit_fee = DepositFee::::get(); ensure!( @@ -37,7 +37,7 @@ impl Pallet { // Remove tx from storage MintTransactions::::remove(tx_id.clone()); // Insert into executed transactions - let now = >::block_number(); + let now = >::block_number(); tx.block = now; ExecutedMintTransactions::::insert(tx_id, &tx); diff --git a/substrate-node/pallets/pallet-tft-price/src/lib.rs b/substrate-node/pallets/pallet-tft-price/src/lib.rs index f07904c54..9357886ed 100644 --- a/substrate-node/pallets/pallet-tft-price/src/lib.rs +++ b/substrate-node/pallets/pallet-tft-price/src/lib.rs @@ -112,7 +112,7 @@ pub mod pallet { #[pallet::storage] #[pallet::getter(fn last_block_set)] - pub type LastBlockSet = StorageValue<_, T::BlockNumber, ValueQuery>; + pub type LastBlockSet = StorageValue<_, BlockNumberFor, ValueQuery>; #[pallet::storage] #[pallet::getter(fn average_tft_price)] @@ -141,7 +141,7 @@ pub mod pallet { pub fn set_prices( origin: OriginFor, price: u32, - block_number: T::BlockNumber, + block_number: BlockNumberFor, ) -> DispatchResultWithPostInfo { let address = ensure_signed(origin)?; @@ -180,7 +180,7 @@ pub mod pallet { #[pallet::hooks] impl Hooks> for Pallet { - fn offchain_worker(block_number: T::BlockNumber) { + fn offchain_worker(block_number: BlockNumberFor) { match Self::offchain_signed_tx(block_number) { Ok(_) => log::info!("offchain worker done."), Err(err) => log::error!("{:?}", err), @@ -189,25 +189,15 @@ pub mod pallet { } #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub min_tft_price: u32, pub max_tft_price: u32, pub _data: PhantomData, } - #[cfg(feature = "std")] - impl Default for GenesisConfig { - fn default() -> Self { - Self { - min_tft_price: 10, - max_tft_price: 1000, - _data: PhantomData, - } - } - } - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { + impl BuildGenesisConfig for GenesisConfig { fn build(&self) { MinTftPrice::::put(self.min_tft_price); MaxTftPrice::::put(self.max_tft_price); diff --git a/substrate-node/pallets/pallet-tft-price/src/tft_price.rs b/substrate-node/pallets/pallet-tft-price/src/tft_price.rs index a5609f466..9e9f0e6b0 100644 --- a/substrate-node/pallets/pallet-tft-price/src/tft_price.rs +++ b/substrate-node/pallets/pallet-tft-price/src/tft_price.rs @@ -1,6 +1,9 @@ use super::*; use frame_support::{dispatch::DispatchResultWithPostInfo, pallet_prelude::Pays}; -use frame_system::offchain::{SendSignedTransaction, SignMessage, Signer}; +use frame_system::{ + offchain::{SendSignedTransaction, SignMessage, Signer}, + pallet_prelude::BlockNumberFor, +}; use ringbuffer::{RingBufferTrait, RingBufferTransient}; use scale_info::prelude::format; use serde_json::Value; @@ -24,7 +27,7 @@ pub const DST_AMOUNT: u32 = 100; impl Pallet { pub(crate) fn calculate_and_set_price( price: u32, - block_number: T::BlockNumber, + block_number: BlockNumberFor, ) -> DispatchResultWithPostInfo { log::info!("price {:?}", price); @@ -111,7 +114,7 @@ impl Pallet { Ok(tft_usd) } - pub(crate) fn offchain_signed_tx(block_number: T::BlockNumber) -> Result<(), Error> { + pub(crate) fn offchain_signed_tx(block_number: BlockNumberFor) -> Result<(), Error> { let signer = Signer::::AuthorityId>::any_account(); // Only allow the author of the next block to trigger price fetching @@ -120,7 +123,7 @@ impl Pallet { Err(_) => return Ok(()), } - let last_block_set: T::BlockNumber = LastBlockSet::::get(); + let last_block_set: BlockNumberFor = LastBlockSet::::get(); // Fetch the price every 1 minutes if block_number.saturated_into::() - last_block_set.saturated_into::() < 10 { return Ok(()); diff --git a/substrate-node/pallets/pallet-validator/src/lib.rs b/substrate-node/pallets/pallet-validator/src/lib.rs index 1d71586ca..e8263a172 100644 --- a/substrate-node/pallets/pallet-validator/src/lib.rs +++ b/substrate-node/pallets/pallet-validator/src/lib.rs @@ -93,21 +93,13 @@ pub mod pallet { impl Hooks> for Pallet {} #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub validators: Vec, } - #[cfg(feature = "std")] - impl Default for GenesisConfig { - fn default() -> Self { - Self { - validators: Vec::new(), - } - } - } - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { + impl BuildGenesisConfig for GenesisConfig { fn build(&self) {} } diff --git a/substrate-node/pallets/substrate-validator-set/src/lib.rs b/substrate-node/pallets/substrate-validator-set/src/lib.rs index 73547359d..31c94b3e9 100644 --- a/substrate-node/pallets/substrate-validator-set/src/lib.rs +++ b/substrate-node/pallets/substrate-validator-set/src/lib.rs @@ -102,21 +102,13 @@ pub mod pallet { impl Hooks> for Pallet {} #[pallet::genesis_config] + #[derive(frame_support::DefaultNoBound)] pub struct GenesisConfig { pub initial_validators: Vec, } - #[cfg(feature = "std")] - impl Default for GenesisConfig { - fn default() -> Self { - Self { - initial_validators: Default::default(), - } - } - } - #[pallet::genesis_build] - impl GenesisBuild for GenesisConfig { + impl BuildGenesisConfig for GenesisConfig { fn build(&self) { Pallet::::initialize_validators(&self.initial_validators); } @@ -206,20 +198,20 @@ pub mod pallet { fn start_session(_start_index: u32) {} } - impl EstimateNextSessionRotation for Pallet { - fn average_session_length() -> T::BlockNumber { + impl EstimateNextSessionRotation> for Pallet { + fn average_session_length() -> BlockNumberFor { Zero::zero() } fn estimate_current_session_progress( - _now: T::BlockNumber, + _now: BlockNumberFor, ) -> (Option, frame_support::dispatch::Weight) { (None, Zero::zero()) } fn estimate_next_session_rotation( - _now: T::BlockNumber, - ) -> (Option, frame_support::dispatch::Weight) { + _now: BlockNumberFor, + ) -> (Option>, frame_support::dispatch::Weight) { (None, Zero::zero()) } } From c8439313daab6774110c45728a78fd677a744b03 Mon Sep 17 00:00:00 2001 From: renauter Date: Mon, 27 Nov 2023 23:14:13 -0300 Subject: [PATCH 16/25] update pallets mock --- .../pallets/pallet-burning/src/mock.rs | 30 +++++------ substrate-node/pallets/pallet-dao/src/mock.rs | 28 ++++------ .../pallets/pallet-kvstore/README.md | 52 +++++++++++-------- .../pallets/pallet-kvstore/src/tests.rs | 27 ++++------ .../pallets/pallet-smart-contract/src/mock.rs | 33 +++++------- .../pallets/pallet-tfgrid/src/mock.rs | 35 +++++-------- .../pallets/pallet-tft-bridge/src/mock.rs | 29 +++++------ .../pallets/pallet-tft-price/src/mock.rs | 29 +++++------ .../pallets/pallet-validator/src/mock.rs | 31 +++++------ .../pallets/substrate-validator-set/readme.md | 29 +++++------ .../substrate-validator-set/src/mock.rs | 31 +++++------ 11 files changed, 156 insertions(+), 198 deletions(-) diff --git a/substrate-node/pallets/pallet-burning/src/mock.rs b/substrate-node/pallets/pallet-burning/src/mock.rs index a8701a91e..24a7faac0 100644 --- a/substrate-node/pallets/pallet-burning/src/mock.rs +++ b/substrate-node/pallets/pallet-burning/src/mock.rs @@ -6,10 +6,9 @@ use frame_support::{construct_runtime, parameter_types, traits::ConstU32}; use pallet_balances; use sp_core::{sr25519, Pair, Public, H256}; use sp_runtime::{ - testing::Header, traits::{BlakeTwo256, IdentityLookup}, traits::{IdentifyAccount, Verify}, - MultiSignature, + BuildStorage, MultiSignature, }; use sp_std::convert::{TryFrom, TryInto}; @@ -17,16 +16,12 @@ pub type Signature = MultiSignature; pub type AccountId = <::Signer as IdentifyAccount>::AccountId; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; construct_runtime!( - pub enum TestRuntime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum TestRuntime { - System: frame_system::{Pallet, Call, Config, Storage, Event}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, BurningModule: pallet_burning::{Pallet, Call, Event}, } @@ -38,25 +33,24 @@ parameter_types! { impl frame_system::Config for TestRuntime { type BaseCallFilter = frame_support::traits::Everything; + type Block = Block; type BlockWeights = (); type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; + type AccountId = AccountId; type RuntimeCall = RuntimeCall; - type BlockNumber = u64; + type Lookup = IdentityLookup; + type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); + type AccountData = pallet_balances::AccountData; type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); @@ -83,7 +77,7 @@ impl pallet_balances::Config for TestRuntime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type FreezeIdentifier = (); type MaxFreezes = (); - type HoldIdentifier = (); + type RuntimeHoldReason = (); type MaxHolds = (); } @@ -121,8 +115,8 @@ pub fn bob() -> AccountId { } pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default() - .build_storage::() + let mut t = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); let genesis = pallet_balances::GenesisConfig:: { balances: vec![(alice(), 1000000000000), (bob(), 2500000000)], diff --git a/substrate-node/pallets/pallet-dao/src/mock.rs b/substrate-node/pallets/pallet-dao/src/mock.rs index e15828f0a..3044ba6be 100644 --- a/substrate-node/pallets/pallet-dao/src/mock.rs +++ b/substrate-node/pallets/pallet-dao/src/mock.rs @@ -1,4 +1,3 @@ -use crate::mock::sp_api_hidden_includes_construct_runtime::hidden_include::traits::GenesisBuild; use crate::{self as pallet_dao}; use frame_support::{construct_runtime, parameter_types, traits::ConstU32, BoundedVec}; use frame_system::EnsureRoot; @@ -14,24 +13,20 @@ use pallet_tfgrid::{ use pallet_timestamp; use sp_core::H256; use sp_runtime::{ - testing::Header, traits::{BlakeTwo256, IdentityLookup}, + BuildStorage, }; use sp_std::convert::{TryFrom, TryInto}; use tfchain_support::traits::{ChangeNode, PublicIpModifier}; use tfchain_support::types::PublicIP; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; // Configure a mock runtime to test the pallet. construct_runtime!( - pub enum TestRuntime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum TestRuntime { - System: frame_system::{Pallet, Call, Config, Storage, Event}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, DaoModule: pallet_dao::pallet::{Pallet, Call, Storage, Event}, TfgridModule: pallet_tfgrid::{Pallet, Call, Storage, Event}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, @@ -46,25 +41,24 @@ parameter_types! { impl frame_system::Config for TestRuntime { type BaseCallFilter = frame_support::traits::Everything; + type Block = Block; type BlockWeights = (); type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; + type AccountId = u64; type RuntimeCall = RuntimeCall; - type BlockNumber = u64; + type Lookup = IdentityLookup; + type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); + type AccountData = (); type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); @@ -235,8 +229,8 @@ pub(crate) fn get_longitude_input(longitude_input: &[u8]) -> LongitudeInput { // Build genesis storage according to the mock runtime. pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default() - .build_storage::() + let mut t = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); let genesis = pallet_collective::GenesisConfig::::default(); diff --git a/substrate-node/pallets/pallet-kvstore/README.md b/substrate-node/pallets/pallet-kvstore/README.md index 6710d114c..47fcd9d51 100644 --- a/substrate-node/pallets/pallet-kvstore/README.md +++ b/substrate-node/pallets/pallet-kvstore/README.md @@ -7,9 +7,10 @@ Some use cases for this module are storing user profiles, preferences, or settin ## Overview The Key-value Store Pallet provides [dictionary-like data storage](https://paritytech.github.io/substrate/master/frame_support/storage/trait.StorageDoubleMap.html#) and functions for: -- Storing key-value pairs. -- Retrieving the value associated with the specified key. -- Removing a value associated with the specified key. + +* Storing key-value pairs. +* Retrieving the value associated with the specified key. +* Removing a value associated with the specified key. The key value store uses under hood a map with two keys @@ -17,36 +18,42 @@ The key value store uses under hood a map with two keys **Key1** is provided by the runtime set to the account that signed the extrinsic. **Key2** and **Value** are user provided -You can think of the key1 as namespace that make it easier to come up with unique names which distinguished from other accounts' names. +You can think of the key1 as namespace that make it easier to come up with unique names which distinguished from other accounts' names. The key value store pallet impose restrictions on the size of the keys and values. see [Assumptions](#assumptions) section. ## Terminology -- Key-value store: A key-value store, or key-value database is a simple database that uses an associative array (think of a map or dictionary) as the fundamental data model where each key is associated with one and only one value in a collection. This relationship is referred to as a key-value pair. + +* Key-value store: A key-value store, or key-value database is a simple database that uses an associative array (think of a map or dictionary) as the fundamental data model where each key is associated with one and only one value in a collection. This relationship is referred to as a key-value pair. ## Implementations + NA ## Interface + ### Dispatchable Functions -- `set(key: Vec, value: Vec)` store value for a pair of keys (key1, key2) in the store. The first key is automatically set to the account ID of the signer of the transaction, while the second key is given by the user. This way, you can assign ownership of a key to the account that created it, and also use freely any name for a key that might be already taken by someone else. If the key pair already exists in the store, the value is overwritten with the new one. Emits `EntrySet` event. -- `delete(key: Vec)` remove a value stored under a pair of keys (key1, key2) from the store. The first key is automatically set to the account ID of the sender of the transaction, while the second key is given by the user. so by design, only the owner of a key pair can delete it from the store. Emits `EntryTaken` event. +* `set(key: Vec, value: Vec)` store value for a pair of keys (key1, key2) in the store. The first key is automatically set to the account ID of the signer of the transaction, while the second key is given by the user. This way, you can assign ownership of a key to the account that created it, and also use freely any name for a key that might be already taken by someone else. If the key pair already exists in the store, the value is overwritten with the new one. Emits `EntrySet` event. +* `delete(key: Vec)` remove a value stored under a pair of keys (key1, key2) from the store. The first key is automatically set to the account ID of the sender of the transaction, while the second key is given by the user. so by design, only the owner of a key pair can delete it from the store. Emits `EntryTaken` event. ### Events -- `EntrySet(T::AccountId, Vec, Vec)` The value for the specified key has been stored/updated. -- `EntryGot(T::AccountId, Vec, Vec)` The value for the specified key has been queried. (This Event Defined But Not Used By the runtime) -- `EntryTaken(T::AccountId, Vec, Vec)` The value stored under the specified key has been removed. + +* `EntrySet(T::AccountId, Vec, Vec)` The value for the specified key has been stored/updated. +* `EntryGot(T::AccountId, Vec, Vec)` The value for the specified key has been queried. (This Event Defined But Not Used By the runtime) +* `EntryTaken(T::AccountId, Vec, Vec)` The value stored under the specified key has been removed. All events included account id, the user key name and the value. ### Errors -- `NoValueStored` The double key (Account ID, Provided Key) is not in the `StorageDoubleMap` -- `KeyIsTooLarge` The key length exceed the maximum length. see [Assumptions](#assumptions) section. -- `ValueIsTooLarge` The key length exceed the maximum length. see [Assumptions](#assumptions) section. + +* `NoValueStored` The double key (Account ID, Provided Key) is not in the `StorageDoubleMap` +* `KeyIsTooLarge` The key length exceed the maximum length. see [Assumptions](#assumptions) section. +* `ValueIsTooLarge` The key length exceed the maximum length. see [Assumptions](#assumptions) section. ## Config + ```rust pub trait Config: Config { type RuntimeEvent: From> + IsType<::RuntimeEvent>; @@ -59,6 +66,7 @@ The main purpose of this trait is to act as an interface between this pallet and Consequently, a runtime that wants to include this pallet must implement this trait. ### Required Associated Types + ```rust type RuntimeEvent: From> + IsType<::RuntimeEvent> ``` @@ -72,17 +80,16 @@ type WeightInfo: WeightInfo Weight information for extrinsics in this pallet. ## Usage + The following example shows how to use the key value store pallet in your runtime: + ```rust // Import the key value store pallet pub use pallet_kvstore; // Add it to your runtime configuration construct_runtime!( - pub enum Runtime where - Block = Block, - NodeBlock = opaque::Block, - UncheckedExtrinsic = UncheckedExtrinsic + pub enum Runtime { // ... KeyValueStore: pallet_kvstore::{Pallet, Call, Storage, Event}, @@ -95,11 +102,14 @@ impl pallet_kvstore::Config for Runtime { type WeightInfo = pallet_kvstore::weights::SubstrateWeight; } ``` + ## Genesis config + NA ## Assumptions -- The key length must not exceed 512 bytes. -- The value length must not exceed 2048 bytes. -- The user is responsible for ensuring the uniqueness of the key within their account, otherwise the previous value associated with the key will be replaced or updated. -- The stored information is publicly accessible and queryable. This means that anyone can see your data without your permission. The user must not store any sensitive information unencrypted, such as personal details, passwords, credit card numbers, or confidential information. Doing so can have serious consequences. Please use encryption tools to protect your sensitive data before storing it on this store. + +* The key length must not exceed 512 bytes. +* The value length must not exceed 2048 bytes. +* The user is responsible for ensuring the uniqueness of the key within their account, otherwise the previous value associated with the key will be replaced or updated. +* The stored information is publicly accessible and queryable. This means that anyone can see your data without your permission. The user must not store any sensitive information unencrypted, such as personal details, passwords, credit card numbers, or confidential information. Doing so can have serious consequences. Please use encryption tools to protect your sensitive data before storing it on this store. diff --git a/substrate-node/pallets/pallet-kvstore/src/tests.rs b/substrate-node/pallets/pallet-kvstore/src/tests.rs index 8f12d1e95..461060f1a 100644 --- a/substrate-node/pallets/pallet-kvstore/src/tests.rs +++ b/substrate-node/pallets/pallet-kvstore/src/tests.rs @@ -6,21 +6,17 @@ use frame_system::{EventRecord, Phase}; use sp_core::H256; use sp_io::TestExternalities; use sp_runtime::{ - testing::Header, traits::{BlakeTwo256, IdentityLookup}, + BuildStorage, }; use sp_std::convert::{TryFrom, TryInto}; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; construct_runtime!( - pub enum TestRuntime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum TestRuntime { - System: frame_system::{Pallet, Call, Config, Storage, Event}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, TFKVStoreModule: pallet_kvstore::{Pallet, Call, Storage, Event}, } ); @@ -31,25 +27,24 @@ parameter_types! { impl frame_system::Config for TestRuntime { type BaseCallFilter = frame_support::traits::Everything; + type Block = Block; type BlockWeights = (); type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; + type AccountId = u64; type RuntimeCall = RuntimeCall; - type BlockNumber = u64; + type Lookup = IdentityLookup; + type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); + type AccountData = (); type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); @@ -66,8 +61,8 @@ pub struct ExternalityBuilder; impl ExternalityBuilder { pub fn build() -> TestExternalities { - let storage = frame_system::GenesisConfig::default() - .build_storage::() + let storage = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); let mut ext = TestExternalities::from(storage); ext.execute_with(|| System::set_block_number(1)); diff --git a/substrate-node/pallets/pallet-smart-contract/src/mock.rs b/substrate-node/pallets/pallet-smart-contract/src/mock.rs index a79e65af6..cc765f286 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/mock.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/mock.rs @@ -6,7 +6,7 @@ use frame_support::{ dispatch::DispatchErrorWithPostInfo, dispatch::PostDispatchInfo, parameter_types, - traits::{ConstU32, EitherOfDiverse, GenesisBuild}, + traits::{ConstU32, EitherOfDiverse}, BoundedVec, }; use frame_system::EnsureRoot; @@ -33,11 +33,11 @@ use sp_keystore::{testing::MemoryKeystore, Keystore, KeystoreExt}; use sp_runtime::{ impl_opaque_keys, offchain::TransactionPool, - testing::{Header, TestXt, UintAuthorityId}, + testing::{TestXt, UintAuthorityId}, traits::{ BlakeTwo256, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, OpaqueKeys, Verify, }, - AccountId32, MultiSignature, + AccountId32, BuildStorage, MultiSignature, }; use sp_std::{ convert::{TryFrom, TryInto}, @@ -96,16 +96,12 @@ pub type AccountId = <::Signer as IdentifyAccount>::Account pub type Moment = u64; pub type Extrinsic = TestXt; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; construct_runtime!( - pub enum TestRuntime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum TestRuntime { - System: frame_system::{Pallet, Call, Config, Storage, Event}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, TfgridModule: pallet_tfgrid::{Pallet, Call, Storage, Event}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, @@ -125,25 +121,24 @@ parameter_types! { impl frame_system::Config for TestRuntime { type BaseCallFilter = frame_support::traits::Everything; + type Block = Block; type BlockWeights = (); type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; + type AccountId = AccountId; type RuntimeCall = RuntimeCall; - type BlockNumber = u64; + type Lookup = IdentityLookup; + type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); + type AccountData = pallet_balances::AccountData; type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); @@ -172,7 +167,7 @@ impl pallet_balances::Config for TestRuntime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type FreezeIdentifier = (); type MaxFreezes = (); - type HoldIdentifier = (); + type RuntimeHoldReason = (); type MaxHolds = (); } @@ -512,8 +507,8 @@ pub fn new_test_ext() -> sp_io::TestExternalities { // for showing logs in tests let _ = env_logger::try_init(); - let mut storage = frame_system::GenesisConfig::default() - .build_storage::() + let mut storage = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); let genesis = pallet_balances::GenesisConfig:: { balances: vec![ diff --git a/substrate-node/pallets/pallet-tfgrid/src/mock.rs b/substrate-node/pallets/pallet-tfgrid/src/mock.rs index e7c8d6d4d..5b636a10d 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/mock.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/mock.rs @@ -2,7 +2,6 @@ use crate::{ self as tfgridModule, farm::FarmName, interface::{InterfaceIp, InterfaceMac, InterfaceName}, - mock::sp_api_hidden_includes_construct_runtime::hidden_include::traits::GenesisBuild, node::{CityName, CountryName, Location, SerialNumber}, terms_cond::TermsAndConditions, weights, CityNameInput, Config, CountryNameInput, DocumentHashInput, DocumentLinkInput, @@ -15,9 +14,8 @@ use frame_system::EnsureRoot; use sp_core::{ed25519, sr25519, Pair, Public, H256}; use sp_io::TestExternalities; use sp_runtime::{ - testing::Header, traits::{BlakeTwo256, IdentifyAccount, IdentityLookup, Verify}, - MultiSignature, + BuildStorage, MultiSignature, }; use sp_std::prelude::*; @@ -29,17 +27,13 @@ pub type Signature = MultiSignature; pub type AccountId = <::Signer as IdentifyAccount>::AccountId; pub type Moment = u64; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; construct_runtime!( - pub enum TestRuntime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum TestRuntime { Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, - System: frame_system::{Pallet, Call, Config, Storage, Event}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, TfgridModule: tfgridModule::{Pallet, Call, Storage, Config, Event}, Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent}, Council: pallet_collective::::{Pallet, Call, Origin, Event, Config}, @@ -54,25 +48,24 @@ parameter_types! { impl frame_system::Config for TestRuntime { type BaseCallFilter = frame_support::traits::Everything; + type Block = Block; type BlockWeights = (); type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; + type AccountId = AccountId; type RuntimeCall = RuntimeCall; - type BlockNumber = u64; + type Lookup = IdentityLookup; + type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); + type AccountData = pallet_balances::AccountData; type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); @@ -158,7 +151,7 @@ impl pallet_balances::Config for TestRuntime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type FreezeIdentifier = (); type MaxFreezes = (); - type HoldIdentifier = (); + type RuntimeHoldReason = (); type MaxHolds = (); } @@ -208,8 +201,8 @@ impl ExternalityBuilder { pub fn build() -> TestExternalities { let _ = env_logger::try_init(); - let storage = frame_system::GenesisConfig::default() - .build_storage::() + let storage = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); let mut ext = TestExternalities::from(storage); ext.execute_with(|| System::set_block_number(1)); @@ -221,8 +214,8 @@ type AccountPublic = ::Signer; pub fn new_test_ext() -> sp_io::TestExternalities { let _ = env_logger::try_init(); - let mut t = frame_system::GenesisConfig::default() - .build_storage::() + let mut t = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); let genesis = pallet_balances::GenesisConfig:: { diff --git a/substrate-node/pallets/pallet-tft-bridge/src/mock.rs b/substrate-node/pallets/pallet-tft-bridge/src/mock.rs index 106df1d76..0f3c32605 100644 --- a/substrate-node/pallets/pallet-tft-bridge/src/mock.rs +++ b/substrate-node/pallets/pallet-tft-bridge/src/mock.rs @@ -8,8 +8,8 @@ use sp_core::{sr25519, Pair, Public, H256}; use sp_runtime::traits::{IdentifyAccount, Verify}; use sp_runtime::MultiSignature; use sp_runtime::{ - testing::Header, traits::{BlakeTwo256, IdentityLookup}, + BuildStorage, }; use pallet_balances; @@ -18,16 +18,12 @@ pub type Signature = MultiSignature; pub type AccountId = <::Signer as IdentifyAccount>::AccountId; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; construct_runtime!( - pub enum TestRuntime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum TestRuntime { - System: frame_system::{Pallet, Call, Config, Storage, Event}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, TFTBridgeModule: pallet_tft_bridge::{Pallet, Storage, Call, Event}, Balances: pallet_balances::{Pallet, Call, Storage, Config, Event}, } @@ -42,25 +38,24 @@ parameter_types! { impl frame_system::Config for TestRuntime { type BaseCallFilter = frame_support::traits::Everything; + type Block = Block; type BlockWeights = (); type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; + type AccountId = AccountId; type RuntimeCall = RuntimeCall; - type BlockNumber = u64; + type Lookup = IdentityLookup; + type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = pallet_balances::AccountData; type OnNewAccount = (); type OnKilledAccount = (); + type AccountData = pallet_balances::AccountData; type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); @@ -86,7 +81,7 @@ impl pallet_balances::Config for TestRuntime { type WeightInfo = pallet_balances::weights::SubstrateWeight; type FreezeIdentifier = (); type MaxFreezes = (); - type HoldIdentifier = (); + type RuntimeHoldReason = (); type MaxHolds = (); } @@ -138,8 +133,8 @@ pub fn eve() -> AccountId { } pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default() - .build_storage::() + let mut t = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); let genesis = pallet_balances::GenesisConfig:: { balances: vec![(alice(), 1000000000000), (bob(), 2500000000)], diff --git a/substrate-node/pallets/pallet-tft-price/src/mock.rs b/substrate-node/pallets/pallet-tft-price/src/mock.rs index d089ad626..2fe51e333 100644 --- a/substrate-node/pallets/pallet-tft-price/src/mock.rs +++ b/substrate-node/pallets/pallet-tft-price/src/mock.rs @@ -2,7 +2,6 @@ use super::*; use crate::{self as pallet_tft_price, tft_price::KEY_TYPE}; -use frame_support::traits::GenesisBuild; use frame_support::{construct_runtime, parameter_types, traits::ConstU32}; use frame_system::mocking; use frame_system::EnsureRoot; @@ -17,11 +16,11 @@ use sp_io::TestExternalities; use sp_keystore::{testing::MemoryKeystore, Keystore, KeystoreExt}; use sp_runtime::{ impl_opaque_keys, - testing::{Header, UintAuthorityId}, + testing::UintAuthorityId, traits::{ BlakeTwo256, Extrinsic as ExtrinsicT, IdentifyAccount, IdentityLookup, OpaqueKeys, Verify, }, - MultiSignature, + BuildStorage, MultiSignature, }; use sp_std::marker::PhantomData; use std::cell::RefCell; @@ -71,12 +70,9 @@ impl OpaqueKeys for PreUpgradeMockSessionKeys { // For testing the module, we construct a mock runtime. construct_runtime!( - pub enum TestRuntime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum TestRuntime { - System: frame_system::{Pallet, Call, Config, Storage, Event}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, TFTPriceModule: pallet_tft_price::{Pallet, Call, Storage, Config, Event}, Authorship: pallet_authorship::{Pallet, Storage}, ValidatorSet: substrate_validator_set::{Event}, @@ -90,25 +86,24 @@ parameter_types! { impl frame_system::Config for TestRuntime { type BaseCallFilter = frame_support::traits::Everything; + type Block = Block; type BlockWeights = (); type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; + type AccountId = AccountId; type RuntimeCall = RuntimeCall; - type BlockNumber = u64; + type Lookup = IdentityLookup; + type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = AccountId; - type Lookup = IdentityLookup; - type Header = Header; type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); + type AccountData = (); type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); @@ -274,8 +269,8 @@ impl ExternalityBuilder { .sr25519_generate_new(KEY_TYPE, Some(&format!("{}/hunter1", PHRASE))) .unwrap(); - let mut storage = frame_system::GenesisConfig::default() - .build_storage::() + let mut storage = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); let session_genesis = pallet_session::GenesisConfig:: { diff --git a/substrate-node/pallets/pallet-validator/src/mock.rs b/substrate-node/pallets/pallet-validator/src/mock.rs index 137208f5e..b89849f8b 100644 --- a/substrate-node/pallets/pallet-validator/src/mock.rs +++ b/substrate-node/pallets/pallet-validator/src/mock.rs @@ -1,27 +1,23 @@ use crate as pallet_validator; use core::cell::RefCell; -use frame_support::{bounded_vec, construct_runtime, parameter_types, traits::{ConstU32, GenesisBuild}}; +use frame_support::{bounded_vec, construct_runtime, parameter_types, traits::ConstU32}; use frame_system::EnsureRoot; use pallet_session::{SessionHandler, ShouldEndSession}; use sp_core::{crypto::key_types::DUMMY, H256}; use sp_runtime::{ impl_opaque_keys, - testing::{Header, UintAuthorityId}, + testing::UintAuthorityId, traits::{BlakeTwo256, IdentityLookup, OpaqueKeys}, - RuntimeAppPublic, + BuildStorage, RuntimeAppPublic, }; use sp_std::convert::{TryFrom, TryInto}; -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; construct_runtime!( - pub enum TestRuntime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum TestRuntime { - System: frame_system::{Pallet, Call, Config, Storage, Event}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, Session: pallet_session::{Pallet, Call, Storage, Event, Config}, ValidatorModule: pallet_validator::{Pallet, Call, Storage, Event}, Council: pallet_collective::::{Pallet, Call, Origin, Event, Config}, @@ -44,25 +40,24 @@ parameter_types! { impl frame_system::Config for TestRuntime { type BaseCallFilter = frame_support::traits::Everything; + type Block = Block; type BlockWeights = (); type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; + type AccountId = u64; type RuntimeCall = RuntimeCall; - type BlockNumber = u64; + type Lookup = IdentityLookup; + type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); + type AccountData = (); type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); @@ -181,8 +176,8 @@ impl pallet_membership::Config for TestRuntime { } pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default() - .build_storage::() + let mut t = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); let genesis = pallet_collective::GenesisConfig::::default(); diff --git a/substrate-node/pallets/substrate-validator-set/readme.md b/substrate-node/pallets/substrate-validator-set/readme.md index 3780c09a7..e1eb2ca35 100644 --- a/substrate-node/pallets/substrate-validator-set/readme.md +++ b/substrate-node/pallets/substrate-validator-set/readme.md @@ -4,7 +4,7 @@ Code changes are in `diff.patch` -A [Substrate](https://github.com/paritytech/substrate/) pallet to add/remove validators using extrinsics, in Substrate-based PoA networks. +A [Substrate](https://github.com/paritytech/substrate/) pallet to add/remove validators using extrinsics, in Substrate-based PoA networks. **Note: Current build is compatible with Substrate [v3.0.0](https://github.com/paritytech/substrate/releases/tag/v3.0.0) release.** @@ -14,7 +14,7 @@ To see this pallet in action in a Substrate runtime, watch this video - https:// ## Setup with Substrate Node Template -* Add the module's dependency in the `Cargo.toml` of your runtime directory. Make sure to enter the correct path or git url of the pallet as per your setup. +* Add the module's dependency in the `Cargo.toml` of your runtime directory. Make sure to enter the correct path or git url of the pallet as per your setup. ```toml validatorset = { @@ -33,9 +33,9 @@ std = [ ] ``` -* Make sure that you also have the Substrate [session pallet](https://github.com/paritytech/substrate/tree/master/frame/session) as part of your runtime. This is because the validator-set pallet is based on the session pallet. +* Make sure that you also have the Substrate [session pallet](https://github.com/paritytech/substrate/tree/master/frame/session) as part of your runtime. This is because the validator-set pallet is based on the session pallet. -* Import `OpaqueKeys` in your `runtime/src/lib.rs`. +* Import `OpaqueKeys` in your `runtime/src/lib.rs`. ```rust use sp_runtime::traits::{ @@ -43,7 +43,7 @@ use sp_runtime::traits::{ }; ``` -* Declare the pallet in your `runtime/src/lib.rs`. +* Declare the pallet in your `runtime/src/lib.rs`. ```rust impl validatorset::Config for Runtime { @@ -51,7 +51,7 @@ impl validatorset::Config for Runtime { } ``` -* Also, declare the session pallet in your `runtime/src/lib.rs`. The type configuration of session pallet would depend on the ValidatorSet pallet as shown below. +* Also, declare the session pallet in your `runtime/src/lib.rs`. The type configuration of session pallet would depend on the ValidatorSet pallet as shown below. ```rust impl pallet_session::Config for Runtime { @@ -68,17 +68,14 @@ impl pallet_session::Config for Runtime { } ``` -* Add both `session` and `validatorset` pallets in `construct_runtime` macro. **Make sure to add them before `Aura` and `Grandpa` pallets and after `Balances`.** +* Add both `session` and `validatorset` pallets in `construct_runtime` macro. **Make sure to add them before `Aura` and `Grandpa` pallets and after `Balances`.** ```rust construct_runtime!( - pub enum Runtime where - Block = Block, - NodeBlock = opaque::Block, - UncheckedExtrinsic = UncheckedExtrinsic + pub enum Runtime { ... - Balances: pallet_balances::{Module, Call, Storage, Config, Event}, + Balances: pallet_balances::{Module, Call, Storage, Config, Event}, Session: pallet_session::{Module, Call, Storage, Event, Config}, ValidatorSet: validatorset::{Module, Call, Storage, Event, Config}, Aura: aura::{Module, Config, Inherent(Timestamp)}, @@ -89,7 +86,7 @@ construct_runtime!( ); ``` -* Add genesis config in the `chain_spec.rs` file for `session` and `validatorset` pallets, and update it for `Aura` and `Grandpa` pallets. Because the validators are provided by the `session` pallet, we do not initialize them explicitly for `Aura` and `Grandpa` pallets. Order is important, notice that `pallet_session` is declared after `pallet_balances` since it depends on it (session accounts should have some balance). +* Add genesis config in the `chain_spec.rs` file for `session` and `validatorset` pallets, and update it for `Aura` and `Grandpa` pallets. Because the validators are provided by the `session` pallet, we do not initialize them explicitly for `Aura` and `Grandpa` pallets. Order is important, notice that `pallet_session` is declared after `pallet_balances` since it depends on it (session accounts should have some balance). ```rust fn testnet_genesis(initial_authorities: Vec<(AccountId, AuraId, GrandpaId)>, @@ -119,7 +116,7 @@ fn testnet_genesis(initial_authorities: Vec<(AccountId, AuraId, GrandpaId)>, } ``` -* Make sure you have the same number and order of session keys for your runtime. First in `runtime/src/lib.rs`: +* Make sure you have the same number and order of session keys for your runtime. First in `runtime/src/lib.rs`: ```rust pub struct SessionKeys { @@ -128,7 +125,7 @@ pub struct SessionKeys { } ``` -* And then in `src/chain_spec.rs`: +* And then in `src/chain_spec.rs`: ```rust fn session_keys( @@ -151,7 +148,7 @@ pub fn authority_keys_from_seed(seed: &str) -> ( } ``` -* `cargo build --release` and then `cargo run --release -- --dev` +* `cargo build --release` and then `cargo run --release -- --dev` ## Sample diff --git a/substrate-node/pallets/substrate-validator-set/src/mock.rs b/substrate-node/pallets/substrate-validator-set/src/mock.rs index 59baa0ea3..0b5ecdeec 100644 --- a/substrate-node/pallets/substrate-validator-set/src/mock.rs +++ b/substrate-node/pallets/substrate-validator-set/src/mock.rs @@ -3,16 +3,16 @@ #![cfg(test)] use crate as validator_set; -use frame_support::{parameter_types, traits::ConstU32, traits::GenesisBuild, BasicExternalities}; +use frame_support::{parameter_types, traits::ConstU32, BasicExternalities}; use frame_system::EnsureRoot; use pallet_session::*; use parity_scale_codec::{Decode, Encode}; use sp_core::{crypto::key_types::DUMMY, H256}; use sp_runtime::{ impl_opaque_keys, - testing::{Header, UintAuthorityId}, + testing::UintAuthorityId, traits::{BlakeTwo256, IdentityLookup, OpaqueKeys}, - KeyTypeId, RuntimeAppPublic, + BuildStorage, KeyTypeId, RuntimeAppPublic, }; use sp_std::convert::{TryFrom, TryInto}; use std::cell::RefCell; @@ -54,16 +54,12 @@ impl OpaqueKeys for PreUpgradeMockSessionKeys { } } -type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic; type Block = frame_system::mocking::MockBlock; frame_support::construct_runtime!( - pub enum TestRuntime where - Block = Block, - NodeBlock = Block, - UncheckedExtrinsic = UncheckedExtrinsic, + pub enum TestRuntime { - System: frame_system::{Pallet, Call, Config, Storage, Event}, + System: frame_system::{Pallet, Call, Config, Storage, Event}, ValidatorSet: validator_set::{Pallet, Call, Storage, Event, Config}, Session: pallet_session::{Pallet, Call, Storage, Event, Config}, } @@ -124,8 +120,8 @@ pub fn authorities() -> Vec { } pub fn new_test_ext() -> sp_io::TestExternalities { - let mut t = frame_system::GenesisConfig::default() - .build_storage::() + let mut t = frame_system::GenesisConfig::::default() + .build_storage() .unwrap(); let keys: Vec<_> = NEXT_VALIDATORS.with(|l| { l.borrow() @@ -159,25 +155,24 @@ parameter_types! { impl frame_system::Config for TestRuntime { type BaseCallFilter = frame_support::traits::Everything; + type Block = Block; type BlockWeights = (); type BlockLength = (); - type RuntimeOrigin = RuntimeOrigin; - type Index = u64; + type AccountId = u64; type RuntimeCall = RuntimeCall; - type BlockNumber = u64; + type Lookup = IdentityLookup; + type Nonce = u64; type Hash = H256; type Hashing = BlakeTwo256; - type AccountId = u64; - type Lookup = IdentityLookup; - type Header = Header; type RuntimeEvent = RuntimeEvent; + type RuntimeOrigin = RuntimeOrigin; type BlockHashCount = BlockHashCount; type DbWeight = (); type Version = (); type PalletInfo = PalletInfo; - type AccountData = (); type OnNewAccount = (); type OnKilledAccount = (); + type AccountData = (); type SystemWeightInfo = (); type SS58Prefix = (); type OnSetCode = (); From b47b484572a541ceedf1e1c4aee30ff9f6f45f7a Mon Sep 17 00:00:00 2001 From: renauter Date: Mon, 27 Nov 2023 23:44:30 -0300 Subject: [PATCH 17/25] update pallets benchmarking --- substrate-node/pallets/pallet-burning/src/benchmarking.rs | 4 ++-- .../pallets/pallet-smart-contract/src/benchmarking.rs | 6 +++--- substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs | 8 ++++---- .../pallets/pallet-tft-price/src/benchmarking.rs | 4 ++-- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/substrate-node/pallets/pallet-burning/src/benchmarking.rs b/substrate-node/pallets/pallet-burning/src/benchmarking.rs index 6ce893530..591ec0bd3 100644 --- a/substrate-node/pallets/pallet-burning/src/benchmarking.rs +++ b/substrate-node/pallets/pallet-burning/src/benchmarking.rs @@ -4,7 +4,7 @@ use super::*; use crate::Pallet as BurningModule; use frame_benchmarking::{benchmarks, whitelisted_caller, Zero}; use frame_support::traits::Currency; -use frame_system::{EventRecord, Pallet as System, RawOrigin}; +use frame_system::{pallet_prelude::BlockNumberFor, EventRecord, Pallet as System, RawOrigin}; use sp_runtime::{traits::StaticLookup, SaturatedConversion}; use sp_std::vec; @@ -20,7 +20,7 @@ benchmarks! { verify { let burns = BurningModule::::burns().unwrap_or(vec![]); assert_eq!(burns.len(), 1); - let block = T::BlockNumber::from(1 as u32); + let block = BlockNumberFor::::from(1 as u32); assert_eq!(T::Currency::free_balance(&target), BalanceOf::::zero()); assert_last_event::(Event::BurnTransactionCreated(target, amount, block, message).into()); } diff --git a/substrate-node/pallets/pallet-smart-contract/src/benchmarking.rs b/substrate-node/pallets/pallet-smart-contract/src/benchmarking.rs index 8e6ff1d37..a66fb40f2 100644 --- a/substrate-node/pallets/pallet-smart-contract/src/benchmarking.rs +++ b/substrate-node/pallets/pallet-smart-contract/src/benchmarking.rs @@ -8,7 +8,7 @@ use frame_support::{ traits::{OnFinalize, OnInitialize}, BoundedVec, }; -use frame_system::{EventRecord, Pallet as System, RawOrigin}; +use frame_system::{pallet_prelude::BlockNumberFor, EventRecord, Pallet as System, RawOrigin}; use pallet_balances::Pallet as Balances; use pallet_tfgrid::{ types::{self as tfgrid_types, LocationInput}, @@ -515,7 +515,7 @@ fn assert_last_event(generic_event: ::RuntimeEvent) { assert_eq!(event, &system_event); } -pub fn run_to_block(n: T::BlockNumber) { +pub fn run_to_block(n: BlockNumberFor) { while System::::block_number() < n { crate::Pallet::::on_finalize(System::::block_number()); System::::on_finalize(System::::block_number()); @@ -586,7 +586,7 @@ fn _create_farming_policy() { 10, 8, 9999, - ::BlockNumber::max_value(), + BlockNumberFor::::max_value(), true, true, NodeCertification::Diy, diff --git a/substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs b/substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs index 17e5800b6..958880ad6 100644 --- a/substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs +++ b/substrate-node/pallets/pallet-tfgrid/src/benchmarking.rs @@ -4,7 +4,7 @@ use super::*; use crate::Pallet as TfgridModule; use frame_benchmarking::{account, benchmarks, whitelisted_caller}; use frame_support::{assert_ok, BoundedVec}; -use frame_system::{EventRecord, Pallet as System, RawOrigin}; +use frame_system::{pallet_prelude::BlockNumberFor, EventRecord, Pallet as System, RawOrigin}; // use hex; // use scale_info::prelude::format; // use sp_core::{ed25519, Pair, Public}; @@ -497,7 +497,7 @@ benchmarks! { let nu = 10; let ipv4 = 8; let minimal_uptime = 9999; - let policy_end = BlockNumberFor::max_value(); + let policy_end = BlockNumberFor::::max_value(); let immutable = true; let default = true; let node_certification = NodeCertification::Diy; @@ -680,7 +680,7 @@ benchmarks! { let power = Power::Down; }: _(RawOrigin::Signed(caller), power) verify { - let power_state = PowerState::Down(BlockNumberFor::from(1 as u32)); + let power_state = PowerState::Down(BlockNumberFor::::from(1 as u32)); let node_power = TfgridModule::::node_power_state(node_id); assert_eq!(node_power.state, power_state); assert_last_event::(Event::PowerStateChanged { @@ -812,7 +812,7 @@ fn _create_farming_policy() { let nu = 10; let ipv4 = 8; let minimal_uptime = 9999; - let policy_end = BlockNumberFor::max_value(); + let policy_end = BlockNumberFor::::max_value(); let immutable = true; let default = true; let node_certification = NodeCertification::Diy; diff --git a/substrate-node/pallets/pallet-tft-price/src/benchmarking.rs b/substrate-node/pallets/pallet-tft-price/src/benchmarking.rs index cbc14ed6e..3a5f92131 100644 --- a/substrate-node/pallets/pallet-tft-price/src/benchmarking.rs +++ b/substrate-node/pallets/pallet-tft-price/src/benchmarking.rs @@ -3,7 +3,7 @@ use super::*; use crate::Pallet as TFTPriceModule; use frame_benchmarking::benchmarks; -use frame_system::{EventRecord, Pallet as System, RawOrigin}; +use frame_system::{pallet_prelude::BlockNumberFor, EventRecord, Pallet as System, RawOrigin}; use pallet_session::Pallet as Session; benchmarks! { @@ -14,7 +14,7 @@ benchmarks! { // set_prices() set_prices { - let block = T::BlockNumber::from(1u32); + let block = BlockNumberFor::::from(1u32); let price = 500; let validators = Session::::validators(); From 3574ed047ac258a91d7eb11aeba7a6d2a0277354 Mon Sep 17 00:00:00 2001 From: renauter Date: Tue, 28 Nov 2023 11:37:22 -0300 Subject: [PATCH 18/25] fix merge --- substrate-node/pallets/pallet-tft-bridge/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substrate-node/pallets/pallet-tft-bridge/src/lib.rs b/substrate-node/pallets/pallet-tft-bridge/src/lib.rs index 077928233..d0d9e85ea 100644 --- a/substrate-node/pallets/pallet-tft-bridge/src/lib.rs +++ b/substrate-node/pallets/pallet-tft-bridge/src/lib.rs @@ -147,7 +147,7 @@ pub mod pallet { // Minting events MintTransactionProposed(Vec, T::AccountId, u64), MintTransactionVoted(Vec), - MintCompleted(MintTransaction>), + MintCompleted(MintTransaction>, Vec), MintTransactionExpired(Vec, u64, T::AccountId), // Burn events BurnTransactionCreated(u64, T::AccountId, Vec, u64), From 15f42e1eb115d6341cbf15ce273a57a9953c9670 Mon Sep 17 00:00:00 2001 From: renauter Date: Mon, 4 Dec 2023 23:52:46 -0300 Subject: [PATCH 19/25] bump storage versions --- substrate-node/runtime/src/lib.rs | 1 + substrate-node/runtime/src/migrations/mod.rs | 3 ++- .../runtime/src/migrations/update_storage_version.rs | 10 ++++++++++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 substrate-node/runtime/src/migrations/update_storage_version.rs diff --git a/substrate-node/runtime/src/lib.rs b/substrate-node/runtime/src/lib.rs index 4f8f6be3b..fdc145038 100644 --- a/substrate-node/runtime/src/lib.rs +++ b/substrate-node/runtime/src/lib.rs @@ -776,6 +776,7 @@ pub type Executive = frame_executive::Executive< type Migrations = ( pallet_tfgrid::migrations::v17::FixFarmPublicIps, pallet_tft_bridge::migrations::v2::MigrateBurnTransactionsV2, + migrations::update_storage_version::UpdateStorageVersion, ); // follows Substrate's non destructive way of eliminating otherwise required diff --git a/substrate-node/runtime/src/migrations/mod.rs b/substrate-node/runtime/src/migrations/mod.rs index 5344a1c6c..1aadb54b3 100644 --- a/substrate-node/runtime/src/migrations/mod.rs +++ b/substrate-node/runtime/src/migrations/mod.rs @@ -1,2 +1,3 @@ +pub mod remove_sudo; pub mod tfgrid_v15_smart_contract_v8; -pub mod remove_sudo; \ No newline at end of file +pub mod update_storage_version; diff --git a/substrate-node/runtime/src/migrations/update_storage_version.rs b/substrate-node/runtime/src/migrations/update_storage_version.rs new file mode 100644 index 000000000..3ee0114af --- /dev/null +++ b/substrate-node/runtime/src/migrations/update_storage_version.rs @@ -0,0 +1,10 @@ +pub struct UpdateStorageVersion; +impl frame_support::traits::OnRuntimeUpgrade for UpdateStorageVersion { + fn on_runtime_upgrade() -> frame_support::weights::Weight { + frame_support::pallet_prelude::StorageVersion::new(1).put::(); + frame_support::pallet_prelude::StorageVersion::new(4).put::(); + frame_support::pallet_prelude::StorageVersion::new(1).put::(); + + frame_support::weights::Weight::from_all(3) + } +} From 607e98ced2c7555ddd9a8994516f95653b7cbc46 Mon Sep 17 00:00:00 2001 From: renauter Date: Tue, 5 Dec 2023 01:13:57 -0300 Subject: [PATCH 20/25] apply respective migartions --- substrate-node/runtime/src/lib.rs | 4 ++++ .../src/migrations/update_storage_version.rs | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/substrate-node/runtime/src/lib.rs b/substrate-node/runtime/src/lib.rs index fdc145038..133258e57 100644 --- a/substrate-node/runtime/src/lib.rs +++ b/substrate-node/runtime/src/lib.rs @@ -776,7 +776,11 @@ pub type Executive = frame_executive::Executive< type Migrations = ( pallet_tfgrid::migrations::v17::FixFarmPublicIps, pallet_tft_bridge::migrations::v2::MigrateBurnTransactionsV2, + pallet_scheduler::migration::v3::MigrateToV4, + pallet_scheduler::migration::v4::CleanupAgendas, + // pallet_balances::migration::MigrateManyToTrackInactive, migrations::update_storage_version::UpdateStorageVersion, + migrations::update_storage_version::PalletSessionToV1, ); // follows Substrate's non destructive way of eliminating otherwise required diff --git a/substrate-node/runtime/src/migrations/update_storage_version.rs b/substrate-node/runtime/src/migrations/update_storage_version.rs index 3ee0114af..617156e35 100644 --- a/substrate-node/runtime/src/migrations/update_storage_version.rs +++ b/substrate-node/runtime/src/migrations/update_storage_version.rs @@ -1,10 +1,19 @@ +use frame_support::pallet_prelude::PhantomData; + pub struct UpdateStorageVersion; impl frame_support::traits::OnRuntimeUpgrade for UpdateStorageVersion { fn on_runtime_upgrade() -> frame_support::weights::Weight { frame_support::pallet_prelude::StorageVersion::new(1).put::(); - frame_support::pallet_prelude::StorageVersion::new(4).put::(); - frame_support::pallet_prelude::StorageVersion::new(1).put::(); - frame_support::weights::Weight::from_all(3) + frame_support::weights::Weight::from_all(1) + } +} + +pub struct PalletSessionToV1(PhantomData); +impl frame_support::traits::OnRuntimeUpgrade + for PalletSessionToV1 +{ + fn on_runtime_upgrade() -> frame_support::weights::Weight { + pallet_session::migrations::v1::migrate::() } } From 22dee96dd295caf175c55783a4cbb942fa631464 Mon Sep 17 00:00:00 2001 From: renauter Date: Tue, 5 Dec 2023 01:15:53 -0300 Subject: [PATCH 21/25] useless v4::CleanupAgendas --- substrate-node/runtime/src/lib.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/substrate-node/runtime/src/lib.rs b/substrate-node/runtime/src/lib.rs index 133258e57..9d183b5b0 100644 --- a/substrate-node/runtime/src/lib.rs +++ b/substrate-node/runtime/src/lib.rs @@ -777,7 +777,6 @@ type Migrations = ( pallet_tfgrid::migrations::v17::FixFarmPublicIps, pallet_tft_bridge::migrations::v2::MigrateBurnTransactionsV2, pallet_scheduler::migration::v3::MigrateToV4, - pallet_scheduler::migration::v4::CleanupAgendas, // pallet_balances::migration::MigrateManyToTrackInactive, migrations::update_storage_version::UpdateStorageVersion, migrations::update_storage_version::PalletSessionToV1, From 0621dc2edb5583e7e9099a2c651cf0a884e8676c Mon Sep 17 00:00:00 2001 From: renauter Date: Tue, 5 Dec 2023 09:22:17 -0300 Subject: [PATCH 22/25] finalize storage version --- substrate-node/runtime/src/lib.rs | 3 +-- .../runtime/src/migrations/update_storage_version.rs | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/substrate-node/runtime/src/lib.rs b/substrate-node/runtime/src/lib.rs index 9d183b5b0..26a039ee6 100644 --- a/substrate-node/runtime/src/lib.rs +++ b/substrate-node/runtime/src/lib.rs @@ -777,8 +777,7 @@ type Migrations = ( pallet_tfgrid::migrations::v17::FixFarmPublicIps, pallet_tft_bridge::migrations::v2::MigrateBurnTransactionsV2, pallet_scheduler::migration::v3::MigrateToV4, - // pallet_balances::migration::MigrateManyToTrackInactive, - migrations::update_storage_version::UpdateStorageVersion, + migrations::update_storage_version::PalletBalancesToV1, migrations::update_storage_version::PalletSessionToV1, ); diff --git a/substrate-node/runtime/src/migrations/update_storage_version.rs b/substrate-node/runtime/src/migrations/update_storage_version.rs index 617156e35..175cb78bf 100644 --- a/substrate-node/runtime/src/migrations/update_storage_version.rs +++ b/substrate-node/runtime/src/migrations/update_storage_version.rs @@ -1,7 +1,7 @@ use frame_support::pallet_prelude::PhantomData; -pub struct UpdateStorageVersion; -impl frame_support::traits::OnRuntimeUpgrade for UpdateStorageVersion { +pub struct PalletBalancesToV1; +impl frame_support::traits::OnRuntimeUpgrade for PalletBalancesToV1 { fn on_runtime_upgrade() -> frame_support::weights::Weight { frame_support::pallet_prelude::StorageVersion::new(1).put::(); From 994e2ee76d36576c63f270bf100c6864fba70615 Mon Sep 17 00:00:00 2001 From: renauter Date: Tue, 5 Dec 2023 12:29:47 -0300 Subject: [PATCH 23/25] pallet_balances remove old `StorageVersion` type --- substrate-node/runtime/src/lib.rs | 2 +- .../runtime/src/migrations/update_storage_version.rs | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/substrate-node/runtime/src/lib.rs b/substrate-node/runtime/src/lib.rs index 26a039ee6..dadd2f0ee 100644 --- a/substrate-node/runtime/src/lib.rs +++ b/substrate-node/runtime/src/lib.rs @@ -777,7 +777,7 @@ type Migrations = ( pallet_tfgrid::migrations::v17::FixFarmPublicIps, pallet_tft_bridge::migrations::v2::MigrateBurnTransactionsV2, pallet_scheduler::migration::v3::MigrateToV4, - migrations::update_storage_version::PalletBalancesToV1, + migrations::update_storage_version::PalletBalancesToV1, migrations::update_storage_version::PalletSessionToV1, ); diff --git a/substrate-node/runtime/src/migrations/update_storage_version.rs b/substrate-node/runtime/src/migrations/update_storage_version.rs index 175cb78bf..4ef9a3cf1 100644 --- a/substrate-node/runtime/src/migrations/update_storage_version.rs +++ b/substrate-node/runtime/src/migrations/update_storage_version.rs @@ -1,8 +1,14 @@ -use frame_support::pallet_prelude::PhantomData; +use frame_support::pallet_prelude::{PalletInfoAccess, PhantomData}; -pub struct PalletBalancesToV1; -impl frame_support::traits::OnRuntimeUpgrade for PalletBalancesToV1 { +pub struct PalletBalancesToV1(PhantomData); +impl frame_support::traits::OnRuntimeUpgrade for PalletBalancesToV1 { fn on_runtime_upgrade() -> frame_support::weights::Weight { + // Remove the old `StorageVersion` type. + frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( + pallet_balances::Pallet::::name().as_bytes(), + "StorageVersion".as_bytes(), + )); + frame_support::pallet_prelude::StorageVersion::new(1).put::(); frame_support::weights::Weight::from_all(1) From 9a5a8ab8cbf5481c99cc03a0a2d56663706fe3d6 Mon Sep 17 00:00:00 2001 From: renauter Date: Wed, 6 Dec 2023 11:19:30 -0300 Subject: [PATCH 24/25] fix idempotent migration --- .../src/migrations/update_storage_version.rs | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/substrate-node/runtime/src/migrations/update_storage_version.rs b/substrate-node/runtime/src/migrations/update_storage_version.rs index 4ef9a3cf1..b994689ac 100644 --- a/substrate-node/runtime/src/migrations/update_storage_version.rs +++ b/substrate-node/runtime/src/migrations/update_storage_version.rs @@ -1,25 +1,36 @@ use frame_support::pallet_prelude::{PalletInfoAccess, PhantomData}; +use frame_support::{ + pallet_prelude::StorageVersion, + traits::{GetStorageVersion, OnRuntimeUpgrade}, + weights::Weight, +}; + pub struct PalletBalancesToV1(PhantomData); -impl frame_support::traits::OnRuntimeUpgrade for PalletBalancesToV1 { - fn on_runtime_upgrade() -> frame_support::weights::Weight { +impl OnRuntimeUpgrade for PalletBalancesToV1 { + fn on_runtime_upgrade() -> Weight { // Remove the old `StorageVersion` type. frame_support::storage::unhashed::kill(&frame_support::storage::storage_prefix( pallet_balances::Pallet::::name().as_bytes(), "StorageVersion".as_bytes(), )); - frame_support::pallet_prelude::StorageVersion::new(1).put::(); + StorageVersion::new(1).put::(); - frame_support::weights::Weight::from_all(1) + Weight::from_all(1) } } pub struct PalletSessionToV1(PhantomData); -impl frame_support::traits::OnRuntimeUpgrade - for PalletSessionToV1 -{ - fn on_runtime_upgrade() -> frame_support::weights::Weight { - pallet_session::migrations::v1::migrate::() +impl OnRuntimeUpgrade for PalletSessionToV1 { + fn on_runtime_upgrade() -> Weight { + let on_chain_storage_version = + ::on_chain_storage_version(); + + if on_chain_storage_version < 1 { + return pallet_session::migrations::v1::migrate::(); + } + + Weight::zero() } } From 8e92a7821232f990de6edb23447e2d82f7bb0b8e Mon Sep 17 00:00:00 2001 From: renauter Date: Wed, 6 Dec 2023 12:19:07 -0300 Subject: [PATCH 25/25] make bridge migration idempotent --- .../pallets/pallet-tft-bridge/src/migrations/v2.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs b/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs index 28cd2598c..9518fca70 100644 --- a/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs +++ b/substrate-node/pallets/pallet-tft-bridge/src/migrations/v2.rs @@ -19,10 +19,9 @@ impl OnRuntimeUpgrade for MigrateBurnTransactionsV2 { #[cfg(feature = "try-runtime")] fn pre_upgrade() -> Result, sp_runtime::TryRuntimeError> { info!("current pallet version: {:?}", PalletVersion::::get()); - ensure!( - PalletVersion::::get() == types::StorageVersion::V1, - DispatchError::Other("Unexpected pallet version") - ); + if PalletVersion::::get() != types::StorageVersion::V1 { + return Ok(Vec::::new()); + } let burn_transactions_count: u64 = migrations::types::v1::BurnTransactions::::iter().count() as u64; @@ -39,7 +38,7 @@ impl OnRuntimeUpgrade for MigrateBurnTransactionsV2 { ); info!("👥 TFT-BRIDGE pallet to V1 passes PRE migrate checks ✅",); - return Ok(Vec::::new()); + Ok(Vec::::new()) } fn on_runtime_upgrade() -> Weight {