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

Generate People chain specs with Identity off-chain migration #2931

Closed
wants to merge 46 commits into from
Closed
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
407d4d9
script done
NachoPal Sep 23, 2023
442976a
clean up + README
NachoPal Sep 25, 2023
5485501
get IdentityOf info
NachoPal Oct 9, 2023
7b65fd5
added identity migration file
NachoPal Oct 24, 2023
83479b8
discord migration done
NachoPal Oct 24, 2023
86ff8cd
ready
NachoPal Oct 25, 2023
5120076
ready
NachoPal Oct 25, 2023
7dc2f91
update README
NachoPal Oct 25, 2023
7835e5e
Merge branch 'master' into nacho/script-migrate-data-to-genesis
NachoPal Oct 25, 2023
e2db65b
rename riot to matrix
NachoPal Oct 25, 2023
664bd5c
Merge branch 'nacho/script-migrate-data-to-genesis' of github.com:par…
NachoPal Oct 25, 2023
cb442cf
Apply suggestions from code review
joepetrowski Nov 28, 2023
001400c
comments nits
NachoPal Dec 19, 2023
0dc630e
fix
NachoPal Dec 20, 2023
077510e
undo
NachoPal Dec 20, 2023
a3a8104
Merge branch 'master' into nacho/script-migrate-data-to-genesis
NachoPal Dec 20, 2023
69ebd35
set SubsOf deposit to 0
NachoPal Dec 20, 2023
cfb1322
Merge branch 'nacho/script-migrate-data-to-genesis' of github.com:par…
NachoPal Dec 20, 2023
ab1fcef
add Username
NachoPal Jan 5, 2024
a6b3a83
Bump workspace unified version
EgorPopelyaev Jan 10, 2024
3865fd8
Bump node version to 1.6.0 in polkadot-cli
EgorPopelyaev Jan 10, 2024
950a366
Bump crate versions in: cumulus/polkadot-parachain/Cargo.toml
EgorPopelyaev Jan 10, 2024
2e7cc70
Bump spec_version
EgorPopelyaev Jan 10, 2024
680adc7
Bump people spec_version
EgorPopelyaev Jan 11, 2024
fd14874
move prdoc files to the release folder
EgorPopelyaev Jan 12, 2024
7e86691
regenerate people-rococo base chain_spec
NachoPal Jan 15, 2024
a3e30c6
Merge branch 'nacho/script-migrate-data-to-genesis' into nacho/people…
NachoPal Jan 15, 2024
9091da1
recover lost chain_spec json
NachoPal Jan 15, 2024
1240928
Merge branch 'master' into nacho/people-chain-spec-with-migation
NachoPal Jan 15, 2024
feb7818
chain spec with off-chain migration done
NachoPal Jan 15, 2024
d2203c4
merge master
joepetrowski Jan 17, 2024
e078264
Merge branch 'master' into nacho/people-chain-spec-with-migation
NachoPal Jan 22, 2024
fca5044
people-westend chain_spec regenerated
NachoPal Jan 22, 2024
70606b1
Update cumulus/scripts/migrate_storage_to_genesis/index.js
NachoPal Jan 24, 2024
3e83c3d
Update cumulus/scripts/migrate_storage_to_genesis/README.md
NachoPal Jan 24, 2024
e115230
fix comments
NachoPal Jan 24, 2024
b0b45a7
Merge branch 'master' into nacho/people-chain-spec-with-migation
NachoPal Jan 24, 2024
dd57153
more fix comments
NachoPal Jan 24, 2024
956df13
merge marster
NachoPal Apr 5, 2024
2365851
Merge branch 'master' into nacho/people-chain-spec-with-migation
joepetrowski Apr 10, 2024
62d38aa
Merge branch 'master' into nacho/people-chain-spec-with-migation
NachoPal Apr 17, 2024
0887f9a
edit genesis people kusama
NachoPal Apr 18, 2024
0a47dc2
fix conflict
NachoPal Apr 29, 2024
d9c8753
People Chain migration: filter `FeePaid ` judgements (#4909)
muharem Jun 28, 2024
12f690e
Add scripts to generate people chain base chainspecs (#4910)
seadanda Jul 3, 2024
f4bfc3d
Add people-polkadot genesis chainspec
seadanda Jul 10, 2024
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
63 changes: 41 additions & 22 deletions cumulus/parachains/chain-specs/people-rococo.json

Large diffs are not rendered by default.

201 changes: 179 additions & 22 deletions cumulus/parachains/chain-specs/people-westend.json

Large diffs are not rendered by default.

30 changes: 5 additions & 25 deletions cumulus/scripts/create_people_rococo_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,18 @@ cat chain-spec-plain.json | jq --rawfile code rt-hex.txt '.genesis.runtimeGenesi
| jq '.id = "people-rococo"' \
| jq '.chainType = "Live"' \
| jq '.bootNodes = [
"/dns/rococo-people-collator-node-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWDZg5jMYhKXTu6RU491V5sxsFnP4oaEmZJEUfcRkYzps5",
"/dns/rococo-people-collator-node-0.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWDZg5jMYhKXTu6RU491V5sxsFnP4oaEmZJEUfcRkYzps5",
"/dns/rococo-people-collator-node-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWGGR5i6qQqfo7iDNp7vjDRKPWuDk53idGV6nFLwS12X5H",
"/dns/rococo-people-collator-node-1.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWGGR5i6qQqfo7iDNp7vjDRKPWuDk53idGV6nFLwS12X5H",
"/dns/rococo-people-collator-node-2.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWBvA9BmBfrsVMcAcqVXGYFCpMTvkSk2igNXpmoareYbeT",
"/dns/rococo-people-collator-node-2.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWBvA9BmBfrsVMcAcqVXGYFCpMTvkSk2igNXpmoareYbeT",
"/dns/rococo-people-collator-node-3.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWQ7Q9jLcJTPXy7KEp5hSZ8YMY9pHx9CnQVz3T8TKQ81UG",
"/dns/rococo-people-collator-node-3.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWQ7Q9jLcJTPXy7KEp5hSZ8YMY9pHx9CnQVz3T8TKQ81UG"
"/dns/rococo-people-collator-node-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWDZg5jMYhKXTu6RU491V5sxsFnP4oaEmZJEUfcRkYzps5",
"/dns/rococo-people-collator-node-0.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWDZg5jMYhKXTu6RU491V5sxsFnP4oaEmZJEUfcRkYzps5",
"/dns/rococo-people-collator-node-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWGGR5i6qQqfo7iDNp7vjDRKPWuDk53idGV6nFLwS12X5H",
"/dns/rococo-people-collator-node-1.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWGGR5i6qQqfo7iDNp7vjDRKPWuDk53idGV6nFLwS12X5H"
]' \
| jq '.relay_chain = "rococo"' \
| jq --argjson para_id $para_id '.para_id = $para_id' \
| jq --argjson para_id $para_id '.genesis.runtimeGenesis.patch.parachainInfo.parachainId = $para_id' \
| jq '.genesis.runtimeGenesis.patch.balances.balances = []' \
| jq '.genesis.runtimeGenesis.patch.collatorSelection.invulnerables = [
"5Gnjmw1iuF2kV4PecFgetJed7B8quBKfLiRM99ELcXvFH9Vn",
"5FLZRxyeRPhG69zo4ZPqCJSYboSKaRBUjBvQc1nkuWoBpZ5P",
"5DNnmPH2MT6SXpfqbJZbTz4eERmuZegssfxc4ysL8PWrHaNN",
"5DkKcSP5MboNMpXScW1CyRqaktKMXH8QLP4Mn49TwS5vhL6k"
"5FLZRxyeRPhG69zo4ZPqCJSYboSKaRBUjBvQc1nkuWoBpZ5P"
]' \
| jq '.genesis.runtimeGenesis.patch.session.keys = [
[
Expand All @@ -74,20 +68,6 @@ cat chain-spec-plain.json | jq --rawfile code rt-hex.txt '.genesis.runtimeGenesi
{
"aura": "5FLZRxyeRPhG69zo4ZPqCJSYboSKaRBUjBvQc1nkuWoBpZ5P"
}
],
[
"5DNnmPH2MT6SXpfqbJZbTz4eERmuZegssfxc4ysL8PWrHaNN",
"5DNnmPH2MT6SXpfqbJZbTz4eERmuZegssfxc4ysL8PWrHaNN",
{
"aura": "5DNnmPH2MT6SXpfqbJZbTz4eERmuZegssfxc4ysL8PWrHaNN"
}
],
[
"5DkKcSP5MboNMpXScW1CyRqaktKMXH8QLP4Mn49TwS5vhL6k",
"5DkKcSP5MboNMpXScW1CyRqaktKMXH8QLP4Mn49TwS5vhL6k",
{
"aura": "5DkKcSP5MboNMpXScW1CyRqaktKMXH8QLP4Mn49TwS5vhL6k"
}
]
]' \
> edited-chain-spec-plain.json
Expand Down
25 changes: 3 additions & 22 deletions cumulus/scripts/create_people_westend_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,15 @@ cat chain-spec-plain.json | jq --rawfile code rt-hex.txt '.genesis.runtimeGenesi
"/dns/westend-people-collator-node-0.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWDcLjDLTu9fNhmas9DTWtqdv8eUbFMWQzVwvXRK7QcjHD",
"/dns/westend-people-collator-node-0.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWDcLjDLTu9fNhmas9DTWtqdv8eUbFMWQzVwvXRK7QcjHD",
"/dns/westend-people-collator-node-1.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWM56JbKWAXsDyWh313z73aKYVMp1Hj2nSnAKY3q6MnoC9",
"/dns/westend-people-collator-node-1.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWM56JbKWAXsDyWh313z73aKYVMp1Hj2nSnAKY3q6MnoC9",
"/dns/westend-people-collator-node-2.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWGVYTVKW7tYe51JvetvGvVLDPXzqQX1mueJgz14FgkmHG",
"/dns/westend-people-collator-node-2.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWGVYTVKW7tYe51JvetvGvVLDPXzqQX1mueJgz14FgkmHG",
"/dns/westend-people-collator-node-3.parity-testnet.parity.io/tcp/30333/p2p/12D3KooWCF1eA2Gap69zgXD7Df3e9DqDUsGoByocggTGejoHjK23",
"/dns/westend-people-collator-node-3.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWCF1eA2Gap69zgXD7Df3e9DqDUsGoByocggTGejoHjK23"
"/dns/westend-people-collator-node-1.parity-testnet.parity.io/tcp/443/wss/p2p/12D3KooWM56JbKWAXsDyWh313z73aKYVMp1Hj2nSnAKY3q6MnoC9"
]' \
| jq '.relay_chain = "westend"' \
| jq --argjson para_id $para_id '.para_id = $para_id' \
| jq --argjson para_id $para_id '.genesis.runtimeGenesis.patch.parachainInfo.parachainId = $para_id' \
| jq '.genesis.runtimeGenesis.patch.balances.balances = []' \
| jq '.genesis.runtimeGenesis.patch.collatorSelection.invulnerables = [
"5CFYvshLff1dHmT33jUcBc7mEKbVRJKbA9HzPqmLfjksHah6",
"5HgEdsYyVGVsyNmbE1sUxeDLrxTLJXnAKCNa2HJ9QXXEir1B",
"5EZmD6eA9wm1Y2Dy2wefLCsFJJcC7o8bVfWm7Mfbuanc8JYo",
"5EkJFfUtbo258dCaqgYSvajN1tNtXhT3SrybW8ZhygoMP3kE"
"5HgEdsYyVGVsyNmbE1sUxeDLrxTLJXnAKCNa2HJ9QXXEir1B"
]' \
| jq '.genesis.runtimeGenesis.patch.session.keys = [
[
Expand All @@ -74,22 +68,9 @@ cat chain-spec-plain.json | jq --rawfile code rt-hex.txt '.genesis.runtimeGenesi
{
"aura": "5HgEdsYyVGVsyNmbE1sUxeDLrxTLJXnAKCNa2HJ9QXXEir1B"
}
],
[
"5EZmD6eA9wm1Y2Dy2wefLCsFJJcC7o8bVfWm7Mfbuanc8JYo",
"5EZmD6eA9wm1Y2Dy2wefLCsFJJcC7o8bVfWm7Mfbuanc8JYo",
{
"aura": "5EZmD6eA9wm1Y2Dy2wefLCsFJJcC7o8bVfWm7Mfbuanc8JYo"
}
],
[
"5EkJFfUtbo258dCaqgYSvajN1tNtXhT3SrybW8ZhygoMP3kE",
"5EkJFfUtbo258dCaqgYSvajN1tNtXhT3SrybW8ZhygoMP3kE",
{
"aura": "5EkJFfUtbo258dCaqgYSvajN1tNtXhT3SrybW8ZhygoMP3kE"
}
]
]' \
| jq '.genesis.runtimeGenesis.patch.polkadotXcm.safeXcmVersion = 3' \
> edited-chain-spec-plain.json

