Skip to content

Commit 10b650b

Browse files
committed
Refact dev chain
- reuse asgard for dev and clean unused codes - integrate rpc api
1 parent 2ea1889 commit 10b650b

27 files changed

+150
-3292
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ output
1616
deploy
1717
snapshot.bin
1818
*.wasm
19+
data

Cargo.lock

Lines changed: 1 addition & 97 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Makefile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,9 @@ deploy-bifrost-live:
125125
pm2 deploy scripts/bifrost-ecosystem.config.js production
126126

127127
# Run dev chain
128-
.PHONY: run-dev
129-
run-dev:
130-
RUST_LOG=debug cargo run -p node-cli --locked --features "with-dev-runtime" -- --tmp --dev
131-
132128
.PHONY: run-dev-manual-seal
133-
run-dev-manual-seal:
134-
RUST_LOG=debug cargo run -p node-cli --locked --features "with-dev-runtime" -- --tmp --dev --sealing instant --rpc-cors all --unsafe-ws-external
129+
run-dev:
130+
RUST_LOG=debug CARGO_INCREMENTAL=0 cargo run -p node-cli --locked --features "with-asgard-runtime" -- --tmp --dev --sealing instant --rpc-cors all --unsafe-ws-external
135131

136132
# Build docker image
137133
.PHONY: build-docker-image

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ make try-bifrost-runtime-upgrade
6666
## Run development chain
6767

6868
```bash
69-
RUST_LOG=debug cargo run -p node-cli --locked --features "with-dev-runtime" -- --tmp --dev
69+
make run-dev
7070
```
7171

7272
## Run local testnet with polkadot-launch

