Skip to content

Commit

Permalink
Eliott/2.0.0 mainnet upgrade (#304)
Browse files Browse the repository at this point in the history
* allow usecase where one account can trigger a claim for someone else's account

* remove outdated runtime migrations
  • Loading branch information
ETeissonniere authored Feb 11, 2021
1 parent e4b3257 commit 3b8b7b7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 51 deletions.
2 changes: 1 addition & 1 deletion pallets/grants/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ benchmarks! {
for x in 0 .. b {
Module::<T>::do_add_vesting_schedule(&config.granter, &config.grantee, config.schedule.clone())?;
}
}: _(RawOrigin::Signed(config.grantee))
}: _(RawOrigin::Signed(config.grantee), config.grantee_lookup)

cancel_all_vesting_schedules {
let u in 1 .. 1000;
Expand Down
12 changes: 7 additions & 5 deletions pallets/grants/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,14 @@ decl_module! {
fn deposit_event() = default;

/// Claim funds that have been vested so far
#[weight = 30_000_000 + T::DbWeight::get().reads_writes(2, 2)]
pub fn claim(origin) {
let who = ensure_signed(origin)?;
let locked_amount = Self::do_claim(&who);
#[weight = 30_000_000 + T::DbWeight::get().reads_writes(3, 2)]
pub fn claim(origin, grantee: <T::Lookup as StaticLookup>::Source) {
let _who = ensure_signed(origin)?;
let dest = T::Lookup::lookup(grantee)?;

Self::deposit_event(RawEvent::Claimed(who, locked_amount));
let locked_amount = Self::do_claim(&dest);

Self::deposit_event(RawEvent::Claimed(dest, locked_amount));
}

/// Wire funds to be vested by the receiver
Expand Down
6 changes: 3 additions & 3 deletions pallets/grants/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ fn claim_works() {
// remain locked if not claimed
assert!(PalletBalances::transfer(Origin::signed(BOB), ALICE, 10).is_err());
// unlocked after claiming
assert_ok!(Vesting::claim(Origin::signed(BOB)));
assert_ok!(Vesting::claim(Origin::signed(BOB), BOB));
assert_ok!(PalletBalances::transfer(Origin::signed(BOB), ALICE, 10));
// more are still locked
assert!(PalletBalances::transfer(Origin::signed(BOB), ALICE, 1).is_err());

System::set_block_number(21);
// claim more
assert_ok!(Vesting::claim(Origin::signed(BOB)));
// claim more, alice pays for bob
assert_ok!(Vesting::claim(Origin::signed(ALICE), BOB));
assert_ok!(PalletBalances::transfer(Origin::signed(BOB), ALICE, 10));
// all used up
assert_eq!(PalletBalances::free_balance(BOB), 0);
Expand Down
43 changes: 1 addition & 42 deletions 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: 43,
spec_version: 44,

/// 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,46 +838,6 @@ 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 @@ -911,7 +871,6 @@ pub type Executive = frame_executive::Executive<
frame_system::ChainContext<Runtime>,
Runtime,
AllModules,
RuntimeUpgradeStallFork,
>;

sp_api::impl_runtime_apis! {
Expand Down

0 comments on commit 3b8b7b7

Please sign in to comment.