mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 20:27:58 +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
@@ -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