@acala-network/chopsticks 0.4.0 → 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.
- package/lib/blockchain/index.d.ts +2 -2
- package/lib/blockchain/index.js +2 -2
- package/lib/blockchain/txpool.d.ts +5 -1
- package/lib/blockchain/txpool.js +7 -2
- package/lib/cli.js +2 -1
- package/lib/rpc/substrate/author.js +1 -1
- package/lib/server.js +1 -1
- package/lib/setup-with-server.js +1 -1
- package/lib/utils/time-travel.js +3 -2
- package/lib/xcm/downward.js +1 -1
- package/lib/xcm/horizontal.js +2 -6
- package/lib/xcm/upward.js +1 -5
- package/package.json +7 -7
|
@@ -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(
|
|
41
|
+
upcomingBlock(params?: UpcomingBlockParams): Promise<Block>;
|
|
42
42
|
dryRunExtrinsic(extrinsic: HexString | {
|
|
43
43
|
call: HexString;
|
|
44
44
|
address: string;
|
package/lib/blockchain/index.js
CHANGED
|
@@ -121,8 +121,8 @@ class Blockchain {
|
|
|
121
121
|
await this.#txpool.buildBlock(params);
|
|
122
122
|
return this.#head;
|
|
123
123
|
}
|
|
124
|
-
async upcomingBlock(
|
|
125
|
-
return this.#txpool.upcomingBlock(
|
|
124
|
+
async upcomingBlock(params) {
|
|
125
|
+
return this.#txpool.upcomingBlock(params);
|
|
126
126
|
}
|
|
127
127
|
async dryRunExtrinsic(extrinsic, at) {
|
|
128
128
|
await this.api.isReady;
|
|
@@ -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(
|
|
38
|
+
upcomingBlock(params?: UpcomingBlockParams): Promise<Block>;
|
|
35
39
|
}
|
package/lib/blockchain/txpool.js
CHANGED
|
@@ -54,10 +54,15 @@ class TxPool {
|
|
|
54
54
|
await this.#lastBuildBlockPromise;
|
|
55
55
|
this.#last.next(this.#chain.head);
|
|
56
56
|
}
|
|
57
|
-
async upcomingBlock(
|
|
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
|
-
|
|
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;
|
package/lib/cli.js
CHANGED
|
@@ -28,8 +28,9 @@ const processConfig = async (path) => {
|
|
|
28
28
|
};
|
|
29
29
|
const processArgv = async (argv) => {
|
|
30
30
|
if (argv.config) {
|
|
31
|
-
|
|
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 = {
|
package/lib/server.js
CHANGED
|
@@ -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
|
|
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) {
|
package/lib/setup-with-server.js
CHANGED
|
@@ -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
|
|
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();
|
package/lib/utils/time-travel.js
CHANGED
|
@@ -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(
|
|
12
|
-
: await chain.head.get(
|
|
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();
|
package/lib/xcm/downward.js
CHANGED
|
@@ -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
|
|
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);
|
package/lib/xcm/horizontal.js
CHANGED
|
@@ -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
|
|
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:
|
|
22
|
+
[Number(id)]: [{ sentAt: head.number, data }],
|
|
27
23
|
};
|
|
28
24
|
const receiver = parachains[recipient];
|
|
29
25
|
if (receiver) {
|
package/lib/xcm/upward.js
CHANGED
|
@@ -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
|
|
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"types": "./lib/index.d.ts",
|
|
6
6
|
"author": "Bryan Chen <xlchen1291@gmail.com>",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"dev:moonbeam": "ts-node-dev --transpile-only --inspect --notify=false src/cli.ts -- dev --config=../../configs/moonbeam.yml"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"@acala-network/chopsticks-executor": "0.4.
|
|
23
|
+
"@acala-network/chopsticks-executor": "0.4.1",
|
|
24
24
|
"@polkadot/api": "^9.14.2",
|
|
25
25
|
"@polkadot/rpc-provider": "^9.14.2",
|
|
26
26
|
"@polkadot/types": "^9.14.2",
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
"js-yaml": "^4.1.0",
|
|
33
33
|
"jsondiffpatch": "^0.4.1",
|
|
34
34
|
"lodash": "^4.17.21",
|
|
35
|
-
"pino": "^8.
|
|
36
|
-
"pino-pretty": "^9.
|
|
35
|
+
"pino": "^8.11.0",
|
|
36
|
+
"pino-pretty": "^9.4.0",
|
|
37
37
|
"reflect-metadata": "^0.1.13",
|
|
38
38
|
"sqlite3": "^5.1.4",
|
|
39
39
|
"typeorm": "^0.3.12",
|
|
@@ -44,11 +44,11 @@
|
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@types/js-yaml": "^4.0.5",
|
|
46
46
|
"@types/lodash": "^4.14.191",
|
|
47
|
-
"@types/node": "^18.14.
|
|
47
|
+
"@types/node": "^18.14.2",
|
|
48
48
|
"@types/prettier": "^2.7.2",
|
|
49
49
|
"@types/ws": "^8.5.4",
|
|
50
50
|
"@types/yargs": "^17.0.22",
|
|
51
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^5.54.0",
|
|
52
52
|
"@typescript-eslint/parser": "^5.53.0",
|
|
53
53
|
"eslint": "^8.34.0",
|
|
54
54
|
"eslint-config-prettier": "^8.6.0",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"ts-node": "^10.9.1",
|
|
59
59
|
"ts-node-dev": "^2.0.0",
|
|
60
60
|
"typescript": "^4.9.5",
|
|
61
|
-
"vitest": "^0.
|
|
61
|
+
"vitest": "^0.29.2"
|
|
62
62
|
},
|
|
63
63
|
"files": [
|
|
64
64
|
"lib",
|