# build a raw spec
Expand Down
13 changes: 13 additions & 0 deletions cumulus/scripts/migrate_storage_to_genesis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Migrate storage to genesis state
Script to query storage under a particular key and add it to a raw chain_spec json file as genesis state.

# How to use
The storage to be quired can be selected by either providing a pallet name or a key in hex format.
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
```
yarn migrate -c <wss_chain_enpoint> -f <chain_spec_raw_to_edit.json> -p <pallet_name> -k <storage_key> -m <js_migration_function_file>
```

Example for migrating `Identity` pallet from Polkadot:
```
yarn migrate -c wss://rpc.polkadot.io -f new_genesis_raw.json -p Identity -m ./identityMigration.js
```
108 changes: 108 additions & 0 deletions cumulus/scripts/migrate_storage_to_genesis/identityMigration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
const { u8aToHex, hexToString } = require('@polkadot/util');
const { xxhashAsHex } = require('@polkadot/util-crypto');

const migrateIdentity = async (key, data, api) => {
// Register the new `Registration` format type
api.registry.register({
IdentityInfoNew: {
_fallback: 'IdentityInfoTo198',
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
display: 'Data',
legal: 'Data',
web: 'Data',
matrix: 'Data',
email: 'Data',
pgpFingerprint: 'Option<H160>',
image: 'Data',
twitter: 'Data',
github: 'Data',
discord: 'Data',
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
},
RegistrationNew: {
_fallback: 'RegistrationTo198',
judgements: 'Vec<RegistrationJudgement>',
deposit: 'Balance',
info: 'IdentityInfoNew'
},
Username: 'Vec<u8>',
});

// We want to migrate `IdentityOf` storage item
let IdentityOfkeyToMigrate = "IdentityOf";
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
let IdentityOfHexkeyToMigrate = xxhashAsHex(IdentityOfkeyToMigrate, 128);

// We want to migrate `SubsOf` storage item
let SubsOfkeyToMigrate = "SubsOf";
let SubsOfHexkeyToMigrate = xxhashAsHex(SubsOfkeyToMigrate, 128);
NachoPal marked this conversation as resolved.
Show resolved Hide resolved

// We take the second half of the key, which is the storage item identifier
let storageItem = u8aToHex(key.toU8a().slice(18, 34));

// Migrate `IdentityOf` data to its new format
if (IdentityOfHexkeyToMigrate === storageItem) {
let decoded = api.createType('(Registration, Option<Username>)', data.toU8a(true));

// Default value for `discord` and `github` fields.
let discord = { none: null };
let github = { none: null };

// Get the `Registration` part from the `IdentityInfo` tuple
let decodedJson = decoded.toJSON()[0];

// Look for `Discord` and `Github` keys in `additional` field
decodedJson.info.additional.forEach(([key, data]) => {
let keyString = hexToString(key.raw)

if (keyString.toLowerCase() === "discord") {
discord = { raw: data.raw };
} else if (keyString.toLowerCase() === "github") {
github = { raw: data.raw };
}
});

// Migrate `IdentityInfo` data to the new format:
// - remove `additional` field
// - add `discord` field
// - add `github` field
// - set `deposit` to 0
let decodedNew = api.createType(
'(RegistrationNew, Option<Username>)',
[
{
judgements: decodedJson.judgements,
deposit: 0,
info: {
display: decodedJson.info.display,
legal: decodedJson.info.legal,
web: decodedJson.info.web,
matrix: decodedJson.info.riot,
email: decodedJson.info.email,
pgpFingerprint: decodedJson.info.pgpFingerprint,
image: decodedJson.info.image,
twitter: decodedJson.info.twitter,
github: github,
discord: discord,
}
},
null
]
);

data = decodedNew.toHex();

} else if (SubsOfHexkeyToMigrate === storageItem) {
let decoded = api.createType('(Balance, BoundedVec<AccountId, MaxApprovals>)', data.toU8a(true));

// Migrate `SubsOf` data:
// - set Deposit to 0
let decodedNew = api.createType(
'(Balance, BoundedVec<AccountId, MaxApprovals>)',
[0, decoded.toJSON()[1]]
);

data = decodedNew.toHex();
}

return data;
};

