mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-09 18:47:59 +00:00
feat/ocw/bookkeeping (#5200)
Co-Authored-By: Kian Paimani <5588131+kianenigma@users.noreply.github.com> Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
f66168505b
commit
72ee7d5797
@@ -136,6 +136,18 @@ arg_enum! {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
arg_enum! {
|
||||
/// Whether off-chain workers are enabled.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum OffchainWorkerEnabled {
|
||||
Always,
|
||||
Never,
|
||||
WhenValidating,
|
||||
}
|
||||
}
|
||||
|
||||
/// Default value for the `--execution-syncing` parameter.
|
||||
pub const DEFAULT_EXECUTION_SYNCING: ExecutionStrategy = ExecutionStrategy::NativeElseWasm;
|
||||
/// Default value for the `--execution-import-block` parameter.
|
||||
|
||||
@@ -144,6 +144,12 @@ macro_rules! substrate_cli_subcommands {
|
||||
}
|
||||
}
|
||||
|
||||
fn offchain_worker_params(&self) -> Option<&$crate::OffchainWorkerParams> {
|
||||
match self {
|
||||
$($enum::$variant(cmd) => cmd.offchain_worker_params()),*
|
||||
}
|
||||
}
|
||||
|
||||
fn base_path(&self) -> $crate::Result<::std::option::Option<::std::path::PathBuf>> {
|
||||
match self {
|
||||
$($enum::$variant(cmd) => cmd.base_path()),*
|
||||
@@ -327,7 +333,7 @@ macro_rules! substrate_cli_subcommands {
|
||||
}
|
||||
}
|
||||
|
||||
fn offchain_worker(&self, role: &::sc_service::Role) -> $crate::Result<bool> {
|
||||
fn offchain_worker(&self, role: &::sc_service::Role) -> $crate::Result<::sc_service::config::OffchainWorkerConfig> {
|
||||
match self {
|
||||
$($enum::$variant(cmd) => cmd.offchain_worker(role)),*
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ use crate::params::KeystoreParams;
|
||||
use crate::params::NetworkParams;
|
||||
use crate::params::SharedParams;
|
||||
use crate::params::TransactionPoolParams;
|
||||
use crate::params::OffchainWorkerParams;
|
||||
use crate::CliConfiguration;
|
||||
use regex::Regex;
|
||||
use sc_service::{
|
||||
@@ -28,18 +29,7 @@ use sc_service::{
|
||||
};
|
||||
use sc_telemetry::TelemetryEndpoints;
|
||||
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
|
||||
use structopt::{clap::arg_enum, StructOpt};
|
||||
|
||||
arg_enum! {
|
||||
/// Whether off-chain workers are enabled.
|
||||
#[allow(missing_docs)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum OffchainWorkerEnabled {
|
||||
Always,
|
||||
Never,
|
||||
WhenValidating,
|
||||
}
|
||||
}
|
||||
use structopt::StructOpt;
|
||||
|
||||
/// The `run` command used to run a node.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
@@ -173,17 +163,9 @@ pub struct RunCmd {
|
||||
#[structopt(long = "telemetry-url", value_name = "URL VERBOSITY", parse(try_from_str = parse_telemetry_endpoints))]
|
||||
pub telemetry_endpoints: Vec<(String, u8)>,
|
||||
|
||||
/// Should execute offchain workers on every block.
|
||||
///
|
||||
/// By default it's only enabled for nodes that are authoring new blocks.
|
||||
#[structopt(
|
||||
long = "offchain-worker",
|
||||
value_name = "ENABLED",
|
||||
possible_values = &OffchainWorkerEnabled::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = "WhenValidating"
|
||||
)]
|
||||
pub offchain_worker: OffchainWorkerEnabled,
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
pub offchain_worker_params: OffchainWorkerParams,
|
||||
|
||||
#[allow(missing_docs)]
|
||||
#[structopt(flatten)]
|
||||
@@ -300,6 +282,10 @@ impl CliConfiguration for RunCmd {
|
||||
Some(&self.keystore_params)
|
||||
}
|
||||
|
||||
fn offchain_worker_params(&self) -> Option<&OffchainWorkerParams> {
|
||||
Some(&self.offchain_worker_params)
|
||||
}
|
||||
|
||||
fn node_name(&self) -> Result<String> {
|
||||
let name: String = match (self.name.as_ref(), self.get_keyring()) {
|
||||
(Some(name), _) => name.to_string(),
|
||||
@@ -439,15 +425,6 @@ impl CliConfiguration for RunCmd {
|
||||
Ok(self.unsafe_rpc_expose)
|
||||
}
|
||||
|
||||
fn offchain_worker(&self, role: &Role) -> Result<bool> {
|
||||
Ok(match (&self.offchain_worker, role) {
|
||||
(OffchainWorkerEnabled::WhenValidating, Role::Authority { .. }) => true,
|
||||
(OffchainWorkerEnabled::Always, _) => true,
|
||||
(OffchainWorkerEnabled::Never, _) => false,
|
||||
(OffchainWorkerEnabled::WhenValidating, _) => false,
|
||||
})
|
||||
}
|
||||
|
||||
fn transaction_pool(&self) -> Result<TransactionPoolOptions> {
|
||||
Ok(self.pool_config.transaction_pool())
|
||||
}
|
||||
|
||||
@@ -19,15 +19,15 @@
|
||||
use crate::error::Result;
|
||||
use crate::{
|
||||
init_logger, ImportParams, KeystoreParams, NetworkParams, NodeKeyParams,
|
||||
PruningParams, SharedParams, SubstrateCli,
|
||||
OffchainWorkerParams, PruningParams, SharedParams, SubstrateCli,
|
||||
};
|
||||
use crate::arg_enums::Database;
|
||||
use app_dirs::{AppDataType, AppInfo};
|
||||
use names::{Generator, Name};
|
||||
use sc_service::config::{
|
||||
Configuration, DatabaseConfig, ExecutionStrategies, ExtTransport, KeystoreConfig,
|
||||
NetworkConfiguration, NodeKeyConfig, PrometheusConfig, PruningMode, Role, TelemetryEndpoints,
|
||||
TransactionPoolOptions, WasmExecutionMethod,
|
||||
NetworkConfiguration, NodeKeyConfig, OffchainWorkerConfig, PrometheusConfig, PruningMode,
|
||||
Role, TelemetryEndpoints, TransactionPoolOptions, WasmExecutionMethod,
|
||||
};
|
||||
use sc_service::{ChainSpec, TracingReceiver};
|
||||
use std::future::Future;
|
||||
@@ -67,6 +67,11 @@ pub trait CliConfiguration: Sized {
|
||||
None
|
||||
}
|
||||
|
||||
/// Get a reference to `OffchainWorkerParams` for this object.
|
||||
fn offchain_worker_params(&self) -> Option<&OffchainWorkerParams> {
|
||||
None
|
||||
}
|
||||
|
||||
/// Get the NodeKeyParams for this object
|
||||
fn node_key_params(&self) -> Option<&NodeKeyParams> {
|
||||
self.network_params()
|
||||
@@ -301,11 +306,13 @@ pub trait CliConfiguration: Sized {
|
||||
Ok(Default::default())
|
||||
}
|
||||
|
||||
/// Returns `Ok(true)` if offchain worker should be used
|
||||
/// Returns an offchain worker config wrapped in `Ok(_)`
|
||||
///
|
||||
/// By default this is `false`.
|
||||
fn offchain_worker(&self, _role: &Role) -> Result<bool> {
|
||||
Ok(Default::default())
|
||||
/// By default offchain workers are disabled.
|
||||
fn offchain_worker(&self, role: &Role) -> Result<OffchainWorkerConfig> {
|
||||
self.offchain_worker_params()
|
||||
.map(|x| x.offchain_worker(role))
|
||||
.unwrap_or_else(|| { Ok(OffchainWorkerConfig::default()) })
|
||||
}
|
||||
|
||||
/// Returns `Ok(true)` if authoring should be forced
|
||||
|
||||
@@ -21,6 +21,7 @@ mod node_key_params;
|
||||
mod pruning_params;
|
||||
mod shared_params;
|
||||
mod transaction_pool_params;
|
||||
mod offchain_worker_params;
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::str::FromStr;
|
||||
@@ -29,6 +30,7 @@ pub use crate::params::import_params::*;
|
||||
pub use crate::params::keystore_params::*;
|
||||
pub use crate::params::network_params::*;
|
||||
pub use crate::params::node_key_params::*;
|
||||
pub use crate::params::offchain_worker_params::*;
|
||||
pub use crate::params::pruning_params::*;
|
||||
pub use crate::params::shared_params::*;
|
||||
pub use crate::params::transaction_pool_params::*;
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
// Copyright 2020 Parity Technologies (UK) Ltd.
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Substrate 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.
|
||||
|
||||
// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
//! Offchain worker related configuration parameters.
|
||||
//!
|
||||
//! A subset of configuration parameters which are relevant to
|
||||
//! the inner working of offchain workers. The usage is solely
|
||||
//! targeted at handling input parameter parsing providing
|
||||
//! a reasonable abstraction.
|
||||
|
||||
use structopt::StructOpt;
|
||||
use sc_service::config::OffchainWorkerConfig;
|
||||
use sc_network::config::Role;
|
||||
|
||||
use crate::error;
|
||||
use crate::OffchainWorkerEnabled;
|
||||
|
||||
|
||||
/// Offchain worker related parameters.
|
||||
#[derive(Debug, StructOpt, Clone)]
|
||||
pub struct OffchainWorkerParams {
|
||||
/// Should execute offchain workers on every block.
|
||||
///
|
||||
/// By default it's only enabled for nodes that are authoring new blocks.
|
||||
#[structopt(
|
||||
long = "offchain-worker",
|
||||
value_name = "ENABLED",
|
||||
possible_values = &OffchainWorkerEnabled::variants(),
|
||||
case_insensitive = true,
|
||||
default_value = "WhenValidating"
|
||||
)]
|
||||
pub enabled: OffchainWorkerEnabled,
|
||||
|
||||
/// Enable Offchain Indexing API, which allows block import to write to Offchain DB.
|
||||
///
|
||||
/// Enables a runtime to write directly to a offchain workers
|
||||
/// DB during block import.
|
||||
#[structopt(
|
||||
long = "enable-offchain-indexing",
|
||||
value_name = "ENABLE_OFFCHAIN_INDEXING"
|
||||
)]
|
||||
pub indexing_enabled: bool,
|
||||
}
|
||||
|
||||
impl OffchainWorkerParams {
|
||||
/// Load spec to `Configuration` from `OffchainWorkerParams` and spec factory.
|
||||
pub fn offchain_worker(
|
||||
&self,
|
||||
role: &Role,
|
||||
) -> error::Result<OffchainWorkerConfig>
|
||||
{
|
||||
let enabled = match (&self.enabled, role) {
|
||||
(OffchainWorkerEnabled::WhenValidating, Role::Authority { .. }) => true,
|
||||
(OffchainWorkerEnabled::Always, _) => true,
|
||||
(OffchainWorkerEnabled::Never, _) => false,
|
||||
(OffchainWorkerEnabled::WhenValidating, _) => false,
|
||||
};
|
||||
|
||||
let indexing_enabled = enabled && self.indexing_enabled;
|
||||
|
||||
Ok(OffchainWorkerConfig { enabled, indexing_enabled })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user