1+ // Get live chain data on the URL provided with `forkFrom`, and
2+ // insert the necessary data into a chain spec to launch a new chain with.
3+ //
4+ // ### Arguments
5+ // - `rawSpec`: Path to the raw chain spec to modify
6+ // - `forkFrom`: URL of the chain's WS port to get the data from
7+ //
8+ // ### Usage
9+ // `chainql --tla-code=rawSpec="import 'parachain-spec-raw.json'" --tla-str=forkFrom="wss://some-parachain.node:443" fork.jsonnet`
110
211function (rawSpec, forkFrom)
3- local sourceChain = cql.chain(forkFrom).latest;
12+ local sourceChainState = cql.chain(forkFrom).latest;
413
5- local raw = local sourceRaw = sourceChain ._raw._preloadKeys; {
14+ local raw = local sourceRaw = sourceChainState ._raw._preloadKeys; {
615 [key]: cql.toHex(sourceRaw[key])
716 for key in std.objectFields (sourceRaw)
817 if sourceRaw[key] != null
918};
1019
11- local typeNames = (import './typeNames.jsonnet' )(sourceChain);
12-
1320local
1421auraKeys = [
15- // AuraExt.Authorities, we don't have aura pallet enabled for some reason, to refer using cql api
16- '0x3c311d57d4daf52904616cf69648081e5e0621c4869aa60c02be9adcc98a0d1d' ,
17- // Aura.Authorities
18- '0x57f8dc2f5ab09467896f47300f0424385e0621c4869aa60c02be9adcc98a0d1d' ,
19- ],
22+ sourceChainState.AuraExt._key.Authorities,
23+ sourceChainState.Aura._key.Authorities,
24+ ] + (if 'CollatorSelection' in sourceChainState then [
25+ sourceChainState.CollatorSelection._key.Candidates,
26+ sourceChainState.CollatorSelection._key.Invulnerables,
27+ ] else []),
2028
2129// Keys, which should be migrated from passed spec, rather than from forked chain
2230wantedKeys = [
23- sourceChain.ParachainInfo._key.ParachainId,
24- sourceChain.Sudo._key.Key,
25- sourceChain.System.BlockHash._key['0' ],
26- sourceChain.System._key.ParentHash,
31+ sourceChainState.ParachainInfo._key.ParachainId,
32+ sourceChainState.Sudo._key.Key,
33+ sourceChainState.System.BlockHash._key['0' ],
34+ // Always [69, 69, 69, ..., 69, 69, 69]
35+ sourceChainState.System._key.ParentHash,
2736] + auraKeys,
28-
2937// Keys to remove from original chain
3038unwantedPrefixes = [
31- // Aura.CurrentSlot
32- '0x57f8dc2f5ab09467896f47300f04243806155b3cd9a8c9e5e9a23fd5dc13a5ed' ,
39+ sourceChainState.Aura._key.CurrentSlot,
3340 // Ensure there will be no panics caused by unexpected kept state
34- sourceChain.ParachainSystem._key.ValidationData,
35- sourceChain.ParachainSystem._key.RelayStateProof,
36- sourceChain.ParachainSystem._key.HostConfiguration,
37- sourceChain.ParachainSystem._key.LastDmqMqcHead,
41+ sourceChainState.ParachainSystem._key.ValidationData,
42+ sourceChainState.ParachainSystem._key.RelayStateProof,
43+ sourceChainState.ParachainSystem._key.HostConfiguration,
44+ sourceChainState.ParachainSystem._key.LastRelayChainBlockNumber,
45+ sourceChainState.ParachainSystem._key.LastDmqMqcHead,
3846 // Part of head
39- sourceChain .System._key.BlockHash,
40- sourceChain .System._key.Number,
41- sourceChain .System._key.Digest,
47+ sourceChainState .System._key.BlockHash,
48+ sourceChainState .System._key.Number,
49+ sourceChainState .System._key.Digest,
4250] + auraKeys,
4351
4452cleanupRaw(raw) = {
@@ -61,33 +69,37 @@ local outSpec = rawSpec {
6169 },
6270};
6371
72+ local pow10(n) = std.foldl (function (a, _) a * std.bigint('10' ), std.range (0 , n), std.bigint('1' ));
73+
6474local
65- aliceAccount = sourceChain.System._encodeKey.Account(['0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d' ]),
66- totalIssuance = sourceChain.Balances._encodeKey.TotalIssuance([]),
67- unique = cql.calc(["10" , "18" , "**" ]),
68- Munique = cql.calc([unique, "10" , "6" , "**" , "*" ]),
75+ aliceAccount = sourceChainState.System._encodeKey.Account(['0xd43593c715fdd31c61141abd04a99fd6822c8558854ccde39a5684e7a56da27d' ]),
76+ totalIssuance = sourceChainState.Balances._encodeKey.TotalIssuance([]),
77+ Munique = pow10(6 + 18 ),
6978;
7079
7180outSpec {
7281 genesis+: {
7382 raw+: {
7483 top+: {
75- [totalIssuance]: cql.calc([
76- Munique,
77- if std.objectHas (super , totalIssuance) then sourceChain._decode(typeNames.u128, super [totalIssuance]) else '0' ,
78- if std.objectHas (super , aliceAccount) then sourceChain._decode(typeNames.AccountInfo, super [aliceAccount]).data.free else '0' ,
79- '-' , '+' ,
80- ]),
81- [aliceAccount]: sourceChain._encode(typeNames.AccountInfo, {
84+ [totalIssuance]: sourceChainState.Balances._encodeValue.TotalIssuance(
85+ if std.objectHas (super , totalIssuance)
86+ then sourceChainState.Balances._decodeValue.TotalIssuance(super [totalIssuance])
87+ else std.bigint(0 )
88+ - if std.objectHas (super , aliceAccount)
89+ then sourceChainState.System._decodeValue.Account(super [aliceAccount]).data.free
90+ else std.bigint(0 )
91+ + Munique
92+ ),
93+ [aliceAccount]: sourceChainState.System._encodeValue.Account({
8294 nonce: 0 ,
8395 consumers: 3 ,
8496 providers: 1 ,
8597 sufficients: 0 ,
8698 data: {
8799 free: Munique,
88- reserved: "0" ,
89- misc_frozen: "0" ,
90- fee_frozen: "0" ,
100+ reserved: std.bigint( '0' ) ,
101+ misc_frozen: std.bigint( '0' ) ,
102+ fee_frozen: std.bigint( '0' ) ,
91103 },
92104 },)
93105 },
0 commit comments