Skip to content

Commit

Permalink
feat: make --dev work standalone (#334)
Browse files Browse the repository at this point in the history
* feat: make --dev work standalone

* feat: set address

* fix: prefund root account

* feat: add index token deposit range (#336)

* feat: add deposit range

* feat: remove dot contribution limits

* feat(docs): Adds mkdocs for project documentation  (#332)

* feat: added docs

* wip: pint documentation

* Update index.md

* Update index.md

* docs: update docs

* docs: add resources readme

* fix: typos

* docs: add note about parachain

* docs: add standalone chain docs

* docs: update run commands

* docs: add note

* feat(docs): adds docker option in getting-started

* feat(docs): adds test chapter in installation

* feat(docs): adds summary of e2e testing

* feat(docs): note git submodule in e2e tests

* feat(docs): fix typo in the submmary of e2e tests

Co-authored-by: Redwan <redwan.meslem@gmail.Com>
Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
Co-authored-by: clearloop <mercuryfletcher@gmail.com>

* feat(js): adds scripts in js directory (#339)

* feat(js): adds scripts updating types.json in js

* feat(js): export e2e script to workspace

* chore(docs): add more chain spec info (#341)

* chore: upgrade chainlink pallet (#340)

* chore: upgrade chainlink pallet

* fix: use latest genesis config

* chore(docs): update readme

* fix: dev command argument

Co-authored-by: Dustin Brickwood <dustinbrickwood204@gmail.com>
Co-authored-by: Redwan <redwan.meslem@gmail.Com>
Co-authored-by: clearloop <mercuryfletcher@gmail.com>
Co-authored-by: clearloop <udtrokia@gmail.com>
  • Loading branch information
5 people authored Sep 7, 2021
1 parent 80d0418 commit ac38962
Show file tree
Hide file tree
Showing 7 changed files with 207 additions and 13 deletions.
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,26 @@ build on another machine.

### Development Chain

You can start a standalone development chain with:
You can start a standalone development chain with instant sealing:

```bash
cargo run -- --dev --instant-sealing
cargo run -- --tmp --dev --instant-sealing
```

Use a chain spec file with pre funded Developer accounts

```bash
cargo run -- --tmp --chain ./resources/pint-dev.json --instant-sealing
```

__NOTE: the amount of PINT in all the endowed accounts (dev accounts) of the balances pallet (
see [pint-dev.json](resources/pint-dev.json)) directly affects the NAV, since this is the total amount of PINT in
curculation at genesis__

Or if already built

```bash
./target/release/pint --dev --instant-sealing
./target/release/pint --tmp --dev --instant-sealing
```

This will use the [`node/src/chain_spec/dev.rs`](node/src/chain_spec/dev.rs) chain spec.
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain_spec/dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn pint_testnet_genesis(
code: WASM_BINARY.expect("WASM binary was not build, please build it!").to_vec(),
changes_trie_config: Default::default(),
},
balances: BalancesConfig { balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 12)).collect() },
balances: BalancesConfig { balances: vec![(root_key.clone(), 1 << 60)] },
committee: CommitteeConfig { council_members: council_members.clone(), ..Default::default() },
chainlink_feed: ChainlinkFeedConfig {
feeds: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain_spec/kusama.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn pint_testnet_genesis(
code: WASM_BINARY.expect("WASM binary was not build, please build it!").to_vec(),
changes_trie_config: Default::default(),
},
balances: BalancesConfig { balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect() },
balances: BalancesConfig { balances: vec![(root_key.clone(), 1 << 60)] },
committee: CommitteeConfig { council_members: council_members.clone(), ..Default::default() },
chainlink_feed: ChainlinkFeedConfig {
feeds: Default::default(),
Expand Down
2 changes: 1 addition & 1 deletion node/src/chain_spec/polkadot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ fn pint_testnet_genesis(
code: WASM_BINARY.expect("WASM binary was not build, please build it!").to_vec(),
changes_trie_config: Default::default(),
},
balances: BalancesConfig { balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect() },
balances: BalancesConfig { balances: vec![(root_key.clone(), 1 << 60)] },
committee: CommitteeConfig { council_members: council_members.clone(), ..Default::default() },
chainlink_feed: ChainlinkFeedConfig {
feeds: Default::default(),
Expand Down
6 changes: 6 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ pub struct Cli {
/// Relaychain arguments
#[structopt(raw = true)]
pub relaychain_args: Vec<String>,

/// Instant block sealing
///
/// Can only be used with `--dev`
#[structopt(long = "instant-sealing")]
pub instant_sealing: bool,
}

#[derive(Debug)]
Expand Down
26 changes: 25 additions & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use std::{io::Write, net::SocketAddr};
fn load_spec(id: &str, para_id: ParaId) -> std::result::Result<Box<dyn sc_service::ChainSpec>, String> {
Ok(match id {
"pint-local" => Box::new(chain_spec::dev::pint_local_config(para_id)),
"pint-dev" => Box::new(chain_spec::dev::pint_development_config(para_id)),
"dev" | "pint-dev" => Box::new(chain_spec::dev::pint_development_config(para_id)),
#[cfg(feature = "kusama")]
"pint-kusama-local" => Box::new(chain_spec::kusama::pint_local_config(para_id)),
#[cfg(feature = "kusama")]
Expand Down Expand Up @@ -150,6 +150,20 @@ impl SubstrateCli for RelayChainCli {
}
}

fn set_default_ss58_version(spec: &Box<dyn sc_chain_spec::ChainSpec>) {
use sp_core::crypto::Ss58AddressFormat;

let ss58_version = if spec.is_kusama() {
Ss58AddressFormat::KusamaAccount
} else if spec.is_polkadot() {
Ss58AddressFormat::PolkadotAccount
} else {
Ss58AddressFormat::SubstrateAccount
};

sp_core::crypto::set_default_ss58_version(ss58_version);
}

fn extract_genesis_wasm(chain_spec: &Box<dyn sc_service::ChainSpec>) -> Result<Vec<u8>> {
let mut storage = chain_spec.build_storage()?;

Expand Down Expand Up @@ -296,10 +310,20 @@ pub fn run() -> Result<()> {
}
None => {
let runner = cli.create_runner(&cli.run.normalize())?;
let chain_spec = &runner.config().chain_spec;
let is_pint_dev = cli.run.base.shared_params.dev || cli.instant_sealing;

set_default_ss58_version(chain_spec);

runner.run_node_until_exit(|config| async move {
let para_id = chain_spec::Extensions::try_get(&*config.chain_spec).map(|e| e.para_id);

if is_pint_dev {
return service::pint_dev(config, cli.instant_sealing).map_err(Into::into);
} else if cli.instant_sealing {
return Err("Instant sealing can be turned on only in `--dev` mode".into());
}

let polkadot_cli = RelayChainCli::new(
&config,
[RelayChainCli::executable_name().to_string()].iter().chain(cli.relaychain_args.iter()),
Expand Down
166 changes: 160 additions & 6 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ use sc_consensus_aura::ImportQueueParams;
pub use sc_executor::NativeExecutor;
use sc_executor::{native_executor_instance, NativeExecutionDispatch};
use sc_network::NetworkService;
use sc_service::{Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager};
use sc_service::{
error::Error as ServiceError, Configuration, PartialComponents, Role, TFullBackend, TFullClient, TaskManager,
};
use sc_telemetry::{Telemetry, TelemetryHandle, TelemetryWorker, TelemetryWorkerHandle};
use sc_transaction_pool::BasicPool;
use sp_api::ConstructRuntimeApi;
Expand Down Expand Up @@ -69,15 +71,15 @@ pub trait IdentifyVariant {

impl IdentifyVariant for Box<dyn ChainSpec> {
fn is_kusama(&self) -> bool {
self.id().starts_with("kusama")
self.id().contains("kusama")
}

fn is_polkadot(&self) -> bool {
self.id().starts_with("polkadot")
self.id().contains("polkadot")
}

fn is_dev(&self) -> bool {
self.id().starts_with("dev")
self.id().starts_with("pint_dev")
}
}

Expand All @@ -87,7 +89,7 @@ type FullBackend = TFullBackend<Block>;
/// PINT's full client.
type FullClient<RuntimeApi, Executor> = TFullClient<Block, RuntimeApi, Executor>;

/// Maybe Mandala Dev full select chain.
/// Maybe PINT Dev full select chain.
type MaybeFullSelectChain = Option<LongestChain<FullBackend, Block>>;

fn default_mock_parachain_inherent_data_provider() -> MockValidationDataInherentDataProvider {
Expand Down Expand Up @@ -505,7 +507,159 @@ pub fn new_chain_ops(
Err(POLKADOT_RUNTIME_NOT_AVAILABLE.into())
} else {
let PartialComponents { client, backend, import_queue, task_manager, .. } =
new_partial::<pint_runtime_dev::RuntimeApi, DevExecutor>(config, false, false)?;
new_partial(config, config.chain_spec.is_dev(), false)?;
Ok((Arc::new(Client::Dev(client)), backend, import_queue, task_manager))
}
}

fn inner_pint_dev(config: Configuration, instant_sealing: bool) -> Result<TaskManager, ServiceError> {
use futures::stream::StreamExt;

let sc_service::PartialComponents {
client,
backend,
mut task_manager,
import_queue,
keystore_container,
select_chain: maybe_select_chain,
transaction_pool,
other: (mut telemetry, _),
} = new_partial::<pint_runtime_dev::RuntimeApi, DevExecutor>(&config, true, instant_sealing)?;

let (network, system_rpc_tx, network_starter) = sc_service::build_network(sc_service::BuildNetworkParams {
config: &config,
client: client.clone(),
transaction_pool: transaction_pool.clone(),
spawn_handle: task_manager.spawn_handle(),
import_queue,
on_demand: None,
block_announce_validator_builder: None,
warp_sync: None,
})?;

if config.offchain_worker.enabled {
sc_service::build_offchain_workers(&config, task_manager.spawn_handle(), client.clone(), network.clone());
}

let prometheus_registry = config.prometheus_registry().cloned();

let role = config.role.clone();
let force_authoring = config.force_authoring;
let backoff_authoring_blocks: Option<()> = None;

let select_chain =
maybe_select_chain.expect("In pint dev mode, `new_partial` will return some `select_chain`; qed");

if role.is_authority() {
let proposer_factory = sc_basic_authorship::ProposerFactory::new(
task_manager.spawn_handle(),
client.clone(),
transaction_pool.clone(),
prometheus_registry.as_ref(),
telemetry.as_ref().map(|x| x.handle()),
);

if instant_sealing {
let pool = transaction_pool.pool().clone();
let commands_stream = pool.validated_pool().import_notification_stream().map(|_| {
sc_consensus_manual_seal::rpc::EngineCommand::SealNewBlock {
create_empty: false,
finalize: true,
parent_hash: None,
sender: None,
}
});

let authorship_future =
sc_consensus_manual_seal::run_manual_seal(sc_consensus_manual_seal::ManualSealParams {
block_import: client.clone(),
env: proposer_factory,
client: client.clone(),
pool: transaction_pool.clone(),
commands_stream,
select_chain,
consensus_data_provider: None,
create_inherent_data_providers: |_, _| async {
Ok((
sp_timestamp::InherentDataProvider::from_system_time(),
default_mock_parachain_inherent_data_provider(),
))
},
});
// we spawn the future on a background thread managed by service.
task_manager.spawn_essential_handle().spawn_blocking("instant-seal", authorship_future);
} else {
// aura
let can_author_with = sp_consensus::CanAuthorWithNativeVersion::new(client.executor().clone());
let slot_duration = sc_consensus_aura::slot_duration(&*client)?.slot_duration();
let aura = sc_consensus_aura::start_aura::<AuraPair, _, _, _, _, _, _, _, _, _, _, _>(
sc_consensus_aura::StartAuraParams {
slot_duration: sc_consensus_aura::slot_duration(&*client)?,
client: client.clone(),
select_chain,
block_import: client.clone(),
proposer_factory,
create_inherent_data_providers: move |_, ()| async move {
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();

let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_duration(
*timestamp,
slot_duration,
);

Ok((timestamp, slot, default_mock_parachain_inherent_data_provider()))
},
force_authoring,
backoff_authoring_blocks,
keystore: keystore_container.sync_keystore(),
can_author_with,
sync_oracle: network.clone(),
justification_sync_link: network.clone(),
// We got around 500ms for proposing
block_proposal_slot_portion: SlotProportion::new(1f32 / 24f32),
// And a maximum of 750ms if slots are skipped
max_block_proposal_slot_portion: Some(SlotProportion::new(1f32 / 16f32)),
telemetry: telemetry.as_ref().map(|x| x.handle()),
},
)?;

// the AURA authoring task is considered essential, i.e. if it
// fails we take down the service with it.
task_manager.spawn_essential_handle().spawn_blocking("aura", aura);
}
}

let rpc_extensions_builder = {
let client = client.clone();
let transaction_pool = transaction_pool.clone();

Box::new(move |deny_unsafe, _| {
let deps = pint_rpc::FullDeps { client: client.clone(), pool: transaction_pool.clone(), deny_unsafe };

Ok(pint_rpc::create_full(deps))
})
};

sc_service::spawn_tasks(sc_service::SpawnTasksParams {
on_demand: None,
remote_blockchain: None,
rpc_extensions_builder,
client,
transaction_pool,
task_manager: &mut task_manager,
config,
keystore: keystore_container.sync_keystore(),
backend,
network,
system_rpc_tx,
telemetry: telemetry.as_mut(),
})?;

network_starter.start_network();

Ok(task_manager)
}

pub fn pint_dev(config: Configuration, instant_sealing: bool) -> Result<TaskManager, ServiceError> {
inner_pint_dev(config, instant_sealing)
}

0 comments on commit ac38962

Please sign in to comment.