module.exports = migrateIdentity;
137 changes: 137 additions & 0 deletions cumulus/scripts/migrate_storage_to_genesis/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
const fs = require('fs-extra');
const yargs = require('yargs');
const { resolve } = require('path');
const { ApiPromise, WsProvider } = require('@polkadot/api');
const { xxhashAsHex } = require('@polkadot/util-crypto');


// Open chain_spec raw file
const openFile = (filePath) => {
try {
const jsonData = fs.readJSONSync(filePath);
return jsonData;
} catch(e) {
console.log(`${filePath} file could not be opened. Make sure it exists`);
process.exit(1);
}
}

// Connect to chain
const connect = async (endpoint) => {
console.log(`Conecting to ${endpoint}...`);
const wsProvider = new WsProvider(endpoint);
return await ApiPromise.create({ provider: wsProvider });
}

// Migrate data using the migration function
const migrateData = async (path, key, data, api) => {
let absolutePath = resolve('.', path);
let migrationFunction;

try {
migrationFunction = await import(absolutePath);
} catch (e) {
console.log(`No data migration file can be found in ${path}`, e);
process.exit(1);
}

if (typeof migrationFunction.default === 'function') {
let migratedValue = await migrationFunction.default(key, data, api);
return migratedValue;
} else {
console.log(
`Data migration function must be default exported from the file ${path}`
);
process.exit(1);
}
}

