Skip to content

Commit ab8261a

Browse files
jiguantongboundless-foresthackfisheracgxv
authored
Configure instant sealing for dev chains (#119)
* Add start_dev_node * Add start_dev_node to command Fix compile * Don't check relay chain for dev node * Correct chain spec Identify * Add instant finalize * Clean * Add tip * Fix CI * opt * format * Revert "Fix CI" This reverts commit 63ae56a8a4ff329a708de8ae7287b3a2133fac19. * Format Signed-off-by: Xavier Lau <xavier@inv.cafe> * Remove redundant clone Signed-off-by: Xavier Lau <xavier@inv.cafe> Co-authored-by: bear <boundless.forest@outlook.com> Co-authored-by: fisher <denny.wang@itering.io> Co-authored-by: Xavier Lau <xavier@inv.cafe>
1 parent 1b9a5fc commit ab8261a

6 files changed

Lines changed: 324 additions & 10 deletions

File tree

Cargo.lock

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

node/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/substrate"
1515
[dependencies]
1616
# crates.io
1717
array-bytes = { version = "6.0" }
18+
async-trait = { version = "0.1" }
1819
clap = { version = "3.2", features = ["derive"] }
1920
codec = { package = "parity-scale-codec", version = "3.2" }
2021
futures = { version = "0.3" }
@@ -68,10 +69,12 @@ sc-chain-spec = { git = "https://github.com/paritytech/substrat
6869
sc-cli = { features = ["wasmtime"], git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
6970
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
7071
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
72+
sc-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
7173
sc-executor = { features = ["wasmtime"], git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
7274
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
7375
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
7476
sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
77+
sc-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
7578
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
7679
sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
7780
sc-service = { features = ["wasmtime"], git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }

node/src/chain_spec/pangolin.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,18 @@ pub fn genesis_config() -> ChainSpec {
154154
balances: Default::default(),
155155
transaction_payment: Default::default(),
156156
assets: AssetsConfig {
157-
assets: vec![(AssetIds::PKton as _, array_bytes::hex_n_into_unchecked(ALITH), true, 1)],
158-
metadata: vec![(AssetIds::PKton as _, b"Pangolin Commitment Token".to_vec(), b"PKTON".to_vec(), 18)],
157+
assets: vec![(
158+
AssetIds::PKton as _,
159+
array_bytes::hex_n_into_unchecked(ALITH),
160+
true,
161+
1,
162+
)],
163+
metadata: vec![(
164+
AssetIds::PKton as _,
165+
b"Pangolin Commitment Token".to_vec(),
166+
b"PKTON".to_vec(),
167+
18,
168+
)],
159169
..Default::default()
160170
},
161171

node/src/command.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -558,9 +558,6 @@ pub fn run() -> Result<()> {
558558
.map_err(|e| format!("{:?}", e))?;
559559
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
560560
let tokio_handle = config.tokio_handle.clone();
561-
let polkadot_config =
562-
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
563-
.map_err(|err| format!("Relay chain argument error: {}", err))?;
564561
let eth_rpc_config = cli.eth_args.build_eth_rpc_config();
565562

566563
log::info!("Parachain id: {:?}", id);
@@ -571,7 +568,33 @@ pub fn run() -> Result<()> {
571568
if config.role.is_authority() { "yes" } else { "no" }
572569
);
573570

574-
crate::service::start_parachain_node(
571+
if chain_spec.is_dev() {
572+
return if chain_spec.is_crab() {
573+
service::start_dev_node::<CrabRuntimeApi, CrabRuntimeExecutor>(
574+
config,
575+
&eth_rpc_config,
576+
)
577+
.map_err(Into::into)
578+
} else if chain_spec.is_pangolin() {
579+
service::start_dev_node::<PangolinRuntimeApi, PangolinRuntimeExecutor>(
580+
config,
581+
&eth_rpc_config,
582+
)
583+
.map_err(Into::into)
584+
} else {
585+
service::start_dev_node::<DarwiniaRuntimeApi, DarwiniaRuntimeExecutor>(
586+
config,
587+
&eth_rpc_config,
588+
)
589+
.map_err(Into::into)
590+
};
591+
}
592+
593+
let polkadot_config =
594+
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
595+
.map_err(|err| format!("Relay chain argument error: {}", err))?;
596+
597+
service::start_parachain_node(
575598
config,
576599
polkadot_config,
577600
collator_options,
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This file is part of Darwinia.
2+
//
3+
// Copyright (C) 2018-2022 Darwinia Network
4+
// SPDX-License-Identifier: GPL-3.0
5+
//
6+
// Darwinia is free software: you can redistribute it and/or modify
7+
// it under the terms of the GNU General Public License as published by
8+
// the Free Software Foundation, either version 3 of the License, or
9+
// (at your option) any later version.
10+
//
11+
// Darwinia is distributed in the hope that it will be useful,
12+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
// GNU General Public License for more details.
15+
//
16+
// You should have received a copy of the GNU General Public License
17+
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.
18+
19+
// substrate
20+
use sc_consensus::BlockImport;
21+
use sp_runtime::traits::Block as BlockT;
22+
23+
pub struct InstantFinalizeBlockImport<I>(I);
24+
impl<I> InstantFinalizeBlockImport<I> {
25+
/// Create a new instance.
26+
pub fn new(inner: I) -> Self {
27+
Self(inner)
28+
}
29+
}
30+
#[async_trait::async_trait]
31+
impl<Block, I> BlockImport<Block> for InstantFinalizeBlockImport<I>
32+
where
33+
Block: BlockT,
34+
I: BlockImport<Block> + Send,
35+
{
36+
type Error = I::Error;
37+
type Transaction = I::Transaction;
38+
39+
async fn check_block(
40+
&mut self,
41+
block: sc_consensus::BlockCheckParams<Block>,
42+
) -> Result<sc_consensus::ImportResult, Self::Error> {
43+
self.0.check_block(block).await
44+
}
45+
46+
async fn import_block(
47+
&mut self,
48+
mut block_import_params: sc_consensus::BlockImportParams<Block, Self::Transaction>,
49+
cache: std::collections::HashMap<sp_consensus::CacheKeyId, Vec<u8>>,
50+
) -> Result<sc_consensus::ImportResult, Self::Error> {
51+
block_import_params.finalized = true;
52+
self.0.import_block(block_import_params, cache).await
53+
}
54+
}

0 commit comments

Comments
 (0)