From 975e416b7e5f2e46eac6debed288f1176d37414d Mon Sep 17 00:00:00 2001
From: bgallois <benjamin@gallois.cc>
Date: Thu, 14 Mar 2024 13:47:29 +0100
Subject: [PATCH] fix
 https://git.duniter.org/nodes/rust/duniter-v2s/-/issues/222

---
 Cargo.lock                 |  3 +++
 node/Cargo.toml            |  1 +
 node/src/command.rs        | 39 +-------------------------------------
 runtime/common/Cargo.toml  |  3 +++
 runtime/common/src/apis.rs | 16 ++++++----------
 runtime/g1/Cargo.toml      |  3 +++
 runtime/gdev/Cargo.toml    |  3 +++
 runtime/gtest/Cargo.toml   |  4 ++--
 8 files changed, 22 insertions(+), 50 deletions(-)

diff --git a/Cargo.lock b/Cargo.lock
index 0da887cda..bea13a15d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1465,6 +1465,7 @@ dependencies = [
  "frame-support",
  "frame-system",
  "frame-system-benchmarking",
+ "frame-try-runtime",
  "pallet-authority-members",
  "pallet-babe",
  "pallet-balances",
@@ -3437,6 +3438,7 @@ dependencies = [
  "frame-system",
  "frame-system-benchmarking",
  "frame-system-rpc-runtime-api",
+ "frame-try-runtime",
  "hex-literal",
  "log",
  "node-primitives",
@@ -3510,6 +3512,7 @@ dependencies = [
  "frame-system",
  "frame-system-benchmarking",
  "frame-system-rpc-runtime-api",
+ "frame-try-runtime",
  "hex-literal",
  "log",
  "node-primitives",
diff --git a/node/Cargo.toml b/node/Cargo.toml
index fc62d177c..4f1958cfa 100644
--- a/node/Cargo.toml
+++ b/node/Cargo.toml
@@ -48,6 +48,7 @@ runtime-benchmarks = [
 	"sp-runtime/runtime-benchmarks",
 ]
 try-runtime = [
+  "runtime-benchmarks",
 	"common-runtime/try-runtime",
 	"dc-distance/try-runtime",
 	"distance-oracle?/try-runtime",
diff --git a/node/src/command.rs b/node/src/command.rs
index c1ce8bfff..096e947e4 100644
--- a/node/src/command.rs
+++ b/node/src/command.rs
@@ -357,44 +357,7 @@ pub fn run() -> sc_cli::Result<()> {
             You can enable it with `--features runtime-benchmarks`."
                 .into())
         }
-        #[cfg(feature = "try-runtime")]
-        Some(Subcommand::TryRuntime(cmd)) => {
-            let runner = cli.create_runner(cmd)?;
-            let chain_spec = &runner.config().chain_spec;
-
-            use sc_service::TaskManager;
-            let registry = &runner
-                .config()
-                .prometheus_config
-                .as_ref()
-                .map(|cfg| &cfg.registry);
-            let task_manager = TaskManager::new(runner.config().tokio_handle.clone(), *registry)
-                .map_err(|e| {
-                    sc_cli::Error::Application(format!("Fail to create TaskManager: {}", e).into())
-                })?;
-
-            // Ensure dev spec
-            if !chain_spec.id().ends_with("dev") {
-                return Err(sc_cli::Error::Application(
-                    "try-runtime only support dev specs".into(),
-                ));
-            }
-
-            match chain_spec.runtime_type() {
-                #[cfg(feature = "gdev")]
-                RuntimeType::GDev => runner.async_run(|config| {
-                    Ok((
-                        cmd.run::<gdev_runtime::Block, Executor>(config),
-                        task_manager,
-                    ))
-                }),
-                _ => Err(sc_cli::Error::Application("unknown runtime type".into())),
-            }
-        }
-        #[cfg(not(feature = "try-runtime"))]
-        Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \
-				You can enable it with `--features try-runtime`."
-            .into()),
+        Some(Subcommand::TryRuntime) => todo!("Deprecated"),
         None => {
             let runner = cli.create_runner(&cli.run)?;
             runner.run_node_until_exit(|mut config| async move {
diff --git a/runtime/common/Cargo.toml b/runtime/common/Cargo.toml
index 4dae70831..0c25cfa29 100644
--- a/runtime/common/Cargo.toml
+++ b/runtime/common/Cargo.toml
@@ -54,6 +54,7 @@ std = [
 	"frame-support/std",
 	"frame-system-benchmarking?/std",
 	"frame-system/std",
+	"frame-try-runtime/std",
 	"pallet-authority-members/std",
 	"pallet-babe/std",
 	"pallet-balances/std",
@@ -96,6 +97,7 @@ try-runtime = [
 	"duniter-primitives/try-runtime",
 	"frame-support/try-runtime",
 	"frame-system/try-runtime",
+	"frame-try-runtime/try-runtime",
 	"pallet-authority-members/try-runtime",
 	"pallet-babe/try-runtime",
 	"pallet-balances/try-runtime",
@@ -134,6 +136,7 @@ frame-benchmarking = { workspace = true }
 frame-support = { workspace = true }
 frame-system = { workspace = true }
 frame-system-benchmarking = { workspace = true, optional = true }
+frame-try-runtime = { workspace = true, optional = true }
 pallet-authority-members = { workspace = true }
 pallet-babe = { workspace = true }
 pallet-balances = { workspace = true }
diff --git a/runtime/common/src/apis.rs b/runtime/common/src/apis.rs
index af95e113f..e654b9249 100644
--- a/runtime/common/src/apis.rs
+++ b/runtime/common/src/apis.rs
@@ -231,23 +231,19 @@ macro_rules! runtime_apis {
 	}
 
             #[cfg(feature = "try-runtime")]
-            impl frame_try_runtime::TryRuntime<Block> for Runtime where <Runtime as frame_system::Config>::BlockNumber: Clone + sp_std::fmt::Debug + sp_runtime::traits::AtLeast32BitUnsigned {
-                fn on_runtime_upgrade() -> (Weight, Weight) {
-                    log::info!("try-runtime::on_runtime_upgrade.");
-                    todo!()
-                    // TODO solve the problem to uncomment this:
-                    //let weight = Executive::try_runtime_upgrade().unwrap();
-                    //(weight, BlockWeights::get().max_block)
+            impl frame_try_runtime::TryRuntime<Block> for Runtime {
+                fn on_runtime_upgrade(checks: frame_try_runtime::UpgradeCheckSelect) -> (Weight, Weight) {
+                    let weight = Executive::try_runtime_upgrade(checks).unwrap();
+					(weight, BlockWeights::get().max_block)
                 }
 
                 fn execute_block(
                     block: Block,
                     state_root_check: bool,
+					signature_check: bool,
                     select: frame_try_runtime::TryStateSelect,
                 ) -> Weight {
-                    todo!()
-                    // TODO solve the problem to uncomment this:
-                    //Executive::try_execute_block(block, state_root_check, select).expect("try_execute_block failed")
+                    Executive::try_execute_block(block, state_root_check, signature_check, select).expect("execute-block failed")
                 }
             }
 
diff --git a/runtime/g1/Cargo.toml b/runtime/g1/Cargo.toml
index 76c98358b..94b683b12 100644
--- a/runtime/g1/Cargo.toml
+++ b/runtime/g1/Cargo.toml
@@ -60,6 +60,7 @@ std = [
 	"frame-system-benchmarking/std",
 	"frame-system-rpc-runtime-api/std",
 	"frame-system/std",
+	"frame-try-runtime/std",
 	"log/std",
 	"node-primitives/std",
 	"pallet-atomic-swap/std",
@@ -124,6 +125,7 @@ try-runtime = [
 	"frame-executive/try-runtime",
 	"frame-support/try-runtime",
 	"frame-system/try-runtime",
+	"frame-try-runtime/try-runtime",
 	"pallet-atomic-swap/try-runtime",
 	"pallet-authority-discovery/try-runtime",
 	"pallet-authority-members/try-runtime",
@@ -178,6 +180,7 @@ frame-benchmarking = { workspace = true }
 frame-system-benchmarking = { workspace = true }
 frame-system = { workspace = true }
 frame-system-rpc-runtime-api = { workspace = true }
+frame-try-runtime = { workspace = true, optional = true }
 hex-literal = { workspace = true, optional = true }
 log = { workspace = true }
 pallet-atomic-swap = { workspace = true }
diff --git a/runtime/gdev/Cargo.toml b/runtime/gdev/Cargo.toml
index ef804b7e9..76c167816 100644
--- a/runtime/gdev/Cargo.toml
+++ b/runtime/gdev/Cargo.toml
@@ -60,6 +60,7 @@ std = [
 	"frame-system-benchmarking/std",
 	"frame-system-rpc-runtime-api/std",
 	"frame-system/std",
+	"frame-try-runtime/std",
 	"log/std",
 	"node-primitives/std",
 	"pallet-atomic-swap/std",
@@ -126,6 +127,7 @@ try-runtime = [
 	"frame-executive/try-runtime",
 	"frame-support/try-runtime",
 	"frame-system/try-runtime",
+	"frame-try-runtime/try-runtime",
 	"pallet-atomic-swap/try-runtime",
 	"pallet-authority-discovery/try-runtime",
 	"pallet-authority-members/try-runtime",
@@ -182,6 +184,7 @@ frame-support = { workspace = true }
 frame-system = { workspace = true }
 frame-system-benchmarking = { workspace = true, optional = true }
 frame-system-rpc-runtime-api = { workspace = true }
+frame-try-runtime = { workspace = true, optional = true }
 hex-literal = { workspace = true, optional = true }
 log = { workspace = true }
 node-primitives = { workspace = true }
diff --git a/runtime/gtest/Cargo.toml b/runtime/gtest/Cargo.toml
index 2b7cbbcc1..3e14eae27 100644
--- a/runtime/gtest/Cargo.toml
+++ b/runtime/gtest/Cargo.toml
@@ -59,7 +59,7 @@ std = [
 	"frame-system-benchmarking/std",
 	"frame-system-rpc-runtime-api/std",
 	"frame-system/std",
-	"frame-try-runtime?/std",
+	"frame-try-runtime/std",
 	"log/std",
 	"node-primitives/std",
 	"pallet-atomic-swap/std",
@@ -124,7 +124,7 @@ try-runtime = [
 	"frame-executive/try-runtime",
 	"frame-support/try-runtime",
 	"frame-system/try-runtime",
-	"frame-try-runtime?/try-runtime",
+	"frame-try-runtime/try-runtime",
 	"pallet-atomic-swap/try-runtime",
 	"pallet-authority-discovery/try-runtime",
 	"pallet-authority-members/try-runtime",
-- 
GitLab