Skip to content

Commit

Permalink
fix stall spec (#300)
Browse files Browse the repository at this point in the history
* create dummy chain spec to avoid duplicating test balances when forking

* write runtime migration to fix the vesting schedules

* new main chain spec
  • Loading branch information
ETeissonniere authored Oct 20, 2020
1 parent 948a356 commit 1b8baaf
Show file tree
Hide file tree
Showing 4 changed files with 5,582 additions and 5,527 deletions.
11,038 changes: 5,513 additions & 5,525 deletions node/res/main.json

Large diffs are not rendered by default.

26 changes: 25 additions & 1 deletion node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ pub fn testnet_genesis(
.cloned()
.map(|k| (k, ENDOWMENT))
.chain(oracles.iter().map(|x| (x.clone(), ENDOWMENT)))
.chain(initial_authorities.iter().map(|x| (x.0.clone(), ENDOWMENT)))
.chain(roots.iter().map(|x| (x.clone(), ENDOWMENT)))
.collect(),
}),
Expand Down Expand Up @@ -264,6 +263,31 @@ pub fn local_testnet_config() -> ChainSpec {
)
}

fn dummy_testnet_genesis() -> GenesisConfig {
testnet_genesis(
vec![get_authority_keys_from_seed("Alice")],
vec![],
vec![],
Some(vec![]),
Some(vec![]),
)
}

/// Dummy testnet config no balances, alice is a validator
pub fn dummy_testnet_config() -> ChainSpec {
ChainSpec::from_genesis(
"Dummy Network",
"dummy_network",
ChainType::Live,
dummy_testnet_genesis,
vec![],
None,
None,
None,
Default::default(),
)
}

/// Arcadia config, from json chainspec
pub fn arcadia_config() -> ChainSpec {
ChainSpec::from_json_bytes(&include_bytes!("../res/arcadia.json")[..]).unwrap()
Expand Down
2 changes: 2 additions & 0 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ impl SubstrateCli for Cli {
Ok(match id {
"dev" => Box::new(chain_spec::development_config()),
"local" => Box::new(chain_spec::local_testnet_config()),
// Dummy chain is a chain wiht no accounts and only alice as an authority. Useful for forks
"dummy" => Box::new(chain_spec::dummy_testnet_config()),
"main" => Box::new(chain_spec::main_config()),
"" | "arcadia" => Box::new(chain_spec::arcadia_config()),
path => Box::new(chain_spec::ChainSpec::from_json_file(
Expand Down
43 changes: 42 additions & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
/// Version of the runtime specification. A full-node will not attempt to use its native
/// runtime in substitute for the on-chain Wasm runtime unless all of `spec_name`,
/// `spec_version` and `authoring_version` are the same between Wasm and native.
spec_version: 42,
spec_version: 43,

/// Version of the implementation of the specification. Nodes are free to ignore this; it
/// serves only as an indication that the code is different; as long as the other two versions
Expand Down Expand Up @@ -838,6 +838,46 @@ construct_runtime!(
}
);

pub struct RuntimeUpgradeStallFork;
impl frame_support::traits::OnRuntimeUpgrade for RuntimeUpgradeStallFork {
fn on_runtime_upgrade() -> frame_support::weights::Weight {
use frame_support::migration::{put_storage_value, StorageIterator};
sp_runtime::print("🕊️ Recomputing Grants...");

for (account_id, grants) in StorageIterator::<
Vec<pallet_grants::VestingSchedule<BlockNumber, Balance>>,
>::new(b"Vesting", b"VestingSchedules")
.drain()
{
// The network was stopped at block 1905656. We simply remove those blocks from
// the start value since the network restarts at block 0.

let previous_network_stopped_at = 1905656;
put_storage_value(
b"Vesting",
b"VestingSchedules",
&account_id,
grants
.iter()
.clone()
.map(
|grant| pallet_grants::VestingSchedule::<BlockNumber, Balance> {
start: grant.start.saturating_sub(previous_network_stopped_at),
period: grant.period,
period_count: grant.period_count,
per_period: grant.per_period,
},
)
.collect::<Vec<_>>(),
);
}

sp_runtime::print("🕊️ Grants migrated");

MaximumBlockWeight::get()
}
}

/// The address format for describing accounts.
pub type Address = <Indices as StaticLookup>::Source;
/// Block header type as expected by this runtime.
Expand Down Expand Up @@ -871,6 +911,7 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllModules,
RuntimeUpgradeStallFork,
>;

sp_api::impl_runtime_apis! {
Expand Down

0 comments on commit 1b8baaf

Please sign in to comment.