@acala-network/chopsticks 0.3.12 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/chopsticks.js +1 -1
  2. package/{dist → lib}/blockchain/index.d.ts +2 -2
  3. package/{dist → lib}/blockchain/index.js +2 -2
  4. package/{dist → lib}/blockchain/inherent/parachain/babe-randomness.d.ts +1 -1
  5. package/{dist → lib}/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +1 -1
  6. package/{dist → lib}/blockchain/inherent/parachain/validation-data.d.ts +1 -1
  7. package/{dist → lib}/blockchain/inherent/parachain/validation-data.js +63 -38
  8. package/{dist → lib}/blockchain/txpool.d.ts +5 -1
  9. package/{dist → lib}/blockchain/txpool.js +7 -2
  10. package/{dist → lib}/cli.js +2 -1
  11. package/{dist → lib}/executor.js +2 -6
  12. package/{dist → lib}/rpc/substrate/author.js +2 -2
  13. package/lib/rpc/substrate/system.d.ts +3 -0
  14. package/{dist → lib}/server.js +1 -1
  15. package/{dist → lib}/setup-with-server.js +1 -1
  16. package/{dist → lib}/setup.js +3 -1
  17. package/{dist → lib}/utils/time-travel.js +3 -2
  18. package/{dist → lib}/xcm/downward.js +1 -1
  19. package/{dist → lib}/xcm/horizontal.js +2 -6
  20. package/{dist → lib}/xcm/upward.js +1 -5
  21. package/package.json +40 -63
  22. package/LICENSE +0 -201
  23. package/README.md +0 -71
  24. package/dist/executor.test.d.ts +0 -1
  25. package/dist/executor.test.js +0 -138
  26. package/dist/rpc/substrate/author.d.ts +0 -3
  27. /package/{dist → lib}/api.d.ts +0 -0
  28. /package/{dist → lib}/api.js +0 -0
  29. /package/{dist → lib}/blockchain/block-builder.d.ts +0 -0
  30. /package/{dist → lib}/blockchain/block-builder.js +0 -0
  31. /package/{dist → lib}/blockchain/block.d.ts +0 -0
  32. /package/{dist → lib}/blockchain/block.js +0 -0
  33. /package/{dist → lib}/blockchain/head-state.d.ts +0 -0
  34. /package/{dist → lib}/blockchain/head-state.js +0 -0
  35. /package/{dist → lib}/blockchain/inherent/index.d.ts +0 -0
  36. /package/{dist → lib}/blockchain/inherent/index.js +0 -0
  37. /package/{dist → lib}/blockchain/inherent/para-enter.d.ts +0 -0
  38. /package/{dist → lib}/blockchain/inherent/para-enter.js +0 -0
  39. /package/{dist → lib}/blockchain/inherent/parachain/babe-randomness.js +0 -0
  40. /package/{dist → lib}/blockchain/inherent/parachain/nimbus-author-inherent.js +0 -0
  41. /package/{dist → lib}/blockchain/storage-layer.d.ts +0 -0
  42. /package/{dist → lib}/blockchain/storage-layer.js +0 -0
  43. /package/{dist → lib}/cli.d.ts +0 -0
  44. /package/{dist → lib}/db/entities.d.ts +0 -0
  45. /package/{dist → lib}/db/entities.js +0 -0
  46. /package/{dist → lib}/db/index.d.ts +0 -0
  47. /package/{dist → lib}/db/index.js +0 -0
  48. /package/{dist → lib}/dry-run-preimage.d.ts +0 -0
  49. /package/{dist → lib}/dry-run-preimage.js +0 -0
  50. /package/{dist → lib}/dry-run.d.ts +0 -0
  51. /package/{dist → lib}/dry-run.js +0 -0
  52. /package/{dist → lib}/executor.d.ts +0 -0
  53. /package/{dist → lib}/genesis-provider.d.ts +0 -0
  54. /package/{dist → lib}/genesis-provider.js +0 -0
  55. /package/{dist → lib}/index.d.ts +0 -0
  56. /package/{dist → lib}/index.js +0 -0
  57. /package/{dist → lib}/logger.d.ts +0 -0
  58. /package/{dist → lib}/logger.js +0 -0
  59. /package/{dist → lib}/rpc/dev.d.ts +0 -0
  60. /package/{dist → lib}/rpc/dev.js +0 -0
  61. /package/{dist → lib}/rpc/index.d.ts +0 -0
  62. /package/{dist → lib}/rpc/index.js +0 -0
  63. /package/{dist → lib}/rpc/shared.d.ts +0 -0
  64. /package/{dist → lib}/rpc/shared.js +0 -0
  65. /package/{dist/rpc/substrate/index.d.ts → lib/rpc/substrate/author.d.ts} +0 -0
  66. /package/{dist → lib}/rpc/substrate/chain.d.ts +0 -0
  67. /package/{dist → lib}/rpc/substrate/chain.js +0 -0
  68. /package/{dist/rpc/substrate/payment.d.ts → lib/rpc/substrate/index.d.ts} +0 -0
  69. /package/{dist → lib}/rpc/substrate/index.js +0 -0
  70. /package/{dist/rpc/substrate/state.d.ts → lib/rpc/substrate/payment.d.ts} +0 -0
  71. /package/{dist → lib}/rpc/substrate/payment.js +0 -0
  72. /package/{dist/rpc/substrate/system.d.ts → lib/rpc/substrate/state.d.ts} +0 -0
  73. /package/{dist → lib}/rpc/substrate/state.js +0 -0
  74. /package/{dist → lib}/rpc/substrate/system.js +0 -0
  75. /package/{dist → lib}/run-block.d.ts +0 -0
  76. /package/{dist → lib}/run-block.js +0 -0
  77. /package/{dist → lib}/schema/index.d.ts +0 -0
  78. /package/{dist → lib}/schema/index.js +0 -0
  79. /package/{dist → lib}/server.d.ts +0 -0
  80. /package/{dist → lib}/setup-with-server.d.ts +0 -0
  81. /package/{dist → lib}/setup.d.ts +0 -0
  82. /package/{dist → lib}/utils/decoder.d.ts +0 -0
  83. /package/{dist → lib}/utils/decoder.js +0 -0
  84. /package/{dist → lib}/utils/generate-html-diff.d.ts +0 -0
  85. /package/{dist → lib}/utils/generate-html-diff.js +0 -0
  86. /package/{dist → lib}/utils/import-storage.d.ts +0 -0
  87. /package/{dist → lib}/utils/import-storage.js +0 -0
  88. /package/{dist → lib}/utils/index.d.ts +0 -0
  89. /package/{dist → lib}/utils/index.js +0 -0
  90. /package/{dist → lib}/utils/open-html.d.ts +0 -0
  91. /package/{dist → lib}/utils/open-html.js +0 -0
  92. /package/{dist → lib}/utils/proof.d.ts +0 -0
  93. /package/{dist → lib}/utils/proof.js +0 -0
  94. /package/{dist → lib}/utils/set-storage.d.ts +0 -0
  95. /package/{dist → lib}/utils/set-storage.js +0 -0
  96. /package/{dist → lib}/utils/time-travel.d.ts +0 -0
  97. /package/{dist → lib}/xcm/downward.d.ts +0 -0
  98. /package/{dist → lib}/xcm/horizontal.d.ts +0 -0
  99. /package/{dist → lib}/xcm/index.d.ts +0 -0
  100. /package/{dist → lib}/xcm/index.js +0 -0
  101. /package/{dist → lib}/xcm/upward.d.ts +0 -0
