Skip to content
Snippets Groups Projects
Commit 1e3c4043 authored by Benjamin Gallois's avatar Benjamin Gallois Committed by Hugo Trentesaux
Browse files

Refactor node implementation (!256)

* fix formatting

* remove unused code

* fix #215

* fix #222

* refactor command

* remove unused type

* refactor client

* refactor executor
parent 07bb8814
Branches
Tags
1 merge request!256Refactor node implementation
Pipeline #36587 passed
......@@ -1465,6 +1465,7 @@ dependencies = [
"frame-support",
"frame-system",
"frame-system-benchmarking",
"frame-try-runtime",
"pallet-authority-members",
"pallet-babe",
"pallet-balances",
......@@ -3438,6 +3439,7 @@ dependencies = [
"frame-system",
"frame-system-benchmarking",
"frame-system-rpc-runtime-api",
"frame-try-runtime",
"hex-literal",
"log",
"node-primitives",
......@@ -3511,6 +3513,7 @@ dependencies = [
"frame-system",
"frame-system-benchmarking",
"frame-system-rpc-runtime-api",
"frame-try-runtime",
"hex-literal",
"log",
"node-primitives",
......
......@@ -27,6 +27,7 @@
- [git-conventions](./docs/dev/git-conventions.md)
- [launch-a-live-network](./docs/dev/launch-a-live-network.md)
- [setup](./docs/dev/setup.md)
- [compilation features](./docs/dev/compilation.md)
- [verify-runtime-code](./docs/dev/verify-runtime-code.md)
- [weights-benchmarking](./docs/dev/weights-benchmarking.md)
- [upgrade-substrate](./docs/dev/upgrade-substrate.md)
......
# Compilation
Duniter is compiled using the Rust compiler. For a general overview, refer to the [Rustc Dev Guide](https://rustc-dev-guide.rust-lang.org/overview.html).
Substrate and Duniter provide a set of features enabling or disabling parts of the code using conditional compilation. More information on conditional compilation can be found [here](https://doc.rust-lang.org/reference/conditional-compilation.html), or by enabling or disabling compilation of packages. Below is a list of all available features:
## External
- **runtime-benchmarks**: Compiles the runtime with benchmarks for extrinsics benchmarking.
- **try-runtime**: Compiles the runtime for tests and verifies operations in a simulated environment.
- **std**: Enables the Rust standard library.
## Duniter
- **gdev**: Sets `gdev-runtime` and `std` used to build the development chain.
- **gtest**: Sets `gtest-runtime` and `std` used to build the test chain.
- **g1**: Sets `g1-runtime` and `std` used to build the production chain.
- **constant-fees**: Uses a constant and predictable weight-to-fee conversion only for testing.
- **embed**: Enables hardcoded live chainspecs loaded from "../specs/gtest-raw.json" file.
- **native**: Compiles the runtime into native-platform executable only for debugging purposes.
Note: By default, Duniter will be compiled using the `gdev` feature and including the compilation of the distance oracle. Since the three Duniter chains are mutually exclusive, it is mandatory to disable the default feature to compile `gtest` and `g1` as follows:
- `cargo build --no-default-features --features gtest`
- `cargo build --no-default-features --features g1`
- `cargo build --no-default-features -p distance-oracle --features std`
......@@ -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",
......
......@@ -83,7 +83,7 @@ pub enum Subcommand {
/// Try some command against runtime state.
#[cfg(feature = "try-runtime")]
TryRuntime(try_runtime_cli::TryRuntimeCmd),
TryRuntime,
/// Try some command against runtime state. Note: `try-runtime` feature must be enabled.
#[cfg(not(feature = "try-runtime"))]
......
......@@ -20,16 +20,9 @@
pub mod key;
pub mod utils;
#[cfg(feature = "gtest")]
use crate::chain_spec::gtest;
use crate::cli::{Cli, Subcommand};
#[cfg(feature = "g1")]
use crate::service::g1_executor::G1Executor;
#[cfg(feature = "gdev")]
use crate::service::gdev_executor::GDevExecutor;
#[cfg(feature = "gtest")]
use crate::service::gtest_executor::GTestExecutor;
use crate::service::{IdentifyRuntimeType, RuntimeType};
use crate::service::runtime_executor::Executor;
use crate::service::RuntimeType;
use crate::{chain_spec, service};
use clap::CommandFactory;
#[cfg(feature = "runtime-benchmarks")]
......@@ -56,14 +49,7 @@ macro_rules! unwrap_client {
$code:expr
) => {
match $client.as_ref() {
#[cfg(feature = "g1")]
crate::service::client::Client::G1($client) => $code,
#[cfg(feature = "gtest")]
crate::service::client::Client::GTest($client) => $code,
#[cfg(feature = "gdev")]
crate::service::client::Client::GDev($client) => $code,
#[allow(unreachable_patterns)]
_ => panic!("unknown runtime"),
crate::service::client::Client::Client($client) => $code,
}
};
}
......@@ -95,19 +81,20 @@ impl SubstrateCli for Cli {
fn load_spec(&self, id: &str) -> Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
// === GDEV ===
// development chainspec with generated genesis and Alice validator
// Development chainspec with generated genesis and Alice as a validator
#[cfg(feature = "gdev")]
"dev" => Box::new(chain_spec::gdev::local_testnet_config(1, 3, 4)?),
// local testnet with g1 data, gdev configuration (parameters & smiths) and Alice validator
// > optionally from DUNITER_GENESIS_CONFIG file to override default gdev configuration
// Local testnet with G1 data, Gdev configuration (parameters & Smiths), and Alice as a validator.
// Optionally, load configuration from DUNITER_GENESIS_CONFIG file to override default Gdev configuration.
#[cfg(feature = "gdev")]
"gdev_dev" => Box::new(chain_spec::gdev::gdev_development_chain_spec(
"resources/gdev.yaml".to_string(),
)?),
// chainspecs for live network with g1 data, gdev configuration (parameters & smiths)
// but must have a smith with declared session keys
// > optionally from DUNITER_GENESIS_CONFIG file to override default gdev configuration
// Chainspecs for live network with G1 data, Gdev configuration (parameters & Smiths).
// A Smith with declared session keys is required.
// Optionally load configuration from DUNITER_GENESIS_CONFIG file to override default Gdev configuration.
#[cfg(feature = "gdev")]
"gdev_live" => {
const CLIENT_SPEC: &str = "./node/specs/gdev_client-specs.yaml";
......@@ -119,34 +106,33 @@ impl SubstrateCli for Cli {
.map_err(|e| format!("failed to read {CLIENT_SPEC} {e}"))?[..],
)
.map_err(|e| format!("failed to parse {e}"))?;
// rebuild chainspecs from these files
Box::new(chain_spec::gdev::gen_live_conf(
client_spec,
"resources/gdev.yaml".to_string(),
)?)
}
// hardcoded previously generated raw chainspecs
// yields a pointlessly heavy binary because of hexadecimal-text-encoded values
// Hardcoded raw chainspecs with previously generated values, resulting in a needlessly heavy binary due to hexadecimal-text-encoded values.
#[cfg(feature = "gdev")]
"gdev" => Box::new(chain_spec::gdev::ChainSpec::from_json_bytes(
&include_bytes!("../specs/gdev-raw.json")[..],
)?),
// === GTEST ===
// generate dev chainspecs with Alice validator
// provide DUNITER_GTEST_GENESIS env var if you want to build genesis from json
// otherwise you get a local testnet with generated genesis
// Generate development chainspecs with Alice as a validator.
// Provide the DUNITER_GTEST_GENESIS environment variable to build genesis from JSON; otherwise, a local testnet with generated genesis will be used.
#[cfg(feature = "gtest")]
"gtest_dev" => Box::new(chain_spec::gtest::development_chainspecs(
"resources/gtest.yaml".to_string(),
)?),
// chainspecs for live network
// must have following files in ./node/specs folder or overwrite with env var:
// Chainspecs for the live network.
// Required files in the ./node/specs folder or override with environment variables:
// - gtest.json / DUNITER_GTEST_GENESIS
// - gtest_client-specs.json / DUNITER_GTEST_CLIENT_SPEC
#[cfg(feature = "gtest")]
"gtest_live" => {
const JSON_CLIENT_SPEC: &str = "./node/specs/gtest_client-specs.yaml";
let client_spec: gtest::ClientSpec = serde_yaml::from_slice(
let client_spec: chain_spec::gtest::ClientSpec = serde_yaml::from_slice(
&std::fs::read(
std::env::var("DUNITER_CLIENT_SPEC")
.unwrap_or_else(|_| JSON_CLIENT_SPEC.to_string()),
......@@ -154,31 +140,27 @@ impl SubstrateCli for Cli {
.map_err(|e| format!("failed to read {JSON_CLIENT_SPEC} {e}"))?[..],
)
.map_err(|e| format!("failed to parse {e}"))?;
// rebuild chainspecs from these files
Box::new(chain_spec::gtest::live_chainspecs(
client_spec,
"resources/gtest.yaml".to_string(),
)?)
}
// return hardcoded live chainspecs, only with embed feature
// embed client spec and genesis to avoid embeding hexadecimal runtime
// and having hexadecimal runtime in git history
// will only build on a branch that has a file
// ./node/specs/gtest-raw.json
// Return hardcoded live chainspecs, only with the embed feature enabled.
// Embed client spec and genesis to avoid embedding hexadecimal runtime
// and having hexadecimal runtime in the git history.
// This will only build on a branch that has a file named ./node/specs/gtest-raw.json.
#[cfg(all(feature = "gtest", feature = "embed"))]
"gtest" => Box::new(chain_spec::gtest::ChainSpec::from_json_bytes(
&include_bytes!("../specs/gtest-raw.json")[..],
)?),
// === G1 ===
#[cfg(feature = "g1")]
"g1" => {
unimplemented!()
//Box::new(chain_spec::g1::ChainSpec::from_json_file(file_path)?)
}
// Specs provided as json specify which runtime to use in their file name. For example,
// `g1-custom.json` uses the g1 runtime.
// `gdev-workshop.json` uses the gdev runtime.
path => {
let path = std::path::PathBuf::from(path);
......@@ -311,7 +293,7 @@ pub fn run() -> sc_cli::Result<()> {
#[cfg(feature = "runtime-benchmarks")]
Some(Subcommand::Benchmark(cmd)) => {
let runner = cli.create_runner(&**cmd)?;
let chain_spec = &runner.config().chain_spec;
let _chain_spec = &runner.config().chain_spec;
match &**cmd {
BenchmarkCmd::Storage(cmd) => runner.sync_run(|config| {
......@@ -346,30 +328,12 @@ pub fn run() -> sc_cli::Result<()> {
}),
BenchmarkCmd::Pallet(cmd) => {
if cfg!(feature = "runtime-benchmarks") {
match chain_spec.runtime_type() {
#[cfg(feature = "g1")]
RuntimeType::G1 => runner.sync_run(|config| {
cmd.run::<g1_runtime::Block, ExtendedHostFunctions<
runner.sync_run(|config| {
cmd.run::<service::runtime_executor::runtime::Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<G1Executor as NativeExecutionDispatch>::ExtendHostFunctions,
<Executor as NativeExecutionDispatch>::ExtendHostFunctions,
>>(config)
}),
#[cfg(feature = "gtest")]
RuntimeType::GTest => runner.sync_run(|config| {
cmd.run::<gtest_runtime::Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<GTestExecutor as NativeExecutionDispatch>::ExtendHostFunctions,
>>(config)
}),
#[cfg(feature = "gdev")]
RuntimeType::GDev => runner.sync_run(|config| {
cmd.run::<gdev_runtime::Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<GDevExecutor as NativeExecutionDispatch>::ExtendHostFunctions,
>>(config)
}),
_ => Err(sc_cli::Error::Application("unknown runtime type".into())),
}
})
} else {
Err("Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
......@@ -392,42 +356,7 @@ pub fn run() -> sc_cli::Result<()> {
.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 => {
//sp_core::crypto::set_default_ss58_version(Ss58AddressFormatRegistry::GDev);
runner.async_run(|config| {
Ok((
cmd.run::<gdev_runtime::Block, GDevExecutor>(config),
task_manager,
))
})
}
_ => Err(sc_cli::Error::Application("unknown runtime type".into())),
}
}
Some(Subcommand::TryRuntime) => Err(try_runtime_cli::DEPRECATION_NOTICE.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`."
......@@ -441,28 +370,13 @@ pub fn run() -> sc_cli::Result<()> {
config.offchain_worker.indexing_enabled = true;
}
match config.chain_spec.runtime_type() {
#[cfg(feature = "g1")]
RuntimeType::G1 => {
service::new_full::<g1_runtime::RuntimeApi, G1Executor>(config, cli.sealing)
.map_err(sc_cli::Error::Service)
}
#[cfg(feature = "gtest")]
RuntimeType::GTest => service::new_full::<
gtest_runtime::RuntimeApi,
GTestExecutor,
>(config, cli.sealing)
.map_err(sc_cli::Error::Service),
#[cfg(feature = "gdev")]
RuntimeType::GDev => {
service::new_full::<gdev_runtime::RuntimeApi, GDevExecutor>(
{
service::new_full::<service::runtime_executor::runtime::RuntimeApi, Executor>(
config,
cli.sealing,
)
.map_err(sc_cli::Error::Service)
}
_ => Err(sc_cli::Error::Application("unknown runtime".into())),
}
})
}
}
......
......@@ -29,6 +29,7 @@ use sc_consensus_manual_seal::{run_manual_seal, EngineCommand, ManualSealParams}
use sc_service::WarpSyncParams;
use sc_service::{error::Error as ServiceError, Configuration, PartialComponents, TaskManager};
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_consensus_babe::inherents::InherentDataProvider;
use sp_core::H256;
use sp_runtime::traits::BlakeTwo256;
use std::{sync::Arc, time::Duration};
......@@ -54,91 +55,30 @@ type FullClient<RuntimeApi, Executor> =
type FullBackend = sc_service::TFullBackend<Block>;
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
#[cfg(feature = "gdev")]
pub mod gdev_executor {
pub mod runtime_executor {
use crate::service::HostFunctions;
pub use gdev_runtime;
use sc_executor::sp_wasm_interface::{Function, HostFunctionRegistry};
pub struct GDevExecutor;
impl sc_executor::NativeExecutionDispatch for GDevExecutor {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
gdev_runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
gdev_runtime::native_version()
}
}
impl sc_executor::sp_wasm_interface::HostFunctions for GDevExecutor {
fn host_functions() -> Vec<&'static dyn Function> {
HostFunctions::host_functions()
}
fn register_static<T>(registry: &mut T) -> Result<(), T::Error>
where
T: HostFunctionRegistry,
{
HostFunctions::register_static(registry)
}
}
}
#[allow(dead_code)]
#[cfg(feature = "g1")]
pub mod g1_executor {
use crate::service::HostFunctions;
pub use g1_runtime;
use sc_executor::sp_wasm_interface::{Function, HostFunctionRegistry};
pub struct G1Executor;
impl sc_executor::NativeExecutionDispatch for G1Executor {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
g1_runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
g1_runtime::native_version()
}
}
impl sc_executor::sp_wasm_interface::HostFunctions for G1Executor {
fn host_functions() -> Vec<&'static dyn Function> {
HostFunctions::host_functions()
}
fn register_static<T>(registry: &mut T) -> Result<(), T::Error>
where
T: HostFunctionRegistry,
{
HostFunctions::register_static(registry)
}
}
}
#[allow(dead_code)]
pub use g1_runtime as runtime;
#[cfg(feature = "gdev")]
pub use gdev_runtime as runtime;
#[cfg(feature = "gtest")]
pub mod gtest_executor {
use crate::service::HostFunctions;
pub use gtest_runtime;
pub use gtest_runtime as runtime;
use sc_executor::sp_wasm_interface::{Function, HostFunctionRegistry};
pub struct GTestExecutor;
impl sc_executor::NativeExecutionDispatch for GTestExecutor {
pub struct Executor;
impl sc_executor::NativeExecutionDispatch for Executor {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
gtest_runtime::api::dispatch(method, data)
runtime::api::dispatch(method, data)
}
fn native_version() -> sc_executor::NativeVersion {
gtest_runtime::native_version()
runtime::native_version()
}
}
impl sc_executor::sp_wasm_interface::HostFunctions for GTestExecutor {
impl sc_executor::sp_wasm_interface::HostFunctions for Executor {
fn host_functions() -> Vec<&'static dyn Function> {
HostFunctions::host_functions()
}
......@@ -163,27 +103,6 @@ pub enum RuntimeType {
GTest,
}
/// Can be called for a `Configuration` to check if it is a configuration for
/// a particular runtime type.
pub trait IdentifyRuntimeType {
/// Returns the runtime type
fn runtime_type(&self) -> RuntimeType;
}
impl IdentifyRuntimeType for Box<dyn sc_chain_spec::ChainSpec> {
fn runtime_type(&self) -> RuntimeType {
if self.id().starts_with("g1") {
RuntimeType::G1
} else if self.id().starts_with("dev") || self.id().starts_with("gdev") {
RuntimeType::GDev
} else if self.id().starts_with("gtest") {
RuntimeType::GTest
} else {
panic!("unknown runtime")
}
}
}
/// Builds a new object suitable for chain operations.
#[allow(clippy::type_complexity)]
pub fn new_chain_ops(
......@@ -198,67 +117,23 @@ pub fn new_chain_ops(
),
ServiceError,
> {
match config.chain_spec.runtime_type() {
#[cfg(feature = "g1")]
RuntimeType::G1::G1 => {
let PartialComponents {
client,
backend,
import_queue,
task_manager,
..
} = new_partial::<g1_runtime::RuntimeApi, g1_executor::G1Executor>(
config,
manual_consensus,
)?;
Ok((
Arc::new(Client::G1(client)),
backend,
import_queue,
task_manager,
))
}
#[cfg(feature = "gtest")]
RuntimeType::GTest => {
let PartialComponents {
client,
backend,
import_queue,
task_manager,
..
} = new_partial::<gtest_runtime::RuntimeApi, gtest_executor::GTestExecutor>(
} = new_partial::<runtime_executor::runtime::RuntimeApi, runtime_executor::Executor>(
config,
manual_consensus,
)?;
Ok((
Arc::new(Client::GTest(client)),
Arc::new(Client::Client(client)),
backend,
import_queue,
task_manager,
))
}
#[cfg(feature = "gdev")]
RuntimeType::GDev => {
let PartialComponents {
client,
backend,
import_queue,
task_manager,
..
} = new_partial::<gdev_runtime::RuntimeApi, gdev_executor::GDevExecutor>(
config,
manual_consensus,
)?;
Ok((
Arc::new(Client::GDev(client)),
backend,
import_queue,
task_manager,
))
}
_ => panic!("unknown runtime"),
}
}
type FullGrandpaBlockImport<RuntimeApi, Executor> = sc_consensus_grandpa::GrandpaBlockImport<
FullBackend,
......@@ -382,8 +257,7 @@ where
create_inherent_data_providers: move |_, ()| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
let slot =
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
let slot = InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
......@@ -603,7 +477,7 @@ where
client.clone(),
)
.map_err(|err| format!("{:?}", err))?;
let babe = sp_consensus_babe::inherents::InherentDataProvider::new(
let babe = InherentDataProvider::new(
timestamp.slot(),
);
let distance =
......@@ -643,8 +517,7 @@ where
async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
let slot =
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_slot_duration(
let slot = InherentDataProvider::from_timestamp_and_slot_duration(
*timestamp,
slot_duration,
);
......
......@@ -145,12 +145,14 @@ impl<Api> RuntimeApiCollection for Api where
/// A client instance.
#[derive(Clone)]
pub enum Client {
#[cfg(feature = "g1")]
G1(Arc<super::FullClient<g1_runtime::RuntimeApi, super::g1_executor::G1Executor>>),
#[cfg(feature = "gtest")]
GTest(Arc<super::FullClient<gtest_runtime::RuntimeApi, super::gtest_executor::GTestExecutor>>),
#[cfg(feature = "gdev")]
GDev(Arc<super::FullClient<gdev_runtime::RuntimeApi, super::gdev_executor::GDevExecutor>>),
Client(
Arc<
super::FullClient<
super::runtime_executor::runtime::RuntimeApi,
super::runtime_executor::Executor,
>,
>,
),
}
macro_rules! with_client {
......@@ -162,22 +164,8 @@ macro_rules! with_client {
}
} => {
match $self {
#[cfg(feature = "g1")]
Self::G1($client) => {
Self::Client($client) => {
#[allow(unused_imports)]
use g1_runtime as runtime;
$( $code )*
}
#[cfg(feature = "gtest")]
Self::GTest($client) => {
#[allow(unused_imports)]
use gtest_runtime as runtime;
$( $code )*
}
#[cfg(feature = "gdev")]
Self::GDev($client) => {
#[allow(unused_imports)]
use gdev_runtime as runtime;
$( $code )*
}
}
......@@ -196,52 +184,32 @@ impl ClientHandle for Client {
}
}
#[cfg(feature = "g1")]
impl From<Arc<super::FullClient<g1_runtime::RuntimeApi, super::g1_executor::G1Executor>>>
for Client
{
fn from(
client: Arc<super::FullClient<g1_runtime::RuntimeApi, super::g1_executor::G1Executor>>,
) -> Self {
Self::G1(client)
}
}
#[cfg(feature = "gtest")]
impl From<Arc<super::FullClient<gtest_runtime::RuntimeApi, super::gtest_executor::GTestExecutor>>>
for Client
{
fn from(
client: Arc<
super::FullClient<gtest_runtime::RuntimeApi, super::gtest_executor::GTestExecutor>,
impl
From<
Arc<
super::FullClient<
super::runtime_executor::runtime::RuntimeApi,
super::runtime_executor::Executor,
>,
) -> Self {
Self::GTest(client)
}
}
#[cfg(feature = "gdev")]
impl From<Arc<super::FullClient<gdev_runtime::RuntimeApi, super::gdev_executor::GDevExecutor>>>
for Client
>,
> for Client
{
fn from(
client: Arc<
super::FullClient<gdev_runtime::RuntimeApi, super::gdev_executor::GDevExecutor>,
super::FullClient<
super::runtime_executor::runtime::RuntimeApi,
super::runtime_executor::Executor,
>,
>,
) -> Self {
Self::GDev(client)
Self::Client(client)
}
}
macro_rules! match_client {
($self:ident, $method:ident($($param:ident),*)) => {
match $self {
#[cfg(feature = "g1")]
Self::G1(client) => client.$method($($param),*),
#[cfg(feature = "gtest")]
Self::GTest(client) => client.$method($($param),*),
#[cfg(feature = "gdev")]
Self::GDev(client) => client.$method($($param),*),
Self::Client(client) => client.$method($($param),*),
}
};
}
......@@ -326,23 +294,28 @@ trait BenchmarkCallSigner<RuntimeCall: Encode + Clone, Signer: Pair> {
}
#[cfg(feature = "g1")]
use g1_runtime as runtime;
#[cfg(feature = "g1")]
type FullClient = super::FullClient<runtime::RuntimeApi, super::g1_executor::G1Executor>;
#[cfg(feature = "gdev")]
use gdev_runtime as runtime;
type FullClient = super::FullClient<
super::runtime_executor::runtime::RuntimeApi,
super::runtime_executor::Executor,
>;
#[cfg(feature = "gdev")]
type FullClient = super::FullClient<runtime::RuntimeApi, super::gdev_executor::GDevExecutor>;
#[cfg(feature = "gtest")]
use gtest_runtime as runtime;
type FullClient = super::FullClient<
super::runtime_executor::runtime::RuntimeApi,
super::runtime_executor::Executor,
>;
#[cfg(feature = "gtest")]
type FullClient = super::FullClient<runtime::RuntimeApi, super::gtest_executor::GTestExecutor>;
#[cfg(any(feature = "gdev", feature = "gtest"))]
impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullClient {
type FullClient = super::FullClient<
super::runtime_executor::runtime::RuntimeApi,
super::runtime_executor::Executor,
>;
#[cfg(any(feature = "gdev", feature = "gtest", feature = "g1"))]
impl BenchmarkCallSigner<super::runtime_executor::runtime::RuntimeCall, sp_core::sr25519::Pair>
for FullClient
{
fn sign_call(
&self,
call: runtime::RuntimeCall,
call: super::runtime_executor::runtime::RuntimeCall,
nonce: u32,
current_block: u64,
period: u64,
......@@ -351,17 +324,20 @@ impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullC
) -> sp_runtime::OpaqueExtrinsic {
// use runtime;
let extra: runtime::SignedExtra = (
frame_system::CheckNonZeroSender::<runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<runtime::Runtime>::new(),
frame_system::CheckTxVersion::<runtime::Runtime>::new(),
frame_system::CheckGenesis::<runtime::Runtime>::new(),
frame_system::CheckMortality::<runtime::Runtime>::from(
let extra: super::runtime_executor::runtime::SignedExtra = (
frame_system::CheckNonZeroSender::<super::runtime_executor::runtime::Runtime>::new(),
frame_system::CheckSpecVersion::<super::runtime_executor::runtime::Runtime>::new(),
frame_system::CheckTxVersion::<super::runtime_executor::runtime::Runtime>::new(),
frame_system::CheckGenesis::<super::runtime_executor::runtime::Runtime>::new(),
frame_system::CheckMortality::<super::runtime_executor::runtime::Runtime>::from(
sp_runtime::generic::Era::mortal(period, current_block),
),
frame_system::CheckNonce::<runtime::Runtime>::from(nonce).into(),
frame_system::CheckWeight::<runtime::Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<runtime::Runtime>::from(0),
frame_system::CheckNonce::<super::runtime_executor::runtime::Runtime>::from(nonce)
.into(),
frame_system::CheckWeight::<super::runtime_executor::runtime::Runtime>::new(),
pallet_transaction_payment::ChargeTransactionPayment::<
super::runtime_executor::runtime::Runtime,
>::from(0),
);
let payload = sp_runtime::generic::SignedPayload::from_raw(
......@@ -369,8 +345,8 @@ impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullC
extra.clone(),
(
(),
runtime::VERSION.spec_version,
runtime::VERSION.transaction_version,
super::runtime_executor::runtime::VERSION.spec_version,
super::runtime_executor::runtime::VERSION.transaction_version,
genesis,
genesis,
(),
......@@ -380,7 +356,7 @@ impl BenchmarkCallSigner<runtime::RuntimeCall, sp_core::sr25519::Pair> for FullC
);
let signature = payload.using_encoded(|p| acc.sign(p));
runtime::UncheckedExtrinsic::new_signed(
super::runtime_executor::runtime::UncheckedExtrinsic::new_signed(
call,
sp_runtime::AccountId32::from(acc.public()).into(),
common_runtime::Signature::Sr25519(signature),
......@@ -402,10 +378,10 @@ impl frame_benchmarking_cli::ExtrinsicBuilder for Client {
fn build(&self, nonce: u32) -> std::result::Result<sp_runtime::OpaqueExtrinsic, &'static str> {
with_client! {
self, client, {
let call = runtime::RuntimeCall::System(runtime::SystemCall::remark { remark: vec![] });
let call = super::runtime_executor::runtime::RuntimeCall::System(super::runtime_executor::runtime::SystemCall::remark { remark: vec![] });
let signer = sp_keyring::Sr25519Keyring::Bob.pair();
let period = runtime::BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
let period = super::runtime_executor::runtime::BlockHashCount::get().checked_next_power_of_two().map(|c| c / 2).unwrap_or(2) as u64;
let genesis = client.usage_info().chain.best_hash;
Ok(client.sign_call(call, nonce, 0, period, genesis, signer))
......
......@@ -55,6 +55,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",
......@@ -98,6 +99,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",
......@@ -137,6 +139,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 }
......
......@@ -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")
}
}
......
......@@ -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 }
......
......@@ -33,6 +33,7 @@ pub use common_runtime::{
constants::*, entities::*, handlers::*, AccountId, Address, Balance, BlockNumber,
FullIdentificationOfImpl, GetCurrentEpochIndex, Hash, Header, IdtyIndex, Index, Signature,
};
pub use frame_system::Call as SystemCall;
pub use pallet_balances::Call as BalancesCall;
pub use pallet_identity::{IdtyStatus, IdtyValue};
pub use pallet_im_online::sr25519::AuthorityId as ImOnlineId;
......
......@@ -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 }
......
......@@ -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",
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment