Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Add bridge components #47

Closed
wants to merge 13 commits into from
1,280 changes: 1,051 additions & 229 deletions Cargo.lock

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ sc-rpc-api = { git = "https://github.com/paritytech/substrate.git", branch = "po
sp-blockchain = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sp-block-builder = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sc-basic-authorship = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sc-consensus-grandpa-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
sc-network-common = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
mmr-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }
pallet-transaction-payment-rpc = { git = "https://github.com/paritytech/substrate.git", branch = "polkadot-v1.0.0" }

Expand Down
81 changes: 63 additions & 18 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,80 @@
use hex_literal::hex;
use node_template_runtime::{
AccountId, AuraConfig, BalancesConfig, GrandpaConfig, RuntimeGenesisConfig, SudoConfig,
SystemConfig, WASM_BINARY,
AccountId, AuraConfig, BalancesConfig, GrandpaConfig, RuntimeGenesisConfig, Signature,
SudoConfig, SystemConfig, WASM_BINARY,
};
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_consensus_grandpa::AuthorityId as GrandpaId;
use sp_core::{Pair, Public};
use sp_core::{sr25519, Pair, Public};
use sp_runtime::traits::{IdentifyAccount, Verify};

/// "Names" of the authorities accounts at local testnet.
const LOCAL_AUTHORITIES_ACCOUNTS: [&str; 5] = ["Alice", "Bob", "Charlie", "Dave", "Eve"];
/// "Names" of all possible authorities accounts.
const ALL_AUTHORITIES_ACCOUNTS: [&str; 5] = LOCAL_AUTHORITIES_ACCOUNTS;
/// "Name" of the account, which owns the with-Rococo messages pallet.
const ROCOCO_MESSAGES_PALLET_OWNER: &str = "Rococo.MessagesOwner";
/// "Name" of the account, which owns the with-OwnershipParachain messages pallet.
const OWNERSHIP_PARACHAIN_MESSAGES_PALLET_OWNER: &str = "OwnershipParachain.MessagesOwner";

// The URL for the telemetry server.
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

/// We're using the same set of endowed accounts on all Millau chains (dev/local) to make
/// sure that all accounts, required for bridge to be functional (e.g. relayers fund account,
/// accounts used by relayers in our test deployments, accounts used for demonstration
/// purposes), are all available on these chains.
fn endowed_accounts() -> Vec<AccountId> {
let all_authorities = ALL_AUTHORITIES_ACCOUNTS.iter().flat_map(|x| {
[
get_account_id_from_seed::<sr25519::Public>(x),
get_account_id_from_seed::<sr25519::Public>(&format!("{x}//stash")),
]
});

vec![
// Regular (unused) accounts
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
// Accounts, used by Rococo<>Evochain bridge
get_account_id_from_seed::<sr25519::Public>(ROCOCO_MESSAGES_PALLET_OWNER),
get_account_id_from_seed::<sr25519::Public>("Rococo.HeadersAndMessagesRelay"),
get_account_id_from_seed::<sr25519::Public>("Rococo.OutboundMessagesRelay.Lane00000001"),
get_account_id_from_seed::<sr25519::Public>("Rococo.InboundMessagesRelay.Lane00000001"),
get_account_id_from_seed::<sr25519::Public>("Rococo.MessagesSender"),
// Accounts, used by OwnershipParachain<>Evochain bridge
get_account_id_from_seed::<sr25519::Public>(OWNERSHIP_PARACHAIN_MESSAGES_PALLET_OWNER),
get_account_id_from_seed::<sr25519::Public>("OwnershipParachain.HeadersAndMessagesRelay1"),
get_account_id_from_seed::<sr25519::Public>("OwnershipParachain.HeadersAndMessagesRelay2"),
get_account_id_from_seed::<sr25519::Public>("OwnershipParachain.RococoHeadersRelay1"),
get_account_id_from_seed::<sr25519::Public>("OwnershipParachain.RococoHeadersRelay2"),
get_account_id_from_seed::<sr25519::Public>("OwnershipParachain.MessagesSender"),
]
.into_iter()
.chain(all_authorities)
.collect()
}

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<RuntimeGenesisConfig>;

type AccountPublic = <Signature as Verify>::Signer;

/// Generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{seed}"), None)
.expect("static values are valid; qed")
.public()
}

/// Helper function to generate an account ID from seed
pub fn get_account_id_from_seed<TPublic: Public>(seed: &str) -> AccountId
where
AccountPublic: From<<TPublic::Pair as Pair>::Public>,
{
AccountPublic::from(get_from_seed::<TPublic>(seed)).into_account()
}