node/cli/Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,6 @@ with-asgard-runtime = [
7373
with-bifrost-runtime = [
7474
"node-service/with-bifrost-runtime",
7575
]
76-
with-dev-runtime = [
77-
"node-service/with-dev-runtime"
78-
]
7976
with-all-runtime = [
8077
"with-asgard-runtime",
8178
"with-bifrost-runtime",

node/cli/src/command.rs

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ fn load_spec(
7373
"bifrost-genesis" => Box::new(service::chain_spec::bifrost::chainspec_config(para_id)),
7474
#[cfg(feature = "with-bifrost-runtime")]
7575
"bifrost-local" => Box::new(service::chain_spec::bifrost::local_testnet_config(para_id)?),
76-
#[cfg(feature = "with-dev-runtime")]
77-
"dev" => Box::new(service::chain_spec::dev::development_config(para_id)?),
76+
#[cfg(feature = "with-asgard-runtime")]
77+
"dev" => Box::new(service::chain_spec::asgard::development_config(para_id)?),
7878
path => {
7979
let path = std::path::PathBuf::from(path);
8080
if path.to_str().map(|s| s.contains("asgard")) == Some(true) {
@@ -91,13 +91,6 @@ fn load_spec(
9191
}
9292
#[cfg(not(feature = "with-bifrost-runtime"))]
9393
return Err(service::BIFROST_RUNTIME_NOT_AVAILABLE.into());
94-
} else if path.to_str().map(|s| s.contains("asgard-dev")) == Some(true) {
95-
#[cfg(feature = "with-dev-runtime")]
96-
{
97-
Box::new(service::chain_spec::dev::ChainSpec::from_json_file(path)?)
98-
}
99-
#[cfg(not(feature = "with-dev-runtime"))]
100-
return Err(service::DEV_RUNTIME_NOT_AVAILABLE.into());
10194
} else {
10295
return Err("Unknown runtime is not available.".into());
10396
}
@@ -141,7 +134,7 @@ impl SubstrateCli for Cli {
141134
}
142135

143136
fn native_runtime_version(spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
144-
if spec.is_asgard() {
137+
if spec.is_asgard() || spec.is_dev() {
145138
#[cfg(feature = "with-asgard-runtime")]
146139
{
147140
&service::collator::asgard_runtime::VERSION
@@ -156,12 +149,7 @@ impl SubstrateCli for Cli {
156149
#[cfg(not(feature = "with-bifrost-runtime"))]
157150
panic!("{}", service::BIFROST_RUNTIME_NOT_AVAILABLE);
158151
} else {
159-
#[cfg(feature = "with-dev-runtime")]
160-
{
161-
&service::dev::dev_runtime::VERSION
162-
}
163-
#[cfg(not(feature = "with-dev-runtime"))]
164-
panic!("{}", service::DEV_RUNTIME_NOT_AVAILABLE);
152+
panic!("{}", "unknown runtime!");
165153
}
166154
}
167155
}
@@ -240,14 +228,6 @@ macro_rules! construct_async_run {
240228
let task_manager = $components.task_manager;
241229
{ $( $code )* }.map(|v| (v, task_manager))
242230
});
243-
#[cfg(feature = "with-dev-runtime")]
244-
return runner.async_run(|$config| {
245-
let $components = crate::service::dev::new_partial(
246-
&$config,
247-
)?;
248-
let task_manager = $components.task_manager;
249-
{ $( $code )* }.map(|v| (v, task_manager))
250-
});
251231
}}
252232
}
253233

@@ -265,7 +245,7 @@ macro_rules! with_runtime_or_err {
265245

266246
#[cfg(not(feature = "with-bifrost-runtime"))]
267247
return Err(service::BIFROST_RUNTIME_NOT_AVAILABLE.into());
268-
} else if $chain_spec.is_asgard() {
248+
} else if $chain_spec.is_asgard() || $chain_spec.is_dev() {
269249
#[cfg(feature = "with-asgard-runtime")]
270250
#[allow(unused_imports)]
271251
use asgard_runtime::{Block, RuntimeApi};
@@ -277,8 +257,9 @@ macro_rules! with_runtime_or_err {
277257

278258
#[cfg(not(feature = "with-asgard-runtime"))]
279259
return Err(service::ASGARD_RUNTIME_NOT_AVAILABLE.into());
280-
} else {
281-
return Err(service::DEV_RUNTIME_NOT_AVAILABLE.into());
260+
}
261+
else {
262+
return Err(service::UNKNOWN_RUNTIME.into());
282263
}
283264
}
284265
}
@@ -304,8 +285,8 @@ pub fn run() -> Result<()> {
304285
None => {
305286
let runner = cli.create_runner(&cli.run.normalize())?;
306287
runner.run_node_until_exit(|config| async move {
307-
if config.chain_spec.is_asgard_dev() {
308-
#[cfg(feature = "with-dev-runtime")]
288+
if config.chain_spec.is_dev() {
289+
#[cfg(feature = "with-asgard-runtime")]
309290
{
310291
return service::dev::new_full(config).map_err(Into::into);
311292
}

node/rpc/src/lib.rs

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ use bifrost_salp_rpc_api::{SalpRpcApi, SalpRpcWrapper};
4141
use bifrost_salp_rpc_runtime_api::SalpRuntimeApi;
4242
use node_primitives::{AccountId, Balance, Block, Nonce, ParaId, PoolId};
4343
use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
44-
use sc_client_api::AuxStore;
4544
use sc_rpc_api::DenyUnsafe;
4645
use sc_transaction_pool_api::TransactionPool;
4746
use sp_api::ProvideRuntimeApi;
@@ -64,15 +63,49 @@ pub struct FullDeps<C, P> {
6463
/// A IO handler that uses all Full RPC extensions.
6564
pub type RpcExtension = jsonrpc_core::IoHandler<sc_rpc::Metadata>;
6665

67-
/// Instantiate all Full RPC extensions.
68-
///
69-
/// NOTE: It's a `PATCH` for the RPC of asgard runtime.
66+
/// RPC of bifrost runtime.
7067
#[allow(non_snake_case)]
71-
pub fn create_full<C, P>(deps: FullDeps<C, P>) -> RpcExtension
68+
pub fn create_bifrost_rpc<C, P>(deps: FullDeps<C, P>) -> RpcExtension
69+
where
70+
C: ProvideRuntimeApi<Block>
71+
+ HeaderBackend<Block>
72+
+ HeaderMetadata<Block, Error = BlockChainError>
73+
+ Send
74+
+ Sync
75+
+ 'static,
76+
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
77+
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
78+
C::Api: FeeRuntimeApi<Block, AccountId>,
79+
C::Api: SalpRuntimeApi<Block, ParaId, AccountId>,
80+
C::Api: LiquidityMiningRuntimeApi<Block, AccountId, PoolId>,
81+
C::Api: ZenlinkProtocolRuntimeApi<Block, AccountId>,
82+
C::Api: BlockBuilder<Block>,
83+
P: TransactionPool + Sync + Send + 'static,
84+
{
85+
let mut io = jsonrpc_core::IoHandler::default();
86+
let FullDeps { client, pool, deny_unsafe } = deps;
87+
88+
io.extend_with(SystemApi::to_delegate(FullSystem::new(client.clone(), pool, deny_unsafe)));
89+
io.extend_with(TransactionPaymentApi::to_delegate(TransactionPayment::new(client.clone())));
90+
91+
io.extend_with(FeeRpcApi::to_delegate(FlexibleFeeStruct::new(client.clone())));
92+
93+
io.extend_with(SalpRpcApi::to_delegate(SalpRpcWrapper::new(client.clone())));
94+
95+
io.extend_with(LiquidityMiningRpcApi::to_delegate(LiquidityMiningRpcWrapper::new(
96+
client.clone(),
97+
)));
98+
99+
io.extend_with(ZenlinkProtocolApi::to_delegate(ZenlinkProtocol::new(client.clone())));
100+
101+
io
102+
}
103+
104+
/// RPC of asgard runtime.
105+
pub fn create_asgard_rpc<C, P>(deps: FullDeps<C, P>) -> RpcExtension
72106
where
73107
C: ProvideRuntimeApi<Block>
74108
+ HeaderBackend<Block>
75-
+ AuxStore
76109
+ HeaderMetadata<Block, Error = BlockChainError>
77110
+ Send
78111
+ Sync

node/service/Cargo.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrat
4848

4949
# Substrate Other
5050
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.11" }
51+
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.11" }
5152
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.11" }
5253
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.11" }
5354
try-runtime-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.11", optional = true }
@@ -77,7 +78,6 @@ log = '0.4'
7778
bifrost-runtime-common = { path = "../../runtime/common"}
7879
asgard-runtime = { path = "../../runtime/asgard", optional = true }
7980
bifrost-runtime = { path = "../../runtime/bifrost", optional = true }
80-
dev-runtime = { path = "../../runtime/dev", optional = true }
8181
node-primitives = { path = "../primitives" }
8282
node-rpc = { path = "../rpc" }
8383

@@ -105,9 +105,6 @@ with-asgard-runtime = [
105105
with-bifrost-runtime = [
106106
"bifrost-runtime",
107107
]
108-
with-dev-runtime = [
109-
"dev-runtime",
110-
]
111108
with-all-runtime = [
112109
"with-asgard-runtime",
113110
"with-bifrost-runtime",

0 commit comments

Comments
 (0)