@acala-network/chopsticks-core 1.0.2-2 → 1.0.3

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 (159) hide show
  1. package/dist/cjs/api.d.ts +5 -4
  2. package/dist/cjs/api.js +23 -23
  3. package/dist/cjs/blockchain/block-builder.d.ts +5 -5
  4. package/dist/cjs/blockchain/block-builder.js +17 -18
  5. package/dist/cjs/blockchain/block.d.ts +6 -6
  6. package/dist/cjs/blockchain/block.js +1 -1
  7. package/dist/cjs/blockchain/head-state.d.ts +1 -1
  8. package/dist/cjs/blockchain/index.d.ts +9 -9
  9. package/dist/cjs/blockchain/index.js +5 -5
  10. package/dist/cjs/blockchain/inherent/index.d.ts +5 -5
  11. package/dist/cjs/blockchain/inherent/index.js +1 -1
  12. package/dist/cjs/blockchain/inherent/para-enter.d.ts +4 -4
  13. package/dist/cjs/blockchain/inherent/parachain/babe-randomness.d.ts +4 -4
  14. package/dist/cjs/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +4 -4
  15. package/dist/cjs/blockchain/inherent/parachain/validation-data.d.ts +4 -4
  16. package/dist/cjs/blockchain/inherent/parachain/validation-data.js +3 -3
  17. package/dist/cjs/blockchain/inherent/timestamp.d.ts +3 -3
  18. package/dist/cjs/blockchain/storage-layer.d.ts +3 -3
  19. package/dist/cjs/blockchain/storage-layer.js +5 -4
  20. package/dist/cjs/blockchain/txpool.d.ts +3 -3
  21. package/dist/cjs/blockchain/txpool.js +10 -2
  22. package/dist/cjs/chopsticks-provider.d.ts +3 -3
  23. package/dist/cjs/chopsticks-provider.js +8 -9
  24. package/dist/cjs/database.d.ts +1 -1
  25. package/dist/cjs/genesis-provider.d.ts +4 -4
  26. package/dist/cjs/genesis-provider.js +13 -12
  27. package/dist/cjs/index.d.ts +1 -1
  28. package/dist/cjs/logger.js +5 -3
  29. package/dist/cjs/offchain.d.ts +2 -2
  30. package/dist/cjs/offchain.js +1 -1
  31. package/dist/cjs/rpc/dev/new-block.d.ts +5 -5
  32. package/dist/cjs/rpc/dev/new-block.js +1 -1
  33. package/dist/cjs/rpc/dev/set-block-build-mode.d.ts +1 -1
  34. package/dist/cjs/rpc/dev/set-block-build-mode.js +1 -1
  35. package/dist/cjs/rpc/dev/set-head.d.ts +1 -1
  36. package/dist/cjs/rpc/dev/set-head.js +1 -1
  37. package/dist/cjs/rpc/dev/set-runtime-log-level.d.ts +1 -1
  38. package/dist/cjs/rpc/dev/set-runtime-log-level.js +1 -1
  39. package/dist/cjs/rpc/dev/set-storage.d.ts +3 -3
  40. package/dist/cjs/rpc/dev/set-storage.js +1 -1
  41. package/dist/cjs/rpc/dev/time-travel.d.ts +1 -1
  42. package/dist/cjs/rpc/dev/time-travel.js +1 -1
  43. package/dist/cjs/rpc/index.d.ts +1 -1
  44. package/dist/cjs/rpc/rpc-spec/chainHead_v1.d.ts +11 -2
  45. package/dist/cjs/rpc/rpc-spec/chainHead_v1.js +33 -2
  46. package/dist/cjs/rpc/rpc-spec/chainSpec_v1.d.ts +3 -3
  47. package/dist/cjs/rpc/rpc-spec/transaction_v1.d.ts +2 -2
  48. package/dist/cjs/rpc/shared.d.ts +1 -1
  49. package/dist/cjs/rpc/substrate/archive.d.ts +2 -2
  50. package/dist/cjs/rpc/substrate/author.d.ts +2 -2
  51. package/dist/cjs/rpc/substrate/author.js +1 -1
  52. package/dist/cjs/rpc/substrate/chain.d.ts +2 -2
  53. package/dist/cjs/rpc/substrate/payment.d.ts +2 -2
  54. package/dist/cjs/rpc/substrate/state.d.ts +3 -3
  55. package/dist/cjs/rpc/substrate/state.js +1 -1
  56. package/dist/cjs/rpc/substrate/system.d.ts +3 -3
  57. package/dist/cjs/setup.d.ts +4 -4
  58. package/dist/cjs/setup.js +2 -2
  59. package/dist/cjs/utils/decoder.d.ts +5 -5
  60. package/dist/cjs/utils/decoder.js +2 -2
  61. package/dist/cjs/utils/index.d.ts +4 -4
  62. package/dist/cjs/utils/index.js +1 -1
  63. package/dist/cjs/utils/key-cache.d.ts +1 -1
  64. package/dist/cjs/utils/proof.d.ts +3 -3
  65. package/dist/cjs/utils/set-storage.d.ts +2 -2
  66. package/dist/cjs/utils/set-storage.js +1 -1
  67. package/dist/cjs/utils/time-travel.d.ts +1 -1
  68. package/dist/cjs/utils/well-known-keys.d.ts +2 -2
  69. package/dist/cjs/utils/well-known-keys.js +2 -2
  70. package/dist/cjs/wasm-executor/browser-wasm-executor.js +1 -1
  71. package/dist/cjs/wasm-executor/index.d.ts +3 -3
  72. package/dist/cjs/wasm-executor/index.js +14 -20
  73. package/dist/cjs/wasm-executor/node-wasm-executor.js +1 -1
  74. package/dist/cjs/wasm-executor/node-worker.js +1 -1
  75. package/dist/cjs/xcm/downward.d.ts +1 -1
  76. package/dist/cjs/xcm/horizontal.d.ts +1 -1
  77. package/dist/cjs/xcm/index.d.ts +1 -1
  78. package/dist/cjs/xcm/index.js +2 -2
  79. package/dist/cjs/xcm/upward.d.ts +1 -1
  80. package/dist/esm/api.d.ts +5 -4
  81. package/dist/esm/api.js +23 -23
  82. package/dist/esm/blockchain/block-builder.d.ts +5 -5
  83. package/dist/esm/blockchain/block-builder.js +17 -18
  84. package/dist/esm/blockchain/block.d.ts +6 -6
  85. package/dist/esm/blockchain/block.js +1 -1
  86. package/dist/esm/blockchain/head-state.d.ts +1 -1
  87. package/dist/esm/blockchain/index.d.ts +9 -9
  88. package/dist/esm/blockchain/index.js +5 -5
  89. package/dist/esm/blockchain/inherent/index.d.ts +5 -5
  90. package/dist/esm/blockchain/inherent/index.js +1 -1
  91. package/dist/esm/blockchain/inherent/para-enter.d.ts +4 -4
  92. package/dist/esm/blockchain/inherent/parachain/babe-randomness.d.ts +4 -4
  93. package/dist/esm/blockchain/inherent/parachain/nimbus-author-inherent.d.ts +4 -4
  94. package/dist/esm/blockchain/inherent/parachain/validation-data.d.ts +4 -4
  95. package/dist/esm/blockchain/inherent/parachain/validation-data.js +3 -3
  96. package/dist/esm/blockchain/inherent/timestamp.d.ts +3 -3
  97. package/dist/esm/blockchain/storage-layer.d.ts +3 -3
  98. package/dist/esm/blockchain/storage-layer.js +5 -4
  99. package/dist/esm/blockchain/txpool.d.ts +3 -3
  100. package/dist/esm/blockchain/txpool.js +10 -2
  101. package/dist/esm/chopsticks-provider.d.ts +3 -3
  102. package/dist/esm/chopsticks-provider.js +8 -9
  103. package/dist/esm/database.d.ts +1 -1
  104. package/dist/esm/genesis-provider.d.ts +4 -4
  105. package/dist/esm/genesis-provider.js +4 -3
  106. package/dist/esm/index.d.ts +1 -1
  107. package/dist/esm/logger.js +5 -3
  108. package/dist/esm/offchain.d.ts +2 -2
  109. package/dist/esm/offchain.js +1 -1
  110. package/dist/esm/rpc/dev/new-block.d.ts +5 -5
  111. package/dist/esm/rpc/dev/new-block.js +1 -1
  112. package/dist/esm/rpc/dev/set-block-build-mode.d.ts +1 -1
  113. package/dist/esm/rpc/dev/set-block-build-mode.js +1 -1
  114. package/dist/esm/rpc/dev/set-head.d.ts +1 -1
  115. package/dist/esm/rpc/dev/set-head.js +1 -1
  116. package/dist/esm/rpc/dev/set-runtime-log-level.d.ts +1 -1
  117. package/dist/esm/rpc/dev/set-runtime-log-level.js +1 -1
  118. package/dist/esm/rpc/dev/set-storage.d.ts +3 -3
  119. package/dist/esm/rpc/dev/set-storage.js +1 -1
  120. package/dist/esm/rpc/dev/time-travel.d.ts +1 -1
  121. package/dist/esm/rpc/dev/time-travel.js +1 -1
  122. package/dist/esm/rpc/index.d.ts +1 -1
  123. package/dist/esm/rpc/rpc-spec/chainHead_v1.d.ts +11 -2
  124. package/dist/esm/rpc/rpc-spec/chainHead_v1.js +42 -2
  125. package/dist/esm/rpc/rpc-spec/chainSpec_v1.d.ts +3 -3
  126. package/dist/esm/rpc/rpc-spec/transaction_v1.d.ts +2 -2
  127. package/dist/esm/rpc/shared.d.ts +1 -1
  128. package/dist/esm/rpc/substrate/archive.d.ts +2 -2
  129. package/dist/esm/rpc/substrate/author.d.ts +2 -2
  130. package/dist/esm/rpc/substrate/author.js +1 -1
  131. package/dist/esm/rpc/substrate/chain.d.ts +2 -2
  132. package/dist/esm/rpc/substrate/payment.d.ts +2 -2
  133. package/dist/esm/rpc/substrate/state.d.ts +3 -3
  134. package/dist/esm/rpc/substrate/state.js +1 -1
  135. package/dist/esm/rpc/substrate/system.d.ts +3 -3
  136. package/dist/esm/setup.d.ts +4 -4
  137. package/dist/esm/setup.js +2 -2
  138. package/dist/esm/utils/decoder.d.ts +5 -5
  139. package/dist/esm/utils/decoder.js +2 -2
  140. package/dist/esm/utils/index.d.ts +4 -4
  141. package/dist/esm/utils/index.js +1 -1
  142. package/dist/esm/utils/key-cache.d.ts +1 -1
  143. package/dist/esm/utils/proof.d.ts +3 -3
  144. package/dist/esm/utils/set-storage.d.ts +2 -2
  145. package/dist/esm/utils/set-storage.js +1 -1
  146. package/dist/esm/utils/time-travel.d.ts +1 -1
  147. package/dist/esm/utils/well-known-keys.d.ts +2 -2
  148. package/dist/esm/utils/well-known-keys.js +2 -2
  149. package/dist/esm/wasm-executor/browser-wasm-executor.js +1 -1
  150. package/dist/esm/wasm-executor/index.d.ts +3 -3
  151. package/dist/esm/wasm-executor/index.js +14 -20
  152. package/dist/esm/wasm-executor/node-wasm-executor.js +1 -1
  153. package/dist/esm/wasm-executor/node-worker.js +1 -1
  154. package/dist/esm/xcm/downward.d.ts +1 -1
  155. package/dist/esm/xcm/horizontal.d.ts +1 -1
  156. package/dist/esm/xcm/index.d.ts +1 -1
  157. package/dist/esm/xcm/index.js +2 -2
  158. package/dist/esm/xcm/upward.d.ts +1 -1
  159. package/package.json +16 -16
