@acala-network/chopsticks-core 0.9.4-3 → 0.9.4-4
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/dist/cjs/blockchain/inherent/parachain/validation-data.js +1 -13
- package/dist/cjs/rpc/substrate/author.js +6 -0
- package/dist/cjs/utils/decoder.js +21 -1
- package/dist/cjs/wasm-executor/browser-wasm-executor.js +4 -4
- package/dist/cjs/wasm-executor/index.d.ts +6 -4
- package/dist/cjs/wasm-executor/index.js +4 -4
- package/dist/cjs/wasm-executor/node-wasm-executor.js +4 -4
- package/dist/esm/blockchain/inherent/parachain/validation-data.js +1 -13
- package/dist/esm/rpc/substrate/author.js +6 -0
- package/dist/esm/utils/decoder.js +21 -1
- package/dist/esm/wasm-executor/browser-wasm-executor.js +4 -4
- package/dist/esm/wasm-executor/index.d.ts +6 -4
- package/dist/esm/wasm-executor/index.js +4 -4
- package/dist/esm/wasm-executor/node-wasm-executor.js +4 -4
- package/package.json +2 -2
|
@@ -71,13 +71,7 @@ class SetValidationData {
|
|
|
71
71
|
const dmqMqcHeadKey = (0, _proof.dmqMqcHead)(paraId);
|
|
72
72
|
const hrmpIngressChannelIndexKey = (0, _proof.hrmpIngressChannelIndex)(paraId);
|
|
73
73
|
const hrmpEgressChannelIndexKey = (0, _proof.hrmpEgressChannelIndex)(paraId);
|
|
74
|
-
|
|
75
|
-
const decoded = await (0, _index1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [
|
|
76
|
-
...Object.values(_proof.WELL_KNOWN_KEYS),
|
|
77
|
-
dmqMqcHeadKey,
|
|
78
|
-
hrmpIngressChannelIndexKey,
|
|
79
|
-
hrmpEgressChannelIndexKey
|
|
80
|
-
], extrinsic.relayChainState.trieNodes);
|
|
74
|
+
const decoded = await (0, _index1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, extrinsic.relayChainState.trieNodes);
|
|
81
75
|
for (const key of Object.values(_proof.WELL_KNOWN_KEYS)){
|
|
82
76
|
if (key === _proof.WELL_KNOWN_KEYS.CURRENT_SLOT) {
|
|
83
77
|
// increment current slot
|
|
@@ -140,9 +134,6 @@ class SetValidationData {
|
|
|
140
134
|
receiver: paraId.toNumber()
|
|
141
135
|
});
|
|
142
136
|
const hrmpChannelKey = (0, _proof.hrmpChannels)(channelId);
|
|
143
|
-
const decoded = await (0, _index1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [
|
|
144
|
-
hrmpChannelKey
|
|
145
|
-
], extrinsic.relayChainState.trieNodes);
|
|
146
137
|
const abridgedHrmpRaw = decoded[hrmpChannelKey];
|
|
147
138
|
if (!abridgedHrmpRaw) throw new Error('Canoot find hrmp channels from validation data');
|
|
148
139
|
const abridgedHrmp = meta.registry.createType('AbridgedHrmpChannel', (0, _util.hexToU8a)(abridgedHrmpRaw)).toJSON();
|
|
@@ -175,9 +166,6 @@ class SetValidationData {
|
|
|
175
166
|
receiver
|
|
176
167
|
});
|
|
177
168
|
const hrmpChannelKey = (0, _proof.hrmpChannels)(channelId);
|
|
178
|
-
const decoded = await (0, _index1.decodeProof)(extrinsic.validationData.relayParentStorageRoot, [
|
|
179
|
-
hrmpChannelKey
|
|
180
|
-
], extrinsic.relayChainState.trieNodes);
|
|
181
169
|
newEntries.push([
|
|
182
170
|
hrmpChannelKey,
|
|
183
171
|
decoded[hrmpChannelKey]
|
|
@@ -72,6 +72,12 @@ const author_submitAndWatchExtrinsic = async (context, [extrinsic], { subscribe,
|
|
|
72
72
|
callback({
|
|
73
73
|
ready: null
|
|
74
74
|
});
|
|
75
|
+
// fake broadcast to alice peer
|
|
76
|
+
callback({
|
|
77
|
+
broadcast: [
|
|
78
|
+
'5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
|
|
79
|
+
]
|
|
80
|
+
});
|
|
75
81
|
}, 50);
|
|
76
82
|
} catch (error) {
|
|
77
83
|
logger.error({
|
|
@@ -27,11 +27,15 @@ const _lrucache = require("lru-cache");
|
|
|
27
27
|
const _util = require("@polkadot/util");
|
|
28
28
|
const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
|
|
29
29
|
const _wellknownkeys = require("./well-known-keys.js");
|
|
30
|
+
const _logger = require("../logger.js");
|
|
30
31
|
function _interop_require_default(obj) {
|
|
31
32
|
return obj && obj.__esModule ? obj : {
|
|
32
33
|
default: obj
|
|
33
34
|
};
|
|
34
35
|
}
|
|
36
|
+
const logger = _logger.defaultLogger.child({
|
|
37
|
+
module: 'decoder'
|
|
38
|
+
});
|
|
35
39
|
const _CACHE = {};
|
|
36
40
|
function createCache() {
|
|
37
41
|
return new _lrucache.LRUCache({
|
|
@@ -85,11 +89,27 @@ const decodeKeyValue = (meta, block, key, value, toHuman = true)=>{
|
|
|
85
89
|
}
|
|
86
90
|
const { storage, decodedKey } = decodeKey(meta, block, key);
|
|
87
91
|
if (!storage || !decodedKey) {
|
|
92
|
+
logger.warn({
|
|
93
|
+
key,
|
|
94
|
+
value
|
|
95
|
+
}, 'Failed to decode storage key');
|
|
88
96
|
return undefined;
|
|
89
97
|
}
|
|
90
98
|
const decodeValue = ()=>{
|
|
91
99
|
if (!value) return null;
|
|
92
|
-
|
|
100
|
+
try {
|
|
101
|
+
return meta.registry.createType(decodedKey.outputType, (0, _util.hexToU8a)(value))[toHuman ? 'toHuman' : 'toJSON']();
|
|
102
|
+
} catch (error) {
|
|
103
|
+
logger.warn(error, 'Failed to decode storage value');
|
|
104
|
+
logger.warn({
|
|
105
|
+
key,
|
|
106
|
+
value,
|
|
107
|
+
section: storage.section,
|
|
108
|
+
method: storage.method,
|
|
109
|
+
args: decodedKey.args
|
|
110
|
+
}, 'Failed to decode storage value');
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
93
113
|
};
|
|
94
114
|
return {
|
|
95
115
|
section: storage.section,
|
|
@@ -52,11 +52,11 @@ const getRuntimeVersion = async (code)=>{
|
|
|
52
52
|
const calculateStateRoot = async (entries, trie_version)=>{
|
|
53
53
|
return _chopsticksexecutor.calculate_state_root(entries, trie_version);
|
|
54
54
|
};
|
|
55
|
-
const decodeProof = async (trieRootHash,
|
|
56
|
-
return _chopsticksexecutor.decode_proof(trieRootHash,
|
|
55
|
+
const decodeProof = async (trieRootHash, nodes)=>{
|
|
56
|
+
return _chopsticksexecutor.decode_proof(trieRootHash, nodes);
|
|
57
57
|
};
|
|
58
|
-
const createProof = async (nodes,
|
|
59
|
-
return _chopsticksexecutor.create_proof(nodes,
|
|
58
|
+
const createProof = async (nodes, updates)=>{
|
|
59
|
+
return _chopsticksexecutor.create_proof(nodes, updates);
|
|
60
60
|
};
|
|
61
61
|
const runTask = async (task, callback)=>{
|
|
62
62
|
return _chopsticksexecutor.run_task(task, callback, 'info');
|
|
@@ -33,8 +33,8 @@ export type TaskResponse = {
|
|
|
33
33
|
export interface WasmExecutor {
|
|
34
34
|
getRuntimeVersion: (code: HexString) => Promise<RuntimeVersion>;
|
|
35
35
|
calculateStateRoot: (entries: [HexString, HexString][], trie_version: number) => Promise<HexString>;
|
|
36
|
-
createProof: (nodes: HexString[],
|
|
37
|
-
decodeProof: (trieRootHash: HexString,
|
|
36
|
+
createProof: (nodes: HexString[], updates: [HexString, HexString | null][]) => Promise<[HexString, HexString[]]>;
|
|
37
|
+
decodeProof: (trieRootHash: HexString, nodes: HexString[]) => Promise<[[HexString, HexString]]>;
|
|
38
38
|
runTask: (task: {
|
|
39
39
|
wasm: HexString;
|
|
40
40
|
calls: [string, HexString[]][];
|
|
@@ -50,8 +50,10 @@ export declare const getWorker: () => Promise<{
|
|
|
50
50
|
}>;
|
|
51
51
|
export declare const getRuntimeVersion: ((code: HexString) => Promise<RuntimeVersion>) & _.MemoizedFunction;
|
|
52
52
|
export declare const calculateStateRoot: (entries: [HexString, HexString][], trie_version: number) => Promise<HexString>;
|
|
53
|
-
export declare const decodeProof: (trieRootHash: HexString,
|
|
54
|
-
|
|
53
|
+
export declare const decodeProof: (trieRootHash: HexString, nodes: HexString[]) => Promise<{
|
|
54
|
+
[key: `0x${string}`]: `0x${string}`;
|
|
55
|
+
}>;
|
|
56
|
+
export declare const createProof: (nodes: HexString[], updates: [HexString, HexString | null][]) => Promise<{
|
|
55
57
|
trieRootHash: `0x${string}`;
|
|
56
58
|
nodes: `0x${string}`[];
|
|
57
59
|
}>;
|
|
@@ -120,17 +120,17 @@ const calculateStateRoot = async (entries, trie_version)=>{
|
|
|
120
120
|
const worker = await getWorker();
|
|
121
121
|
return worker.remote.calculateStateRoot(entries, trie_version);
|
|
122
122
|
};
|
|
123
|
-
const decodeProof = async (trieRootHash,
|
|
123
|
+
const decodeProof = async (trieRootHash, nodes)=>{
|
|
124
124
|
const worker = await getWorker();
|
|
125
|
-
const result = await worker.remote.decodeProof(trieRootHash,
|
|
125
|
+
const result = await worker.remote.decodeProof(trieRootHash, nodes);
|
|
126
126
|
return result.reduce((accum, [key, value])=>{
|
|
127
127
|
accum[key] = value;
|
|
128
128
|
return accum;
|
|
129
129
|
}, {});
|
|
130
130
|
};
|
|
131
|
-
const createProof = async (nodes,
|
|
131
|
+
const createProof = async (nodes, updates)=>{
|
|
132
132
|
const worker = await getWorker();
|
|
133
|
-
const [trieRootHash, newNodes] = await worker.remote.createProof(nodes,
|
|
133
|
+
const [trieRootHash, newNodes] = await worker.remote.createProof(nodes, updates);
|
|
134
134
|
return {
|
|
135
135
|
trieRootHash,
|
|
136
136
|
nodes: newNodes
|
|
@@ -59,11 +59,11 @@ const getRuntimeVersion = async (code)=>{
|
|
|
59
59
|
const calculateStateRoot = async (entries, trie_version)=>{
|
|
60
60
|
return _chopsticksexecutor.calculate_state_root(entries, trie_version);
|
|
61
61
|
};
|
|
62
|
-
const decodeProof = async (trieRootHash,
|
|
63
|
-
return _chopsticksexecutor.decode_proof(trieRootHash,
|
|
62
|
+
const decodeProof = async (trieRootHash, nodes)=>{
|
|
63
|
+
return _chopsticksexecutor.decode_proof(trieRootHash, nodes);
|
|
64
64
|
};
|
|
65
|
-
const createProof = async (nodes,
|
|
66
|
-
return _chopsticksexecutor.create_proof(nodes,
|
|
65
|
+
const createProof = async (nodes, updates)=>{
|
|
66
|
+
return _chopsticksexecutor.create_proof(nodes, updates);
|
|
67
67
|
};
|
|
68
68
|
const runTask = async (task, callback)=>{
|
|
69
69
|
return _chopsticksexecutor.run_task(task, callback, process.env.RUST_LOG);
|
|
@@ -56,13 +56,7 @@ export class SetValidationData {
|
|
|
56
56
|
const dmqMqcHeadKey = dmqMqcHead(paraId);
|
|
57
57
|
const hrmpIngressChannelIndexKey = hrmpIngressChannelIndex(paraId);
|
|
58
58
|
const hrmpEgressChannelIndexKey = hrmpEgressChannelIndex(paraId);
|
|
59
|
-
|
|
60
|
-
const decoded = await decodeProof(extrinsic.validationData.relayParentStorageRoot, [
|
|
61
|
-
...Object.values(WELL_KNOWN_KEYS),
|
|
62
|
-
dmqMqcHeadKey,
|
|
63
|
-
hrmpIngressChannelIndexKey,
|
|
64
|
-
hrmpEgressChannelIndexKey
|
|
65
|
-
], extrinsic.relayChainState.trieNodes);
|
|
59
|
+
const decoded = await decodeProof(extrinsic.validationData.relayParentStorageRoot, extrinsic.relayChainState.trieNodes);
|
|
66
60
|
for (const key of Object.values(WELL_KNOWN_KEYS)){
|
|
67
61
|
if (key === WELL_KNOWN_KEYS.CURRENT_SLOT) {
|
|
68
62
|
// increment current slot
|
|
@@ -125,9 +119,6 @@ export class SetValidationData {
|
|
|
125
119
|
receiver: paraId.toNumber()
|
|
126
120
|
});
|
|
127
121
|
const hrmpChannelKey = hrmpChannels(channelId);
|
|
128
|
-
const decoded = await decodeProof(extrinsic.validationData.relayParentStorageRoot, [
|
|
129
|
-
hrmpChannelKey
|
|
130
|
-
], extrinsic.relayChainState.trieNodes);
|
|
131
122
|
const abridgedHrmpRaw = decoded[hrmpChannelKey];
|
|
132
123
|
if (!abridgedHrmpRaw) throw new Error('Canoot find hrmp channels from validation data');
|
|
133
124
|
const abridgedHrmp = meta.registry.createType('AbridgedHrmpChannel', hexToU8a(abridgedHrmpRaw)).toJSON();
|
|
@@ -160,9 +151,6 @@ export class SetValidationData {
|
|
|
160
151
|
receiver
|
|
161
152
|
});
|
|
162
153
|
const hrmpChannelKey = hrmpChannels(channelId);
|
|
163
|
-
const decoded = await decodeProof(extrinsic.validationData.relayParentStorageRoot, [
|
|
164
|
-
hrmpChannelKey
|
|
165
|
-
], extrinsic.relayChainState.trieNodes);
|
|
166
154
|
newEntries.push([
|
|
167
155
|
hrmpChannelKey,
|
|
168
156
|
decoded[hrmpChannelKey]
|
|
@@ -59,6 +59,12 @@ const logger = defaultLogger.child({
|
|
|
59
59
|
callback({
|
|
60
60
|
ready: null
|
|
61
61
|
});
|
|
62
|
+
// fake broadcast to alice peer
|
|
63
|
+
callback({
|
|
64
|
+
broadcast: [
|
|
65
|
+
'5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY'
|
|
66
|
+
]
|
|
67
|
+
});
|
|
62
68
|
}, 50);
|
|
63
69
|
} catch (error) {
|
|
64
70
|
logger.error({
|
|
@@ -3,6 +3,10 @@ import { LRUCache } from 'lru-cache';
|
|
|
3
3
|
import { hexToU8a, u8aToHex } from '@polkadot/util';
|
|
4
4
|
import _ from 'lodash';
|
|
5
5
|
import { decodeWellKnownKey } from './well-known-keys.js';
|
|
6
|
+
import { defaultLogger } from '../logger.js';
|
|
7
|
+
const logger = defaultLogger.child({
|
|
8
|
+
module: 'decoder'
|
|
9
|
+
});
|
|
6
10
|
const _CACHE = {};
|
|
7
11
|
function createCache() {
|
|
8
12
|
return new LRUCache({
|
|
@@ -56,11 +60,27 @@ export const decodeKeyValue = (meta, block, key, value, toHuman = true)=>{
|
|
|
56
60
|
}
|
|
57
61
|
const { storage, decodedKey } = decodeKey(meta, block, key);
|
|
58
62
|
if (!storage || !decodedKey) {
|
|
63
|
+
logger.warn({
|
|
64
|
+
key,
|
|
65
|
+
value
|
|
66
|
+
}, 'Failed to decode storage key');
|
|
59
67
|
return undefined;
|
|
60
68
|
}
|
|
61
69
|
const decodeValue = ()=>{
|
|
62
70
|
if (!value) return null;
|
|
63
|
-
|
|
71
|
+
try {
|
|
72
|
+
return meta.registry.createType(decodedKey.outputType, hexToU8a(value))[toHuman ? 'toHuman' : 'toJSON']();
|
|
73
|
+
} catch (error) {
|
|
74
|
+
logger.warn(error, 'Failed to decode storage value');
|
|
75
|
+
logger.warn({
|
|
76
|
+
key,
|
|
77
|
+
value,
|
|
78
|
+
section: storage.section,
|
|
79
|
+
method: storage.method,
|
|
80
|
+
args: decodedKey.args
|
|
81
|
+
}, 'Failed to decode storage value');
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
64
84
|
};
|
|
65
85
|
return {
|
|
66
86
|
section: storage.section,
|
|
@@ -7,11 +7,11 @@ const getRuntimeVersion = async (code)=>{
|
|
|
7
7
|
const calculateStateRoot = async (entries, trie_version)=>{
|
|
8
8
|
return pkg.calculate_state_root(entries, trie_version);
|
|
9
9
|
};
|
|
10
|
-
const decodeProof = async (trieRootHash,
|
|
11
|
-
return pkg.decode_proof(trieRootHash,
|
|
10
|
+
const decodeProof = async (trieRootHash, nodes)=>{
|
|
11
|
+
return pkg.decode_proof(trieRootHash, nodes);
|
|
12
12
|
};
|
|
13
|
-
const createProof = async (nodes,
|
|
14
|
-
return pkg.create_proof(nodes,
|
|
13
|
+
const createProof = async (nodes, updates)=>{
|
|
14
|
+
return pkg.create_proof(nodes, updates);
|
|
15
15
|
};
|
|
16
16
|
const runTask = async (task, callback)=>{
|
|
17
17
|
return pkg.run_task(task, callback, 'info');
|
|
@@ -33,8 +33,8 @@ export type TaskResponse = {
|
|
|
33
33
|
export interface WasmExecutor {
|
|
34
34
|
getRuntimeVersion: (code: HexString) => Promise<RuntimeVersion>;
|
|
35
35
|
calculateStateRoot: (entries: [HexString, HexString][], trie_version: number) => Promise<HexString>;
|
|
36
|
-
createProof: (nodes: HexString[],
|
|
37
|
-
decodeProof: (trieRootHash: HexString,
|
|
36
|
+
createProof: (nodes: HexString[], updates: [HexString, HexString | null][]) => Promise<[HexString, HexString[]]>;
|
|
37
|
+
decodeProof: (trieRootHash: HexString, nodes: HexString[]) => Promise<[[HexString, HexString]]>;
|
|
38
38
|
runTask: (task: {
|
|
39
39
|
wasm: HexString;
|
|
40
40
|
calls: [string, HexString[]][];
|
|
@@ -50,8 +50,10 @@ export declare const getWorker: () => Promise<{
|
|
|
50
50
|
}>;
|
|
51
51
|
export declare const getRuntimeVersion: ((code: HexString) => Promise<RuntimeVersion>) & _.MemoizedFunction;
|
|
52
52
|
export declare const calculateStateRoot: (entries: [HexString, HexString][], trie_version: number) => Promise<HexString>;
|
|
53
|
-
export declare const decodeProof: (trieRootHash: HexString,
|
|
54
|
-
|
|
53
|
+
export declare const decodeProof: (trieRootHash: HexString, nodes: HexString[]) => Promise<{
|
|
54
|
+
[key: `0x${string}`]: `0x${string}`;
|
|
55
|
+
}>;
|
|
56
|
+
export declare const createProof: (nodes: HexString[], updates: [HexString, HexString | null][]) => Promise<{
|
|
55
57
|
trieRootHash: `0x${string}`;
|
|
56
58
|
nodes: `0x${string}`[];
|
|
57
59
|
}>;
|
|
@@ -33,17 +33,17 @@ export const calculateStateRoot = async (entries, trie_version)=>{
|
|
|
33
33
|
const worker = await getWorker();
|
|
34
34
|
return worker.remote.calculateStateRoot(entries, trie_version);
|
|
35
35
|
};
|
|
36
|
-
export const decodeProof = async (trieRootHash,
|
|
36
|
+
export const decodeProof = async (trieRootHash, nodes)=>{
|
|
37
37
|
const worker = await getWorker();
|
|
38
|
-
const result = await worker.remote.decodeProof(trieRootHash,
|
|
38
|
+
const result = await worker.remote.decodeProof(trieRootHash, nodes);
|
|
39
39
|
return result.reduce((accum, [key, value])=>{
|
|
40
40
|
accum[key] = value;
|
|
41
41
|
return accum;
|
|
42
42
|
}, {});
|
|
43
43
|
};
|
|
44
|
-
export const createProof = async (nodes,
|
|
44
|
+
export const createProof = async (nodes, updates)=>{
|
|
45
45
|
const worker = await getWorker();
|
|
46
|
-
const [trieRootHash, newNodes] = await worker.remote.createProof(nodes,
|
|
46
|
+
const [trieRootHash, newNodes] = await worker.remote.createProof(nodes, updates);
|
|
47
47
|
return {
|
|
48
48
|
trieRootHash,
|
|
49
49
|
nodes: newNodes
|
|
@@ -9,11 +9,11 @@ const getRuntimeVersion = async (code)=>{
|
|
|
9
9
|
const calculateStateRoot = async (entries, trie_version)=>{
|
|
10
10
|
return pkg.calculate_state_root(entries, trie_version);
|
|
11
11
|
};
|
|
12
|
-
const decodeProof = async (trieRootHash,
|
|
13
|
-
return pkg.decode_proof(trieRootHash,
|
|
12
|
+
const decodeProof = async (trieRootHash, nodes)=>{
|
|
13
|
+
return pkg.decode_proof(trieRootHash, nodes);
|
|
14
14
|
};
|
|
15
|
-
const createProof = async (nodes,
|
|
16
|
-
return pkg.create_proof(nodes,
|
|
15
|
+
const createProof = async (nodes, updates)=>{
|
|
16
|
+
return pkg.create_proof(nodes, updates);
|
|
17
17
|
};
|
|
18
18
|
const runTask = async (task, callback)=>{
|
|
19
19
|
return pkg.run_task(task, callback, process.env.RUST_LOG);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-core",
|
|
3
|
-
"version": "0.9.4-
|
|
3
|
+
"version": "0.9.4-4",
|
|
4
4
|
"author": "Acala Developers <hello@acala.network>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"docs:prep": "typedoc"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@acala-network/chopsticks-executor": "0.9.4-
|
|
15
|
+
"@acala-network/chopsticks-executor": "0.9.4-4",
|
|
16
16
|
"@polkadot/rpc-provider": "^10.10.1",
|
|
17
17
|
"@polkadot/types": "^10.10.1",
|
|
18
18
|
"@polkadot/types-codec": "^10.10.1",
|