Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use suffixes to clear storage #24

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
100 changes: 54 additions & 46 deletions src/hotfixes/runtime-1900-fix-staking-reserve-to-lock-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import "@moonbeam-network/api-augment";
import { ApiPromise, Keyring } from "@polkadot/api";
import { getApiFor, NETWORK_YARGS_OPTIONS } from "../utils/networks";
import { blake2AsHex, xxhashAsHex } from "@polkadot/util-crypto";
import { numberToHex } from "@polkadot/util";

const argv = yargs(process.argv.slice(2))
.usage("Usage: $0")
Expand Down Expand Up @@ -86,57 +87,64 @@ async function main() {
return keys.concat(await getAllKeys(api, prefix, keys[keys.length - 1]));
}

const delegatorPrefix =
const delegatorPrefixBase =
xxhashAsHex("ParachainStaking", 128) +
xxhashAsHex("DelegatorReserveToLockMigrations", 128).slice(2);
const collatorPrefix =
const collatorPrefixBase =
xxhashAsHex("ParachainStaking", 128) +
xxhashAsHex("CollatorReserveToLockMigrations", 128).slice(2);

const delegatorKeys = await getAllKeys(api, delegatorPrefix);
const collatorKeys = await getAllKeys(api, collatorPrefix);

console.log(
`DelegatorReserveToLockMigrations: ${delegatorKeys.length
.toString()
.padStart(6, " ")} (prefix: ${delegatorPrefix})`
);
console.log(
` CollatorReserveToLockMigrations: ${collatorKeys.length
.toString()
.padStart(6, " ")} (prefix: ${collatorPrefix})`
);

const toPropose = api.tx.utility.batch([
api.tx.system.remarkWithEvent("State cleanup: reserve-to-lock storage items 1/1"),
api.tx.system.killPrefix(delegatorPrefix, delegatorKeys.length),
api.tx.system.killPrefix(collatorPrefix, collatorKeys.length),
]);
let encodedProposal = toPropose?.method.toHex() || "";
let encodedHash = blake2AsHex(encodedProposal);
console.log("Encoded proposal after schedule is", encodedProposal);
console.log("Encoded proposal hash after schedule is", encodedHash);
console.log("Encoded length", encodedProposal.length);

if (argv["sudo"]) {
await api.tx.sudo.sudo(toPropose).signAndSend(account, { nonce: nonce++ });
} else {
if (argv["send-preimage-hash"]) {
await api.tx.democracy
.notePreimage(encodedProposal)
.signAndSend(account, { nonce: nonce++ });
}

if (argv["send-proposal-as"] == "democracy") {
await api.tx.democracy
.propose(encodedHash, proposalAmount)
.signAndSend(account, { nonce: nonce++ });
} else if (argv["send-proposal-as"] == "council-external") {
let external = api.tx.democracy.externalProposeMajority(encodedHash);

await api.tx.councilCollective
.propose(collectiveThreshold, external, external.length)
.signAndSend(account, { nonce: nonce++ });
for (let i = 0; i < 256; i++) {
const delegatorPrefix = `${delegatorPrefixBase}${numberToHex(i).slice(2)}`;
const collatorPrefix = `${collatorPrefixBase}${numberToHex(i).slice(2)}`;

const delegatorKeys = await getAllKeys(api, delegatorPrefix);
const collatorKeys = await getAllKeys(api, collatorPrefix);

console.log(
`DelegatorReserveToLockMigrations: ${delegatorKeys.length
.toString()
.padStart(6, " ")} (prefix: ${delegatorPrefix})`
);
console.log(
` CollatorReserveToLockMigrations: ${collatorKeys.length
.toString()
.padStart(6, " ")} (prefix: ${collatorPrefix})`
);

const toPropose = api.tx.scheduler.scheduleAfter(i + 1, null, 0, {
Value: api.tx.utility.batch([
api.tx.system.remarkWithEvent("State cleanup: reserve-to-lock storage items 1/1"),
api.tx.system.killPrefix(delegatorPrefix, delegatorKeys.length),
api.tx.system.killPrefix(collatorPrefix, collatorKeys.length),
]),
});
let encodedProposal = toPropose?.method.toHex() || "";
let encodedHash = blake2AsHex(encodedProposal);
console.log("Encoded proposal after schedule is", encodedProposal);
console.log("Encoded proposal hash after schedule is", encodedHash);
console.log("Encoded length", encodedProposal.length);

if (argv["sudo"]) {
await api.tx.sudo.sudo(toPropose).signAndSend(account, { nonce: nonce++ });
} else {
if (argv["send-preimage-hash"]) {
await api.tx.democracy
.notePreimage(encodedProposal)
.signAndSend(account, { nonce: nonce++ });
}

if (argv["send-proposal-as"] == "democracy") {
await api.tx.democracy
.propose(encodedHash, proposalAmount)
.signAndSend(account, { nonce: nonce++ });
} else if (argv["send-proposal-as"] == "council-external") {
let external = api.tx.democracy.externalProposeMajority(encodedHash);

await api.tx.councilCollective
.propose(collectiveThreshold, external, external.length)
.signAndSend(account, { nonce: nonce++ });
}
}
}
} finally {
Expand Down