Skip to content

Commit

Permalink
Configure instant sealing for dev chains (#119)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Remove redundant clone

Signed-off-by: Xavier Lau <[email protected]>
Co-authored-by: bear <[email protected]>
Co-authored-by: fisher <[email protected]>
Co-authored-by: Xavier Lau <[email protected]>
  • Loading branch information
4 people authored Dec 15, 2022
1 parent 1b9a5fc commit ab8261a
Show file tree
Hide file tree
Showing 6 changed files with 324 additions and 10 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/substrate"
[dependencies]
# crates.io
array-bytes = { version = "6.0" }
async-trait = { version = "0.1" }
clap = { version = "3.2", features = ["derive"] }
codec = { package = "parity-scale-codec", version = "3.2" }
futures = { version = "0.3" }
Expand Down Expand Up @@ -68,10 +69,12 @@ sc-chain-spec = { git = "https://github.com/paritytech/substrat
sc-cli = { features = ["wasmtime"], git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-executor = { features = ["wasmtime"], git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-network-common = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-rpc-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
sc-service = { features = ["wasmtime"], git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.30" }
Expand Down
14 changes: 12 additions & 2 deletions node/src/chain_spec/pangolin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,18 @@ pub fn genesis_config() -> ChainSpec {
balances: Default::default(),
transaction_payment: Default::default(),
assets: AssetsConfig {
assets: vec![(AssetIds::PKton as _, array_bytes::hex_n_into_unchecked(ALITH), true, 1)],
metadata: vec![(AssetIds::PKton as _, b"Pangolin Commitment Token".to_vec(), b"PKTON".to_vec(), 18)],
assets: vec![(
AssetIds::PKton as _,
array_bytes::hex_n_into_unchecked(ALITH),
true,
1,
)],
metadata: vec![(
AssetIds::PKton as _,
b"Pangolin Commitment Token".to_vec(),
b"PKTON".to_vec(),
18,
)],
..Default::default()
},

Expand Down
31 changes: 27 additions & 4 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,9 +558,6 @@ pub fn run() -> Result<()> {
.map_err(|e| format!("{:?}", e))?;
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));
let tokio_handle = config.tokio_handle.clone();
let polkadot_config =
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
.map_err(|err| format!("Relay chain argument error: {}", err))?;
let eth_rpc_config = cli.eth_args.build_eth_rpc_config();

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

crate::service::start_parachain_node(
if chain_spec.is_dev() {
return if chain_spec.is_crab() {
service::start_dev_node::<CrabRuntimeApi, CrabRuntimeExecutor>(
config,
&eth_rpc_config,
)
.map_err(Into::into)
} else if chain_spec.is_pangolin() {
service::start_dev_node::<PangolinRuntimeApi, PangolinRuntimeExecutor>(
config,
&eth_rpc_config,
)
.map_err(Into::into)
} else {
service::start_dev_node::<DarwiniaRuntimeApi, DarwiniaRuntimeExecutor>(
config,
&eth_rpc_config,
)
.map_err(Into::into)
};
}

let polkadot_config =
SubstrateCli::create_configuration(&polkadot_cli, &polkadot_cli, tokio_handle)
.map_err(|err| format!("Relay chain argument error: {}", err))?;

service::start_parachain_node(
config,
polkadot_config,
collator_options,
Expand Down
54 changes: 54 additions & 0 deletions node/src/service/instant_finalize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// This file is part of Darwinia.
//
// Copyright (C) 2018-2022 Darwinia Network
// SPDX-License-Identifier: GPL-3.0
//
// Darwinia is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Darwinia is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

// substrate
use sc_consensus::BlockImport;
use sp_runtime::traits::Block as BlockT;

pub struct InstantFinalizeBlockImport<I>(I);
impl<I> InstantFinalizeBlockImport<I> {
/// Create a new instance.
pub fn new(inner: I) -> Self {
Self(inner)
}
}
#[async_trait::async_trait]
impl<Block, I> BlockImport<Block> for InstantFinalizeBlockImport<I>
where
Block: BlockT,
I: BlockImport<Block> + Send,
{
type Error = I::Error;
type Transaction = I::Transaction;

async fn check_block(
&mut self,
block: sc_consensus::BlockCheckParams<Block>,
) -> Result<sc_consensus::ImportResult, Self::Error> {
self.0.check_block(block).await
}

async fn import_block(
&mut self,
mut block_import_params: sc_consensus::BlockImportParams<Block, Self::Transaction>,
cache: std::collections::HashMap<sp_consensus::CacheKeyId, Vec<u8>>,
) -> Result<sc_consensus::ImportResult, Self::Error> {
block_import_params.finalized = true;
self.0.import_block(block_import_params, cache).await
}
}
Loading

0 comments on commit ab8261a

Please sign in to comment.