Skip to content
This repository has been archived by the owner on May 21, 2024. It is now read-only.

Commit

Permalink
feat: migrate to polkadot-v1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
José Molina committed Aug 24, 2023
1 parent 2b15ae8 commit 85bde1c
Show file tree
Hide file tree
Showing 25 changed files with 2,724 additions and 2,835 deletions.
1,522 changes: 817 additions & 705 deletions Cargo.lock

Large diffs are not rendered by default.

226 changes: 113 additions & 113 deletions Cargo.toml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "trappist"
version = "0.9.43"
version = "1.0.0"
description = "A versatile Proof-of-Authority (PoA) Blockchain network."
authors = { workspace = true }
license = { workspace = true }
Expand Down
19 changes: 13 additions & 6 deletions node/src/chain_spec/stout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ use sc_service::ChainType;
use sp_core::sr25519;
use stout_runtime::{
constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AssetsConfig, AuraId, BalancesConfig,
CouncilConfig, GenesisConfig, SessionConfig, SessionKeys, SudoConfig, SystemConfig,
CouncilConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys, SudoConfig, SystemConfig,
};

const DEFAULT_PROTOCOL_ID: &str = "stout";

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<stout_runtime::GenesisConfig, Extensions>;
pub type ChainSpec = sc_service::GenericChainSpec<stout_runtime::RuntimeGenesisConfig, Extensions>;

const STOUT_PARA_ID: u32 = 3000;

