Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Foucoco runtime with instant seal #462

Merged
merged 16 commits into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
203 changes: 119 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,3 +192,35 @@ runtimes `lib.rs` file.
--repeat 20 \
--output runtime/foucoco/src/weights/
```

### How to run in standalone mode

For testing purposes, it is useful to run an instance of the chain locally with the same runtime as the live chain, but using the instant-seal consensus mechanism. This means that upon every successful extrinsic, a new block will be produced instantly.

Currently we only support the use of the foucoco runtime to run the chain in this standalone mode.

To run:

```shell
cargo run -p pendulum-node -- --chain {x}-spec-raw.json --instant-seal
```

Most other flags are irrelevant when instant-seal is used, and should not be passed, but it is still possible
to use the port definition flags to change the default ports used.

#### Run with a specific genesis config

The previous command assumes there exist already a `...spec-raw.json` which defines the genesis config. The process
of creating this file is the same as the one described above in section [How to Generate Genesis State](#how-to-generate-chain-spec)

To run with the default standalone genesis config defined in `node/chain_spec.rs` (`foucoco_standalone_config()` function) use:

```shell
cargo run -p pendulum-node -- --chain res/foucoco-standalone-spec-raw.json --instant-seal
```

or simply:

```shell
cargo run -p pendulum-node -- --chain foucoco-standalone --instant-seal
```
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ sc-chain-spec = { git = "https://github.com/paritytech/substrate", branch = "pol
sc-cli = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sc-client-api = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sc-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sc-consensus-manual-seal = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sc-executor = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sc-network = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
sc-network-sync = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.42" }
Expand Down
128 changes: 124 additions & 4 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use cumulus_primitives_core::ParaId;
use runtime_common::{AccountId, AuraId, Balance, BlockNumber, UNIT};
use runtime_common::{AccountId, AuraId, Balance, BlockNumber, Signature, UNIT};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
use serde::{Deserialize, Serialize};
use sp_core::crypto::{Ss58Codec, UncheckedInto};
use sp_runtime::{FixedPointNumber, FixedU128, Perquintill};
use sp_core::{
crypto::{Ss58Codec, UncheckedInto},
sr25519, Pair, Public,
};
use sp_runtime::{
traits::{IdentifyAccount, Verify},
FixedPointNumber, FixedU128, Perquintill,
};
use spacewalk_primitives::{oracle::Key, Asset, CurrencyId, CurrencyId::XCM, VaultCurrencyPair};

use crate::constants::{
Expand Down Expand Up @@ -36,6 +42,23 @@ pub fn create_pendulum_multisig_account(id: &str) -> AccountId {
pallet_multisig::Pallet::<pendulum_runtime::Runtime>::multi_account_id(&signatories[..], 4)
}

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

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

/// 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()
}

/// The extensions for the [`ChainSpec`].
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, ChainSpecGroup, ChainSpecExtension)]
#[serde(deny_unknown_fields)]
Expand Down Expand Up @@ -169,6 +192,102 @@ pub fn foucoco_config() -> FoucocoChainSpec {
sudo_account.clone(),
foucoco::PARACHAIN_ID.into(),
false,
vec![],
)
},
// Bootnodes
Vec::new(),
// Telemetry
None,
// Protocol ID
Some("foucoco"),
// Fork ID
None,
// Properties
Some(properties),
// Extensions
ParachainExtensions {
relay_chain: "kusama".into(), // You MUST set this to the correct network!
para_id: foucoco::PARACHAIN_ID,
},
)
}

pub fn foucoco_standalone_config() -> FoucocoChainSpec {
ebma marked this conversation as resolved.
Show resolved Hide resolved
sp_core::crypto::set_default_ss58_version(foucoco_runtime::SS58Prefix::get().into());

// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "AMPE".into());
properties.insert("tokenDecimals".into(), foucoco::TOKEN_DECIMALS.into());
properties.insert("ss58Format".into(), foucoco_runtime::SS58Prefix::get().into());

let mut signatories: Vec<_> = foucoco::INITIAL_SUDO_SIGNATORIES
.iter()
.map(|ss58| AccountId::from_ss58check(ss58).unwrap())
.collect();
signatories.sort();

// add mock accounts to signatories so they get funded
// Pre-funded accounts
let prefunded_accounts = vec![
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Charlie"),
get_account_id_from_seed::<sr25519::Public>("Dave"),
get_account_id_from_seed::<sr25519::Public>("Eve"),
get_account_id_from_seed::<sr25519::Public>("Ferdie"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
get_account_id_from_seed::<sr25519::Public>("Charlie//stash"),
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
];

signatories.extend(prefunded_accounts.iter().cloned());

let invulnerables: Vec<_> = foucoco::INITIAL_COLLATORS
.iter()
.map(|ss58| AccountId::from_ss58check(ss58).unwrap())
.collect();

let sudo_account = get_account_id_from_seed::<sr25519::Public>("Alice");

let offchain_worker_price_feeder =
AccountId::from_ss58check(foucoco::OFF_CHAIN_WORKER_ADDRESS).unwrap();

let allowed_currencies = vec![
CurrencyId::Native,
CurrencyId::XCM(0),
CurrencyId::XCM(1),
CurrencyId::XCM(2),
CurrencyId::XCM(3),
CurrencyId::XCM(4),
CurrencyId::XCM(5),
CurrencyId::XCM(6),
CurrencyId::XCM(7),
CurrencyId::XCM(8),
CurrencyId::XCM(9),
CurrencyId::XCM(10),
];

FoucocoChainSpec::from_genesis(
// Name
"Foucoco-Standalone",
// ID
"foucoco-standalone",
ebma marked this conversation as resolved.
Show resolved Hide resolved
ChainType::Development,
move || {
let allowed_currencies_clone = allowed_currencies.clone();
foucoco_genesis(
// initial collators.
invulnerables.clone(),
signatories.clone(),
vec![sudo_account.clone(), offchain_worker_price_feeder.clone()],
sudo_account.clone(),
foucoco::PARACHAIN_ID.into(),
false,
allowed_currencies_clone,
)
},
// Bootnodes
Expand Down Expand Up @@ -502,6 +621,7 @@ fn foucoco_genesis(
sudo_account: AccountId,
id: ParaId,
start_shutdown: bool,
allowed_currencies: Vec<CurrencyId>,
) -> foucoco_runtime::GenesisConfig {
fn get_vault_currency_pair(
collateral: CurrencyId,
Expand Down Expand Up @@ -539,7 +659,6 @@ fn foucoco_genesis(
.iter()
.flat_map(|k| vec![(k.0.clone(), XCM(0), u128::pow(10, 18))])
.collect();


let stakers: Vec<_> = invulnerables
.iter()
Expand Down Expand Up @@ -745,6 +864,7 @@ fn foucoco_genesis(
batching_api: b"https://dia-00.pendulumchain.tech/currencies".to_vec(),
coin_infos_map: vec![],
},
token_allowance: foucoco_runtime::TokenAllowanceConfig { allowed_currencies },
}
}

Expand Down
4 changes: 4 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ pub struct Cli {
/// Relay chain arguments
#[arg(raw = true)]
pub relay_chain_args: Vec<String>,

/// Instant block sealing
#[clap(long = "instant-seal")]
pub instant_seal: bool,
}

#[derive(Debug)]
Expand Down
Loading
Loading