/// Generate an Aura authority key.
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
Expand All @@ -41,14 +95,9 @@ pub fn development_config() -> Result<ChainSpec, String> {
// Initial PoA authorities
vec![authority_keys_from_seed("Alice")],
// Sudo account
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")),
AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")),
],
endowed_accounts(),
true,
)
},
Expand Down Expand Up @@ -81,14 +130,9 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
// Initial PoA authorities
vec![authority_keys_from_seed("Alice"), authority_keys_from_seed("Bob")],
// Sudo account
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Pre-funded accounts
vec![
AccountId::from(hex!("f24FF3a9CF04c71Dbc94D0b566f7A27B94566cac")),
AccountId::from(hex!("3Cd0A705a2DC65e5b1E1205896BaA2be8A07c6e0")),
AccountId::from(hex!("798d4Ba9baf0064Ec19eB4F0a1a45785ae9D6DFc")),
AccountId::from(hex!("773539d4Ac0e786233D90A233654ccEE26a613D9")),
],
endowed_accounts(),
true,
)
},
Expand Down Expand Up @@ -136,5 +180,6 @@ fn testnet_genesis(
key: Some(root_key),
},
transaction_payment: Default::default(),
..Default::default()
}
}
50 changes: 23 additions & 27 deletions node/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
use crate::{
// benchmarking::{inherent_benchmark_data, RemarkBuilder, TransferKeepAliveBuilder},
chain_spec,
cli::{Cli, Subcommand},
service,
};
// use frame_benchmarking_cli::{BenchmarkCmd, ExtrinsicFactory, SUBSTRATE_REFERENCE_HARDWARE};
use node_template_runtime::Block;
use sc_cli::SubstrateCli;
use sc_service::PartialComponents;
// use sp_keyring::Sr25519Keyring;

#[cfg(feature = "try-runtime")]
use try_runtime_cli::block_building_info::timestamp_with_aura_info;

impl SubstrateCli for Cli {
fn impl_name() -> String {
Expand Down Expand Up @@ -176,27 +170,29 @@ pub fn run() -> sc_cli::Result<()> {
})
}, */
#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
use crate::service::ExecutorDispatch;
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
let runner = cli.create_runner(cmd)?;
runner.async_run(|config| {
// we don't need any of the components of new_partial, just a runtime, or a task
// manager to do `async_run`.
let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
let task_manager =
sc_service::TaskManager::new(config.tokio_handle.clone(), registry)
.map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;
let info_provider = timestamp_with_aura_info(6000);

Ok((
cmd.run::<Block, ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<ExecutorDispatch as NativeExecutionDispatch>::ExtendHostFunctions,
>, _>(Some(info_provider)),
task_manager,
))
})
Some(Subcommand::TryRuntime(_cmd)) => {
// use crate::service::ExecutorDispatch;
// use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
// let runner = cli.create_runner(cmd)?;
// runner.async_run(|config| {
// // we don't need any of the components of new_partial, just a runtime, or a task
// // manager to do `async_run`.
// let registry = config.prometheus_config.as_ref().map(|cfg| &cfg.registry);
// let task_manager =
// sc_service::TaskManager::new(config.tokio_handle.clone(), registry)
// .map_err(|e| sc_cli::Error::Service(sc_service::Error::Prometheus(e)))?;
// let info_provider = timestamp_with_aura_info(6000);

// Ok((
// cmd.run::<Block, ExtendedHostFunctions<
// sp_io::SubstrateHostFunctions,
// <ExecutorDispatch as NativeExecutionDispatch>::ExtendHostFunctions,
// >, _>(Some(info_provider)),
// task_manager,
// ))
// })
// TODO: uncomment and fix it
Ok(())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it will be nicer to add a todo!() instead of do nothing and exit silently

},
#[cfg(not(feature = "try-runtime"))]
Some(Subcommand::TryRuntime) => Err("TryRuntime wasn't enabled when building the node. \
Expand Down
1 change: 0 additions & 1 deletion node/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod chain_spec;
pub mod rpc;
pub mod service;
1 change: 0 additions & 1 deletion node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ mod chain_spec;
mod service;
mod cli;
mod command;
mod rpc;

fn main() -> sc_cli::Result<()> {
command::run()
Expand Down
2 changes: 1 addition & 1 deletion node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use std::sync::Arc;

use jsonrpsee::RpcModule;
use node_template_runtime::{opaque::Block, AccountId, Balance, Index};
use node_template_runtime::{AccountId, Balance, Block, Index};
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_block_builder::BlockBuilder;
Expand Down
Loading