My goal is to allocate a balance in the genesis block to both:
- A list of endowed accounts already included in the chain specification chain_spec.rs
- A list of further accounts and balances included in a JSON file called genesis.json genesis block (overwrite the balance value of any duplicate accounts that are also in the list of endowed accounts).
However, I have encountered the following problems:
- None of the endowed accounts or the accounts in the JSON file are being credited
- polkadot-launch generates invalid values for "genesis_head" and "validation_code" in the parachain chain specification rococo-local.json that it generates (see below for details).
I've tried creating this Pull Request https://github.com/DataHighway-DHX/DataHighway-Parachain/pull/5 which is based on Substrate v0.9.16 and it compiles successfully with ./scripts/init.sh && cargo build --release
.
I have forked the polkadot-launch repository in this Pull Request https://github.com/DataHighway-DHX/polkadot-launch/pull/2, which includes instructions and shell scripts that I follow to configure it on a macOS M1, but when I follow the default polkadot-launch steps, for example copying the DataHighway-Parachain binary cp ./target/release/datahighway-collator ~/code/DataHighway-DHX/polkadot-launch/bin/datahighway-collator
to the relevant polkadot-launch folder and after cloning and building the v0.9.16 branch of the polkadot repository and also copying the polkadot binary to the same polkadot-launch folder, and then running polkadot-launch yarn start config.json
using a relevant version of Node.js (i.e. v16.3.0), the polkadot-launch logs give an error message when it generates the rococo-local.json chain specification file Error: 0: Other: Error parsing spec file: 0x prefix is missing at line 208 column 1756
, as shown below:
🧹 Resolving parachain id...
2022-02-10 14:05:34 Building chain spec
🧹 Starting with a fresh authority set...
👤 Added Genesis Authority alice
👤 Added Genesis Authority bob
👤 Added Genesis Authority charlie
👤 Added Genesis Authority dave
⚙ Updating Relay Chain Genesis Configuration
✓ Updated Genesis Configuration [ validation_upgrade_frequency: 10 ]
✓ Updated Genesis Configuration [ validation_upgrade_delay: 10 ]
⛓ Adding Genesis Parachains
✓ Added Genesis Parachain 2000
✓ Added Genesis Parachain 3000
⛓ Adding Genesis HRMP Channels
✓ Added HRMP channel 2000 -> 3000
Added Boot Nodes: /ip4/127.0.0.1/tcp/30336/p2p/12D3KooWF66thRTDXG2ksKm3nMCHeoMneuohs71Q4anPLVnBSsSp,/ip4/127.0.0.1/tcp/30337/p2p/12D3KooWAZ1VKfix84y8rrrLekd6xVksDgjiYooTNTBi32GSXCWN,/ip4/127.0.0.1/tcp/30338/p2p/12D3KooWEpmRWnuEga2oFPZ7P8BfcJBZj928XT46hhj6zyieA72R,/ip4/127.0.0.1/tcp/30339/p2p/12D3KooWFUiU4LrYD1MVwbvkE4wqvCTy2feU9LijMKPoEXBJhArG
2022-02-10 14:05:36 Building chain spec
Error:
0: Other: Error parsing spec file: 0x prefix is missing at line 208 column 1756
...
I found that the error is caused because the rococo-local.json file that it generates isn't being generated correctly, and its including snippets of the actual codebase and newline characters in front of the hex values of the "genesis_head" value and "validation_code" properties as shown below:
rococo-local.json
...
"paras": {
"paras": [
[
2000,
{
"genesis_head": "account_public_key_json "a42b7518d62a942344fec55d414f1654bf3fd325dbfa32a3c30534d5976acb21"\naccount_balance_json 60000000000000000000000\naccount_ss58_address_json a42b7518d62a942344fec55d414f1654bf3fd325dbfa32a3c30534d5976acb21 (5FmxcuFw...)\nno match b/w endowed and json for "a42b7518d62a942344fec55d414f1654bf3fd325dbfa32a3c30534d5976acb21" so adding it to the list\n0x0000000000000000000000000000000000000000000000000000000000000000005c76496ba72...",
"validation_code": "account_public_key_json "a42b7518d62a942344fec55d414f1654bf3fd325dbfa32a3c30534d5976acb21"\naccount_balance_json 60000000000000000000000\naccount_ss58_address_json a42b7518d62a942344fec55d414f1654bf3fd325dbfa32a3c30534d5976acb21 (5FmxcuFw...)\nno match b/w endowed and json for "a42b7518d62a942344fec55d414f1654bf3fd325dbfa32a3c30534d5976acb21" so adding it to the list\n0x52bc5376
Since I can't figure out how to debug (i.e. using println! or log::trace, etc), in the chain_spec.rs file of DataHighway-Parachain codebase, I instead replicated the relevant parts of the code in a separate Rust project https://github.com/ltfschoen/RustTest/tree/master/projects/endow to see what was going on, but it appeared to be combining and returning the accounts and balances correctly:
[
(
a42b7518d62a942344fec55d414f1654bf3fd325dbfa32a3c30534d5976acb21 (5FmxcuFw...),
30000000000000000000000,
),
...
]
So in the DataHighway-Parachain codebase, I tried to isolate the issue as follows:
I found that if I only use the for
loop https://github.com/DataHighway-DHX/DataHighway-Parachain/pull/5/files#diff-f2256017c4e606a30f53708578da46675512cc1300be6542ed5f77e58af0d6dcR961 and remove the line that calls get_allocation
so it doesn't try to load and included the accounts and balances in the genesis.json file into the genesis, then it generates an error Error parsing spec file: 0x prefix is missing at line
when i use polkadot-launch.
Whereas if comment out that for
loop (so it doesn't credit the endowed accounts), and I uncomment the get_allocation
function again (so it only credits the accounts loaded from the genesis.json file), then it compiles successfully, and after I copy the latest datahighway-collator binary file to polkadot-launch and run polkadot-launch, it launches the relay chain and collator nodes successfully, but it doesn't credit the accounts loaded from the genesis.json file as expected, because I checked the balance of the accounts included in genesis.json by adding them to the Polkadot.js Apps address book https://polkadot.js.org/apps/?rpc=ws%3A%2F%2F127.0.0.1:9988#/addresses but they didn't have a balance.
I also suspect it may be because I am not sure when you use AccountId
(of type type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::AccountId;
that is included in DataHighway-Parachain/runtime/src/types.rs) instead of AccountId32
(which I understand is a struct that creates an instance of inner type [u8; 32]
).