Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(devnet): add ismp #270

Merged
merged 9 commits into from
Sep 20, 2024
Merged
259 changes: 248 additions & 11 deletions Cargo.lock

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ sp-genesis-builder = { version = "0.14.0", default-features = false }
sp-inherents = { version = "33.0.0", default-features = false }
sp-io = { version = "37.0.0", default-features = false }
sp-keystore = "0.40.0"
sp-mmr-primitives = { version = "33.0.0", default-features = false }
sp-offchain = { version = "33.0.0", default-features = false }
sp-runtime = { version = "38.0.0", default-features = false }
sp-session = { version = "34.0.0", default-features = false }
Expand Down Expand Up @@ -175,3 +176,12 @@ paseo-runtime-constants = { git = "https://github.com/polkadot-fellows/runtimes"
# asset-hub-paseo-runtime = { git = "https://github.com/paseo-network/runtimes/", tag = "v1.2.5-system-chains", default-features = false }
# paseo-runtime = { git = "https://github.com/paseo-network/runtimes/", tag = "v1.2.5-system-chains", default-features = false }
# paseo-runtime-constants = { git = "https://github.com/paseo-network/runtimes/", tag = "v1.2.5-system-chains", default-features = false }

ismp = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }
peterwht marked this conversation as resolved.
Show resolved Hide resolved
ismp-parachain = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }
ismp-parachain-inherent = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }
ismp-parachain-runtime-api = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }
pallet-ismp = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }
pallet-ismp-demo = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }
peterwht marked this conversation as resolved.
Show resolved Hide resolved
pallet-ismp-rpc = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }
pallet-ismp-runtime-api = { git = "https://github.com/r0gue-io/ismp", branch = "polkadot-v1.14.0", default-features = false }
11 changes: 10 additions & 1 deletion networks/devnet.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,13 @@ balances = [
[[parachains.collators]]
name = "pop"
rpc_port = 9944
args = ["-lruntime::contracts=debug", "-lpopapi::extension=debug"]
args = ["-lruntime::contracts=debug", "-lpopapi::extension=debug", "--enable-offchain-indexing=true"]

[[parachains]]
id = 1000
chain = "asset-hub-rococo-local"

[[parachains.collators]]
name = "asset-hub"
args = ["-lxcm=trace"]
rpc_port = 9977
10 changes: 9 additions & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = "0.2.0-alpha"
clap.workspace = true
codec.workspace = true
futures.workspace = true
jsonrpsee.workspace = true
jsonrpsee = { workspace = true, features = [ "server" ] }
log.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand Down Expand Up @@ -78,6 +78,13 @@ cumulus-primitives-core.workspace = true
cumulus-primitives-parachain-inherent.workspace = true
cumulus-relay-chain-interface.workspace = true

# ismp
ismp-parachain.workspace = true
ismp-parachain-inherent.workspace = true
ismp-parachain-runtime-api.workspace = true
pallet-ismp-rpc.workspace = true
pallet-ismp-runtime-api.workspace = true

[build-dependencies]
substrate-build-script-utils.workspace = true

Expand Down Expand Up @@ -106,4 +113,5 @@ try-runtime = [
"sp-runtime/try-runtime",
]

ismp = [ "pop-runtime-devnet/default" ]
on-chain-release-build = [ "pop-runtime-mainnet/on-chain-release-build" ]
9 changes: 8 additions & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ fn devnet_genesis(
id: ParaId,
) -> serde_json::Value {
use pop_runtime_devnet::EXISTENTIAL_DEPOSIT;
let asset_hub = ismp_parachain::ParachainData { id: 1000, slot_duration: 6000 };
peterwht marked this conversation as resolved.
Show resolved Hide resolved

serde_json::json!({
"balances": {
Expand Down Expand Up @@ -342,7 +343,13 @@ fn devnet_genesis(
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"sudo": { "key": Some(root) }
"sudo": { "key": Some(root) },
// Set the following parachains to be tracked via ISMP.
"ismpParachain": pop_runtime_devnet::IsmpParachainConfig {
// Asset Hub
parachains: vec![asset_hub],
..Default::default()
},
})
}

Expand Down
118 changes: 74 additions & 44 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,22 +173,32 @@ macro_rules! construct_async_run {
})
}
Runtime::Testnet => {
runner.async_run(|$config| {
let $components = new_partial::<pop_runtime_testnet::RuntimeApi>(
&$config
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
#[cfg(feature = "ismp")]
unimplemented!("ISMP is not supported in testnet");
#[cfg(not(feature = "ismp"))]
{
runner.async_run(|$config| {
let $components = new_partial::<pop_runtime_testnet::RuntimeApi>(
&$config
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
}
}
Runtime::Mainnet => {
runner.async_run(|$config| {
let $components = new_partial::<pop_runtime_mainnet::RuntimeApi>(
&$config
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
#[cfg(feature = "ismp")]
unimplemented!("ISMP is not supported in mainnet");
#[cfg(not(feature = "ismp"))]
{
runner.async_run(|$config| {
let $components = new_partial::<pop_runtime_mainnet::RuntimeApi>(
&$config
)?;
let task_manager = $components.task_manager;
{ $( $code )* }.map(|v| (v, task_manager))
})
}
}
}
}}
Expand All @@ -202,12 +212,22 @@ macro_rules! construct_benchmark_partials {
$code
},
Runtime::Testnet => {
let $partials = new_partial::<pop_runtime_testnet::RuntimeApi>(&$config)?;
$code
#[cfg(feature = "ismp")]
unimplemented!("ISMP is not supported in testnet");
#[cfg(not(feature = "ismp"))]
{
let $partials = new_partial::<pop_runtime_testnet::RuntimeApi>(&$config)?;
$code
}
},
Runtime::Mainnet => {
let $partials = new_partial::<pop_runtime_mainnet::RuntimeApi>(&$config)?;
$code
#[cfg(feature = "ismp")]
unimplemented!("ISMP is not supported in mainnet");
#[cfg(not(feature = "ismp"))]
{
let $partials = new_partial::<pop_runtime_mainnet::RuntimeApi>(&$config)?;
$code
}
},
}
};
Expand Down Expand Up @@ -367,34 +387,44 @@ pub fn run() -> Result<()> {
.map_err(Into::into)
},
Runtime::Testnet => {
sp_core::crypto::set_default_ss58_version(
pop_runtime_testnet::SS58Prefix::get().into(),
);
crate::service::start_parachain_node::<pop_runtime_testnet::RuntimeApi>(
config,
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
.map_err(Into::into)
#[cfg(feature = "ismp")]
unimplemented!("ISMP is not supported in testnet");
#[cfg(not(feature = "ismp"))]
{
sp_core::crypto::set_default_ss58_version(
pop_runtime_testnet::SS58Prefix::get().into(),
);
crate::service::start_parachain_node::<pop_runtime_testnet::RuntimeApi>(
config,
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
.map_err(Into::into)
}
},
Runtime::Mainnet => {
sp_core::crypto::set_default_ss58_version(
pop_runtime_mainnet::SS58Prefix::get().into(),
);
crate::service::start_parachain_node::<pop_runtime_mainnet::RuntimeApi>(
config,
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
.map_err(Into::into)
#[cfg(feature = "ismp")]
unimplemented!("ISMP is not supported in mainnet");
#[cfg(not(feature = "ismp"))]
{
sp_core::crypto::set_default_ss58_version(
pop_runtime_mainnet::SS58Prefix::get().into(),
);
crate::service::start_parachain_node::<pop_runtime_mainnet::RuntimeApi>(
config,
polkadot_config,
collator_options,
id,
hwbench,
)
.await
.map(|r| r.0)
.map_err(Into::into)
}
},
}
})
Expand Down
60 changes: 53 additions & 7 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,33 +7,44 @@

use std::sync::Arc;

use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use pop_runtime_common::{AccountId, Balance, Block, Nonce};
use sc_client_api::{AuxStore, BlockBackend, ProofProvider};
pub use sc_rpc::DenyUnsafe;
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
#[cfg(feature = "ismp")]
use sp_core::H256;
use substrate_frame_rpc_system::{System, SystemApiServer};

/// A type representing all RPC extensions.
pub type RpcExtension = jsonrpsee::RpcModule<()>;

/// Full client dependencies
pub struct FullDeps<C, P> {
pub struct FullDeps<C, P, B> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// Whether to deny unsafe calls
pub deny_unsafe: DenyUnsafe,
/// Backend used by the node.
pub backend: Arc<B>,

Check warning on line 34 in node/src/rpc.rs

View workflow job for this annotation

GitHub Actions / clippy

field `backend` is never read

warning: field `backend` is never read --> node/src/rpc.rs:34:6 | 26 | pub struct FullDeps<C, P, B> { | -------- field in this struct ... 34 | pub backend: Arc<B>, | ^^^^^^^ | = note: `#[warn(dead_code)]` on by default
}

/// Instantiate all RPC extensions.
pub fn create_full<C, P>(
deps: FullDeps<C, P>,
#[cfg(not(feature = "ismp"))]
pub fn create_full<C, P, B>(
deps: FullDeps<C, P, B>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ AuxStore
+ BlockBackend<Block>
+ ProofProvider<Block>
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
Expand All @@ -42,14 +53,49 @@
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: BlockBuilder<Block>,
P: TransactionPool + Sync + Send + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashingFor<Block>>,
{
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer};
use substrate_frame_rpc_system::{System, SystemApiServer};
let mut module = RpcExtension::new(());
let FullDeps { client, pool, deny_unsafe, backend: _ } = deps;

module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;

Ok(module)
}

/// Instantiate all RPC extensions.
#[cfg(feature = "ismp")]
pub fn create_full<C, P, B>(
deps: FullDeps<C, P, B>,
) -> Result<RpcExtension, Box<dyn std::error::Error + Send + Sync>>
where
C: ProvideRuntimeApi<Block>
+ HeaderBackend<Block>
+ AuxStore
+ BlockBackend<Block>
+ ProofProvider<Block>
+ HeaderMetadata<Block, Error = BlockChainError>
+ Send
+ Sync
+ 'static,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: BlockBuilder<Block>,
C::Api: pallet_ismp_runtime_api::IsmpRuntimeApi<Block, H256>,
P: TransactionPool + Sync + Send + 'static,
B: sc_client_api::Backend<Block> + Send + Sync + 'static,
B::State: sc_client_api::StateBackend<sp_runtime::traits::HashingFor<Block>>,
{
let mut module = RpcExtension::new(());
let FullDeps { client, pool, deny_unsafe } = deps;
let FullDeps { client, pool, deny_unsafe, backend } = deps;

module.merge(System::new(client.clone(), pool, deny_unsafe).into_rpc())?;
module.merge(TransactionPayment::new(client).into_rpc())?;
module.merge(TransactionPayment::new(client.clone()).into_rpc())?;

use pallet_ismp_rpc::{IsmpApiServer, IsmpRpcHandler};
module.merge(IsmpRpcHandler::new(client, backend.clone())?.into_rpc())?;

Ok(module)
}
Loading
Loading