Skip to content

Commit

Permalink
Added missing offchain worker code. Toufeeq
Browse files Browse the repository at this point in the history
  • Loading branch information
markopoloparadox committed Oct 10, 2023
1 parent 8505886 commit e884588
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 5 deletions.
35 changes: 35 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ sp-transaction-pool = { git = "https://github.com/paritytech/substrate.git", bra
sp-transaction-storage-proof = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-keystore = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-state-machine = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sc-offchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-statement-store = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-trie = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-externalities = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ sc-consensus-babe-rpc = "0.10.0-dev"
sp-consensus-babe = "0.10.0-dev"
sp-consensus = "0.10.0-dev"
sc-consensus = "0.10.0-dev"
sc-offchain = "4.0.0-dev"
# Renamed: (https://github.com/paritytech/substrate/pull/13458)
sc-consensus-grandpa-rpc = { 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" }
Expand Down
31 changes: 26 additions & 5 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
//! Service and ServiceFactory implementation. Specialized wrapper over substrate service.
#![allow(dead_code)]

use std::sync::Arc;

use avail_core::AppId;
use codec::Encode;
use da_runtime::{apis::RuntimeApi, NodeBlock as Block, Runtime};
use frame_system_rpc_runtime_api::AccountNonceApi;
use futures::prelude::*;
use pallet_transaction_payment::ChargeTransactionPayment;
use sc_client_api::Backend;
use sc_client_api::BlockBackend;
use sc_consensus_babe::{self, SlotProportion};
pub use sc_executor::NativeElseWasmExecutor;
Expand All @@ -39,6 +38,7 @@ use sc_transaction_pool_api::OffchainTransactionPoolFactory;
use sp_api::ProvideRuntimeApi;
use sp_core::crypto::Pair;
use sp_runtime::{generic::Era, traits::Block as BlockT, SaturatedConversion};
use std::sync::Arc;
use substrate_prometheus_endpoint::{PrometheusError, Registry};

use crate::rpc as node_rpc;
Expand Down Expand Up @@ -406,14 +406,14 @@ pub fn new_full_base(
let name = config.network.node_name.clone();
let enable_grandpa = !config.disable_grandpa;
let prometheus_registry = config.prometheus_registry().cloned();
let _enable_offchain_worker = config.offchain_worker.enabled;
let enable_offchain_worker = config.offchain_worker.enabled;
if let Some(reg) = prometheus_registry.as_ref() {
extend_metrics(reg)?;
}

let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
config,
backend,
backend: backend.clone(),
client: client.clone(),
keystore: keystore_container.keystore(),
network: network.clone(),
Expand Down Expand Up @@ -546,7 +546,7 @@ pub fn new_full_base(
name: Some(name),
observer_enabled: false,
keystore,
local_role: role,
local_role: role.clone(),
telemetry: telemetry.as_ref().map(|x| x.handle()),
protocol_name: grandpa_protocol_name,
};
Expand Down Expand Up @@ -579,6 +579,27 @@ pub fn new_full_base(
);
}

if enable_offchain_worker {
task_manager.spawn_handle().spawn(
"offchain-workers-runner",
"offchain-work",
sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions {
runtime_api_provider: client.clone(),
keystore: Some(keystore_container.keystore()),
offchain_db: backend.offchain_storage(),
transaction_pool: Some(OffchainTransactionPoolFactory::new(
transaction_pool.clone(),
)),
network_provider: network.clone(),
is_validator: role.is_authority(),
enable_http_requests: true,
custom_extensions: move |_| vec![],
})
.run(client.clone(), task_manager.spawn_handle())
.boxed(),
);
}

network_starter.start_network();
Ok(NewFullBase {
task_manager,
Expand Down

0 comments on commit e884588

Please sign in to comment.