// Query all storage under a certain key
const queryStorage = async (api, argv) => {
let rootKey = argv.key ? argv.key : xxhashAsHex(argv.pallet);

let storageKeyValues = new Object();

let keys = await api.rpc.state.getKeys(rootKey);

console.log("Querying pallet state...")

for (let key of keys) {
let data = await api.rpc.state.getStorage(key);
data = await migrateData(argv.migration, key, data, api)
storageKeyValues[key] = data
}

return storageKeyValues;
}

// Edit chain_spec raw adding the queried storage
const editChainSpec = (filePath, jsonData, storageKeyValues) => {
console.log("Editing json chain_spec...")

if (jsonData.genesis?.raw?.top) {
for (const key in storageKeyValues) {
jsonData.genesis.raw.top[key] = storageKeyValues[key];
}
} else {
console.log(`${filePath} - invalid raw chain_spec format json file`);
process.exit(1);
}

fs.writeJSONSync(filePath, jsonData, { spaces: 2 });
}

// Run the script
const run = async () => {
const argv = yargs
.option('chain', {
alias: 'c',
describe: 'Endpoint to the chain to query sorage',
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
demandOption: true, // Requires the --chain option
type: 'string',
})
.option('file', {
alias: 'f',
describe: 'Path to the JSON file',
demandOption: true, // Requires the --file option
type: 'string',
})
.option('pallet', {
alias: 'p',
describe: 'Pallet name',
type: 'string',
})
.option('key', {
alias: 'k',
describe: 'Storage key',
type: 'string',
})
.option('migration', {
alias: 'm',
describe: 'Path to the migration file function',
demandOption: true, // Requires the --migration option
type: 'string',
})
.check((args) => {
if (!args.pallet && !args.key) {
throw new Error('Please provide either --pallet or --key option.');
}
return true;
})
.help()
.alias('help', 'h').argv;

const filePath = argv.file;

let jsonData = openFile(filePath);

let api = await connect(argv.chain);

let storageKeyValues = await queryStorage(api, argv);

editChainSpec(filePath, jsonData, storageKeyValues)

process.exit(0);
}

run()
17 changes: 17 additions & 0 deletions cumulus/scripts/migrate_storage_to_genesis/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "migrate_storage_to_genesis",
"version": "1.0.0",
"description": "query storage from a pallet and add it to a new chain_spec_raw.json",
"main": "index.js",
"scripts": {
"migrate": "node index.js"
},
"author": "Parity Technologies <admin@parity.io>",
"license": "ISC",
NachoPal marked this conversation as resolved.
Show resolved Hide resolved
"dependencies": {
"@polkadot/api": "^10.9.1",
"@polkadot/util-crypto": "^12.5.1",
"fs-extra": "^11.1.1",
"yargs": "^17.7.2"
}
}
Loading
Loading