package/chopsticks.js CHANGED
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- require('./dist/cli.js')
2
+ require('./lib/cli.js')
@@ -4,7 +4,7 @@ import { HexString } from '@polkadot/util/types';
4
4
  import { RegisteredTypes } from '@polkadot/types/types';
5
5
  import { Api } from '../api';
6
6
  import { Block } from './block';
7
- import { BuildBlockMode, BuildBlockParams, HorizontalMessage, TxPool } from './txpool';
7
+ import { BuildBlockMode, BuildBlockParams, HorizontalMessage, TxPool, UpcomingBlockParams } from './txpool';
8
8
  import { HeadState } from './head-state';
9
9
  import { InherentProvider } from './inherent';
10
10
  export interface Options {
@@ -38,7 +38,7 @@ export declare class Blockchain {
38
38
  setHead(block: Block): Promise<void>;
39
39
  submitExtrinsic(extrinsic: HexString): Promise<HexString>;
40
40
  newBlock(params?: BuildBlockParams): Promise<Block>;
41
- upcomingBlock(skipCount?: number): Promise<Block>;
41
+ upcomingBlock(params?: UpcomingBlockParams): Promise<Block>;
42
42
  dryRunExtrinsic(extrinsic: HexString | {
43
43
  call: HexString;
44
44
  address: string;
@@ -121,8 +121,8 @@ class Blockchain {
121
121
  await this.#txpool.buildBlock(params);
122
122
  return this.#head;
123
123
  }
124
- async upcomingBlock(skipCount = 0) {
125
- return this.#txpool.upcomingBlock(skipCount);
124
+ async upcomingBlock(params) {
125
+ return this.#txpool.upcomingBlock(params);
126
126
  }
127
127
  async dryRunExtrinsic(extrinsic, at) {
128
128
  await this.api.isReady;
@@ -1,5 +1,5 @@
1
1
  import { HexString } from '@polkadot/util/types';
2
- import { Block } from '../../../blockchain/block';
2
+ import { Block } from '../../block';
3
3
  import { BuildBlockParams } from '../../txpool';
4
4
  import { CreateInherents } from '..';
5
5
  export declare class SetBabeRandomness implements CreateInherents {
@@ -1,5 +1,5 @@
1
1
  import { HexString } from '@polkadot/util/types';
2
- import { Block } from '../../../blockchain/block';
2
+ import { Block } from '../../block';
3
3
  import { BuildBlockParams } from '../../txpool';
4
4
  import { CreateInherents } from '..';
5
5
  export declare class SetNimbusAuthorInherent implements CreateInherents {
@@ -1,5 +1,5 @@
1
1
  import { HexString } from '@polkadot/util/types';
2
- import { Block } from '../../../blockchain/block';
2
+ import { Block } from '../../block';
3
3
  import { BuildBlockParams } from '../../txpool';
4
4
  import { CreateInherents } from '..';
5
5
  export type ValidationData = {
@@ -1,12 +1,16 @@
1
1
  "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
2
5
  Object.defineProperty(exports, "__esModule", { value: true });
3
6
  exports.SetValidationData = void 0;
4
7
  const types_1 = require("@polkadot/types");
5
8
  const util_1 = require("@polkadot/util");
9
+ const lodash_1 = __importDefault(require("lodash"));
10
+ const proof_1 = require("../../../utils/proof");
6
11
  const util_crypto_1 = require("@polkadot/util-crypto");
7
12
  const utils_1 = require("../../../utils");
8
13
  const executor_1 = require("../../../executor");
9
- const proof_1 = require("../../../utils/proof");
10
14
  const MOCK_VALIDATION_DATA = {
11
15
  validationData: {
12
16
  relayParentNumber: 1000,
@@ -60,13 +64,18 @@ class SetValidationData {
60
64
  const paraId = await (0, utils_1.getParaId)(parent.chain);
61
65
  const dmqMqcHeadKey = (0, proof_1.dmqMqcHead)(paraId);
62
66
  const hrmpIngressChannelIndexKey = (0, proof_1.hrmpIngressChannelIndex)(paraId);
63
- const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [dmqMqcHeadKey, hrmpIngressChannelIndexKey], extrinsic.relayChainState.trieNodes);
67
+ const hrmpEgressChannelIndexKey = (0, proof_1.hrmpEgressChannelIndex)(paraId);
68
+ // TODO: refactor this to have a single decodeProof
69
+ const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [...Object.values(proof_1.WELL_KNOWN_KEYS), dmqMqcHeadKey, hrmpIngressChannelIndexKey, hrmpEgressChannelIndexKey], extrinsic.relayChainState.trieNodes);
70
+ for (const key of Object.values(proof_1.WELL_KNOWN_KEYS)) {
71
+ newEntries.push([key, decoded[key]]);
72
+ }
73
+ newEntries.push([hrmpIngressChannelIndexKey, decoded[hrmpIngressChannelIndexKey]]);
74
+ newEntries.push([hrmpEgressChannelIndexKey, decoded[hrmpEgressChannelIndexKey]]);
64
75
  // inject downward messages
65
- if (params?.downwardMessages) {
66
- let dmqMqcHeadHash = decoded[dmqMqcHeadKey];
67
- if (!dmqMqcHeadHash)
68
- throw new Error('Canoot find dmqMqcHead from validation data');
69
- for (const { msg, sentAt } of params.downwardMessages) {
76
+ let dmqMqcHeadHash = decoded[dmqMqcHeadKey];
77
+ if (dmqMqcHeadHash) {
78
+ for (const { msg, sentAt } of params?.downwardMessages || []) {
70
79
  // calculate new hash
71
80
  dmqMqcHeadHash = (0, util_crypto_1.blake2AsHex)((0, util_1.u8aConcat)(meta.registry.createType('Hash', dmqMqcHeadHash).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), (0, util_crypto_1.blake2AsU8a)(meta.registry.createType('Bytes', msg).toU8a(), 256)), 256);
72
81
  downwardMessages.push({
@@ -79,39 +88,55 @@ class SetValidationData {
79
88
  const hrmpIngressChannels = meta.registry
80
89
  .createType('Vec<ParaId>', decoded[hrmpIngressChannelIndexKey])
81
90
  .toJSON();
91
+ const hrmpEgressChannels = meta.registry
92
+ .createType('Vec<ParaId>', decoded[hrmpEgressChannelIndexKey])
93
+ .toJSON();
94
+ const hrmpMessages = {
95
+ ...lodash_1.default.mapValues(extrinsic.horizontalMessages, () => []),
96
+ ...(params?.horizontalMessages || {}),
97
+ };
82
98
  // inject horizontal messages
83
- if (params?.horizontalMessages) {
84
- for (const [id, messages] of Object.entries(params.horizontalMessages)) {
85
- const sender = Number(id);
86
- if (hrmpIngressChannels.includes(sender)) {
87
- const channelId = meta.registry.createType('HrmpChannelId', {
88
- sender,
89
- receiver: paraId.toNumber(),
90
- });
91
- const hrmpChannelKey = (0, proof_1.hrmpChannels)(channelId);
92
- const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
93
- const abridgedHrmpRaw = decoded[hrmpChannelKey];
94
- if (!abridgedHrmpRaw)
95
- throw new Error('Canoot find hrmp channels from validation data');
96
- const abridgedHrmp = meta.registry
97
- .createType('AbridgedHrmpChannel', (0, util_1.hexToU8a)(abridgedHrmpRaw))
98
- .toJSON();
99
- const paraMessages = [];
100
- for (const { data, sentAt } of messages) {
101
- // calculate new hash
102
- const bytes = meta.registry.createType('Bytes', data);
103
- abridgedHrmp.mqcHead = (0, util_crypto_1.blake2AsHex)((0, util_1.u8aConcat)(meta.registry.createType('Hash', abridgedHrmp.mqcHead).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), (0, util_crypto_1.blake2AsU8a)(bytes.toU8a(), 256)), 256);
104
- abridgedHrmp.msgCount = abridgedHrmp.msgCount + 1;
105
- abridgedHrmp.totalSize = abridgedHrmp.totalSize + bytes.length;
106
- paraMessages.push({
107
- data,
108
- sent_at: sentAt,
109
- });
110
- }
111
- horizontalMessages[sender] = paraMessages;
112
- newEntries.push([hrmpChannelKey, meta.registry.createType('AbridgedHrmpChannel', abridgedHrmp).toHex()]);
113
- }
99
+ for (const id of hrmpIngressChannels) {
100
+ const messages = hrmpMessages[id];
101
+ const sender = Number(id);
102
+ const channelId = meta.registry.createType('HrmpChannelId', {
103
+ sender,
104
+ receiver: paraId.toNumber(),
105
+ });
106
+ const hrmpChannelKey = (0, proof_1.hrmpChannels)(channelId);
107
+ const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
108
+ const abridgedHrmpRaw = decoded[hrmpChannelKey];
109
+ if (!abridgedHrmpRaw)
110
+ throw new Error('Canoot find hrmp channels from validation data');
111
+ const abridgedHrmp = meta.registry
112
+ .createType('AbridgedHrmpChannel', (0, util_1.hexToU8a)(abridgedHrmpRaw))
113
+ .toJSON();
114
+ const paraMessages = [];
115
+ for (const { data, sentAt } of messages) {
116
+ // calculate new hash
117
+ const bytes = meta.registry.createType('Bytes', data);
118
+ abridgedHrmp.mqcHead = (0, util_crypto_1.blake2AsHex)((0, util_1.u8aConcat)(meta.registry.createType('Hash', abridgedHrmp.mqcHead).toU8a(), meta.registry.createType('BlockNumber', sentAt).toU8a(), (0, util_crypto_1.blake2AsU8a)(bytes.toU8a(), 256)), 256);
119
+ abridgedHrmp.msgCount = abridgedHrmp.msgCount + 1;
120
+ abridgedHrmp.totalSize = abridgedHrmp.totalSize + bytes.length;
121
+ paraMessages.push({
122
+ data,
123
+ sent_at: sentAt,
124
+ });
114
125
  }
126
+ horizontalMessages[sender] = paraMessages;
127
+ newEntries.push([hrmpChannelKey, meta.registry.createType('AbridgedHrmpChannel', abridgedHrmp).toHex()]);
128
+ }
129
+ // inject hrmpEgressChannels proof
130
+ for (const id of hrmpEgressChannels) {
131
+ // const messages = hrmpMessages[id]
132
+ const receiver = Number(id);
133
+ const channelId = meta.registry.createType('HrmpChannelId', {
134
+ sender: paraId.toNumber(),
135
+ receiver,
136
+ });
137
+ const hrmpChannelKey = (0, proof_1.hrmpChannels)(channelId);
138
+ const decoded = await (0, executor_1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [hrmpChannelKey], extrinsic.relayChainState.trieNodes);
139
+ newEntries.push([hrmpChannelKey, decoded[hrmpChannelKey]]);
115
140
  }
116
141
  const upgradeKey = (0, proof_1.upgradeGoAheadSignal)(paraId);
117
142
  const pendingUpgrade = await parent.get((0, utils_1.compactHex)(meta.query.parachainSystem.pendingValidationCode()));
@@ -24,6 +24,10 @@ export interface BuildBlockParams {
24
24
  horizontalMessages?: Record<number, HorizontalMessage[]>;
25
25
  };
26
26
  }
27
+ export interface UpcomingBlockParams {
28
+ skipCount?: number;
29
+ timeout?: number;
30
+ }
27
31
  export declare class TxPool {
28
32
  #private;
29
33
  readonly event: EventEmitter;
@@ -31,5 +35,5 @@ export declare class TxPool {
31
35
  get pendingExtrinsics(): HexString[];
32
36
  submitExtrinsic(extrinsic: HexString): void;
33
37
  buildBlock(params?: BuildBlockParams): Promise<void>;
34
- upcomingBlock(skipCount?: number): Promise<Block>;
38
+ upcomingBlock(params?: UpcomingBlockParams): Promise<Block>;
35
39
  }
@@ -54,10 +54,15 @@ class TxPool {
54
54
  await this.#lastBuildBlockPromise;
55
55
  this.#last.next(this.#chain.head);
56
56
  }
57
- async upcomingBlock(skipCount = 0) {
57
+ async upcomingBlock(params) {
58
+ const { skipCount, timeout: millisecs } = { skipCount: 0, ...(params || {}) };
58
59
  if (skipCount < 0)
59
60
  throw new Error('skipCount needs to be greater or equal to 0');
60
- return (0, rxjs_1.firstValueFrom)(this.#last.pipe((0, operators_1.skip)(1 + skipCount), (0, operators_1.take)(1)));
61
+ let stream$ = this.#last.pipe();
62
+ if (millisecs) {
63
+ stream$ = stream$.pipe((0, operators_1.timeout)(millisecs));
64
+ }
65
+ return (0, rxjs_1.firstValueFrom)(stream$.pipe((0, operators_1.skip)(1 + skipCount), (0, operators_1.take)(1)));
61
66
  }
62
67
  async #buildBlock(wait, params) {
63
68
  await this.#chain.api.isReady;
@@ -28,8 +28,9 @@ const processConfig = async (path) => {
28
28
  };
29
29
  const processArgv = async (argv) => {
30
30
  if (argv.config) {
31
- return { ...(await processConfig(argv.config)), ...argv };
31
+ argv = { ...(await processConfig(argv.config)), ...argv };
32
32
  }
33
+ argv.port = argv.port ?? (process.env.PORT ? Number(process.env.PORT) : 8000);
33
34
  return argv;
34
35
  };
35
36
  const defaultOptions = {
@@ -21,12 +21,8 @@ const calculateStateRoot = async (entries) => {
21
21
  return (0, chopsticks_executor_1.calculate_state_root)(entries);
22
22
  };
23
23
  exports.calculateStateRoot = calculateStateRoot;
24
- const nodesAddLength = (nodes) => {
25
- const nodesWithLength = nodes.map((x) => (0, util_1.compactAddLength)((0, util_1.hexToU8a)(x)));
26
- return (0, util_1.u8aToHex)((0, util_1.u8aConcatStrict)([(0, util_1.compactToU8a)(nodesWithLength.length), (0, util_1.u8aConcat)(...nodesWithLength)]));
27
- };
28
24
  const decodeProof = async (trieRootHash, keys, nodes) => {
29
- const decoded = await (0, chopsticks_executor_1.decode_proof)(trieRootHash, keys, nodesAddLength(nodes));
25
+ const decoded = await (0, chopsticks_executor_1.decode_proof)(trieRootHash, keys, nodes);
30
26
  return decoded.reduce((accum, [key, value]) => {
31
27
  accum[key] = value;
32
28
  return accum;
@@ -34,7 +30,7 @@ const decodeProof = async (trieRootHash, keys, nodes) => {
34
30
  };
35
31
  exports.decodeProof = decodeProof;
36
32
  const createProof = async (trieRootHash, nodes, entries) => {
37
- const result = await (0, chopsticks_executor_1.create_proof)(trieRootHash, nodesAddLength(nodes), entries);
33
+ const result = await (0, chopsticks_executor_1.create_proof)(trieRootHash, nodes, entries);
38
34
  return { trieRootHash: result[0], nodes: result[1] };
39
35
  };
40
36
  exports.createProof = createProof;
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const txpool_1 = require("../../blockchain/txpool");
4
- const shared_1 = require("../../rpc/shared");
4
+ const shared_1 = require("../shared");
5
5
  const logger_1 = require("../../logger");
6
6
  const logger = logger_1.defaultLogger.child({ name: 'rpc-author' });
7
7
  const handlers = {
@@ -49,7 +49,7 @@ const handlers = {
49
49
  })
50
50
  .catch((error) => {
51
51
  logger.error({ error }, 'ExtrinsicFailed');
52
- callback(error.toJSON());
52
+ callback(error?.toJSON() ?? error);
53
53
  done(id);
54
54
  });
55
55
  return id;
@@ -0,0 +1,3 @@
1
+ import { Handlers } from '../shared';
2
+ declare const handlers: Handlers;
3
+ export default handlers;
@@ -51,7 +51,7 @@ const createServer = async (handler, port) => {
51
51
  let wss;
52
52
  let listenPort;
53
53
  for (let i = 0; i < 5; i++) {
54
- const preferPort = (port || 0) + i;
54
+ const preferPort = (port ?? 0) > 0 ? (port ?? 0) + i : 0;
55
55
  logger.debug('Try starting on port %d', preferPort);
56
56
  const [maybeWss, maybeListenPort] = await createWS(preferPort);
57
57
  if (maybeWss && maybeListenPort) {
@@ -7,7 +7,7 @@ const shared_1 = require("./rpc/shared");
7
7
  const setup_1 = require("./setup");
8
8
  const setupWithServer = async (argv) => {
9
9
  const context = await (0, setup_1.setup)(argv);
10
- const port = argv.port || Number(process.env.PORT) || 8000;
10
+ const port = argv.port ?? 8000;
11
11
  if (argv.genesis) {
12
12
  // mine 1st block when starting from genesis to set some mock validation data
13
13
  await context.chain.newBlock();
@@ -63,8 +63,10 @@ const setup = async (argv) => {
63
63
  });
64
64
  if (argv.timestamp)
65
65
  await (0, time_travel_1.timeTravel)(chain, argv.timestamp);
66
- await (0, import_storage_1.importStorage)(chain, argv['import-storage']);
66
+ // override wasm before importing storage, in case new pallets have been
67
+ // added that have storage imports
67
68
  await (0, import_storage_1.overrideWasm)(chain, argv['wasm-override']);
69
+ await (0, import_storage_1.importStorage)(chain, argv['import-storage']);
68
70
  return { chain, api, ws: provider };
69
71
  };
70
72
  exports.setup = setup;
@@ -7,9 +7,10 @@ const executor_1 = require("../executor");
7
7
  const set_storage_1 = require("./set-storage");
8
8
  const getCurrentSlot = async (chain) => {
9
9
  const meta = await chain.head.meta;
10
+ // use raw key here because some chain did not expose those storage to metadata
10
11
  const slotRaw = meta.consts.babe
11
- ? await chain.head.get((0, _1.compactHex)(meta.query.babe.currentSlot()))
12
- : await chain.head.get((0, _1.compactHex)(meta.query.aura.currentSlot()));
12
+ ? await chain.head.get('0x1cb6f36e027abb2091cfb5110ab5087f06155b3cd9a8c9e5e9a23fd5dc13a5ed') // babe.currentSlot
13
+ : await chain.head.get('0x57f8dc2f5ab09467896f47300f04243806155b3cd9a8c9e5e9a23fd5dc13a5ed'); // aura.currentSlot
13
14
  if (!slotRaw)
14
15
  throw new Error('Cannot find current slot');
15
16
  return meta.registry.createType('Slot', (0, util_1.hexToU8a)(slotRaw)).toNumber();
@@ -13,7 +13,7 @@ const connectDownward = async (relaychain, parachain) => {
13
13
  const value = pairs[0][1];
14
14
  if (!value)
15
15
  return;
16
- const meta = await relaychain.head.meta;
16
+ const meta = await head.meta;
17
17
  const downwardMessageQueuesKey = (0, utils_1.compactHex)(meta.query.dmp.downwardMessageQueues(paraId));
18
18
  // clear relaychain message queue
19
19
  await (0, set_storage_1.setStorage)(relaychain, [[downwardMessageQueuesKey, null]], head.hash);
@@ -4,7 +4,6 @@ exports.connectHorizontal = void 0;
4
4
  const util_1 = require("@polkadot/util");
5
5
  const utils_1 = require("../utils");
6
6
  const _1 = require(".");
7
- const set_storage_1 = require("../utils/set-storage");
8
7
  const connectHorizontal = async (parachains) => {
9
8
  for (const [id, chain] of Object.entries(parachains)) {
10
9
  const meta = await chain.head.meta;
@@ -13,17 +12,14 @@ const connectHorizontal = async (parachains) => {
13
12
  const value = pairs[0][1];
14
13
  if (!value)
15
14
  return;
16
- const meta = await chain.head.meta;
17
- const hrmpOutboundMessagesKey = (0, utils_1.compactHex)(meta.query.parachainSystem.hrmpOutboundMessages());
18
- // clear sender message queue
19
- await (0, set_storage_1.setStorage)(chain, [[hrmpOutboundMessagesKey, null]], head.hash);
15
+ const meta = await head.meta;
20
16
  const outboundHrmpMessage = meta.registry
21
17
  .createType('Vec<PolkadotCorePrimitivesOutboundHrmpMessage>', (0, util_1.hexToU8a)(value))
22
18
  .toJSON();
23
19
  _1.logger.info({ outboundHrmpMessage }, 'outboundHrmpMessage');
24
20
  for (const { recipient, data } of outboundHrmpMessage) {
25
21
  const horizontalMessages = {
26
- [Number(id)]: [{ sentAt: chain.head.number, data }],
22
+ [Number(id)]: [{ sentAt: head.number, data }],
27
23
  };
28
24
  const receiver = parachains[recipient];
29
25
  if (receiver) {
@@ -4,7 +4,6 @@ exports.connectUpward = void 0;
4
4
  const util_1 = require("@polkadot/util");
5
5
  const utils_1 = require("../utils");
6
6
  const _1 = require(".");
7
- const set_storage_1 = require("../utils/set-storage");
8
7
  const connectUpward = async (parachain, relaychain) => {
9
8
  const meta = await parachain.head.meta;
10
9
  const paraId = await (0, utils_1.getParaId)(parachain);
@@ -13,10 +12,7 @@ const connectUpward = async (parachain, relaychain) => {
13
12
  const value = pairs[0][1];
14
13
  if (!value)
15
14
  return;
16
- const parachainMeta = await parachain.head.meta;
17
- const upwardMessagesKey = (0, utils_1.compactHex)(parachainMeta.query.parachainSystem.upwardMessages());
18
- // clear parachain message queue
19
- await (0, set_storage_1.setStorage)(parachain, [[upwardMessagesKey, null]], head.hash);
15
+ const parachainMeta = await head.meta;
20
16
  const relaychainMeta = await relaychain.head.meta;
21
17
  const upwardMessages = parachainMeta.registry.createType('Vec<Bytes>', (0, util_1.hexToU8a)(value));
22
18
  if (upwardMessages.length === 0)
package/package.json CHANGED
@@ -1,91 +1,68 @@
1
1
  {
2
2
  "name": "@acala-network/chopsticks",
3
- "version": "0.3.12",
4
- "main": "./dist/index.js",
5
- "types": "./dist/index.d.ts",
3
+ "version": "0.4.1",
4
+ "main": "./lib/index.js",
5
+ "types": "./lib/index.d.ts",
6
6
  "author": "Bryan Chen <xlchen1291@gmail.com>",
7
7
  "license": "Apache-2.0",
8
- "packageManager": "yarn@3.2.4",
9
- "workspaces": [
10
- ".",
11
- "executor/pkg"
12
- ],
13
8
  "bin": "./chopsticks.js",
14
9
  "scripts": {
15
10
  "lint": "tsc --noEmit --project tsconfig.json && eslint . --ext .js,.ts && prettier --check .",
16
11
  "fix": "eslint . --ext .js,.ts --fix && prettier -w .",
17
- "prepare": "husky install",
18
- "start": "ts-node --transpile-only src/cli.ts",
19
- "build": "rm -rf dist && tsc -p tsconfig.prod.json",
20
- "build-wasm": "wasm-pack build executor --target nodejs --scope acala-network",
21
- "build-wasm-logging": "yarn build-wasm --features=logging",
22
- "check": "cd executor && cargo check --locked",
23
- "test": "vitest --silent",
24
- "test:dev": "LOG_LEVEL=trace vitest --inspect",
25
- "dev": "LOG_LEVEL=trace ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/dev.yml",
26
- "dev:karura": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/karura.yml",
27
- "dev:acala": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/acala.yml",
28
- "dev:moonriver": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/moonriver.yml",
29
- "dev:moonbeam": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=configs/moonbeam.yml"
12
+ "build": "rm -rf lib && tsc -p ./tsconfig.json",
13
+ "test": "vitest run",
14
+ "test:watch": "vitest",
15
+ "script:start": "cd ../..; ts-node packages/chopsticks/src/cli.ts",
16
+ "script:run": "LOG_LEVEL=trace ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=../../configs/dev.yml",
17
+ "dev:karura": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=../../configs/karura.yml",
18
+ "dev:acala": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=../../configs/acala.yml",
19
+ "dev:moonriver": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=../../configs/moonriver.yml",
20
+ "dev:moonbeam": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=../../configs/moonbeam.yml"
30
21
  },
31
22
  "dependencies": {
32
- "@acala-network/chopsticks-executor": "0.3.12",
33
- "@polkadot/api": "^9.12.1",
34
- "@polkadot/rpc-provider": "^9.12.1",
35
- "@polkadot/types": "^9.12.1",
36
- "@polkadot/types-codec": "^9.12.1",
37
- "@polkadot/types-known": "^9.12.1",
38
- "@polkadot/util": "^10.2.6",
39
- "@polkadot/util-crypto": "^10.2.6",
40
- "axios": "^1.2.5",
23
+ "@acala-network/chopsticks-executor": "0.4.1",
24
+ "@polkadot/api": "^9.14.2",
25
+ "@polkadot/rpc-provider": "^9.14.2",
26
+ "@polkadot/types": "^9.14.2",
27
+ "@polkadot/types-codec": "^9.14.2",
28
+ "@polkadot/types-known": "^9.14.2",
29
+ "@polkadot/util": "^10.4.2",
30
+ "@polkadot/util-crypto": "^10.4.2",
31
+ "axios": "^1.3.3",
41
32
  "js-yaml": "^4.1.0",
42
33
  "jsondiffpatch": "^0.4.1",
43
34
  "lodash": "^4.17.21",
44
- "pino": "^8.8.0",
45
- "pino-pretty": "^9.1.1",
35
+ "pino": "^8.11.0",
36
+ "pino-pretty": "^9.4.0",
46
37
  "reflect-metadata": "^0.1.13",
47
38
  "sqlite3": "^5.1.4",
48
- "typeorm": "^0.3.11",
49
- "typescript": "^4.9.4",
50
- "ws": "^8.12.0",
51
- "yargs": "^17.6.2",
52
- "zod": "^3.20.2"
39
+ "typeorm": "^0.3.12",
40
+ "ws": "^8.12.1",
41
+ "yargs": "^17.7.1",
42
+ "zod": "^3.20.6"
53
43
  },
54
44
  "devDependencies": {
55
45
  "@types/js-yaml": "^4.0.5",
56
46
  "@types/lodash": "^4.14.191",
57
- "@types/node": "^18.11.18",
47
+ "@types/node": "^18.14.2",
48
+ "@types/prettier": "^2.7.2",
58
49
  "@types/ws": "^8.5.4",
59
- "@types/yargs": "^17.0.20",
60
- "@typescript-eslint/eslint-plugin": "^5.50.0",
61
- "@typescript-eslint/parser": "^5.50.0",
62
- "eslint": "^8.32.0",
50
+ "@types/yargs": "^17.0.22",
51
+ "@typescript-eslint/eslint-plugin": "^5.54.0",
52
+ "@typescript-eslint/parser": "^5.53.0",
53
+ "eslint": "^8.34.0",
63
54
  "eslint-config-prettier": "^8.6.0",
64
55
  "eslint-plugin-import": "^2.27.5",
65
56
  "eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
66
- "husky": "^8.0.3",
67
- "lint-staged": "^13.1.0",
68
- "prettier": "^2.8.3",
57
+ "prettier": "^2.8.4",
69
58
  "ts-node": "^10.9.1",
70
59
  "ts-node-dev": "^2.0.0",
71
- "vitest": "^0.28.3",
72
- "wasm-pack": "^0.10.3"
60
+ "typescript": "^4.9.5",
61
+ "vitest": "^0.29.2"
73
62
  },
74
63
  "files": [
75
- "dist",
76
- "bin",
77
- "template"
78
- ],
79
- "engines": {
80
- "node": ">=v14"
81
- },
82
- "prettier": {
83
- "tabWidth": 2,
84
- "semi": false,
85
- "singleQuote": true
86
- },
87
- "lint-staged": {
88
- "*.{js,ts}": "eslint --cache --fix",
89
- "*.{js,ts,css,md}": "prettier --write"
90
- }
64
+ "lib",
65
+ "template",
66
+ "chopsticks.js"
67
+ ]
91
68
  }