@acala-network/chopsticks-core 0.8.0-5 → 0.8.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/lib/blockchain/block-builder.d.ts +2 -2
- package/lib/blockchain/block-builder.js +10 -6
- package/lib/blockchain/index.d.ts +2 -1
- package/lib/blockchain/index.js +17 -4
- package/lib/blockchain/txpool.d.ts +1 -0
- package/lib/blockchain/txpool.js +3 -1
- package/lib/db/entities.d.ts +1 -2
- package/package.json +4 -5
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Header, TransactionValidityError } from '@polkadot/types/interfaces';
|
|
2
2
|
import { Block, TaskCallResponse } from './block';
|
|
3
3
|
import { HexString } from '@polkadot/util/types';
|
|
4
|
-
export declare const newHeader: (head: Block) => Promise<Header>;
|
|
5
|
-
export declare const buildBlock: (head: Block, inherents: HexString[], extrinsics: HexString[], ump: Record<number, HexString[]>, onApplyExtrinsicError: (extrinsic: HexString, error: TransactionValidityError) => void) => Promise<[Block, HexString[]]>;
|
|
4
|
+
export declare const newHeader: (head: Block, unsafeBlockHeight?: number) => Promise<Header>;
|
|
5
|
+
export declare const buildBlock: (head: Block, inherents: HexString[], extrinsics: HexString[], ump: Record<number, HexString[]>, onApplyExtrinsicError: (extrinsic: HexString, error: TransactionValidityError) => void, unsafeBlockHeight?: number) => Promise<[Block, HexString[]]>;
|
|
6
6
|
export declare const dryRunExtrinsic: (head: Block, inherents: HexString[], extrinsic: HexString | {
|
|
7
7
|
call: HexString;
|
|
8
8
|
address: string;
|
|
@@ -42,7 +42,7 @@ const getNewSlot = (digest, slotNumber) => {
|
|
|
42
42
|
}
|
|
43
43
|
return digest.toJSON();
|
|
44
44
|
};
|
|
45
|
-
const newHeader = (head) => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
const newHeader = (head, unsafeBlockHeight) => __awaiter(void 0, void 0, void 0, function* () {
|
|
46
46
|
var _a, _b;
|
|
47
47
|
const meta = yield head.meta;
|
|
48
48
|
const parentHeader = yield head.header;
|
|
@@ -80,7 +80,7 @@ const newHeader = (head) => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
80
80
|
}
|
|
81
81
|
const header = meta.registry.createType('Header', {
|
|
82
82
|
parentHash: head.hash,
|
|
83
|
-
number: head.number + 1,
|
|
83
|
+
number: unsafeBlockHeight !== null && unsafeBlockHeight !== void 0 ? unsafeBlockHeight : head.number + 1,
|
|
84
84
|
stateRoot: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
85
85
|
extrinsicsRoot: '0x0000000000000000000000000000000000000000000000000000000000000000',
|
|
86
86
|
digest: {
|
|
@@ -126,14 +126,18 @@ const initNewBlock = (head, header, inherents, storageLayer) => __awaiter(void 0
|
|
|
126
126
|
layers: layers,
|
|
127
127
|
};
|
|
128
128
|
});
|
|
129
|
-
const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicError) => __awaiter(void 0, void 0, void 0, function* () {
|
|
129
|
+
const buildBlock = (head, inherents, extrinsics, ump, onApplyExtrinsicError, unsafeBlockHeight) => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
130
|
const registry = yield head.registry;
|
|
131
|
-
const header = yield (0, exports.newHeader)(head);
|
|
131
|
+
const header = yield (0, exports.newHeader)(head, unsafeBlockHeight);
|
|
132
|
+
const newBlockNumber = header.number.toNumber();
|
|
133
|
+
if (newBlockNumber < head.number) {
|
|
134
|
+
throw new Error('unsafeBlockHeight is not allowed to be less than current block number');
|
|
135
|
+
}
|
|
132
136
|
logger.info({
|
|
133
|
-
number:
|
|
137
|
+
number: newBlockNumber,
|
|
134
138
|
extrinsicsCount: extrinsics.length,
|
|
135
139
|
umpCount: Object.keys(ump).length,
|
|
136
|
-
}, `Try building block #${
|
|
140
|
+
}, `Try building block #${newBlockNumber.toLocaleString()}`);
|
|
137
141
|
let layer;
|
|
138
142
|
// apply ump via storage override hack
|
|
139
143
|
if (Object.keys(ump).length > 0) {
|
|
@@ -32,13 +32,14 @@ export declare class Blockchain {
|
|
|
32
32
|
readonly db: DataSource | undefined;
|
|
33
33
|
readonly mockSignatureHost: boolean;
|
|
34
34
|
readonly allowUnresolvedImports: boolean;
|
|
35
|
-
readonly runtimeLogLevel: number;
|
|
36
35
|
readonly registeredTypes: RegisteredTypes;
|
|
37
36
|
readonly headState: HeadState;
|
|
38
37
|
readonly offchainWorker: OffchainWorker | undefined;
|
|
39
38
|
constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost, allowUnresolvedImports, runtimeLogLevel, registeredTypes, offchainWorker, maxMemoryBlockCount, }: Options);
|
|
40
39
|
get head(): Block;
|
|
41
40
|
get txPool(): TxPool;
|
|
41
|
+
get runtimeLogLevel(): number;
|
|
42
|
+
set runtimeLogLevel(level: number);
|
|
42
43
|
saveBlockToDB(block: Block): Promise<void>;
|
|
43
44
|
/**
|
|
44
45
|
* Try to load block from db and register it
|
package/lib/blockchain/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
19
19
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
20
20
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
21
|
};
|
|
22
|
-
var _Blockchain_instances, _Blockchain_txpool, _Blockchain_inherentProvider, _Blockchain_head, _Blockchain_blocksByNumber, _Blockchain_blocksByHash, _Blockchain_loadingBlocks, _Blockchain_maxMemoryBlockCount, _Blockchain_registerBlock;
|
|
22
|
+
var _Blockchain_instances, _Blockchain_runtimeLogLevel, _Blockchain_txpool, _Blockchain_inherentProvider, _Blockchain_head, _Blockchain_blocksByNumber, _Blockchain_blocksByHash, _Blockchain_loadingBlocks, _Blockchain_maxMemoryBlockCount, _Blockchain_registerBlock;
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
24
|
exports.Blockchain = void 0;
|
|
25
25
|
const util_crypto_1 = require("@polkadot/util-crypto");
|
|
@@ -37,6 +37,7 @@ class Blockchain {
|
|
|
37
37
|
constructor({ api, buildBlockMode, inherentProvider, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 2000, }) {
|
|
38
38
|
_Blockchain_instances.add(this);
|
|
39
39
|
this.uid = Math.random().toString(36).substring(2);
|
|
40
|
+
_Blockchain_runtimeLogLevel.set(this, void 0);
|
|
40
41
|
_Blockchain_txpool.set(this, void 0);
|
|
41
42
|
_Blockchain_inherentProvider.set(this, void 0);
|
|
42
43
|
_Blockchain_head.set(this, void 0);
|
|
@@ -48,7 +49,7 @@ class Blockchain {
|
|
|
48
49
|
this.db = db;
|
|
49
50
|
this.mockSignatureHost = mockSignatureHost;
|
|
50
51
|
this.allowUnresolvedImports = allowUnresolvedImports;
|
|
51
|
-
this
|
|
52
|
+
__classPrivateFieldSet(this, _Blockchain_runtimeLogLevel, runtimeLogLevel, "f");
|
|
52
53
|
this.registeredTypes = registeredTypes;
|
|
53
54
|
__classPrivateFieldSet(this, _Blockchain_head, new block_1.Block(this, header.number, header.hash), "f");
|
|
54
55
|
__classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, __classPrivateFieldGet(this, _Blockchain_head, "f"));
|
|
@@ -66,6 +67,13 @@ class Blockchain {
|
|
|
66
67
|
get txPool() {
|
|
67
68
|
return __classPrivateFieldGet(this, _Blockchain_txpool, "f");
|
|
68
69
|
}
|
|
70
|
+
get runtimeLogLevel() {
|
|
71
|
+
return __classPrivateFieldGet(this, _Blockchain_runtimeLogLevel, "f");
|
|
72
|
+
}
|
|
73
|
+
set runtimeLogLevel(level) {
|
|
74
|
+
__classPrivateFieldSet(this, _Blockchain_runtimeLogLevel, level, "f");
|
|
75
|
+
logger.debug(`Runtime log level set to ${logger.level}`);
|
|
76
|
+
}
|
|
69
77
|
saveBlockToDB(block) {
|
|
70
78
|
return __awaiter(this, void 0, void 0, function* () {
|
|
71
79
|
if (this.db) {
|
|
@@ -101,7 +109,12 @@ class Blockchain {
|
|
|
101
109
|
const { hash, number, header, extrinsics, parentHash } = blockData;
|
|
102
110
|
const parentBlock = parentHash ? __classPrivateFieldGet(this, _Blockchain_blocksByHash, "f")[parentHash] : undefined;
|
|
103
111
|
const storageDiff = (_a = blockData.storageDiff) !== null && _a !== void 0 ? _a : undefined;
|
|
104
|
-
const
|
|
112
|
+
const registry = yield this.head.registry;
|
|
113
|
+
const block = new block_1.Block(this, number, hash, parentBlock, {
|
|
114
|
+
header: registry.createType('Header', header),
|
|
115
|
+
extrinsics,
|
|
116
|
+
storageDiff,
|
|
117
|
+
});
|
|
105
118
|
__classPrivateFieldGet(this, _Blockchain_instances, "m", _Blockchain_registerBlock).call(this, block);
|
|
106
119
|
return block;
|
|
107
120
|
}
|
|
@@ -358,7 +371,7 @@ class Blockchain {
|
|
|
358
371
|
}
|
|
359
372
|
}
|
|
360
373
|
exports.Blockchain = Blockchain;
|
|
361
|
-
_Blockchain_txpool = new WeakMap(), _Blockchain_inherentProvider = new WeakMap(), _Blockchain_head = new WeakMap(), _Blockchain_blocksByNumber = new WeakMap(), _Blockchain_blocksByHash = new WeakMap(), _Blockchain_loadingBlocks = new WeakMap(), _Blockchain_maxMemoryBlockCount = new WeakMap(), _Blockchain_instances = new WeakSet(), _Blockchain_registerBlock = function _Blockchain_registerBlock(block) {
|
|
374
|
+
_Blockchain_runtimeLogLevel = new WeakMap(), _Blockchain_txpool = new WeakMap(), _Blockchain_inherentProvider = new WeakMap(), _Blockchain_head = new WeakMap(), _Blockchain_blocksByNumber = new WeakMap(), _Blockchain_blocksByHash = new WeakMap(), _Blockchain_loadingBlocks = new WeakMap(), _Blockchain_maxMemoryBlockCount = new WeakMap(), _Blockchain_instances = new WeakSet(), _Blockchain_registerBlock = function _Blockchain_registerBlock(block) {
|
|
362
375
|
// if exceed max memory block count, delete the oldest block
|
|
363
376
|
if (__classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").size === __classPrivateFieldGet(this, _Blockchain_maxMemoryBlockCount, "f")) {
|
|
364
377
|
const firstKey = __classPrivateFieldGet(this, _Blockchain_blocksByNumber, "f").keys().next().value;
|
package/lib/blockchain/txpool.js
CHANGED
|
@@ -131,6 +131,7 @@ class TxPool {
|
|
|
131
131
|
const upwardMessages = (params === null || params === void 0 ? void 0 : params.upwardMessages) || Object.assign({}, __classPrivateFieldGet(this, _TxPool_ump, "f"));
|
|
132
132
|
const downwardMessages = (params === null || params === void 0 ? void 0 : params.downwardMessages) || __classPrivateFieldGet(this, _TxPool_dmp, "f").splice(0);
|
|
133
133
|
const horizontalMessages = (params === null || params === void 0 ? void 0 : params.horizontalMessages) || Object.assign({}, __classPrivateFieldGet(this, _TxPool_hrmp, "f"));
|
|
134
|
+
const unsafeBlockHeight = params === null || params === void 0 ? void 0 : params.unsafeBlockHeight;
|
|
134
135
|
if (!(params === null || params === void 0 ? void 0 : params.upwardMessages)) {
|
|
135
136
|
for (const id of Object.keys(__classPrivateFieldGet(this, _TxPool_ump, "f"))) {
|
|
136
137
|
delete __classPrivateFieldGet(this, _TxPool_ump, "f")[id];
|
|
@@ -146,6 +147,7 @@ class TxPool {
|
|
|
146
147
|
upwardMessages,
|
|
147
148
|
downwardMessages,
|
|
148
149
|
horizontalMessages,
|
|
150
|
+
unsafeBlockHeight,
|
|
149
151
|
});
|
|
150
152
|
});
|
|
151
153
|
}
|
|
@@ -206,7 +208,7 @@ _TxPool_chain = new WeakMap(), _TxPool_pool = new WeakMap(), _TxPool_ump = new W
|
|
|
206
208
|
const inherents = yield __classPrivateFieldGet(this, _TxPool_inherentProvider, "f").createInherents(head, params);
|
|
207
209
|
const [newBlock, pendingExtrinsics] = yield (0, block_builder_1.buildBlock)(head, inherents, params.transactions, params.upwardMessages, (extrinsic, error) => {
|
|
208
210
|
this.event.emit(exports.APPLY_EXTRINSIC_ERROR, [extrinsic, error]);
|
|
209
|
-
});
|
|
211
|
+
}, params.unsafeBlockHeight);
|
|
210
212
|
for (const extrinsic of pendingExtrinsics) {
|
|
211
213
|
__classPrivateFieldGet(this, _TxPool_pool, "f").push({ extrinsic, signer: yield __classPrivateFieldGet(this, _TxPool_instances, "m", _TxPool_getSigner).call(this, extrinsic) });
|
|
212
214
|
}
|
package/lib/db/entities.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EntitySchema } from 'typeorm';
|
|
2
|
-
import { Header } from '@polkadot/types/interfaces';
|
|
3
2
|
import { HexString } from '@polkadot/util/types';
|
|
4
3
|
export declare const KeyValuePair: EntitySchema<{
|
|
5
4
|
blockHash: string;
|
|
@@ -9,7 +8,7 @@ export declare const KeyValuePair: EntitySchema<{
|
|
|
9
8
|
export declare const BlockEntity: EntitySchema<{
|
|
10
9
|
hash: HexString;
|
|
11
10
|
number: number;
|
|
12
|
-
header:
|
|
11
|
+
header: object;
|
|
13
12
|
parentHash: HexString | null;
|
|
14
13
|
extrinsics: HexString[];
|
|
15
14
|
storageDiff: Record<HexString, HexString | null> | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-core",
|
|
3
|
-
"version": "0.8.0
|
|
3
|
+
"version": "0.8.0",
|
|
4
4
|
"author": "Bryan Chen <xlchen1291@gmail.com>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"scripts": {
|
|
@@ -9,10 +9,10 @@
|
|
|
9
9
|
"build": "yarn pack-wasm; tsc -p ./tsconfig.json"
|
|
10
10
|
},
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@acala-network/chopsticks-executor": "0.8.0
|
|
12
|
+
"@acala-network/chopsticks-executor": "0.8.0",
|
|
13
13
|
"@polkadot/api": "^10.9.1",
|
|
14
14
|
"@polkadot/util-crypto": "^12.3.2",
|
|
15
|
-
"axios": "^1.
|
|
15
|
+
"axios": "^1.5.0",
|
|
16
16
|
"eventemitter3": "^5.0.1",
|
|
17
17
|
"localforage": "^1.10.0",
|
|
18
18
|
"lodash": "^4.17.21",
|
|
@@ -44,6 +44,5 @@
|
|
|
44
44
|
"default": "./lib/*.js"
|
|
45
45
|
},
|
|
46
46
|
"./package.json": "./package.json"
|
|
47
|
-
}
|
|
48
|
-
"stableVersion": "0.7.3"
|
|
47
|
+
}
|
|
49
48
|
}
|