@@ -40,12 +40,12 @@ _export(exports, {
40
40
  return taskHandler;
41
41
  }
42
42
  });
43
- const _comlink = /*#__PURE__*/ _interop_require_wildcard(require("comlink"));
44
43
  const _util = require("@polkadot/util");
45
44
  const _utilcrypto = require("@polkadot/util-crypto");
45
+ const _comlink = /*#__PURE__*/ _interop_require_wildcard(require("comlink"));
46
46
  const _lodash = /*#__PURE__*/ _interop_require_default(require("lodash"));
47
- const _index = require("../utils/index.js");
48
47
  const _logger = require("../logger.js");
48
+ const _index = require("../utils/index.js");
49
49
  function _interop_require_default(obj) {
50
50
  return obj && obj.__esModule ? obj : {
51
51
  default: obj
@@ -154,10 +154,8 @@ const runTask = async (task, callback = emptyTaskHandler)=>{
154
154
  };
155
155
  const taskHandler = (block)=>{
156
156
  return {
157
- getStorage: async function(key) {
158
- return block.get(key);
159
- },
160
- getNextKey: async function(prefix, key) {
157
+ getStorage: async (key)=>block.get(key),
158
+ getNextKey: async (prefix, key)=>{
161
159
  const [nextKey] = await block.getKeysPaged({
162
160
  prefix: prefix.length === 2 /** 0x */ ? key.slice(0, _index.PREFIX_LENGTH) : prefix,
163
161
  pageSize: 1,
@@ -165,17 +163,13 @@ const taskHandler = (block)=>{
165
163
  });
166
164
  return nextKey && (0, _index.stripChildPrefix)(nextKey);
167
165
  },
168
- offchainGetStorage: async function(key) {
166
+ offchainGetStorage: async (key)=>{
169
167
  if (!block.chain.offchainWorker) throw new Error('offchain worker not found');
170
168
  return block.chain.offchainWorker.get(key);
171
169
  },
172
- offchainTimestamp: async function() {
173
- return Date.now();
174
- },
175
- offchainRandomSeed: async function() {
176
- return (0, _utilcrypto.randomAsHex)(32);
177
- },
178
- offchainSubmitTransaction: async function(tx) {
170
+ offchainTimestamp: async ()=>Date.now(),
171
+ offchainRandomSeed: async ()=>(0, _utilcrypto.randomAsHex)(32),
172
+ offchainSubmitTransaction: async (tx)=>{
179
173
  if (!block.chain.offchainWorker) throw new Error('offchain worker not found');
180
174
  try {
181
175
  const hash = await block.chain.offchainWorker.pushExtrinsic(block, tx);
@@ -193,22 +187,22 @@ const taskHandler = (block)=>{
193
187
  };
194
188
  };
195
189
  const emptyTaskHandler = {
196
- getStorage: async function(_key) {
190
+ getStorage: async (_key)=>{
197
191
  throw new Error('Method not implemented');
198
192
  },
199
- getNextKey: async function(_prefix, _key) {
193
+ getNextKey: async (_prefix, _key)=>{
200
194
  throw new Error('Method not implemented');
201
195
  },
202
- offchainGetStorage: async function(_key) {
196
+ offchainGetStorage: async (_key)=>{
203
197
  throw new Error('Method not implemented');
204
198
  },
205
- offchainTimestamp: async function() {
199
+ offchainTimestamp: async ()=>{
206
200
  throw new Error('Method not implemented');
207
201
  },
208
- offchainRandomSeed: async function() {
202
+ offchainRandomSeed: async ()=>{
209
203
  throw new Error('Method not implemented');
210
204
  },
211
- offchainSubmitTransaction: async function(_tx) {
205
+ offchainSubmitTransaction: async (_tx)=>{
212
206
  throw new Error('Method not implemented');
213
207
  }
214
208
  };
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- const _comlink = /*#__PURE__*/ _interop_require_wildcard(require("comlink"));
6
5
  const _chopsticksexecutor = /*#__PURE__*/ _interop_require_wildcard(require("@acala-network/chopsticks-executor"));
6
+ const _comlink = /*#__PURE__*/ _interop_require_wildcard(require("comlink"));
7
7
  const _nodeworker_threads = require("node:worker_threads");
8
8
  const _nodeadapter = /*#__PURE__*/ _interop_require_default(require("comlink/dist/umd/node-adapter.js"));
9
9
  function _interop_require_default(obj) {
@@ -8,9 +8,9 @@ Object.defineProperty(exports, "startWorker", {
8
8
  return startWorker;
9
9
  }
10
10
  });
11
+ const _nodeworker_threads = /*#__PURE__*/ _interop_require_default(require("node:worker_threads"));
11
12
  const _comlink = require("comlink");
12
13
  const _nodeadapter = /*#__PURE__*/ _interop_require_default(require("comlink/dist/umd/node-adapter.js"));
13
- const _nodeworker_threads = /*#__PURE__*/ _interop_require_default(require("node:worker_threads"));
14
14
  function _interop_require_default(obj) {
15
15
  return obj && obj.__esModule ? obj : {
16
16
  default: obj
@@ -1,2 +1,2 @@
1
- import { Blockchain } from '../blockchain/index.js';
1
+ import type { Blockchain } from '../blockchain/index.js';
2
2
  export declare const connectDownward: (relaychain: Blockchain, parachain: Blockchain) => Promise<void>;
@@ -1,2 +1,2 @@
1
- import { Blockchain } from '../blockchain/index.js';
1
+ import type { Blockchain } from '../blockchain/index.js';
2
2
  export declare const connectHorizontal: (parachains: Record<number, Blockchain>, disableAutoHrmp?: boolean) => Promise<void>;
@@ -1,4 +1,4 @@
1
- import { Blockchain } from '../blockchain/index.js';
1
+ import type { Blockchain } from '../blockchain/index.js';
2
2
  export declare const xcmLogger: import("pino").default.Logger<never, boolean>;
3
3
  export declare const connectVertical: (relaychain: Blockchain, parachain: Blockchain) => Promise<void>;
4
4
  export declare const connectParachains: (parachains: Blockchain[], disableAutoHrmp?: boolean) => Promise<void>;
@@ -19,11 +19,11 @@ _export(exports, {
19
19
  return xcmLogger;
20
20
  }
21
21
  });
22
+ const _logger = require("../logger.js");
23
+ const _index = require("../utils/index.js");
22
24
  const _downward = require("./downward.js");
23
25
  const _horizontal = require("./horizontal.js");
24
26
  const _upward = require("./upward.js");
25
- const _logger = require("../logger.js");
26
- const _index = require("../utils/index.js");
27
27
  const xcmLogger = _logger.defaultLogger.child({
28
28
  name: 'xcm'
29
29
  });
@@ -1,2 +1,2 @@
1
- import { Blockchain } from '../blockchain/index.js';
1
+ import type { Blockchain } from '../blockchain/index.js';
2
2
  export declare const connectUpward: (parachain: Blockchain, relaychain: Blockchain) => Promise<void>;
package/dist/esm/api.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
2
- import { HexString } from '@polkadot/util/types';
3
- import { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
4
- import { ChainProperties, Header, SignedBlock } from './index.js';
1
+ import type { ProviderInterface, ProviderInterfaceCallback } from '@polkadot/rpc-provider/types';
2
+ import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types';
3
+ import type { HexString } from '@polkadot/util/types';
4
+ import type { ChainProperties, Header, SignedBlock } from './index.js';
5
5
  /**
6
6
  * API class. Calls provider to get on-chain data.
7
7
  * Either `endpoint` or `genesis` porvider must be provided.
@@ -29,6 +29,7 @@ export declare class Api {
29
29
  getSystemChain(): Promise<string>;
30
30
  getBlockHash(blockNumber?: number): Promise<`0x${string}` | null>;
31
31
  getHeader(hash?: string): Promise<Header | null>;
32
+ getFinalizedHead(): Promise<string>;
32
33
  getBlock(hash?: string): Promise<SignedBlock | null>;
33
34
  getStorage(key: string, hash?: string): Promise<`0x${string}` | null>;
34
35
  getKeysPaged(prefix: string, pageSize: number, startKey: string, hash?: string): Promise<string[]>;
package/dist/esm/api.js CHANGED
@@ -81,6 +81,9 @@ import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index
81
81
  hash
82
82
  ] : [], !!hash);
83
83
  }
84
+ async getFinalizedHead() {
85
+ return this.send('chain_getFinalizedHead', []);
86
+ }
84
87
  async getBlock(hash) {
85
88
  return this.send('chain_getBlock', hash ? [
86
89
  hash
@@ -96,14 +99,13 @@ import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index
96
99
  ];
97
100
  if (hash) params.push(hash);
98
101
  return this.send('childstate_getStorage', params, !!hash);
99
- } else {
100
- // main storage key, use state_getStorage
101
- const params = [
102
- key
103
- ];
104
- if (hash) params.push(hash);
105
- return this.send('state_getStorage', params, !!hash);
106
102
  }
103
+ // main storage key, use state_getStorage
104
+ const params = [
105
+ key
106
+ ];
107
+ if (hash) params.push(hash);
108
+ return this.send('state_getStorage', params, !!hash);
107
109
  }
108
110
  async getKeysPaged(prefix, pageSize, startKey, hash) {
109
111
  const [child, storageKey] = splitChildKey(prefix);
@@ -118,16 +120,15 @@ import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index
118
120
  ];
119
121
  if (hash) params.push(hash);
120
122
  return this.#provider.send('childstate_getKeysPaged', params, !!hash).then((keys)=>keys.map((key)=>prefixedChildKey(child, key)));
121
- } else {
122
- // main storage key, use state_getKeysPaged
123
- const params = [
124
- prefix,
125
- pageSize,
126
- startKey
127
- ];
128
- if (hash) params.push(hash);
129
- return this.send('state_getKeysPaged', params, !!hash);
130
123
  }
124
+ // main storage key, use state_getKeysPaged
125
+ const params = [
126
+ prefix,
127
+ pageSize,
128
+ startKey
129
+ ];
130
+ if (hash) params.push(hash);
131
+ return this.send('state_getKeysPaged', params, !!hash);
131
132
  }
132
133
  async getStorageBatch(prefix, keys, hash) {
133
134
  const [child] = splitChildKey(prefix);
@@ -140,14 +141,13 @@ import { prefixedChildKey, splitChildKey, stripChildPrefix } from './utils/index
140
141
  ];
141
142
  if (hash) params.push(hash);
142
143
  return this.#provider.send('childstate_getStorageEntries', params, !!hash).then((values)=>_.zip(keys, values));
143
- } else {
144
- // main storage key, use state_getStorageAt
145
- const params = [
146
- keys
147
- ];
148
- if (hash) params.push(hash);
149
- return this.#provider.send('state_queryStorageAt', params, !!hash).then((result)=>result[0]?.['changes'] || []);
150
144
  }
145
+ // main storage key, use state_getStorageAt
146
+ const params = [
147
+ keys
148
+ ];
149
+ if (hash) params.push(hash);
150
+ return this.#provider.send('state_queryStorageAt', params, !!hash).then((result)=>result[0]?.['changes'] || []);
151
151
  }
152
152
  async subscribeRemoteNewHeads(cb) {
153
153
  if (!this.#provider.hasSubscriptions) {
@@ -1,9 +1,9 @@
1
- import { DigestItem, Header, TransactionValidityError } from '@polkadot/types/interfaces';
1
+ import type { DigestItem, Header, TransactionValidityError } from '@polkadot/types/interfaces';
2
+ import type { HexString } from '@polkadot/util/types';
3
+ import type { TaskCallResponse } from '../wasm-executor/index.js';
2
4
  import { Block } from './block.js';
3
- import { BuildBlockParams } from './txpool.js';
4
- import { HexString } from '@polkadot/util/types';
5
- import { InherentProvider } from './inherent/index.js';
6
- import { TaskCallResponse } from '../wasm-executor/index.js';
5
+ import type { InherentProvider } from './inherent/index.js';
6
+ import type { BuildBlockParams } from './txpool.js';
7
7
  export declare const genesisDigestLogs: (head: Block) => Promise<DigestItem[]>;
8
8
  export declare const newHeader: (head: Block, unsafeBlockHeight?: number) => Promise<Header>;
9
9
  export type BuildBlockCallbacks = {
@@ -1,9 +1,9 @@
1
- import { Block } from './block.js';
2
- import { StorageLayer, StorageValueKind } from './storage-layer.js';
3
- import { blake2AsU8a } from '@polkadot/util-crypto';
4
1
  import { compactAddLength, hexToU8a, stringToHex, u8aConcat } from '@polkadot/util';
5
- import { compactHex, getCurrentSlot } from '../utils/index.js';
2
+ import { blake2AsU8a } from '@polkadot/util-crypto';
6
3
  import { defaultLogger, truncate } from '../logger.js';
4
+ import { compactHex, getCurrentSlot } from '../utils/index.js';
5
+ import { Block } from './block.js';
6
+ import { StorageLayer, StorageValueKind } from './storage-layer.js';
7
7
  const logger = defaultLogger.child({
8
8
  name: 'block-builder'
9
9
  });
@@ -30,19 +30,18 @@ export const genesisDigestLogs = async (head)=>{
30
30
  return [
31
31
  digest
32
32
  ];
33
- } else {
34
- const newSlot = meta.registry.createType('Slot', currentSlot + 1);
35
- const consensusEngine = meta.registry.createType('ConsensusEngineId', 'aura');
36
- const digest = meta.registry.createType('DigestItem', {
37
- PreRuntime: [
38
- consensusEngine,
39
- compactAddLength(newSlot.toU8a())
40
- ]
41
- });
42
- return [
43
- digest
44
- ];
45
33
  }
34
+ const newSlot = meta.registry.createType('Slot', currentSlot + 1);
35
+ const consensusEngine = meta.registry.createType('ConsensusEngineId', 'aura');
36
+ const digest = meta.registry.createType('DigestItem', {
37
+ PreRuntime: [
38
+ consensusEngine,
39
+ compactAddLength(newSlot.toU8a())
40
+ ]
41
+ });
42
+ return [
43
+ digest
44
+ ];
46
45
  };
47
46
  const getConsensus = (header)=>{
48
47
  if (header.digest.logs.length === 0) return;
@@ -110,14 +109,14 @@ export const newHeader = async (head, unsafeBlockHeight)=>{
110
109
  }),
111
110
  ...consensus.rest
112
111
  ];
113
- } else if (consensus?.consensusEngine?.toString() == 'nmbs') {
112
+ } else if (consensus?.consensusEngine?.toString() === 'nmbs') {
114
113
  const nmbsKey = stringToHex('nmbs');
115
114
  newLogs = [
116
115
  meta.registry.createType('DigestItem', {
117
116
  // Using previous block author
118
117
  PreRuntime: [
119
118
  consensus.consensusEngine,
120
- parentHeader.digest.logs.find((log)=>log.isPreRuntime && log.asPreRuntime[0].toHex() == nmbsKey)?.asPreRuntime[1].toHex()
119
+ parentHeader.digest.logs.find((log)=>log.isPreRuntime && log.asPreRuntime[0].toHex() === nmbsKey)?.asPreRuntime[1].toHex()
121
120
  ]
122
121
  }),
123
122
  ...consensus.rest
@@ -1,11 +1,11 @@
1
- import { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
2
- import { Header } from '@polkadot/types/interfaces';
3
- import { TypeRegistry } from '@polkadot/types';
4
- import { StorageEntry } from '@polkadot/types/primitive/types';
1
+ import { type TypeRegistry } from '@polkadot/types';
2
+ import type { Header } from '@polkadot/types/interfaces';
3
+ import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
4
+ import type { StorageEntry } from '@polkadot/types/primitive/types';
5
5
  import type { HexString } from '@polkadot/util/types';
6
- import { Blockchain } from './index.js';
7
- import { StorageLayer, StorageLayerProvider, StorageValue } from './storage-layer.js';
8
6
  import type { RuntimeVersion, TaskCallResponse } from '../wasm-executor/index.js';
7
+ import type { Blockchain } from './index.js';
8
+ import { StorageLayer, type StorageLayerProvider, type StorageValue } from './storage-layer.js';
9
9
  /**
10
10
  * Block class.
11
11
  *
@@ -1,9 +1,9 @@
1
1
  import { Metadata } from '@polkadot/types';
2
2
  import { expandMetadata } from '@polkadot/types/metadata';
3
3
  import { hexToU8a, stringToHex } from '@polkadot/util';
4
- import { RemoteStorageLayer, StorageLayer, StorageValueKind } from './storage-layer.js';
5
4
  import { compactHex } from '../utils/index.js';
6
5
  import { getRuntimeVersion, runTask, taskHandler } from '../wasm-executor/index.js';
6
+ import { RemoteStorageLayer, StorageLayer, StorageValueKind } from './storage-layer.js';
7
7
  /**
8
8
  * Block class.
9
9
  *
@@ -1,4 +1,4 @@
1
- import { Block } from './block.js';
1
+ import type { Block } from './block.js';
2
2
  type Callback = (block: Block, pairs: [string, string | null][]) => void | Promise<void>;
3
3
  export declare const randomId: () => string;
4
4
  export declare class HeadState {
@@ -1,16 +1,16 @@
1
- import { ApplyExtrinsicResult } from '@polkadot/types/interfaces';
2
- import { HexString } from '@polkadot/util/types';
3
1
  import { TypeRegistry } from '@polkadot/types';
4
- import { RegisteredTypes } from '@polkadot/types/types';
2
+ import type { ApplyExtrinsicResult } from '@polkadot/types/interfaces';
5
3
  import type { TransactionValidity } from '@polkadot/types/interfaces/txqueue';
6
- import { Api } from '../api.js';
4
+ import type { RegisteredTypes } from '@polkadot/types/types';
5
+ import type { HexString } from '@polkadot/util/types';
6
+ import type { Api } from '../api.js';
7
+ import type { Database } from '../database.js';
8
+ import { OffchainWorker } from '../offchain.js';
9
+ import type { RuntimeVersion } from '../wasm-executor/index.js';
7
10
  import { Block } from './block.js';
8
- import { BuildBlockMode, BuildBlockParams, DownwardMessage, HorizontalMessage, TxPool } from './txpool.js';
9
- import { Database } from '../database.js';
10
11
  import { HeadState } from './head-state.js';
11
- import { InherentProvider } from './inherent/index.js';
12
- import { OffchainWorker } from '../offchain.js';
13
- import { RuntimeVersion } from '../wasm-executor/index.js';
12
+ import type { InherentProvider } from './inherent/index.js';
13
+ import { type BuildBlockMode, type BuildBlockParams, type DownwardMessage, type HorizontalMessage, TxPool } from './txpool.js';
14
14
  export interface Options {
15
15
  /** API instance, for getting on-chain data. */
16
16
  api: Api;
@@ -1,15 +1,15 @@
1
1
  import { Metadata, TypeRegistry } from '@polkadot/types';
2
- import { blake2AsHex, xxhashAsHex } from '@polkadot/util-crypto';
3
2
  import { getSpecExtensions, getSpecHasher, getSpecTypes } from '@polkadot/types-known/util';
4
3
  import { objectSpread, u8aConcat, u8aToHex } from '@polkadot/util';
4
+ import { blake2AsHex, xxhashAsHex } from '@polkadot/util-crypto';
5
5
  import _ from 'lodash';
6
- import { Block } from './block.js';
7
- import { TxPool } from './txpool.js';
8
- import { HeadState } from './head-state.js';
6
+ import { defaultLogger } from '../logger.js';
9
7
  import { OffchainWorker } from '../offchain.js';
10
8
  import { compactHex } from '../utils/index.js';
11
- import { defaultLogger } from '../logger.js';
12
9
  import { dryRunExtrinsic, dryRunInherents } from './block-builder.js';
10
+ import { Block } from './block.js';
11
+ import { HeadState } from './head-state.js';
12
+ import { TxPool } from './txpool.js';
13
13
  const logger = defaultLogger.child({
14
14
  name: 'blockchain'
15
15
  });
@@ -1,12 +1,12 @@
1
- import { Block } from '../block.js';
2
- import { BuildBlockParams } from '../txpool.js';
3
- import { HexString } from '@polkadot/util/types';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { Block } from '../block.js';
3
+ import type { BuildBlockParams } from '../txpool.js';
4
4
  import { ParaInherentEnter } from './para-enter.js';
5
5
  import { SetBabeRandomness } from './parachain/babe-randomness.js';
6
6
  import { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent.js';
7
- import { SetTimestamp } from './timestamp.js';
8
7
  import { SetValidationData } from './parachain/validation-data.js';
8
+ import { SetTimestamp } from './timestamp.js';
9
9
  export interface InherentProvider {
10
10
  createInherents(newBlock: Block, params: BuildBlockParams): Promise<HexString[]>;
11
11
  }
12
- export declare const inherentProviders: (ParaInherentEnter | SetBabeRandomness | SetNimbusAuthorInherent | SetTimestamp | SetValidationData)[];
12
+ export declare const inherentProviders: (ParaInherentEnter | SetBabeRandomness | SetNimbusAuthorInherent | SetValidationData | SetTimestamp)[];
@@ -1,8 +1,8 @@
1
1
  import { ParaInherentEnter } from './para-enter.js';
2
2
  import { SetBabeRandomness } from './parachain/babe-randomness.js';
3
3
  import { SetNimbusAuthorInherent } from './parachain/nimbus-author-inherent.js';
4
- import { SetTimestamp } from './timestamp.js';
5
4
  import { SetValidationData } from './parachain/validation-data.js';
5
+ import { SetTimestamp } from './timestamp.js';
6
6
  export const inherentProviders = [
7
7
  new SetTimestamp(),
8
8
  new SetValidationData(),
@@ -1,7 +1,7 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { Block } from '../block.js';
3
- import { BuildBlockParams } from '../txpool.js';
4
- import { InherentProvider } from './index.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { Block } from '../block.js';
3
+ import type { BuildBlockParams } from '../txpool.js';
4
+ import type { InherentProvider } from './index.js';
5
5
  export declare class ParaInherentEnter implements InherentProvider {
6
6
  createInherents(newBlock: Block, _params: BuildBlockParams): Promise<HexString[]>;
7
7
  }
@@ -1,7 +1,7 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { Block } from '../../block.js';
3
- import { BuildBlockParams } from '../../txpool.js';
4
- import { InherentProvider } from '../index.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { Block } from '../../block.js';
3
+ import type { BuildBlockParams } from '../../txpool.js';
4
+ import type { InherentProvider } from '../index.js';
5
5
  export declare class SetBabeRandomness implements InherentProvider {
6
6
  createInherents(newBlock: Block, _params: BuildBlockParams): Promise<HexString[]>;
7
7
  }
@@ -1,7 +1,7 @@
1
- import { Block } from '../../block.js';
2
- import { BuildBlockParams } from '../../txpool.js';
3
- import { HexString } from '@polkadot/util/types';
4
- import { InherentProvider } from '../index.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { Block } from '../../block.js';
3
+ import type { BuildBlockParams } from '../../txpool.js';
4
+ import type { InherentProvider } from '../index.js';
5
5
  export declare class SetNimbusAuthorInherent implements InherentProvider {
6
6
  createInherents(newBlock: Block, _params: BuildBlockParams): Promise<HexString[]>;
7
7
  }
@@ -1,7 +1,7 @@
1
- import { HexString } from '@polkadot/util/types';
2
- import { Block } from '../../block.js';
3
- import { BuildBlockParams, DownwardMessage, HorizontalMessage } from '../../txpool.js';
4
- import { InherentProvider } from '../index.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { Block } from '../../block.js';
3
+ import type { BuildBlockParams, DownwardMessage, HorizontalMessage } from '../../txpool.js';
4
+ import type { InherentProvider } from '../index.js';
5
5
  export type ValidationData = {
6
6
  downwardMessages: DownwardMessage[];
7
7
  horizontalMessages: Record<number, HorizontalMessage[]>;
@@ -1,9 +1,9 @@
1
- import { hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
2
1
  import { GenericExtrinsic } from '@polkadot/types';
2
+ import { hexToU8a, u8aConcat, u8aToHex } from '@polkadot/util';
3
3
  import _ from 'lodash';
4
- import { WELL_KNOWN_KEYS, dmqMqcHead, hrmpChannels, hrmpEgressChannelIndex, hrmpIngressChannelIndex, paraHead, upgradeGoAheadSignal } from '../../../utils/proof.js';
5
4
  import { blake2AsHex, blake2AsU8a } from '@polkadot/util-crypto';
6
5
  import { compactHex, getCurrentSlot, getParaId } from '../../../utils/index.js';
6
+ import { WELL_KNOWN_KEYS, dmqMqcHead, hrmpChannels, hrmpEgressChannelIndex, hrmpIngressChannelIndex, paraHead, upgradeGoAheadSignal } from '../../../utils/proof.js';
7
7
  import { createProof, decodeProof } from '../../../wasm-executor/index.js';
8
8
  const MOCK_VALIDATION_DATA = {
9
9
  validationData: {
@@ -218,7 +218,7 @@ export class SetValidationData {
218
218
  if (params.relayChainStateOverrides) {
219
219
  for (const [key, value] of params.relayChainStateOverrides){
220
220
  // Remove any entry that matches the key being overridden
221
- newEntries = newEntries.filter(([k, _])=>k != key);
221
+ newEntries = newEntries.filter(([k, _])=>k !== key);
222
222
  // Push override
223
223
  newEntries.push([
224
224
  key,
@@ -1,6 +1,6 @@
1
- import { Block } from '../block.js';
2
- import { HexString } from '@polkadot/util/types';
3
- import { InherentProvider } from './index.js';
1
+ import type { HexString } from '@polkadot/util/types';
2
+ import type { Block } from '../block.js';
3
+ import type { InherentProvider } from './index.js';
4
4
  export declare class SetTimestamp implements InherentProvider {
5
5
  createInherents(newBlock: Block): Promise<HexString[]>;
6
6
  }
@@ -1,6 +1,6 @@
1
- import { Api } from '../api.js';
2
- import { Database } from '../database.js';
3
- export declare const enum StorageValueKind {
1
+ import type { Api } from '../api.js';
2
+ import type { Database } from '../database.js';
3
+ export declare enum StorageValueKind {
4
4
  Deleted = "Deleted",
5
5
  DeletedPrefix = "DeletedPrefix"
6
6
  }
@@ -1,6 +1,6 @@
1
1
  import _ from 'lodash';
2
- import { CHILD_PREFIX_LENGTH, PREFIX_LENGTH, isPrefixedChildKey } from '../utils/index.js';
3
2
  import { defaultLogger } from '../logger.js';
3
+ import { CHILD_PREFIX_LENGTH, PREFIX_LENGTH, isPrefixedChildKey } from '../utils/index.js';
4
4
  import KeyCache from '../utils/key-cache.js';
5
5
  const logger = defaultLogger.child({
6
6
  name: 'layer'
@@ -92,7 +92,7 @@ export class RemoteStorageLayer {
92
92
  // batch fetch storage values and save to db, they may be used later
93
93
  this.#api.getStorageBatch(prefix, batch, this.#at).then((storage)=>{
94
94
  for (const [key, value] of storage){
95
- this.#db.saveStorage(this.#at, key, value);
95
+ this.#db?.saveStorage(this.#at, key, value);
96
96
  }
97
97
  });
98
98
  }
@@ -184,7 +184,8 @@ export class StorageLayer {
184
184
  if (parentBest) {
185
185
  if (!maybeBest) {
186
186
  return parentBest;
187
- } else if (parentBest < maybeBest) {
187
+ }
188
+ if (parentBest < maybeBest) {
188
189
  return parentBest;
189
190
  }
190
191
  }
@@ -200,7 +201,7 @@ export class StorageLayer {
200
201
  const next = await this.findNextKey(prefix, startKey, undefined);
201
202
  if (!next) break;
202
203
  startKey = next;
203
- if (await this.get(next, false) == "Deleted") continue;
204
+ if (await this.get(next, false) === "Deleted") continue;
204
205
  keys.push(next);
205
206
  }
206
207
  return keys;
@@ -1,7 +1,7 @@
1
+ import type { HexString } from '@polkadot/util/types';
1
2
  import { EventEmitter } from 'eventemitter3';
2
- import { HexString } from '@polkadot/util/types';
3
- import { Blockchain } from './index.js';
4
- import { InherentProvider } from './inherent/index.js';
3
+ import type { Blockchain } from './index.js';
4
+ import type { InherentProvider } from './inherent/index.js';
5
5
  export declare const APPLY_EXTRINSIC_ERROR = "TxPool::ApplyExtrinsicError";
6
6
  export declare enum BuildBlockMode {
7
7
  /** One block per batch (default) */
@@ -1,9 +1,9 @@
1
- import { EventEmitter } from 'eventemitter3';
2
1
  import { hexToU8a } from '@polkadot/util/hex/toU8a';
2
+ import { EventEmitter } from 'eventemitter3';
3
3
  import _ from 'lodash';
4
+ import { defaultLogger, truncate } from '../logger.js';
4
5
  import { defer } from '../utils/index.js';
5
6
  import { buildBlock } from './block-builder.js';
6
- import { defaultLogger, truncate } from '../logger.js';
7
7
  const logger = defaultLogger.child({
8
8
  name: 'txpool'
9
9
  });
@@ -201,6 +201,14 @@ export class TxPool {
201
201
  this.#isBuilding = true;
202
202
  try {
203
203
  await this.#buildBlock();
204
+ } catch (error) {
205
+ logger.error({
206
+ error
207
+ }, 'build block failed');
208
+ for (const { deferred } of this.#pendingBlocks){
209
+ deferred.reject(error);
210
+ }
211
+ this.#pendingBlocks.length = 0;
204
212
  } finally{
205
213
  this.#isBuilding = false;
206
214
  }
@@ -1,6 +1,6 @@
1
- import { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
2
- import { Blockchain } from './blockchain/index.js';
3
- import { Database } from './database.js';
1
+ import type { ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitCb, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
2
+ import type { Blockchain } from './blockchain/index.js';
3
+ import type { Database } from './database.js';
4
4
  interface SubscriptionHandler {
5
5
  callback: ProviderInterfaceCallback;
6
6
  type: string;