@acala-network/chopsticks 0.2.3 → 0.3.0
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/README.md +6 -0
- package/dist/api.d.ts +3 -2
- package/dist/api.js +15 -20
- package/dist/blockchain/block-builder.d.ts +4 -0
- package/dist/blockchain/block-builder.js +71 -0
- package/dist/blockchain/block.d.ts +5 -3
- package/dist/blockchain/block.js +22 -23
- package/dist/blockchain/head-state.d.ts +4 -2
- package/dist/blockchain/head-state.js +13 -7
- package/dist/blockchain/index.d.ts +7 -8
- package/dist/blockchain/index.js +26 -26
- package/dist/blockchain/inherent/index.d.ts +17 -0
- package/dist/blockchain/inherent/index.js +32 -0
- package/dist/blockchain/inherent/para-enter.d.ts +7 -0
- package/dist/blockchain/inherent/para-enter.js +33 -0
- package/dist/blockchain/inherent/parachain/validation-data.d.ts +25 -0
- package/dist/blockchain/{inherents.js → inherent/parachain/validation-data.js} +77 -46
- package/dist/blockchain/txpool.d.ts +17 -2
- package/dist/blockchain/txpool.js +46 -81
- package/dist/decode-key.d.ts +2 -0
- package/dist/decode-key.js +24 -0
- package/dist/executor.d.ts +17 -3
- package/dist/executor.js +43 -3
- package/dist/executor.test.js +16 -9
- package/dist/genesis-provider.d.ts +5 -0
- package/dist/genesis-provider.js +15 -3
- package/dist/index.d.ts +1 -18
- package/dist/index.js +43 -147
- package/dist/rpc/dev.js +11 -1
- package/dist/rpc/shared.d.ts +0 -4
- package/dist/rpc/substrate/author.d.ts +1 -1
- package/dist/rpc/substrate/author.js +7 -2
- package/dist/rpc/substrate/chain.js +2 -2
- package/dist/rpc/substrate/state.js +1 -1
- package/dist/rpc/substrate/system.js +3 -3
- package/dist/run-block.d.ts +2 -0
- package/dist/run-block.js +36 -0
- package/dist/schema/index.js +1 -1
- package/dist/server.d.ts +3 -3
- package/dist/server.js +26 -11
- package/dist/setup-with-server.d.ts +8 -0
- package/dist/setup-with-server.js +23 -0
- package/dist/setup.d.ts +10 -0
- package/dist/setup.js +62 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +9 -1
- package/dist/utils/proof.d.ts +10 -2
- package/dist/utils/proof.js +12 -8
- package/dist/utils/set-storage.d.ts +2 -1
- package/dist/utils/time-travel.d.ts +5 -0
- package/dist/utils/time-travel.js +64 -0
- package/dist/xcm/index.d.ts +3 -0
- package/dist/xcm/index.js +67 -0
- package/package.json +5 -5
- package/dist/bindings.d.ts +0 -2
- package/dist/bindings.js +0 -31
- package/dist/blockchain/inherents.d.ts +0 -24
package/dist/utils/proof.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.hrmpEgressChannelIndex = exports.hrmpIngressChannelIndex = exports.upgradeGoAheadSignal = exports.dmqMqcHead = exports.WELL_KNOWN_KEYS = void 0;
|
|
3
|
+
exports.hrmpChannels = exports.hrmpEgressChannelIndex = exports.hrmpIngressChannelIndex = exports.upgradeGoAheadSignal = exports.dmqMqcHead = exports.WELL_KNOWN_KEYS = void 0;
|
|
4
4
|
const util_1 = require("@polkadot/util");
|
|
5
5
|
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
6
6
|
exports.WELL_KNOWN_KEYS = {
|
|
@@ -11,27 +11,31 @@ exports.WELL_KNOWN_KEYS = {
|
|
|
11
11
|
CURRENT_SLOT: '0x1cb6f36e027abb2091cfb5110ab5087f06155b3cd9a8c9e5e9a23fd5dc13a5ed',
|
|
12
12
|
ACTIVE_CONFIG: '0x06de3d8a54d27e44a9d5ce189618f22db4b49d95320d9021994c850f25b8e385',
|
|
13
13
|
};
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
return (0, util_1.u8aToHex)((0, util_1.u8aConcat)((0, util_1.hexToU8a)(prefix), (0, util_crypto_1.xxhashAsU8a)(id, 64), id));
|
|
14
|
+
const hash = (prefix, suffix) => {
|
|
15
|
+
return (0, util_1.u8aToHex)((0, util_1.u8aConcat)((0, util_1.hexToU8a)(prefix), (0, util_crypto_1.xxhashAsU8a)(suffix, 64), suffix));
|
|
17
16
|
};
|
|
18
17
|
const dmqMqcHead = (paraId) => {
|
|
19
18
|
const prefix = '0x63f78c98723ddc9073523ef3beefda0c4d7fefc408aac59dbfe80a72ac8e3ce5';
|
|
20
|
-
return
|
|
19
|
+
return hash(prefix, paraId.toU8a());
|
|
21
20
|
};
|
|
22
21
|
exports.dmqMqcHead = dmqMqcHead;
|
|
23
22
|
const upgradeGoAheadSignal = (paraId) => {
|
|
24
23
|
const prefix = '0xcd710b30bd2eab0352ddcc26417aa1949e94c040f5e73d9b7addd6cb603d15d3';
|
|
25
|
-
return
|
|
24
|
+
return hash(prefix, paraId.toU8a());
|
|
26
25
|
};
|
|
27
26
|
exports.upgradeGoAheadSignal = upgradeGoAheadSignal;
|
|
28
27
|
const hrmpIngressChannelIndex = (paraId) => {
|
|
29
28
|
const prefix = '0x6a0da05ca59913bc38a8630590f2627c1d3719f5b0b12c7105c073c507445948';
|
|
30
|
-
return
|
|
29
|
+
return hash(prefix, paraId.toU8a());
|
|
31
30
|
};
|
|
32
31
|
exports.hrmpIngressChannelIndex = hrmpIngressChannelIndex;
|
|
33
32
|
const hrmpEgressChannelIndex = (paraId) => {
|
|
34
33
|
const prefix = '0x6a0da05ca59913bc38a8630590f2627cf12b746dcf32e843354583c9702cc020';
|
|
35
|
-
return
|
|
34
|
+
return hash(prefix, paraId.toU8a());
|
|
36
35
|
};
|
|
37
36
|
exports.hrmpEgressChannelIndex = hrmpEgressChannelIndex;
|
|
37
|
+
const hrmpChannels = (channelId) => {
|
|
38
|
+
const prefix = '0x6a0da05ca59913bc38a8630590f2627cb6604cff828a6e3f579ca6c59ace013d';
|
|
39
|
+
return hash(prefix, channelId.toU8a());
|
|
40
|
+
};
|
|
41
|
+
exports.hrmpChannels = hrmpChannels;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { HexString } from '@polkadot/util/types';
|
|
1
2
|
import { Blockchain } from '../blockchain';
|
|
2
3
|
type RawStorageValues = [string, string | null][];
|
|
3
4
|
type StorageConfig = Record<string, Record<string, any>>;
|
|
4
5
|
export type StorageValues = RawStorageValues | StorageConfig;
|
|
5
|
-
export declare const setStorage: (chain: Blockchain, storage: StorageValues, blockHash?:
|
|
6
|
+
export declare const setStorage: (chain: Blockchain, storage: StorageValues, blockHash?: HexString) => Promise<HexString>;
|
|
6
7
|
export {};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Blockchain } from '../blockchain';
|
|
2
|
+
export declare const getCurrentSlot: (chain: Blockchain) => Promise<number>;
|
|
3
|
+
export declare const getCurrentTimestamp: (chain: Blockchain) => Promise<number>;
|
|
4
|
+
export declare const getSlotDuration: (chain: Blockchain) => Promise<number>;
|
|
5
|
+
export declare const timeTravel: (chain: Blockchain, timestamp: number) => Promise<void>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.timeTravel = exports.getSlotDuration = exports.getCurrentTimestamp = exports.getCurrentSlot = void 0;
|
|
4
|
+
const util_1 = require("@polkadot/util");
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const executor_1 = require("../executor");
|
|
7
|
+
const set_storage_1 = require("./set-storage");
|
|
8
|
+
const getCurrentSlot = async (chain) => {
|
|
9
|
+
const meta = await chain.head.meta;
|
|
10
|
+
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()));
|
|
13
|
+
if (!slotRaw)
|
|
14
|
+
throw new Error('Cannot find current slot');
|
|
15
|
+
return meta.registry.createType('Slot', (0, util_1.hexToU8a)(slotRaw)).toNumber();
|
|
16
|
+
};
|
|
17
|
+
exports.getCurrentSlot = getCurrentSlot;
|
|
18
|
+
const getCurrentTimestamp = async (chain) => {
|
|
19
|
+
const meta = await chain.head.meta;
|
|
20
|
+
const currentTimestampRaw = (await chain.head.get((0, _1.compactHex)(meta.query.timestamp.now()))) || '0x';
|
|
21
|
+
return meta.registry.createType('u64', (0, util_1.hexToU8a)(currentTimestampRaw)).toNumber();
|
|
22
|
+
};
|
|
23
|
+
exports.getCurrentTimestamp = getCurrentTimestamp;
|
|
24
|
+
const getSlotDuration = async (chain) => {
|
|
25
|
+
const meta = await chain.head.meta;
|
|
26
|
+
return meta.consts.babe
|
|
27
|
+
? meta.consts.babe.expectedBlockTime.toNumber()
|
|
28
|
+
: meta.query.aura
|
|
29
|
+
? (0, executor_1.getAuraSlotDuration)(await chain.head.wasm, meta.registry)
|
|
30
|
+
: 12_000;
|
|
31
|
+
};
|
|
32
|
+
exports.getSlotDuration = getSlotDuration;
|
|
33
|
+
const timeTravel = async (chain, timestamp) => {
|
|
34
|
+
const meta = await chain.head.meta;
|
|
35
|
+
const slotDuration = await (0, exports.getSlotDuration)(chain);
|
|
36
|
+
const newSlot = Math.floor(timestamp / slotDuration);
|
|
37
|
+
// new timestamp
|
|
38
|
+
const storage = [
|
|
39
|
+
[(0, _1.compactHex)(meta.query.timestamp.now()), (0, util_1.u8aToHex)(meta.registry.createType('u64', timestamp).toU8a())],
|
|
40
|
+
];
|
|
41
|
+
if (meta.consts.babe) {
|
|
42
|
+
// new slot
|
|
43
|
+
storage.push([
|
|
44
|
+
(0, _1.compactHex)(meta.query.babe.currentSlot()),
|
|
45
|
+
(0, util_1.u8aToHex)(meta.registry.createType('Slot', newSlot).toU8a()),
|
|
46
|
+
]);
|
|
47
|
+
// new epoch
|
|
48
|
+
const epochDuration = meta.consts.babe.epochDuration.toNumber();
|
|
49
|
+
const newEpoch = Math.floor(timestamp / epochDuration);
|
|
50
|
+
storage.push([
|
|
51
|
+
(0, _1.compactHex)(meta.query.babe.epochIndex()),
|
|
52
|
+
(0, util_1.u8aToHex)(meta.registry.createType('u64', newEpoch).toU8a()),
|
|
53
|
+
]);
|
|
54
|
+
}
|
|
55
|
+
else if (meta.query.aura) {
|
|
56
|
+
// new slot
|
|
57
|
+
storage.push([
|
|
58
|
+
(0, _1.compactHex)(meta.query.aura.currentSlot()),
|
|
59
|
+
(0, util_1.u8aToHex)(meta.registry.createType('Slot', newSlot).toU8a()),
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
await (0, set_storage_1.setStorage)(chain, storage);
|
|
63
|
+
};
|
|
64
|
+
exports.timeTravel = timeTravel;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.connectParachains = exports.connectDownward = void 0;
|
|
4
|
+
const util_1 = require("@polkadot/util");
|
|
5
|
+
const utils_1 = require("../utils");
|
|
6
|
+
const logger_1 = require("../logger");
|
|
7
|
+
const set_storage_1 = require("../utils/set-storage");
|
|
8
|
+
const logger = logger_1.defaultLogger.child({ name: 'xcm' });
|
|
9
|
+
const connectDownward = async (relaychain, parachain) => {
|
|
10
|
+
const meta = await relaychain.head.meta;
|
|
11
|
+
const paraId = await (0, utils_1.getParaId)(parachain);
|
|
12
|
+
const downwardMessageQueuesKey = (0, utils_1.compactHex)(meta.query.dmp.downwardMessageQueues(paraId));
|
|
13
|
+
await relaychain.headState.subscribeStorage([downwardMessageQueuesKey], async (head, pairs) => {
|
|
14
|
+
const value = pairs[0][1];
|
|
15
|
+
if (!value)
|
|
16
|
+
return;
|
|
17
|
+
const meta = await relaychain.head.meta;
|
|
18
|
+
const downwardMessageQueuesKey = (0, utils_1.compactHex)(meta.query.dmp.downwardMessageQueues(paraId));
|
|
19
|
+
// clear relaychain message queue
|
|
20
|
+
await (0, set_storage_1.setStorage)(relaychain, [[downwardMessageQueuesKey, null]], head.hash);
|
|
21
|
+
const downwardMessages = meta.registry
|
|
22
|
+
.createType('Vec<PolkadotCorePrimitivesInboundDownwardMessage>', (0, util_1.hexToU8a)(value))
|
|
23
|
+
.toJSON();
|
|
24
|
+
logger.debug({ downwardMessages }, 'downward_message');
|
|
25
|
+
await parachain.newBlock({ inherent: { downwardMessages } });
|
|
26
|
+
});
|
|
27
|
+
logger.info(`Connected relaychain '${await relaychain.api.getSystemChain()}' with parachain '${await parachain.api.getSystemChain()}'`);
|
|
28
|
+
};
|
|
29
|
+
exports.connectDownward = connectDownward;
|
|
30
|
+
const connectParachains = async (parachains) => {
|
|
31
|
+
const list = {};
|
|
32
|
+
for (const chain of parachains) {
|
|
33
|
+
const paraId = await (0, utils_1.getParaId)(chain);
|
|
34
|
+
list[paraId.toNumber()] = chain;
|
|
35
|
+
}
|
|
36
|
+
await connectHorizontal(list);
|
|
37
|
+
logger.info('Parachains connected');
|
|
38
|
+
};
|
|
39
|
+
exports.connectParachains = connectParachains;
|
|
40
|
+
const connectHorizontal = async (parachains) => {
|
|
41
|
+
for (const [id, chain] of Object.entries(parachains)) {
|
|
42
|
+
const meta = await chain.head.meta;
|
|
43
|
+
const hrmpOutboundMessagesKey = (0, utils_1.compactHex)(meta.query.parachainSystem.hrmpOutboundMessages());
|
|
44
|
+
await chain.headState.subscribeStorage([hrmpOutboundMessagesKey], async (head, pairs) => {
|
|
45
|
+
const value = pairs[0][1];
|
|
46
|
+
if (!value)
|
|
47
|
+
return;
|
|
48
|
+
const meta = await chain.head.meta;
|
|
49
|
+
const hrmpOutboundMessagesKey = (0, utils_1.compactHex)(meta.query.parachainSystem.hrmpOutboundMessages());
|
|
50
|
+
// clear sender message queue
|
|
51
|
+
await (0, set_storage_1.setStorage)(chain, [[hrmpOutboundMessagesKey, null]], head.hash);
|
|
52
|
+
const outboundHrmpMessage = meta.registry
|
|
53
|
+
.createType('Vec<PolkadotCorePrimitivesOutboundHrmpMessage>', (0, util_1.hexToU8a)(value))
|
|
54
|
+
.toJSON();
|
|
55
|
+
logger.info({ outboundHrmpMessage }, 'outboundHrmpMessage');
|
|
56
|
+
for (const { recipient, data } of outboundHrmpMessage) {
|
|
57
|
+
const horizontalMessages = {
|
|
58
|
+
[Number(id)]: [{ sentAt: chain.head.number, data }],
|
|
59
|
+
};
|
|
60
|
+
const receiver = parachains[recipient];
|
|
61
|
+
if (receiver) {
|
|
62
|
+
await receiver.newBlock({ inherent: { horizontalMessages } });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"author": "Bryan Chen <xlchen1291@gmail.com>",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"@polkadot/types-known": "^9.10.1",
|
|
36
36
|
"@polkadot/util": "^10.2.1",
|
|
37
37
|
"@polkadot/util-crypto": "^10.2.1",
|
|
38
|
-
"axios": "^1.2.
|
|
38
|
+
"axios": "^1.2.2",
|
|
39
39
|
"js-yaml": "^4.1.0",
|
|
40
40
|
"lodash": "^4.17.21",
|
|
41
41
|
"pino": "^8.7.0",
|
|
@@ -51,13 +51,13 @@
|
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"@types/js-yaml": "^4.0.5",
|
|
53
53
|
"@types/lodash": "^4.14.191",
|
|
54
|
-
"@types/node": "^18.11.
|
|
54
|
+
"@types/node": "^18.11.18",
|
|
55
55
|
"@types/rimraf": "^3",
|
|
56
56
|
"@types/ws": "^8.5.3",
|
|
57
|
-
"@types/yargs": "^17.0.
|
|
57
|
+
"@types/yargs": "^17.0.18",
|
|
58
58
|
"@typescript-eslint/eslint-plugin": "^5.45.0",
|
|
59
59
|
"@typescript-eslint/parser": "^5.45.0",
|
|
60
|
-
"eslint": "^8.
|
|
60
|
+
"eslint": "^8.31.0",
|
|
61
61
|
"eslint-config-prettier": "^8.5.0",
|
|
62
62
|
"eslint-plugin-import": "^2.26.0",
|
|
63
63
|
"eslint-plugin-sort-imports-es6-autofix": "^0.6.0",
|
package/dist/bindings.d.ts
DELETED
package/dist/bindings.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.setupBindings = void 0;
|
|
4
|
-
const logger_1 = require("./logger");
|
|
5
|
-
const logger = logger_1.defaultLogger.child({ name: 'binding' });
|
|
6
|
-
const setupBindings = (chain) => {
|
|
7
|
-
global._chopsticks_binding_ = {
|
|
8
|
-
getStorage: async function (blockHash, key) {
|
|
9
|
-
const block = await chain.getBlock(blockHash);
|
|
10
|
-
if (!block)
|
|
11
|
-
throw Error(`Block not found ${blockHash}`);
|
|
12
|
-
const value = await block.get(key);
|
|
13
|
-
logger.trace({ blockHash, key, value: value && (0, logger_1.truncate)(value) }, 'exec_storageGet');
|
|
14
|
-
return value;
|
|
15
|
-
},
|
|
16
|
-
getPrefixKeys: async function (blockHash, key) {
|
|
17
|
-
const block = await chain.getBlock(blockHash);
|
|
18
|
-
if (!block)
|
|
19
|
-
throw Error(`Block not found ${blockHash}`);
|
|
20
|
-
return block.getKeysPaged({ prefix: key, pageSize: 1000, startKey: key });
|
|
21
|
-
},
|
|
22
|
-
getNextKey: async function (blockHash, key) {
|
|
23
|
-
const block = await chain.getBlock(blockHash);
|
|
24
|
-
if (!block)
|
|
25
|
-
throw Error(`Block not found ${blockHash}`);
|
|
26
|
-
const keys = await block.getKeysPaged({ prefix: key, pageSize: 1, startKey: key });
|
|
27
|
-
return keys.length > 0 ? keys[0] : '0x';
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
exports.setupBindings = setupBindings;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Block } from './block';
|
|
2
|
-
import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
|
|
3
|
-
import { HexString } from '@polkadot/util/types';
|
|
4
|
-
export interface CreateInherents {
|
|
5
|
-
createInherents(meta: DecoratedMeta, timestamp: number, parent: Block): Promise<HexString[]>;
|
|
6
|
-
}
|
|
7
|
-
export interface InherentProvider extends CreateInherents {
|
|
8
|
-
getTimestamp(blockNumber: number): number;
|
|
9
|
-
}
|
|
10
|
-
export declare class SetTimestamp implements InherentProvider {
|
|
11
|
-
#private;
|
|
12
|
-
constructor(getTimestamp?: (blockNumber: number) => number);
|
|
13
|
-
createInherents(meta: DecoratedMeta, timestamp: number, _parent: Block): Promise<HexString[]>;
|
|
14
|
-
getTimestamp(blockNumber: number): number;
|
|
15
|
-
}
|
|
16
|
-
export declare class InherentProviders implements InherentProvider {
|
|
17
|
-
#private;
|
|
18
|
-
constructor(base: InherentProvider, providers: CreateInherents[]);
|
|
19
|
-
createInherents(meta: DecoratedMeta, timestamp: number, parent: Block): Promise<HexString[]>;
|
|
20
|
-
getTimestamp(blockNumber: number): number;
|
|
21
|
-
}
|
|
22
|
-
export declare class SetValidationData implements CreateInherents {
|
|
23
|
-
createInherents(meta: DecoratedMeta, _timestamp: number, parent: Block): Promise<HexString[]>;
|
|
24
|
-
}
|