@acala-network/chopsticks-core 0.8.0-5 → 0.8.0-6
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.
|
@@ -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) {
|
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/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-6",
|
|
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-6",
|
|
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",
|