Skip to content

Commit 25e8dbb

Browse files
stiiifffclaudeffarall
authored
feat(shc-common): feature gate parachain dependencies (#581)
* feat(shc-common): feature gate parachain dependencies Add `parachain` feature to shc-common crate to allow building without parachain-specific dependencies for solochain deployments. Changes: - Add optional `parachain` feature (disabled by default) that controls: - cumulus-client-service - cumulus-primitives-core - cumulus-primitives-storage-weight-reclaim - Feature gate HostFunctions type: - With `parachain`: uses ParachainHostFunctions - Without `parachain`: uses SubstrateHostFunctions (solochain mode) - Rename types for clarity: - ParachainExecutor → StorageHubExecutor - ParachainClient → StorageHubClient - Keep deprecated aliases for backwards compatibility - Define BlockNumber locally in shp-opaque as u32, removing parachains-common dependency Dependency reduction (shc-common --no-default-features --features std): - Dependency tree: 5,816 → 3,243 lines (44% fewer) - Cumulus crates: 44 → 0 (100% removed) - cumulus-relay-chain-minimal-node: removed 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * fix: 🩹 Merge imports * fix: 🚨 Fix compiler issues after merge --------- Co-authored-by: Claude <[email protected]> Co-authored-by: Facundo Farall <[email protected]>
1 parent 90da68e commit 25e8dbb

File tree

19 files changed

+80
-71
lines changed

19 files changed

+80
-71
lines changed

Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

client/blockchain-service/src/handler.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ use shc_blockchain_service_db::{leadership::LeadershipClient, store::PendingTxSt
3535
use shc_common::{
3636
blockchain_utils::{convert_raw_multiaddresses_to_multiaddr, get_events_at_block},
3737
typed_store::{CFDequeAPI, ProvidesTypedDbSingleAccess},
38-
types::{AccountId, BlockNumber, OpaqueBlock, ParachainClient, TickNumber},
38+
types::{AccountId, BlockNumber, OpaqueBlock, StorageHubClient, TickNumber},
3939
};
4040
use shc_forest_manager::traits::ForestStorageHandler;
4141

@@ -56,7 +56,7 @@ pub(crate) const LOG_TARGET: &str = "blockchain-service";
5656
/// The BlockchainService actor.
5757
///
5858
/// This actor is responsible for sending extrinsics to the runtime and handling block import notifications.
59-
/// For such purposes, it uses the [`ParachainClient<RuntimeApi>`] to interact with the runtime, the [`RpcHandlers`] to send
59+
/// For such purposes, it uses the [`StorageHubClient<RuntimeApi>`] to interact with the runtime, the [`RpcHandlers`] to send
6060
/// extrinsics, and the [`Keystore`] to sign the extrinsics.
6161
pub struct BlockchainService<FSH, Runtime>
6262
where
@@ -68,8 +68,8 @@ where
6868
/// The event bus provider.
6969
pub(crate) event_bus_provider: BlockchainServiceEventBusProvider<Runtime>,
7070
/// The parachain client. Used to interact with the runtime.
71-
/// TODO: Consider not using `ParachainClient` here.
72-
pub(crate) client: Arc<ParachainClient<Runtime::RuntimeApi>>,
71+
/// TODO: Consider not using `StorageHubClient` here.
72+
pub(crate) client: Arc<StorageHubClient<Runtime::RuntimeApi>>,
7373
/// The keystore. Used to sign extrinsics.
7474
pub(crate) keystore: KeystorePtr,
7575
/// The RPC handlers. Used to send extrinsics.
@@ -1355,7 +1355,7 @@ where
13551355
/// Create a new [`BlockchainService`].
13561356
pub fn new(
13571357
config: BlockchainServiceConfig<Runtime>,
1358-
client: Arc<ParachainClient<Runtime::RuntimeApi>>,
1358+
client: Arc<StorageHubClient<Runtime::RuntimeApi>>,
13591359
keystore: KeystorePtr,
13601360
rpc_handlers: Arc<RpcHandlers>,
13611361
forest_storage_handler: FSH,

client/blockchain-service/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ use sp_keystore::KeystorePtr;
1919

2020
use capacity_manager::{CapacityConfig, CapacityRequestQueue};
2121
use shc_actors_framework::actor::{ActorHandle, ActorSpawner, TaskSpawner};
22-
use shc_common::types::ParachainClient;
22+
use shc_common::types::StorageHubClient;
2323

2424
pub use self::handler::BlockchainService;
2525

2626
pub async fn spawn_blockchain_service<FSH, Runtime>(
2727
task_spawner: &TaskSpawner,
2828
config: BlockchainServiceConfig<Runtime>,
29-
client: Arc<ParachainClient<Runtime::RuntimeApi>>,
29+
client: Arc<StorageHubClient<Runtime::RuntimeApi>>,
3030
keystore: KeystorePtr,
3131
rpc_handlers: Arc<RpcHandlers>,
3232
forest_storage_handler: FSH,

client/blockchain-service/src/utils.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use shc_common::{
2727
traits::{ExtensionOperations, KeyTypeOperations, StorageEnableRuntime},
2828
types::{
2929
AccountId, BlockNumber, FileKey, Fingerprint, ForestRoot, MinimalExtension, OpaqueBlock,
30-
ParachainClient, ProofsDealerProviderId, StorageEnableEvents, StorageProviderId,
30+
ProofsDealerProviderId, StorageEnableEvents, StorageHubClient, StorageProviderId,
3131
TrieAddMutation, TrieMutation, TrieRemoveMutation, BCSV_KEY_TYPE,
3232
},
3333
};
@@ -725,7 +725,7 @@ where
725725
/// Construct an extrinsic that can be applied to the runtime using a generic signature type.
726726
pub fn construct_extrinsic(
727727
&self,
728-
client: Arc<ParachainClient<Runtime::RuntimeApi>>,
728+
client: Arc<StorageHubClient<Runtime::RuntimeApi>>,
729729
function: impl Into<Runtime::Call>,
730730
nonce: u32,
731731
tip: u128,

client/common/Cargo.toml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ k256 = { workspace = true, features = ["ecdsa", "arithmetic"] }
5656
# Polkadot
5757
polkadot-primitives = { workspace = true }
5858

59-
# Cumulus
60-
cumulus-client-service = { workspace = true }
61-
cumulus-primitives-core = { workspace = true }
62-
cumulus-primitives-storage-weight-reclaim = { workspace = true }
59+
# Cumulus (optional, for parachain support)
60+
cumulus-client-service = { workspace = true, optional = true }
61+
cumulus-primitives-core = { workspace = true, optional = true }
62+
cumulus-primitives-storage-weight-reclaim = { workspace = true, optional = true }
6363

6464
# Frontier
6565
fp-account = { workspace = true }
@@ -91,6 +91,11 @@ tempfile = "3.8"
9191

9292
[features]
9393
default = ["std"]
94+
parachain = [
95+
"cumulus-client-service",
96+
"cumulus-primitives-core",
97+
"cumulus-primitives-storage-weight-reclaim",
98+
]
9499
std = [
95100
"codec/std",
96101
"frame-benchmarking/std",
@@ -112,8 +117,8 @@ std = [
112117
"sp-std/std",
113118
"trie-db/std",
114119
"polkadot-primitives/std",
115-
"cumulus-primitives-core/std",
116-
"cumulus-primitives-storage-weight-reclaim/std",
120+
"cumulus-primitives-core?/std",
121+
"cumulus-primitives-storage-weight-reclaim?/std",
117122
"shp-constants/std",
118123
"shp-file-key-verifier/std",
119124
"shp-file-metadata/std",

client/common/src/blockchain_utils.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use sp_core::{H256, U256};
1414
use crate::{
1515
traits::{KeyTypeOperations, StorageEnableRuntime},
1616
types::{
17-
Multiaddresses, ParachainClient, StorageHubEventsVec, StorageProviderId, BCSV_KEY_TYPE,
17+
Multiaddresses, StorageHubClient, StorageHubEventsVec, StorageProviderId, BCSV_KEY_TYPE,
1818
},
1919
};
2020

@@ -42,7 +42,7 @@ pub enum EventsRetrievalError {
4242

4343
/// Get the events storage element for a given block.
4444
pub fn get_events_at_block<Runtime: StorageEnableRuntime>(
45-
client: &Arc<ParachainClient<Runtime::RuntimeApi>>,
45+
client: &Arc<StorageHubClient<Runtime::RuntimeApi>>,
4646
block_hash: &H256,
4747
) -> Result<StorageHubEventsVec<Runtime>, EventsRetrievalError> {
4848
// Get the events storage.
@@ -67,7 +67,7 @@ pub fn get_events_at_block<Runtime: StorageEnableRuntime>(
6767
/// - `Ok(None)` if the block hash doesn't exist (may have been pruned)
6868
/// - `Err(...)` if there's an error accessing storage
6969
pub fn get_ethereum_block_hash<RuntimeApi>(
70-
client: &Arc<ParachainClient<RuntimeApi>>,
70+
client: &Arc<StorageHubClient<RuntimeApi>>,
7171
block_hash: &H256,
7272
block_number: u32,
7373
) -> Result<Option<H256>, sp_blockchain::Error> {
@@ -144,7 +144,7 @@ pub enum GetProviderIdError {
144144
/// - `Err(GetProviderIdError::MultipleProviderIds)` if multiple Provider IDs are found
145145
/// - `Err(GetProviderIdError::RuntimeApiError)` if there's an error calling the runtime API
146146
pub fn get_provider_id_from_keystore<Runtime>(
147-
client: &Arc<ParachainClient<Runtime::RuntimeApi>>,
147+
client: &Arc<StorageHubClient<Runtime::RuntimeApi>>,
148148
keystore: &sp_keystore::KeystorePtr,
149149
block_hash: &H256,
150150
) -> Result<Option<StorageProviderId<Runtime>>, GetProviderIdError>

client/common/src/traits.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ use crate::types::*;
4848
///
4949
/// ## In Function Signatures
5050
/// ```ignore
51-
/// fn spawn_blockchain_service<RuntimeApi>(client: Arc<ParachainClient<RuntimeApi>>)
51+
/// fn spawn_blockchain_service<RuntimeApi>(client: Arc<StorageHubClient<RuntimeApi>>)
5252
/// where
5353
/// RuntimeApi::RuntimeApi: StorageEnableApiCollection,
5454
/// {
@@ -181,7 +181,7 @@ where
181181
}
182182

183183
pub trait StorageEnableRuntimeApi:
184-
ConstructRuntimeApi<Block, TFullClient<Block, Self, ParachainExecutor>>
184+
ConstructRuntimeApi<Block, TFullClient<Block, Self, StorageHubExecutor>>
185185
+ Sized
186186
+ Send
187187
+ Sync
@@ -190,7 +190,7 @@ pub trait StorageEnableRuntimeApi:
190190
}
191191

192192
impl<T> StorageEnableRuntimeApi for T where
193-
T: ConstructRuntimeApi<Block, TFullClient<Block, Self, ParachainExecutor>>
193+
T: ConstructRuntimeApi<Block, TFullClient<Block, Self, StorageHubExecutor>>
194194
+ Sized
195195
+ Send
196196
+ Sync

client/common/src/types.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,35 +121,41 @@ pub type StorageHubEventsVec<Runtime> = Vec<
121121
>,
122122
>;
123123

124-
#[cfg(not(feature = "runtime-benchmarks"))]
124+
// Parachain host functions - only available when the `parachain` feature is enabled.
125+
#[cfg(all(feature = "parachain", not(feature = "runtime-benchmarks")))]
125126
type HostFunctions = cumulus_client_service::ParachainHostFunctions;
126127

127-
#[cfg(feature = "runtime-benchmarks")]
128+
#[cfg(all(feature = "parachain", feature = "runtime-benchmarks"))]
128129
type HostFunctions = (
129130
cumulus_client_service::ParachainHostFunctions,
130131
frame_benchmarking::benchmarking::HostFunctions,
131132
);
132133

133-
/// The wasm executor used by the StorageHub client, which has the set of host functions
134-
/// that are available in a regular Polkadot Parachain.
134+
// Solochain host functions - used when the `parachain` feature is disabled.
135+
#[cfg(all(not(feature = "parachain"), not(feature = "runtime-benchmarks")))]
136+
type HostFunctions = sp_io::SubstrateHostFunctions;
137+
138+
#[cfg(all(not(feature = "parachain"), feature = "runtime-benchmarks"))]
139+
type HostFunctions = (
140+
sp_io::SubstrateHostFunctions,
141+
frame_benchmarking::benchmarking::HostFunctions,
142+
);
143+
144+
/// The wasm executor used by the StorageHub client.
135145
///
136-
/// The fact that we're using a `ParachainExecutor` is only because we're using the
137-
/// set of host functions that are available in a regular Polkadot Parachain.
138-
/// If this client would require a different set of host functions, we would need to
139-
/// use a different executor, with a different set of host functions.
140-
pub type ParachainExecutor = WasmExecutor<HostFunctions>;
146+
/// When the `parachain` feature is enabled, this executor uses the set of host functions
147+
/// that are available in a regular Polkadot Parachain (`ParachainHostFunctions`).
148+
/// When the `parachain` feature is disabled (solochain mode), it uses the standard
149+
/// Substrate host functions (`SubstrateHostFunctions`).
150+
pub type StorageHubExecutor = WasmExecutor<HostFunctions>;
141151

142-
/// The full client used by the StorageHub client, which uses the [`ParachainExecutor`]
152+
/// The full client used by the StorageHub client, which uses the [`StorageHubExecutor`]
143153
/// as the wasm executor.
144154
///
145155
/// It is abstracted over the set of runtime APIs, defined later by a `Runtime` type that
146156
/// should implement the [`StorageEnableRuntime`](crate::traits::StorageEnableRuntime) trait.
147-
///
148-
/// The name `ParachainClient` is a bit misleading, as it is not necessarily a client for a
149-
/// parachain. But it is called this way because it uses the `ParachainExecutor` which is
150-
/// a [WasmExecutor] with the [`HostFunctions`] that are available in a regular Polkadot Parachain.
151-
pub type ParachainClient<RuntimeApi> =
152-
TFullClient<shp_opaque::Block, RuntimeApi, ParachainExecutor>;
157+
pub type StorageHubClient<RuntimeApi> =
158+
TFullClient<shp_opaque::Block, RuntimeApi, StorageHubExecutor>;
153159

154160
/// The type of key used for [`BlockchainService`]` operations.
155161
pub const BCSV_KEY_TYPE: KeyTypeId = KeyTypeId(*b"bcsv");

client/fisherman-service/src/handler.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use shc_actors_framework::actor::{Actor, ActorEventLoop};
1717
use shc_common::{
1818
blockchain_utils::get_events_at_block,
1919
traits::StorageEnableRuntime,
20-
types::{BlockNumber, OpaqueBlock, ParachainClient, StorageEnableEvents},
20+
types::{BlockNumber, OpaqueBlock, StorageEnableEvents, StorageHubClient},
2121
};
2222
use shc_indexer_db::models::FileDeletionType;
2323
use shp_types::Hash;
@@ -36,7 +36,7 @@ pub(crate) const LOG_TARGET: &str = "fisherman-service";
3636
/// to the StorageHub protocol to permissionlessly mutate (delete the file key) the merkle forest on chain.
3737
pub struct FishermanService<Runtime: StorageEnableRuntime> {
3838
/// Substrate client for blockchain interaction
39-
client: Arc<ParachainClient<Runtime::RuntimeApi>>,
39+
client: Arc<StorageHubClient<Runtime::RuntimeApi>>,
4040
/// Event bus provider for emitting fisherman events
4141
event_bus_provider: FishermanServiceEventBusProvider,
4242
/// Semaphore to prevent overlapping batch processing cycles (size 1)
@@ -76,7 +76,7 @@ pub enum FileKeyOperation {
7676
impl<Runtime: StorageEnableRuntime> FishermanService<Runtime> {
7777
/// Create a new FishermanService instance
7878
pub fn new(
79-
client: Arc<ParachainClient<Runtime::RuntimeApi>>,
79+
client: Arc<StorageHubClient<Runtime::RuntimeApi>>,
8080
batch_interval_seconds: u64,
8181
batch_deletion_limit: u64,
8282
) -> Self {

client/fisherman-service/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ pub mod handler;
1717
use std::sync::Arc;
1818

1919
use shc_actors_framework::actor::{ActorHandle, ActorSpawner, TaskSpawner};
20-
use shc_common::traits::StorageEnableRuntime;
21-
use shc_common::types::ParachainClient;
20+
use shc_common::{traits::StorageEnableRuntime, types::StorageHubClient};
2221

2322
pub use self::commands::{
2423
FishermanServiceCommand, FishermanServiceCommandInterface, FishermanServiceError,
@@ -32,7 +31,7 @@ pub use events::{BatchFileDeletions, FileDeletionTarget, FishermanServiceEventBu
3231
/// the StorageHub network for file deletion requests and construct proofs of inclusion to delete file keys from Bucket and BSP forests.
3332
pub async fn spawn_fisherman_service<Runtime: StorageEnableRuntime>(
3433
task_spawner: &TaskSpawner,
35-
client: Arc<ParachainClient<Runtime::RuntimeApi>>,
34+
client: Arc<StorageHubClient<Runtime::RuntimeApi>>,
3635
batch_interval_seconds: u64,
3736
batch_deletion_limit: u64,
3837
) -> ActorHandle<FishermanService<Runtime>> {

0 commit comments

Comments
 (0)