Skip to content

Commit

Permalink
refactor: use storage param and dev genesis for enabling instant-seal
Browse files Browse the repository at this point in the history
Signed-off-by: Gregory Hill <gregorydhill@outlook.com>
  • Loading branch information
gregdhill committed Jul 13, 2023
1 parent 5e27f8e commit d194c37
Show file tree
Hide file tree
Showing 14 changed files with 140 additions and 222 deletions.
3 changes: 1 addition & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions parachain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ sp-inherents = { git = "https://github.com/paritytech/substrate", branch = "polk
sp-consensus = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-session = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-state-machine = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-offchain = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
sp-keystore = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31" }
Expand Down
11 changes: 6 additions & 5 deletions parachain/res/README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
# Parachain Runtimes
# Parachain Chain Specs

This folder includes all parachain runtimes based on the interBTC bridge code.
This folder includes the live parachain chain specs.

## Usage

The `kintsugi.json` file serves as the chain specification used together with the `--chain` parameter when starting a [collator](https://docs.interlay.io/#/collator/guide) or [full-node](https://docs.interlay.io/#/full-node/guide).
The `interlay.json` and `kintsugi.json` files serve as the chain specifications used together with the `--chain` parameter when starting a [collator](https://docs.interlay.io/#/collator/guide) or [full-node](https://docs.interlay.io/#/full-node/guide).

## Development

**Note**: The commands below refer to the `kintsugi` chain. Adjust for the desired chain specification.
**Note**: The command below refer to the `kintsugi` chain. Adjust for the desired chain specification.

**Warning!** Create a chain specification only with tagged releases of the parachain!

```shell
docker run interlayhq/interbtc:interbtc-parachain-1.0.2 interbtc-parachain build-spec-with-id --chain kusama --disable-default-bootnode --raw > parachain/res/kintsugi.json
interbtc-parachain build-spec --chain kintsugi --disable-default-bootnode --raw > parachain/res/kintsugi.json
```

The raw chain spec contains all the same information, but it contains the encoded storage keys that the node will use to reference the data in its local storage.
Expand All @@ -23,4 +23,5 @@ Distributing a raw spec ensures that each node will store the data at the proper

## Parachain Ids

- **Interlay**: `2032`
- **Kintsugi**: `2092`
126 changes: 0 additions & 126 deletions parachain/res/testnet.json

This file was deleted.

3 changes: 0 additions & 3 deletions parachain/runtime/common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ frame-system = { git = "https://github.com/paritytech/substrate", branch = "polk
xcm = { git = "https://github.com/paritytech/polkadot", branch = "release-v0.9.31", default-features = false }
xcm-executor = { git = "https://github.com/paritytech/polkadot", default-features = false, branch = "release-v0.9.31" }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false, optional = true }
pallet-aura = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }
pallet-sudo = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.31", default-features = false }

# Parachain dependencies
btc-relay = { path = "../../../crates/btc-relay", default-features = false }
Expand Down Expand Up @@ -54,7 +52,6 @@ orml-xcm-support = { git = "https://github.com/open-web3-stack/open-runtime-modu
orml-unknown-tokens = { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "3fcd3cf9e63fe80fd9671912833a900ba09d1cc0", default-features = false }
orml-asset-registry= { git = "https://github.com/open-web3-stack/open-runtime-module-library", rev = "3fcd3cf9e63fe80fd9671912833a900ba09d1cc0", default-features = false }


# TODO: enable weak dependency activation when available
# https://github.com/rust-lang/cargo/issues/8832
# https://github.com/paritytech/substrate/issues/8161
Expand Down
18 changes: 1 addition & 17 deletions parachain/runtime/common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use core::marker::PhantomData;
use currency::Amount;
use frame_support::{
pallet_prelude::Get,
traits::{Currency, OnTimestampSet, OnUnbalanced, ProcessMessageError, TryDrop},
traits::{Currency, OnUnbalanced, ProcessMessageError, TryDrop},
};
use primitives::{BlockNumber, UnsignedFixedPoint};
use sp_runtime::{DispatchError, FixedPointNumber};
Expand Down Expand Up @@ -143,19 +143,3 @@ where
let _ = NativeCurrency::resolve_creating(&TreasuryAccount::get(), amount);
}
}

pub struct MaybeSetTimestamp<T>(PhantomData<T>);

impl<T> OnTimestampSet<T::Moment> for MaybeSetTimestamp<T>
where
T: frame_system::Config + pallet_aura::Config + pallet_sudo::Config,
{
fn on_timestamp_set(moment: T::Moment) {
// key is not set on mainnet
if pallet_sudo::Pallet::<T>::key().is_none() {
// this hook breaks instant-seal so only call when
// using the mainnet configuration
<pallet_aura::Pallet<T> as OnTimestampSet<T::Moment>>::on_timestamp_set(moment);
}
}
}
15 changes: 13 additions & 2 deletions parachain/runtime/interlay/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use frame_support::{
dispatch::{DispatchError, DispatchResult},
traits::{
ConstU32, Contains, Currency as PalletCurrency, EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg,
EqualPrivilegeOnly, ExistenceRequirement, Imbalance, InstanceFilter, OnUnbalanced,
EqualPrivilegeOnly, ExistenceRequirement, Imbalance, InstanceFilter, OnTimestampSet, OnUnbalanced,
},
weights::ConstantMultiplier,
PalletId,
Expand Down Expand Up @@ -307,12 +307,23 @@ impl pallet_aura::Config for Runtime {

parameter_types! {
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
pub storage EnableManualSeal: bool = false;
}

pub struct ConsensusOnTimestampSet<T>(PhantomData<T>);
impl<T: pallet_aura::Config> OnTimestampSet<T::Moment> for ConsensusOnTimestampSet<T> {
fn on_timestamp_set(moment: T::Moment) {
if EnableManualSeal::get() {
return;
}
<pallet_aura::Pallet<T> as OnTimestampSet<T::Moment>>::on_timestamp_set(moment)
}
}

impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = Moment;
type OnTimestampSet = runtime_common::MaybeSetTimestamp<Runtime>;
type OnTimestampSet = ConsensusOnTimestampSet<Self>;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
}
Expand Down
15 changes: 13 additions & 2 deletions parachain/runtime/kintsugi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use frame_support::{
dispatch::{DispatchError, DispatchResult},
traits::{
ConstU32, Contains, Currency as PalletCurrency, EitherOfDiverse, EnsureOrigin, EnsureOriginWithArg,
EqualPrivilegeOnly, ExistenceRequirement, Imbalance, InstanceFilter, OnUnbalanced,
EqualPrivilegeOnly, ExistenceRequirement, Imbalance, InstanceFilter, OnTimestampSet, OnUnbalanced,
},
weights::ConstantMultiplier,
PalletId,
Expand Down Expand Up @@ -305,12 +305,23 @@ impl pallet_aura::Config for Runtime {

parameter_types! {
pub const MinimumPeriod: u64 = SLOT_DURATION / 2;
pub storage EnableManualSeal: bool = false;
}

pub struct ConsensusOnTimestampSet<T>(PhantomData<T>);
impl<T: pallet_aura::Config> OnTimestampSet<T::Moment> for ConsensusOnTimestampSet<T> {
fn on_timestamp_set(moment: T::Moment) {
if EnableManualSeal::get() {
return;
}
<pallet_aura::Pallet<T> as OnTimestampSet<T::Moment>>::on_timestamp_set(moment)
}
}

impl pallet_timestamp::Config for Runtime {
/// A timestamp: milliseconds since the unix epoch.
type Moment = Moment;
type OnTimestampSet = runtime_common::MaybeSetTimestamp<Runtime>;
type OnTimestampSet = ConsensusOnTimestampSet<Self>;
type MinimumPeriod = MinimumPeriod;
type WeightInfo = weights::pallet_timestamp::WeightInfo<Runtime>;
}
Expand Down
46 changes: 36 additions & 10 deletions parachain/src/chain_spec/interlay.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
use super::*;
use kintsugi_runtime::LoansConfig;
use primitives::Rate;

pub const PARA_ID: u32 = 2032;

/// Specialized `ChainSpec` for the interlay parachain runtime.
pub type InterlayChainSpec = sc_service::GenericChainSpec<interlay_runtime::GenesisConfig, Extensions>;

/// Specialized `ChainSpec` for interlay development.
pub type InterlayDevChainSpec = sc_service::GenericChainSpec<InterlayDevGenesisExt, Extensions>;

/// Extension for the dev genesis config to support a custom changes to the genesis state.
#[derive(Serialize, Deserialize)]
pub struct InterlayDevGenesisExt {
/// Genesis config.
pub(crate) genesis_config: interlay_runtime::GenesisConfig,
/// The flag to enable instant-seal mode.
pub(crate) enable_instant_seal: bool,
}

impl sp_runtime::BuildStorage for InterlayDevGenesisExt {
fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> {
sp_state_machine::BasicExternalities::execute_with_storage(storage, || {
interlay_runtime::EnableManualSeal::set(&self.enable_instant_seal);
});
self.genesis_config.assimilate_storage(storage)
}
}

fn interlay_properties() -> Map<String, Value> {
let mut properties = Map::new();
let mut token_symbol: Vec<String> = vec![];
Expand All @@ -26,14 +48,14 @@ fn default_pair_interlay(currency_id: CurrencyId) -> VaultCurrencyPair<CurrencyI
}
}

pub fn interlay_dev_config() -> InterlayChainSpec {
pub fn interlay_dev_config(enable_instant_seal: bool) -> InterlayDevChainSpec {
let id: ParaId = PARA_ID.into();
InterlayChainSpec::from_genesis(
InterlayDevChainSpec::from_genesis(
"Interlay",
"interlay",
ChainType::Live,
move || {
interlay_genesis(
ChainType::Development,
move || InterlayDevGenesisExt {
genesis_config: interlay_genesis(
vec![get_authority_keys_from_seed("Alice")],
vec![(
get_account_id_from_seed::<sr25519::Public>("Bob"),
Expand All @@ -43,7 +65,9 @@ pub fn interlay_dev_config() -> InterlayChainSpec {
Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
id,
1,
)
false, // disable difficulty check
),
enable_instant_seal,
},
Vec::new(),
None,
Expand Down Expand Up @@ -111,6 +135,7 @@ pub fn interlay_mainnet_config() -> InterlayChainSpec {
None, // no sudo key
id,
SECURE_BITCOIN_CONFIRMATIONS,
false, // enable difficulty check
)
},
Vec::new(),
Expand All @@ -132,6 +157,7 @@ pub fn interlay_genesis(
root_key: Option<AccountId>,
id: ParaId,
bitcoin_confirmations: u32,
disable_difficulty_check: bool,
) -> interlay_runtime::GenesisConfig {
interlay_runtime::GenesisConfig {
system: interlay_runtime::SystemConfig {
Expand Down Expand Up @@ -181,7 +207,7 @@ pub fn interlay_genesis(
btc_relay: interlay_runtime::BTCRelayConfig {
bitcoin_confirmations,
parachain_confirmations: bitcoin_confirmations.saturating_mul(interlay_runtime::BITCOIN_BLOCK_SPACING),
disable_difficulty_check: false,
disable_difficulty_check,
disable_inclusion_check: false,
},
issue: interlay_runtime::IssueConfig {
Expand Down Expand Up @@ -241,7 +267,7 @@ pub fn interlay_genesis(
safe_xcm_version: Some(3),
},
sudo: interlay_runtime::SudoConfig { key: root_key },
loans: LoansConfig {
loans: interlay_runtime::LoansConfig {
max_exchange_rate: Rate::from_inner(loans::DEFAULT_MAX_EXCHANGE_RATE),
min_exchange_rate: Rate::from_inner(loans::DEFAULT_MIN_EXCHANGE_RATE),
},
Expand Down
46 changes: 36 additions & 10 deletions parachain/src/chain_spec/kintsugi.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
use super::*;
use kintsugi_runtime::LoansConfig;
use primitives::Rate;

pub const PARA_ID: u32 = 2092;

/// Specialized `ChainSpec` for the kintsugi parachain runtime.
pub type KintsugiChainSpec = sc_service::GenericChainSpec<kintsugi_runtime::GenesisConfig, Extensions>;

/// Specialized `ChainSpec` for kintsugi development.
pub type KintsugiDevChainSpec = sc_service::GenericChainSpec<KintsugiDevGenesisExt, Extensions>;

/// Extension for the dev genesis config to support a custom changes to the genesis state.
#[derive(Serialize, Deserialize)]
pub struct KintsugiDevGenesisExt {
/// Genesis config.
pub(crate) genesis_config: kintsugi_runtime::GenesisConfig,
/// The flag to enable instant-seal mode.
pub(crate) enable_instant_seal: bool,
}

impl sp_runtime::BuildStorage for KintsugiDevGenesisExt {
fn assimilate_storage(&self, storage: &mut Storage) -> Result<(), String> {
sp_state_machine::BasicExternalities::execute_with_storage(storage, || {
kintsugi_runtime::EnableManualSeal::set(&self.enable_instant_seal);
});
self.genesis_config.assimilate_storage(storage)
}
}

pub fn kintsugi_properties() -> Map<String, Value> {
let mut properties = Map::new();
let mut token_symbol: Vec<String> = vec![];
Expand All @@ -26,14 +48,14 @@ fn default_pair_kintsugi(currency_id: CurrencyId) -> VaultCurrencyPair<CurrencyI
}
}

pub fn kintsugi_dev_config() -> KintsugiChainSpec {
pub fn kintsugi_dev_config(enable_instant_seal: bool) -> KintsugiDevChainSpec {
let id: ParaId = PARA_ID.into();
KintsugiChainSpec::from_genesis(
KintsugiDevChainSpec::from_genesis(
"Kintsugi",
"kintsugi",
ChainType::Live,
move || {
kintsugi_genesis(
ChainType::Development,
move || KintsugiDevGenesisExt {
genesis_config: kintsugi_genesis(
vec![get_authority_keys_from_seed("Alice")],
vec![(
get_account_id_from_seed::<sr25519::Public>("Bob"),
Expand All @@ -43,7 +65,9 @@ pub fn kintsugi_dev_config() -> KintsugiChainSpec {
Some(get_account_id_from_seed::<sr25519::Public>("Alice")),
id,
1,
)
false, // disable difficulty check
),
enable_instant_seal,
},
Vec::new(),
None,
Expand Down Expand Up @@ -115,6 +139,7 @@ pub fn kintsugi_mainnet_config() -> KintsugiChainSpec {
None, // no sudo key
id,
SECURE_BITCOIN_CONFIRMATIONS,
false, // enable difficulty check
)
},
Vec::new(),
Expand All @@ -136,6 +161,7 @@ pub fn kintsugi_genesis(
root_key: Option<AccountId>,
id: ParaId,
bitcoin_confirmations: u32,
disable_difficulty_check: bool,
) -> kintsugi_runtime::GenesisConfig {
kintsugi_runtime::GenesisConfig {
system: kintsugi_runtime::SystemConfig {
Expand Down Expand Up @@ -185,7 +211,7 @@ pub fn kintsugi_genesis(
btc_relay: kintsugi_runtime::BTCRelayConfig {
bitcoin_confirmations,
parachain_confirmations: bitcoin_confirmations.saturating_mul(kintsugi_runtime::BITCOIN_BLOCK_SPACING),
disable_difficulty_check: false,
disable_difficulty_check,
disable_inclusion_check: false,
},
issue: kintsugi_runtime::IssueConfig {
Expand Down Expand Up @@ -269,7 +295,7 @@ pub fn kintsugi_genesis(
safe_xcm_version: Some(3),
},
sudo: kintsugi_runtime::SudoConfig { key: root_key },
loans: LoansConfig {
loans: kintsugi_runtime::LoansConfig {
max_exchange_rate: Rate::from_inner(loans::DEFAULT_MAX_EXCHANGE_RATE),
min_exchange_rate: Rate::from_inner(loans::DEFAULT_MIN_EXCHANGE_RATE),
},
Expand Down
Loading

0 comments on commit d194c37

Please sign in to comment.