Skip to content

Commit f6eb400

Browse files
committed
add mmr rpc to the node
1 parent 7877f6c commit f6eb400

File tree

4 files changed

+41
-4
lines changed

4 files changed

+41
-4
lines changed

Cargo.lock

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

crates/subspace-service/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ futures = "0.3.29"
2424
hex = "0.4.3"
2525
jsonrpsee = { version = "0.16.3", features = ["server"] }
2626
mmr-gadget = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
27+
mmr-rpc = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
2728
pallet-transaction-payment-rpc = { version = "4.0.0-dev", git = "https://github.com/subspace/polkadot-sdk", rev = "d6b500960579d73c43fc4ef550b703acfa61c4c8" }
2829
parity-scale-codec = "3.6.9"
2930
parking_lot = "0.12.1"

crates/subspace-service/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,6 +1055,7 @@ where
10551055
let archived_segment_notification_stream = archived_segment_notification_stream.clone();
10561056
let transaction_pool = transaction_pool.clone();
10571057
let chain_spec = config.base.chain_spec.cloned_box();
1058+
let backend = backend.clone();
10581059

10591060
Box::new(move |deny_unsafe, subscription_executor| {
10601061
let deps = rpc::FullDeps {
@@ -1071,6 +1072,7 @@ where
10711072
segment_headers_store: segment_headers_store.clone(),
10721073
sync_oracle: sync_oracle.clone(),
10731074
kzg: subspace_link.kzg().clone(),
1075+
backend: backend.clone(),
10741076
};
10751077

10761078
rpc::create_full(deps).map_err(Into::into)

crates/subspace-service/src/rpc.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#![warn(missing_docs)]
2323

2424
use jsonrpsee::RpcModule;
25+
use mmr_rpc::{Mmr, MmrApiServer};
2526
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
2627
use sc_client_api::{AuxStore, BlockBackend};
2728
use sc_consensus_subspace::archiver::{ArchivedSegmentNotification, SegmentHeadersStore};
@@ -42,13 +43,14 @@ use sp_consensus_subspace::{FarmerPublicKey, SubspaceApi};
4243
use sp_objects::ObjectsApi;
4344
use std::sync::Arc;
4445
use subspace_core_primitives::crypto::kzg::Kzg;
46+
use subspace_core_primitives::BlockNumber;
4547
use subspace_networking::libp2p::Multiaddr;
4648
use subspace_runtime_primitives::opaque::Block;
4749
use subspace_runtime_primitives::{AccountId, Balance, Nonce};
4850
use substrate_frame_rpc_system::{System, SystemApiServer};
4951

5052
/// Full client dependencies.
51-
pub struct FullDeps<C, P, SO, AS>
53+
pub struct FullDeps<C, P, SO, AS, B>
5254
where
5355
SO: SyncOracle + Send + Sync + Clone,
5456
{
@@ -78,11 +80,13 @@ where
7880
pub sync_oracle: SubspaceSyncOracle<SO>,
7981
/// Kzg instance.
8082
pub kzg: Kzg,
83+
/// Backend used by the node.
84+
pub backend: Arc<B>,
8185
}
8286

8387
/// Instantiate all full RPC extensions.
84-
pub fn create_full<C, P, SO, AS>(
85-
deps: FullDeps<C, P, SO, AS>,
88+
pub fn create_full<C, P, SO, AS, B>(
89+
deps: FullDeps<C, P, SO, AS, B>,
8690
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
8791
where
8892
C: ProvideRuntimeApi<Block>
@@ -96,10 +100,13 @@ where
96100
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
97101
+ BlockBuilder<Block>
98102
+ SubspaceApi<Block, FarmerPublicKey>
103+
+ mmr_rpc::MmrRuntimeApi<Block, <Block as sp_runtime::traits::Block>::Hash, BlockNumber>
99104
+ ObjectsApi<Block>,
100105
P: TransactionPool + 'static,
101106
SO: SyncOracle + Send + Sync + Clone + 'static,
102107
AS: AuxStore + Send + Sync + 'static,
108+
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
109+
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashingFor<Block>>,
103110
{
104111
let mut module = RpcModule::new(());
105112
let FullDeps {
@@ -115,6 +122,7 @@ where
115122
segment_headers_store,
116123
sync_oracle,
117124
kzg,
125+
backend,
118126
} = deps;
119127

120128
let chain_name = chain_spec.name().to_string();
@@ -127,7 +135,7 @@ where
127135

128136
module.merge(
129137
SubspaceRpc::new(SubspaceRpcConfig {
130-
client,
138+
client: client.clone(),
131139
subscription_executor,
132140
new_slot_notification_stream,
133141
reward_signing_notification_stream,
@@ -140,6 +148,15 @@ where
140148
})?
141149
.into_rpc(),
142150
)?;
151+
module.merge(
152+
Mmr::new(
153+
client,
154+
backend
155+
.offchain_storage()
156+
.ok_or("Backend doesn't provide the required offchain storage")?,
157+
)
158+
.into_rpc(),
159+
)?;
143160

144161
Ok(module)
145162
}

0 commit comments

Comments
 (0)