From be66f50aeb50f370c6faf34119e98d0eeee88aa1 Mon Sep 17 00:00:00 2001 From: yahortsaryk Date: Sun, 10 Mar 2024 16:48:13 +0100 Subject: [PATCH] fix: offchain workers are enabled --- Cargo.lock | 44 +++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + node/service/Cargo.toml | 1 + node/service/src/lib.rs | 23 ++++++++++++++++++++- 4 files changed, 68 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 68d2ce301..edd039435 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -981,6 +981,7 @@ dependencies = [ "sc-executor", "sc-network", "sc-network-common", + "sc-offchain", "sc-rpc", "sc-service", "sc-sync-state-rpc", @@ -7324,6 +7325,40 @@ dependencies = [ "substrate-prometheus-endpoint", ] +[[package]] +name = "sc-offchain" +version = "4.0.0-dev" +source = "git+https://github.com/paritytech/substrate?branch=polkadot-v1.0.0#948fbd2fd1233dc26dbb9f9bbc1d2cca2c03945d" +dependencies = [ + "array-bytes", + "bytes", + "fnv", + "futures", + "futures-timer", + "hyper", + "hyper-rustls", + "libp2p", + "log", + "num_cpus", + "once_cell", + "parity-scale-codec", + "parking_lot 0.12.1", + "rand 0.8.5", + "sc-client-api", + "sc-network", + "sc-network-common", + "sc-transaction-pool-api", + "sc-utils", + "sp-api", + "sp-core", + "sp-externalities", + "sp-keystore", + "sp-offchain", + "sp-runtime", + "threadpool", + "tracing", +] + [[package]] name = "sc-proposer-metrics" version = "0.10.0-dev" @@ -9138,6 +9173,15 @@ dependencies = [ "once_cell", ] +[[package]] +name = "threadpool" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" +dependencies = [ + "num_cpus", +] + [[package]] name = "tikv-jemalloc-sys" version = "0.5.4+5.3.0-patched" diff --git a/Cargo.toml b/Cargo.toml index 7fa5b3613..ba48a676e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -126,6 +126,7 @@ sc-sysinfo = { git = "https://github.com/paritytech/substrate.git", branch = "po sc-telemetry = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", default-features = false } sc-transaction-pool = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", default-features = false } sc-transaction-pool-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false } +sc-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0", default-features = false } sp-api = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", default-features = false } sp-arithmetic = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", default-features = false } sp-authority-discovery = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0", default-features = false } diff --git a/node/service/Cargo.toml b/node/service/Cargo.toml index 63b7aad5b..45e90e8be 100644 --- a/node/service/Cargo.toml +++ b/node/service/Cargo.toml @@ -36,6 +36,7 @@ sc-sysinfo = { workspace = true } sc-telemetry = { workspace = true } sc-transaction-pool = { workspace = true } sc-transaction-pool-api = { workspace = true } +sc-offchain = { workspace = true } sp-api = { workspace = true } sp-authority-discovery = { workspace = true } sp-blockchain = { workspace = true } diff --git a/node/service/src/lib.rs b/node/service/src/lib.rs index 997e84395..723eb7a45 100644 --- a/node/service/src/lib.rs +++ b/node/service/src/lib.rs @@ -10,7 +10,7 @@ pub use cere_dev_runtime; #[cfg(feature = "cere-native")] pub use cere_runtime; use futures::prelude::*; -use sc_client_api::BlockBackend; +use sc_client_api::{Backend, BlockBackend}; use sc_consensus_babe::{self, SlotProportion}; pub use sc_executor::NativeExecutionDispatch; use sc_network::{Event, NetworkEventStream}; @@ -399,6 +399,27 @@ where warp_sync_params: Some(WarpSyncParams::WithProvider(warp_sync)), })?; + if config.offchain_worker.enabled { + task_manager.spawn_handle().spawn( + "offchain-workers-runner", + "offchain-worker", + sc_offchain::OffchainWorkers::new(sc_offchain::OffchainWorkerOptions { + runtime_api_provider: client.clone(), + is_validator: config.role.is_authority(), + keystore: Some(keystore_container.keystore()), + offchain_db: backend.offchain_storage(), + transaction_pool: Some(OffchainTransactionPoolFactory::new( + transaction_pool.clone(), + )), + network_provider: network.clone(), + enable_http_requests: true, + custom_extensions: |_| vec![], + }) + .run(client.clone(), task_manager.spawn_handle()) + .boxed(), + ); + } + let role = config.role.clone(); let force_authoring = config.force_authoring; let backoff_authoring_blocks =