Skip to content

Commit

Permalink
Rococo admin (#222)
Browse files Browse the repository at this point in the history
* add back sudo to rococo

* some dummy log statements

* attempt 1 to add try-runtime

* second attempt

* add to the cli

* fix warn issue

* on initialise, remove on runtime upgrade proposasl

* add the new storage version migration

* pick runtime

* new migration for proposals

* fmt

* fix v3-v4 migration test

* fix 2

* fix brief migration test

* clippy

* fmt

* remove logs in fn

---------

Co-authored-by: samelamin <hussam.elamin@gmail.com>
  • Loading branch information
f-gate and samelamin authored Sep 22, 2023
1 parent 7061cd8 commit 914ed50
Show file tree
Hide file tree
Showing 26 changed files with 663 additions and 161 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

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

6 changes: 6 additions & 0 deletions libs/common-traits/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ targets = ['x86_64-unknown-linux-gnu']
[dependencies]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false }
frame-support = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false }
frame-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false }
sp-std = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false }

Expand All @@ -26,6 +27,11 @@ sp-runtime = { git = "https://github.com/paritytech/substrate.git", branch = "po

[features]
default = ['std']
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
]
std = [
"codec/std",
"frame-support/std",
Expand Down
6 changes: 6 additions & 0 deletions libs/common-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ frame-support = { git = "https://github.com/paritytech/substrate", branch = "pol

[features]
default = ['std']
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"common-traits/try-runtime"
]
std = [
'codec/std',
'sp-std/std',
Expand Down
27 changes: 21 additions & 6 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ targets = ['x86_64-unknown-linux-gnu']
[[bin]]
name = 'imbue'

[features]
default = []
runtime-benchmarks = [
'polkadot-cli/runtime-benchmarks',
'imbue-kusama-runtime/runtime-benchmarks',
]


[dependencies]
async-trait = "0.1.57"
Expand Down Expand Up @@ -78,6 +73,7 @@ sp-consensus-aura = { git = "https://github.com/paritytech/substrate", branch =
substrate-prometheus-endpoint = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
substrate-state-trie-migration-rpc = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
substrate-frame-rpc-system = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43" }
try-runtime-cli = { git = "https://github.com/paritytech/substrate", optional = true , branch = "polkadot-v0.9.43" }

# RPC related dependencies
jsonrpsee = { version = "0.16.2", features = ["ws-client"] }
Expand Down Expand Up @@ -124,3 +120,22 @@ rand = "0.7.3"
tempfile = "3.2.0"
tokio = { version = "1.10.0", features = ["macros"] }
cargo-llvm-cov = "0.1.13"

[features]
default = []
runtime-benchmarks = [
"try-runtime-cli/try-runtime",
"imbue-kusama-runtime/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks",
]
try-runtime = [
"try-runtime-cli/try-runtime",
"imbue-kusama-runtime/try-runtime",
"common-runtime/try-runtime",
"pallet-collective/try-runtime",
"pallet-proposals-rpc/try-runtime",
"pallet-xcm/try-runtime",
"polkadot-cli/try-runtime",
"polkadot-service/try-runtime",
"sp-runtime/try-runtime"
]
5 changes: 4 additions & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub fn get_dev_session_keys(
}

fn development_genesis(
_root_key: AccountId,
root_key: AccountId,
initial_authorities: Vec<(AccountId, AuraId)>,
endowed_accounts: Vec<AccountId>,
total_issuance: Option<imbue_kusama_runtime::Balance>,
Expand Down Expand Up @@ -238,6 +238,9 @@ fn development_genesis(
},
balances: imbue_kusama_runtime::BalancesConfig { balances },
orml_asset_registry: Default::default(),
sudo: imbue_kusama_runtime::SudoConfig {
key: Some(root_key),
},
orml_tokens: imbue_kusama_runtime::OrmlTokensConfig {
balances: token_balances,
},
Expand Down
8 changes: 8 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ pub enum Subcommand {
/// The custom benchmark subcommmand benchmarking runtime pallets.
#[clap(subcommand)]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),

/// Try some testing command against a specified runtime state.
#[cfg(feature = "try-runtime")]
TryRuntime(try_runtime_cli::TryRuntimeCmd),

/// Errors since the binary was not build with `--features try-runtime`.
#[cfg(not(feature = "try-runtime"))]
TryRuntime,
}

#[derive(Debug, Parser)]
Expand Down
39 changes: 39 additions & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,45 @@ pub fn run() -> Result<()> {
}
}

#[cfg(feature = "try-runtime")]
Some(Subcommand::TryRuntime(cmd)) => {
use imbue_kusama_runtime::MILLISECS_PER_BLOCK;
use sc_executor::{sp_wasm_interface::ExtendedHostFunctions, NativeExecutionDispatch};
use try_runtime_cli::block_building_info::timestamp_with_aura_info;

let runner = cli.create_runner(cmd)?;

type HostFunctionsOf<E> = ExtendedHostFunctions<
sp_io::SubstrateHostFunctions,
<E as NativeExecutionDispatch>::ExtendHostFunctions,
>;

// grab the task manager.
let registry = &runner
.config()
.prometheus_config
.as_ref()
.map(|cfg| &cfg.registry);
let task_manager =
sc_service::TaskManager::new(runner.config().tokio_handle.clone(), *registry)
.map_err(|e| format!("Error: {:?}", e))?;

let info_provider = timestamp_with_aura_info(MILLISECS_PER_BLOCK);

runner.async_run(|_| {
Ok((
cmd.run::<Block, HostFunctionsOf<ParachainNativeExecutor>, _>(Some(
info_provider,
)),
task_manager,
))
})
}
#[cfg(not(feature = "try-runtime"))]
Some(Subcommand::TryRuntime) => Err("Try-runtime was not enabled when building the node. \
You can enable it with `--features try-runtime`."
.into()),

None => {
let runner = cli.create_runner(&cli.run.normalize())?;
let collator_options = cli.run.collator_options();
Expand Down
24 changes: 22 additions & 2 deletions pallets/briefs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ targets = ["x86_64-unknown-linux-gnu"]
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = [
"derive",
] }
log = { version = "0.4.17", default-features = false }

serde = { version = "1.0.101", default-features=false}
scale-info = { version = "2.1.1", default-features = false, features = ["derive"] }
frame-benchmarking = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v0.9.43", default-features = false, optional = true }
Expand Down Expand Up @@ -55,10 +57,11 @@ common-runtime = { path = "../../runtime/common"}

[features]
default = ['std']

std = [
"codec/std",
"serde/std",
"frame-benchmarking?/std",
"frame-benchmarking/std",
"frame-support/std",
"frame-system/std",
"scale-info/std",
Expand All @@ -79,4 +82,21 @@ runtime-benchmarks = [
"common-runtime/runtime-benchmarks",
]

try-runtime = ["frame-support/try-runtime"]
try-runtime = [
"frame-support/try-runtime",
"frame-system/try-runtime",
"sp-runtime/try-runtime",
"pallet-balances/try-runtime",
"pallet-proposals/try-runtime",
"common-runtime/try-runtime",
"pallet-xcm/try-runtime",
"pallet-deposits/try-runtime",
"pallet-deposits/try-runtime",
"common-traits/try-runtime",
"common-types/try-runtime",
"orml-currencies/try-runtime",
"orml-tokens/try-runtime",
"pallet-identity/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime"
]
25 changes: 4 additions & 21 deletions pallets/briefs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod benchmarking;
#[cfg(any(feature = "runtime-benchmarks", test))]
mod test_utils;

mod migrations;
pub mod migrations;

#[frame_support::pallet]
pub mod pallet {
Expand Down Expand Up @@ -61,7 +61,10 @@ pub mod pallet {

pub type BriefHash = H256;

const STORAGE_VERSION: StorageVersion = StorageVersion::new(2);

#[pallet::pallet]
#[pallet::storage_version(STORAGE_VERSION)]
pub struct Pallet<T>(_);

#[pallet::config]
Expand Down Expand Up @@ -98,17 +101,6 @@ pub mod pallet {
pub type BriefContributions<T> =
StorageMap<_, Blake2_128Concat, BriefHash, BoundedBriefContributions<T>, ValueQuery>;

#[pallet::storage]
pub type StorageVersion<T: Config> = StorageValue<_, Release, ValueQuery>;

#[derive(Encode, Decode, TypeInfo, PartialEq, MaxEncodedLen, Default)]
#[repr(u32)]
pub enum Release {
V0,
#[default]
V1,
}

#[pallet::event]
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
Expand Down Expand Up @@ -157,15 +149,6 @@ pub mod pallet {
MilestonesTotalPercentageMustEqual100,
}

#[pallet::hooks]
impl<T: Config> Hooks<BlockNumberFor<T>> for Pallet<T> {
fn on_runtime_upgrade() -> Weight {
let mut weight: Weight = Zero::zero();
crate::migrations::v1::migrate_to_v1::<T>(&mut weight);
weight
}
}

#[pallet::call]
impl<T: Config> Pallet<T> {
/// Create a brief to be funded or amended.
Expand Down
Loading

0 comments on commit 914ed50

Please sign in to comment.