Skip to content

Commit 67a0162

Browse files
committed
compiling
1 parent 44f592c commit 67a0162

12 files changed

Lines changed: 342 additions & 34 deletions

File tree

Cargo.lock

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

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ ismp-parachain = { git = "https://github.com/polytope-labs/hyperbrid
253253
ismp-parachain-runtime-api = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2409", default-features = false }
254254
pallet-hyperbridge = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2409", default-features = false }
255255
pallet-ismp = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2409", default-features = false }
256+
pallet-ismp-rpc = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2409" }
256257
pallet-ismp-runtime-api = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2409", default-features = false }
257258
pallet-token-gateway = { git = "https://github.com/polytope-labs/hyperbridge", branch = "polkadot-stable2409", default-features = false }
258259

nodes/parachain/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ xcm = { workspace = true, features = ["std"] }
9292
frame-benchmarking = { workspace = true, features = ["std"] }
9393
frame-benchmarking-cli = { workspace = true }
9494

95+
#ISMP
96+
pallet-ismp-rpc = { workspace = true }
97+
pallet-ismp-runtime-api = { workspace = true }
98+
9599
[features]
96100
default = []
97101
fast-gov = ["peregrine-runtime/fast-gov", "runtime-common/fast-gov"]

nodes/parachain/src/rpc.rs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525

2626
use std::sync::Arc;
2727

28-
use sc_client_api::AuxStore;
28+
use pallet_ismp_rpc::{IsmpApiServer, IsmpRpcHandler};
29+
use sc_client_api::{AuxStore, BlockBackend, ProofProvider};
2930
use sc_transaction_pool_api::TransactionPool;
3031
use sp_api::ProvideRuntimeApi;
3132
use sp_block_builder::BlockBuilder;
@@ -37,41 +38,51 @@ use runtime_common::{opaque::Block, AccountId, Balance, Nonce};
3738
pub(crate) type RpcExtension = jsonrpsee::RpcModule<()>;
3839

3940
/// Full client dependencies.
40-
pub(crate) struct FullDeps<C, P> {
41+
pub(crate) struct FullDeps<C, P, B> {
4142
/// The client instance to use.
4243
pub client: Arc<C>,
4344
/// Transaction pool instance.
4445
pub pool: Arc<P>,
46+
/// Backend used by the node.
47+
pub backend: Arc<B>,
4548
}
4649

4750
/// Instantiate all RPC extensions.
48-
pub(crate) fn create_full<C, P>(deps: FullDeps<C, P>) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
51+
pub(crate) fn create_full<C, P, B>(
52+
deps: FullDeps<C, P, B>,
53+
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
4954
where
5055
C: ProvideRuntimeApi<Block>
5156
+ HeaderBackend<Block>
57+
+ BlockBackend<Block>
58+
+ ProofProvider<Block>
5259
+ AuxStore
5360
+ HeaderMetadata<Block, Error = BlockChainError>
5461
+ Send
5562
+ Sync
5663
+ 'static,
5764
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
5865
+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
59-
+ BlockBuilder<Block>,
66+
+ BlockBuilder<Block>
67+
+ pallet_ismp_runtime_api::IsmpRuntimeApi<Block, sp_core::H256>,
68+
6069
P: TransactionPool + 'static,
70+
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
71+
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashingFor<Block>>,
6172
{
6273
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
6374
use substrate_frame_rpc_system::{System, SystemApiServer};
6475

6576
let mut module = RpcExtension::new(());
66-
let FullDeps { client, pool } = deps;
77+
let FullDeps { client, pool, backend } = deps;
6778

6879
module.merge(System::new(Arc::clone(&client), pool).into_rpc())?;
69-
module.merge(TransactionPayment::new(client).into_rpc())?;
80+
module.merge(TransactionPayment::new(Arc::clone(&client)).into_rpc())?;
7081
// Extend this RPC with a custom API by using the following syntax.
7182
// `YourRpcStruct` should have a reference to a client, which is needed
7283
// to call into the runtime.
7384
//
74-
// `module.merge(YourRpcStruct::new(ReferenceToClient).into_rpc())?;`
85+
module.merge(IsmpRpcHandler::new(client, backend)?.into_rpc())?;
7586

7687
Ok(module)
7788
}

nodes/parachain/src/service.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,8 @@ where
210210
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
211211
+ substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>
212212
+ sp_consensus_aura::AuraApi<Block, AuthorityId>
213-
+ cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>,
213+
+ cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>
214+
+ pallet_ismp_runtime_api::IsmpRuntimeApi<Block, sp_core::H256>,
214215
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_state_machine::Backend<BlakeTwo256>,
215216
RB: FnOnce(
216217
Arc<TFullClient<Block, RuntimeApi, WasmExecutor<HostFunctions>>>,
@@ -270,11 +271,13 @@ where
270271
let rpc_builder = {
271272
let client = Arc::clone(&client);
272273
let transaction_pool = Arc::clone(&transaction_pool);
274+
let backend = Arc::clone(&backend);
273275

274276
Box::new(move |_| {
275277
let deps = crate::rpc::FullDeps {
276278
client: Arc::clone(&client),
277279
pool: Arc::clone(&transaction_pool),
280+
backend: Arc::clone(&backend),
278281
};
279282

280283
crate::rpc::create_full(deps).map_err(Into::into)
@@ -430,7 +433,8 @@ where
430433
+ pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>
431434
+ sp_consensus_aura::AuraApi<Block, AuthorityId>
432435
+ cumulus_primitives_core::CollectCollationInfo<Block>
433-
+ cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>,
436+
+ cumulus_primitives_aura::AuraUnincludedSegmentApi<Block>
437+
+ pallet_ismp_runtime_api::IsmpRuntimeApi<Block, sp_core::H256>,
434438
sc_client_api::StateBackendFor<TFullBackend<Block>, Block>: sp_state_machine::Backend<BlakeTwo256>,
435439
{
436440
start_node_impl::<API, _, _>(

runtimes/peregrine/src/ismp.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ use ismp::{host::StateMachine, module::IsmpModule, router::IsmpRouter};
44
use runtime_common::{AccountId, Balance};
55
use sp_core::{ConstU8, Get};
66
use sp_std::{boxed::Box, vec::Vec};
7-
use xcm::v4::prelude::*;
7+
use sp_weights::Weight;
8+
use xcm::v4::Location;
89

910
use crate::{
1011
governance::{RootOrCollectiveProportion, TechnicalCollective},
11-
Balances, Fungibles, Ismp, IsmpParachain, Runtime, RuntimeEvent, Timestamp, Treasury,
12+
Balances, Fungibles, Ismp, IsmpParachain, Runtime, RuntimeEvent, Timestamp, TokenGateway, Treasury,
1213
};
1314

1415
parameter_types! {
@@ -23,29 +24,24 @@ pub struct Router;
2324
impl IsmpRouter for Router {
2425
fn module_for_id(&self, id: Vec<u8>) -> Result<Box<dyn IsmpModule>, anyhow::Error> {
2526
match id.as_slice() {
26-
// pallet_hyperbridge::PALLET_HYPERBRIDGE_ID =>
27-
// Ok(Box::new(pallet_hyperbridge::Pallet::<Runtime>::default())),
28-
// id if TokenGateway::is_token_gateway(&id) => {
29-
// Ok(Box::new(pallet_token_gateway::Pallet::<Runtime>::default()))
30-
// }
27+
pallet_hyperbridge::PALLET_HYPERBRIDGE_ID => Ok(Box::new(pallet_hyperbridge::Pallet::<Runtime>::default())),
28+
id if TokenGateway::is_token_gateway(&id) => {
29+
Ok(Box::new(pallet_token_gateway::Pallet::<Runtime>::default()))
30+
}
3131
_ => Err(ismp::Error::ModuleNotFound(id))?,
3232
}
3333
}
3434
}
3535

3636
impl pallet_ismp::Config for Runtime {
3737
type RuntimeEvent = RuntimeEvent;
38-
// Modify the consensus client's permissions, for example, TechAdmin
3938
type AdminOrigin = RootOrCollectiveProportion<TechnicalCollective, 1, 2>;
4039
// The state machine identifier of the chain -- parachain id
4140
type HostStateMachine = HostStateMachine;
4241
type TimestampProvider = Timestamp;
4342
type Balance = Balance;
4443
type Currency = Balances;
45-
// Co-processor
4644
type Coprocessor = Coprocessor;
47-
// A tuple of types implementing the ConsensusClient interface, which defines
48-
// all consensus algorithms supported by this protocol deployment
4945
type ConsensusClients = (ismp_parachain::ParachainConsensusClient<Runtime, IsmpParachain>,);
5046
type Router = Router;
5147

@@ -55,7 +51,6 @@ impl pallet_ismp::Config for Runtime {
5551

5652
impl pallet_hyperbridge::Config for Runtime {
5753
type RuntimeEvent = RuntimeEvent;
58-
// pallet-ismp implements the IsmpHost
5954
type IsmpHost = Ismp;
6055
}
6156

@@ -86,9 +81,7 @@ impl Get<AccountId> for AssetAdmin {
8681
}
8782

8883
parameter_types! {
89-
// The hyperbridge parachain on Polkadot
90-
pub const NativeAssetId: AssetId = AssetId(Location::here());
91-
84+
pub const NativeAssetId: Location = Location::here();
9285
}
9386

9487
impl pallet_token_gateway::Config for Runtime {

runtimes/peregrine/src/runtime_apis.rs

Lines changed: 64 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use ::xcm::{
44
v4::{Asset, AssetId, Location},
55
VersionedAssetId, VersionedLocation, VersionedXcm,
66
};
7+
use cumulus_pallet_parachain_system::RelayChainState;
78
use cumulus_primitives_aura::Slot;
89
use cumulus_primitives_core::CollationInfo;
910
use frame_support::{
@@ -15,6 +16,11 @@ use frame_support::{
1516
},
1617
weights::Weight,
1718
};
19+
use ismp::{
20+
consensus::{ConsensusClientId, StateMachineHeight, StateMachineId},
21+
host::StateMachine,
22+
router::{Request, Response},
23+
};
1824
use kilt_runtime_api_did::RawDidLinkedInfo;
1925
use kilt_support::traits::ItemFilter;
2026
use pallet_asset_switch::xcm::AccountId32ToAccountId32JunctionConverter;
@@ -49,7 +55,7 @@ use runtime_common::{
4955
AccountId, AuthorityId, Balance, BlockNumber, DidIdentifier, Hash, Nonce,
5056
};
5157
use sp_api::impl_runtime_apis;
52-
use sp_core::OpaqueMetadata;
58+
use sp_core::{OpaqueMetadata, H256};
5359
use sp_inherents::{CheckInherentsResult, InherentData};
5460
use sp_metadata_ir::RuntimeApiMetadataIR;
5561
use sp_runtime::{
@@ -63,8 +69,9 @@ use crate::{
6369
kilt::{DipProofError, DipProofRequest, NativeAndForeignAssets},
6470
parachain::ConsensusHook,
6571
xcm::UniversalLocation,
66-
AssetSwitchPool1, Block, BondedCurrencies, BondedFungibles, Executive, InherentDataExt, ParachainStaking,
67-
ParachainSystem, Runtime, RuntimeCall, RuntimeGenesisConfig, SessionKeys, TransactionPayment, Web3Name, VERSION,
72+
AssetSwitchPool1, Block, BondedCurrencies, BondedFungibles, Executive, InherentDataExt, IsmpParachain,
73+
ParachainStaking, ParachainSystem, Runtime, RuntimeCall, RuntimeGenesisConfig, SessionKeys, TransactionPayment,
74+
Web3Name, VERSION,
6875
};
6976

7077
// This is necessary since by default `RUNTIME_API_VERSIONS` generated by
@@ -617,6 +624,60 @@ impl_runtime_apis! {
617624
}
618625
}
619626

627+
impl pallet_ismp_runtime_api::IsmpRuntimeApi<Block, <Block as BlockT>::Hash> for Runtime {
628+
fn host_state_machine() -> StateMachine {
629+
<Runtime as pallet_ismp::Config>::HostStateMachine::get()
630+
}
631+
632+
fn challenge_period(state_machine_id: StateMachineId) -> Option<u64> {
633+
pallet_ismp::Pallet::<Runtime>::challenge_period(state_machine_id)
634+
}
635+
636+
/// Fetch all ISMP events in the block, should only be called from runtime-api.
637+
fn block_events() -> Vec<::ismp::events::Event> {
638+
pallet_ismp::Pallet::<Runtime>::block_events()
639+
}
640+
641+
/// Fetch all ISMP events and their extrinsic metadata, should only be called from runtime-api.
642+
fn block_events_with_metadata() -> Vec<(::ismp::events::Event, Option<u32>)> {
643+
pallet_ismp::Pallet::<Runtime>::block_events_with_metadata()
644+
}
645+
646+
/// Return the scale encoded consensus state
647+
fn consensus_state(id: ConsensusClientId) -> Option<Vec<u8>> {
648+
pallet_ismp::Pallet::<Runtime>::consensus_states(id)
649+
}
650+
651+
/// Return the timestamp this client was last updated in seconds
652+
fn state_machine_update_time(height: StateMachineHeight) -> Option<u64> {
653+
pallet_ismp::Pallet::<Runtime>::state_machine_update_time(height)
654+
}
655+
656+
/// Return the latest height of the state machine
657+
fn latest_state_machine_height(id: StateMachineId) -> Option<u64> {
658+
pallet_ismp::Pallet::<Runtime>::latest_state_machine_height(id)
659+
}
660+
661+
/// Get actual requests
662+
fn requests(commitments: Vec<H256>) -> Vec<Request> {
663+
pallet_ismp::Pallet::<Runtime>::requests(commitments)
664+
}
665+
666+
/// Get actual requests
667+
fn responses(commitments: Vec<H256>) -> Vec<Response> {
668+
pallet_ismp::Pallet::<Runtime>::responses(commitments)
669+
}
670+
}
671+
672+
impl ismp_parachain_runtime_api::IsmpParachainApi<Block> for Runtime {
673+
fn para_ids() -> Vec<u32> {
674+
IsmpParachain::para_ids()
675+
}
676+
677+
fn current_relay_chain_state() -> RelayChainState {
678+
IsmpParachain::current_relay_chain_state()
679+
}
680+
}
620681

621682
#[cfg(feature = "runtime-benchmarks")]
622683
impl frame_benchmarking::Benchmark<Block> for Runtime {

0 commit comments

Comments
 (0)