Expand Down Expand Up @@ -105,18 +105,22 @@ pub fn testnet_genesis(
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> GenesisConfig {
GenesisConfig {
) -> RuntimeGenesisConfig {
RuntimeGenesisConfig {
system: SystemConfig {
code: stout_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.into_iter().map(|k| (k, 1 << 60)).collect(),
},
parachain_info: stout_runtime::ParachainInfoConfig { parachain_id: id },
parachain_info: stout_runtime::ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
collator_selection: stout_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().map(|(acc, _)| acc).cloned().collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
Expand All @@ -139,7 +143,10 @@ pub fn testnet_genesis(
aura: Default::default(),
aura_ext: Default::default(),
parachain_system: Default::default(),
polkadot_xcm: stout_runtime::PolkadotXcmConfig { safe_xcm_version: Some(SAFE_XCM_VERSION) },
polkadot_xcm: stout_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
sudo: SudoConfig {
// Assign network admin rights.
key: Some(root_key),
Expand Down
31 changes: 21 additions & 10 deletions node/src/chain_spec/trappist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,15 @@ use sc_service::ChainType;
use sp_core::{crypto::UncheckedInto, sr25519};
use trappist_runtime::{
constants::currency::EXISTENTIAL_DEPOSIT, AccountId, AssetsConfig, AuraId, BalancesConfig,
CouncilConfig, GenesisConfig, LockdownModeConfig, SessionConfig, SessionKeys, SudoConfig,
SystemConfig,
CouncilConfig, LockdownModeConfig, RuntimeGenesisConfig, SessionConfig, SessionKeys,
SudoConfig, SystemConfig,
};

const DEFAULT_PROTOCOL_ID: &str = "hop";

/// Specialized `ChainSpec` for the normal parachain runtime.
pub type ChainSpec = sc_service::GenericChainSpec<trappist_runtime::GenesisConfig, Extensions>;
pub type ChainSpec =
sc_service::GenericChainSpec<trappist_runtime::RuntimeGenesisConfig, Extensions>;

const TRAPPIST_PARA_ID: u32 = 1836;

Expand Down Expand Up @@ -159,18 +160,22 @@ pub fn testnet_genesis(
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> GenesisConfig {
GenesisConfig {
) -> RuntimeGenesisConfig {
RuntimeGenesisConfig {
system: SystemConfig {
code: trappist_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.into_iter().map(|k| (k, 1 << 60)).collect(),
},
parachain_info: trappist_runtime::ParachainInfoConfig { parachain_id: id },
parachain_info: trappist_runtime::ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
collator_selection: trappist_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().map(|(acc, _)| acc).cloned().collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
Expand All @@ -196,6 +201,7 @@ pub fn testnet_genesis(
parachain_system: Default::default(),
polkadot_xcm: trappist_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
sudo: SudoConfig {
// Assign network admin rights.
Expand All @@ -207,7 +213,7 @@ pub fn testnet_genesis(
phantom: Default::default(),
},
treasury: Default::default(),
lockdown_mode: LockdownModeConfig { initial_status: false },
lockdown_mode: LockdownModeConfig { initial_status: false, ..Default::default() },
}
}

Expand Down Expand Up @@ -267,12 +273,13 @@ fn trappist_live_genesis(
root_key: AccountId,
endowed_accounts: Vec<AccountId>,
id: ParaId,
) -> GenesisConfig {
GenesisConfig {
) -> RuntimeGenesisConfig {
RuntimeGenesisConfig {
system: SystemConfig {
code: trappist_runtime::WASM_BINARY
.expect("WASM binary was not build, please build it!")
.to_vec(),
..Default::default()
},
balances: BalancesConfig {
balances: endowed_accounts
Expand All @@ -281,7 +288,10 @@ fn trappist_live_genesis(
.chain(std::iter::once((root_key.clone(), 1_000_000_000_000_000_000)))
.collect(),
},
parachain_info: trappist_runtime::ParachainInfoConfig { parachain_id: id },
parachain_info: trappist_runtime::ParachainInfoConfig {
parachain_id: id,
..Default::default()
},
collator_selection: trappist_runtime::CollatorSelectionConfig {
invulnerables: invulnerables.iter().map(|(acc, _)| acc).cloned().collect(),
candidacy_bond: EXISTENTIAL_DEPOSIT * 16,
Expand All @@ -305,6 +315,7 @@ fn trappist_live_genesis(
parachain_system: Default::default(),
polkadot_xcm: trappist_runtime::PolkadotXcmConfig {
safe_xcm_version: Some(SAFE_XCM_VERSION),
..Default::default()
},
sudo: SudoConfig {
// Assign network admin rights.
Expand Down
51 changes: 23 additions & 28 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use parachains_common::AuraId;
use parity_scale_codec::Encode;
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
NetworkParams, Result, RuntimeVersion, SharedParams, SubstrateCli,
NetworkParams, Result, SharedParams, SubstrateCli,
};
use sc_service::config::{BasePath, PrometheusConfig};
use sp_core::hexdisplay::HexDisplay;
Expand All @@ -35,9 +35,12 @@ use crate::{
benchmarking::{inherent_benchmark_data, RemarkBuilder},
chain_spec,
cli::{Cli, RelayChainCli, Subcommand},
service::{new_partial, Block, RuntimeExecutor},
service::{new_partial, Block},
};

#[cfg(feature = "try-runtime")]
use crate::service::RuntimeExecutor;

/// Dispatches the code to the currently selected runtime.
macro_rules! dispatch_runtime {
($runtime:expr, |$alias: ident| $code:expr) => {
Expand Down Expand Up @@ -226,10 +229,6 @@ impl SubstrateCli for Cli {
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
load_spec(id)
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
dispatch_runtime!(chain_spec.runtime(), |runtime| &runtime::VERSION)
}
}

impl SubstrateCli for RelayChainCli {
Expand Down Expand Up @@ -266,10 +265,6 @@ impl SubstrateCli for RelayChainCli {
fn load_spec(&self, id: &str) -> std::result::Result<Box<dyn ChainSpec>, String> {
polkadot_cli::Cli::from_iter([RelayChainCli::executable_name()].iter()).load_spec(id)
}

fn native_runtime_version(chain_spec: &Box<dyn ChainSpec>) -> &'static RuntimeVersion {
polkadot_cli::Cli::native_runtime_version(chain_spec)
}
}

/// Parse command line arguments into service configuration.
Expand Down Expand Up @@ -324,11 +319,9 @@ pub fn run() -> Result<()> {
})
},
Some(Subcommand::ExportGenesisState(cmd)) => {
let runner = cli.create_runner(cmd)?;
runner.sync_run(|_config| {
construct_async_run!(|components, cli, cmd, _config| {
let spec = cli.load_spec(&cmd.shared_params.chain.clone().unwrap_or_default())?;
let state_version = Cli::native_runtime_version(&spec).state_version();
cmd.run::<crate::service::Block>(&*spec, state_version)
Ok(async move { cmd.run::<crate::service::Block>(&*spec, &*components.client) })
})
},
Some(Subcommand::ExportGenesisWasm(cmd)) => {
Expand All @@ -351,7 +344,7 @@ pub fn run() -> Result<()> {
}

dispatch_runtime!(config.chain_spec.runtime(), |runtime| {
cmd.run::<Block, RuntimeExecutor<runtime::Runtime>>(config)
cmd.run::<Block, ()>(config)
})
},
BenchmarkCmd::Block(cmd) => {
Expand Down Expand Up @@ -445,10 +438,8 @@ pub fn run() -> Result<()> {
let parachain_account =
AccountIdConversion::<polkadot_primitives::AccountId>::into_account_truncating(&id);

let state_version = Cli::native_runtime_version(&config.chain_spec).state_version();

let block: crate::service::Block =
generate_genesis_block(&*config.chain_spec, state_version)
generate_genesis_block(&*config.chain_spec, sp_runtime::StateVersion::V1)
.map_err(|e| format!("{e:?}"))?;
let genesis_state = format!("0x{:?}", HexDisplay::from(&block.header().encode()));

Expand Down Expand Up @@ -700,16 +691,20 @@ mod tests {
assert_resolved_runtime(
Runtime::Trappist,
vec![
Box::new(create_default_with_extensions::<trappist_runtime::GenesisConfig, _>(
"trappist-1",
Extensions1::default(),
crate::chain_spec::trappist::testnet_genesis,
)),
Box::new(create_default_with_extensions::<trappist_runtime::GenesisConfig, _>(
"trappist-2",
Extensions2::default(),
crate::chain_spec::trappist::testnet_genesis,
)),
Box::new(
create_default_with_extensions::<trappist_runtime::RuntimeGenesisConfig, _>(
"trappist-1",
Extensions1::default(),
crate::chain_spec::trappist::testnet_genesis,
),
),
Box::new(
create_default_with_extensions::<trappist_runtime::RuntimeGenesisConfig, _>(
"trappist-2",
Extensions2::default(),
crate::chain_spec::trappist::testnet_genesis,
),
),
Box::new(crate::chain_spec::trappist::trappist_local_testnet_config()),
],
)
Expand Down
7 changes: 3 additions & 4 deletions node/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@

use std::sync::Arc;

use parachains_common::{
AccountId, AssetIdForTrustBackedAssets as AssetId, Balance, Block, Index as Nonce,
};
use parachains_common::{AccountId, AssetIdForTrustBackedAssets as AssetId, Balance, Block, Nonce};
use sc_client_api::AuxStore;
pub use sc_rpc::{DenyUnsafe, SubscriptionTaskExecutor};
use sc_transaction_pool_api::TransactionPool;
use sp_api::ProvideRuntimeApi;
use sp_api::{CallApiAt, ProvideRuntimeApi};
use sp_block_builder::BlockBuilder;
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};

Expand Down Expand Up @@ -55,6 +53,7 @@ where
+ Send
+ Sync
+ 'static,
C: CallApiAt<Block>,
C::Api: frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C::Api: BlockBuilder<Block>,
Expand Down
2 changes: 1 addition & 1 deletion node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use cumulus_relay_chain_interface::RelayChainInterface;
use futures::lock::Mutex;
use jsonrpsee::RpcModule;
pub use parachains_common::{
AccountId, AssetIdForTrustBackedAssets as AssetId, Balance, Block, Header, Index as Nonce,
AccountId, AssetIdForTrustBackedAssets as AssetId, Balance, Block, Header, Nonce,
};
use parity_scale_codec::Codec;
use sc_consensus::{
Expand Down
22 changes: 8 additions & 14 deletions pallets/asset-registry/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
// limitations under the License.

use crate as pallet_asset_registry;
use frame_support::traits::{AsEnsureOriginWithArg, ConstU16, ConstU64, GenesisBuild};
use frame_support::traits::{AsEnsureOriginWithArg, ConstU16, ConstU64};
use frame_system as system;
use sp_core::H256;
use sp_runtime::{
testing::Header,
traits::{BlakeTwo256, ConstU32, IdentityLookup},
BuildStorage,
};

type UncheckedExtrinsic = frame_system::mocking::MockUncheckedExtrinsic<Test>;
type Block = frame_system::mocking::MockBlock<Test>;

frame_support::parameter_types! {
Expand All @@ -35,11 +34,7 @@ frame_support::parameter_types! {

// Configure a mock runtime to test the pallet.
frame_support::construct_runtime!(
pub enum Test where
Block = Block,
NodeBlock = Block,
UncheckedExtrinsic = UncheckedExtrinsic,
{
pub struct Test {
System: frame_system,
AssetRegistry: pallet_asset_registry::{Pallet, Call, Storage, Event<T>},
Assets: pallet_assets::{Pallet, Call, Storage, Event<T>},
Expand All @@ -48,19 +43,18 @@ frame_support::construct_runtime!(
);

impl system::Config for Test {
type RuntimeEvent = RuntimeEvent;
type BaseCallFilter = frame_support::traits::Everything;
type BlockWeights = ();
type BlockLength = ();
type RuntimeOrigin = RuntimeOrigin;
type RuntimeCall = RuntimeCall;
type Index = u64;
type BlockNumber = u64;
type Nonce = u64;
type Hash = H256;
type Hashing = BlakeTwo256;
type AccountId = u64;
type Lookup = IdentityLookup<Self::AccountId>;
type Header = Header;
type RuntimeEvent = RuntimeEvent;
type Block = Block;
type BlockHashCount = ConstU64<250>;
type DbWeight = ();
type Version = ();
Expand Down Expand Up @@ -100,7 +94,7 @@ impl pallet_balances::Config for Test {
type ExistentialDeposit = ConstU64<1>;
type AccountStore = System;
type ReserveIdentifier = [u8; 8];
type HoldIdentifier = ();
type RuntimeHoldReason = ();
type FreezeIdentifier = ();
type MaxLocks = ();
type MaxReserves = ();
Expand Down Expand Up @@ -135,7 +129,7 @@ pub const LOCAL_ASSET_ID: u32 = 10;

// Build genesis storage according to the mock runtime.
pub fn new_test_ext() -> sp_io::TestExternalities {
let mut storage = system::GenesisConfig::default().build_storage::<Test>().unwrap();
let mut storage = system::GenesisConfig::<Test>::default().build_storage().unwrap();

let config: pallet_assets::GenesisConfig<Test> = pallet_assets::GenesisConfig {
assets: vec![
Expand Down
Loading

0 comments on commit 85bde1c

Please sign in to comment.