@acala-network/chopsticks-core 1.0.4 → 1.0.5
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/index.d.ts +4 -1
- package/dist/cjs/blockchain/index.js +4 -2
- package/dist/cjs/setup.d.ts +2 -0
- package/dist/cjs/setup.js +2 -1
- package/dist/cjs/wasm-executor/index.js +6 -3
- package/dist/esm/blockchain/index.d.ts +4 -1
- package/dist/esm/blockchain/index.js +4 -2
- package/dist/esm/setup.d.ts +2 -0
- package/dist/esm/setup.js +2 -1
- package/dist/esm/wasm-executor/index.js +6 -3
- package/package.json +2 -2
|
@@ -39,6 +39,8 @@ export interface Options {
|
|
|
39
39
|
maxMemoryBlockCount?: number;
|
|
40
40
|
/** Whether to process queued messages */
|
|
41
41
|
processQueuedMessages?: boolean;
|
|
42
|
+
/** Whether to save blocks to db */
|
|
43
|
+
saveBlocks?: boolean;
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Local blockchain which provides access to blocks, txpool and methods
|
|
@@ -79,10 +81,11 @@ export declare class Blockchain {
|
|
|
79
81
|
readonly headState: HeadState;
|
|
80
82
|
readonly offchainWorker: OffchainWorker | undefined;
|
|
81
83
|
readonly processQueuedMessages: boolean;
|
|
84
|
+
readonly saveBlocks: boolean;
|
|
82
85
|
/**
|
|
83
86
|
* @param options - Options for instantiating the blockchain
|
|
84
87
|
*/
|
|
85
|
-
constructor({ api, buildBlockMode, inherentProviders, db, header, mockSignatureHost, allowUnresolvedImports, runtimeLogLevel, registeredTypes, offchainWorker, maxMemoryBlockCount, processQueuedMessages, }: Options);
|
|
88
|
+
constructor({ api, buildBlockMode, inherentProviders, db, header, mockSignatureHost, allowUnresolvedImports, runtimeLogLevel, registeredTypes, offchainWorker, maxMemoryBlockCount, processQueuedMessages, saveBlocks, }: Options);
|
|
86
89
|
get head(): Block;
|
|
87
90
|
get txPool(): TxPool;
|
|
88
91
|
get runtimeLogLevel(): number;
|
|
@@ -111,7 +111,7 @@ class Blockchain {
|
|
|
111
111
|
return _class_private_field_get(this, _registryBuilder).call(this, cacheKey, metadata, version);
|
|
112
112
|
}
|
|
113
113
|
async saveBlockToDB(block) {
|
|
114
|
-
if (this.db) {
|
|
114
|
+
if (this.db && this.saveBlocks) {
|
|
115
115
|
const { hash, number, header, extrinsics } = block;
|
|
116
116
|
// delete old ones with the same block number if any, keep the latest one
|
|
117
117
|
await this.db.saveBlock({
|
|
@@ -414,7 +414,7 @@ class Blockchain {
|
|
|
414
414
|
}
|
|
415
415
|
/**
|
|
416
416
|
* @param options - Options for instantiating the blockchain
|
|
417
|
-
*/ constructor({ api, buildBlockMode, inherentProviders, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 500, processQueuedMessages = true }){
|
|
417
|
+
*/ constructor({ api, buildBlockMode, inherentProviders, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 500, processQueuedMessages = true, saveBlocks = true }){
|
|
418
418
|
_class_private_method_init(this, _registerBlock);
|
|
419
419
|
/** API instance, for getting on-chain data. */ _define_property(this, "api", void 0);
|
|
420
420
|
/** Datasource for caching storage and blocks data. */ _define_property(this, "db", void 0);
|
|
@@ -456,6 +456,7 @@ class Blockchain {
|
|
|
456
456
|
value: void 0
|
|
457
457
|
});
|
|
458
458
|
_define_property(this, "processQueuedMessages", true);
|
|
459
|
+
_define_property(this, "saveBlocks", void 0);
|
|
459
460
|
// first arg is used as cache key
|
|
460
461
|
_class_private_field_init(this, _registryBuilder, {
|
|
461
462
|
writable: true,
|
|
@@ -487,6 +488,7 @@ class Blockchain {
|
|
|
487
488
|
}
|
|
488
489
|
_class_private_field_set(this, _maxMemoryBlockCount, maxMemoryBlockCount);
|
|
489
490
|
this.processQueuedMessages = processQueuedMessages;
|
|
491
|
+
this.saveBlocks = saveBlocks;
|
|
490
492
|
}
|
|
491
493
|
}
|
|
492
494
|
function registerBlock(block) {
|
package/dist/cjs/setup.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type SetupOptions = {
|
|
|
18
18
|
offchainWorker?: boolean;
|
|
19
19
|
maxMemoryBlockCount?: number;
|
|
20
20
|
processQueuedMessages?: boolean;
|
|
21
|
+
saveBlocks?: boolean;
|
|
21
22
|
rpcTimeout?: number;
|
|
22
23
|
hooks?: {
|
|
23
24
|
apiFetching?: () => void;
|
|
@@ -38,6 +39,7 @@ export declare const processOptions: (options: SetupOptions) => Promise<{
|
|
|
38
39
|
offchainWorker?: boolean;
|
|
39
40
|
maxMemoryBlockCount?: number;
|
|
40
41
|
processQueuedMessages?: boolean;
|
|
42
|
+
saveBlocks?: boolean;
|
|
41
43
|
rpcTimeout?: number;
|
|
42
44
|
hooks?: {
|
|
43
45
|
apiFetching?: () => void;
|
package/dist/cjs/setup.js
CHANGED
|
@@ -88,7 +88,8 @@ const setup = async (options)=>{
|
|
|
88
88
|
registeredTypes: opts.registeredTypes || {},
|
|
89
89
|
offchainWorker: opts.offchainWorker,
|
|
90
90
|
maxMemoryBlockCount: opts.maxMemoryBlockCount,
|
|
91
|
-
processQueuedMessages: opts.processQueuedMessages
|
|
91
|
+
processQueuedMessages: opts.processQueuedMessages,
|
|
92
|
+
saveBlocks: opts.saveBlocks
|
|
92
93
|
});
|
|
93
94
|
if (opts.genesis) {
|
|
94
95
|
// build 1st block
|
|
@@ -135,20 +135,23 @@ const createProof = async (nodes, updates)=>{
|
|
|
135
135
|
nodes: newNodes
|
|
136
136
|
};
|
|
137
137
|
};
|
|
138
|
+
let nextTaskId = 0;
|
|
138
139
|
const runTask = async (task, callback = emptyTaskHandler)=>{
|
|
140
|
+
const taskId = nextTaskId++;
|
|
139
141
|
const task2 = {
|
|
140
142
|
...task,
|
|
143
|
+
id: taskId,
|
|
141
144
|
storageProofSize: task.storageProofSize ?? 0
|
|
142
145
|
};
|
|
143
146
|
const worker = await getWorker();
|
|
144
|
-
logger.trace((0, _logger.truncate)(task2),
|
|
147
|
+
logger.trace((0, _logger.truncate)(task2), `runTask #${taskId}`);
|
|
145
148
|
const response = await worker.remote.runTask(task2, _comlink.proxy(callback));
|
|
146
149
|
if ('Call' in response) {
|
|
147
|
-
logger.trace((0, _logger.truncate)(response.Call),
|
|
150
|
+
logger.trace((0, _logger.truncate)(response.Call), `taskResponse #${taskId}`);
|
|
148
151
|
} else {
|
|
149
152
|
logger.trace({
|
|
150
153
|
response
|
|
151
|
-
},
|
|
154
|
+
}, `taskResponse ${taskId}`);
|
|
152
155
|
}
|
|
153
156
|
return response;
|
|
154
157
|
};
|
|
@@ -39,6 +39,8 @@ export interface Options {
|
|
|
39
39
|
maxMemoryBlockCount?: number;
|
|
40
40
|
/** Whether to process queued messages */
|
|
41
41
|
processQueuedMessages?: boolean;
|
|
42
|
+
/** Whether to save blocks to db */
|
|
43
|
+
saveBlocks?: boolean;
|
|
42
44
|
}
|
|
43
45
|
/**
|
|
44
46
|
* Local blockchain which provides access to blocks, txpool and methods
|
|
@@ -79,10 +81,11 @@ export declare class Blockchain {
|
|
|
79
81
|
readonly headState: HeadState;
|
|
80
82
|
readonly offchainWorker: OffchainWorker | undefined;
|
|
81
83
|
readonly processQueuedMessages: boolean;
|
|
84
|
+
readonly saveBlocks: boolean;
|
|
82
85
|
/**
|
|
83
86
|
* @param options - Options for instantiating the blockchain
|
|
84
87
|
*/
|
|
85
|
-
constructor({ api, buildBlockMode, inherentProviders, db, header, mockSignatureHost, allowUnresolvedImports, runtimeLogLevel, registeredTypes, offchainWorker, maxMemoryBlockCount, processQueuedMessages, }: Options);
|
|
88
|
+
constructor({ api, buildBlockMode, inherentProviders, db, header, mockSignatureHost, allowUnresolvedImports, runtimeLogLevel, registeredTypes, offchainWorker, maxMemoryBlockCount, processQueuedMessages, saveBlocks, }: Options);
|
|
86
89
|
get head(): Block;
|
|
87
90
|
get txPool(): TxPool;
|
|
88
91
|
get runtimeLogLevel(): number;
|
|
@@ -52,6 +52,7 @@ const logger = defaultLogger.child({
|
|
|
52
52
|
offchainWorker;
|
|
53
53
|
#maxMemoryBlockCount;
|
|
54
54
|
processQueuedMessages = true;
|
|
55
|
+
saveBlocks;
|
|
55
56
|
// first arg is used as cache key
|
|
56
57
|
#registryBuilder = _.memoize(async (_cacheKey, metadata, version)=>{
|
|
57
58
|
const chain = await this.api.chain;
|
|
@@ -66,7 +67,7 @@ const logger = defaultLogger.child({
|
|
|
66
67
|
});
|
|
67
68
|
/**
|
|
68
69
|
* @param options - Options for instantiating the blockchain
|
|
69
|
-
*/ constructor({ api, buildBlockMode, inherentProviders, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 500, processQueuedMessages = true }){
|
|
70
|
+
*/ constructor({ api, buildBlockMode, inherentProviders, db, header, mockSignatureHost = false, allowUnresolvedImports = false, runtimeLogLevel = 0, registeredTypes = {}, offchainWorker = false, maxMemoryBlockCount = 500, processQueuedMessages = true, saveBlocks = true }){
|
|
70
71
|
this.api = api;
|
|
71
72
|
this.db = db;
|
|
72
73
|
this.mockSignatureHost = mockSignatureHost;
|
|
@@ -83,6 +84,7 @@ const logger = defaultLogger.child({
|
|
|
83
84
|
}
|
|
84
85
|
this.#maxMemoryBlockCount = maxMemoryBlockCount;
|
|
85
86
|
this.processQueuedMessages = processQueuedMessages;
|
|
87
|
+
this.saveBlocks = saveBlocks;
|
|
86
88
|
}
|
|
87
89
|
#registerBlock(block) {
|
|
88
90
|
// if exceed max memory block count, delete the oldest block
|
|
@@ -113,7 +115,7 @@ const logger = defaultLogger.child({
|
|
|
113
115
|
return this.#registryBuilder(cacheKey, metadata, version);
|
|
114
116
|
}
|
|
115
117
|
async saveBlockToDB(block) {
|
|
116
|
-
if (this.db) {
|
|
118
|
+
if (this.db && this.saveBlocks) {
|
|
117
119
|
const { hash, number, header, extrinsics } = block;
|
|
118
120
|
// delete old ones with the same block number if any, keep the latest one
|
|
119
121
|
await this.db.saveBlock({
|
package/dist/esm/setup.d.ts
CHANGED
|
@@ -18,6 +18,7 @@ export type SetupOptions = {
|
|
|
18
18
|
offchainWorker?: boolean;
|
|
19
19
|
maxMemoryBlockCount?: number;
|
|
20
20
|
processQueuedMessages?: boolean;
|
|
21
|
+
saveBlocks?: boolean;
|
|
21
22
|
rpcTimeout?: number;
|
|
22
23
|
hooks?: {
|
|
23
24
|
apiFetching?: () => void;
|
|
@@ -38,6 +39,7 @@ export declare const processOptions: (options: SetupOptions) => Promise<{
|
|
|
38
39
|
offchainWorker?: boolean;
|
|
39
40
|
maxMemoryBlockCount?: number;
|
|
40
41
|
processQueuedMessages?: boolean;
|
|
42
|
+
saveBlocks?: boolean;
|
|
41
43
|
rpcTimeout?: number;
|
|
42
44
|
hooks?: {
|
|
43
45
|
apiFetching?: () => void;
|
package/dist/esm/setup.js
CHANGED
|
@@ -70,7 +70,8 @@ export const setup = async (options)=>{
|
|
|
70
70
|
registeredTypes: opts.registeredTypes || {},
|
|
71
71
|
offchainWorker: opts.offchainWorker,
|
|
72
72
|
maxMemoryBlockCount: opts.maxMemoryBlockCount,
|
|
73
|
-
processQueuedMessages: opts.processQueuedMessages
|
|
73
|
+
processQueuedMessages: opts.processQueuedMessages,
|
|
74
|
+
saveBlocks: opts.saveBlocks
|
|
74
75
|
});
|
|
75
76
|
if (opts.genesis) {
|
|
76
77
|
// build 1st block
|
|
@@ -48,20 +48,23 @@ export const createProof = async (nodes, updates)=>{
|
|
|
48
48
|
nodes: newNodes
|
|
49
49
|
};
|
|
50
50
|
};
|
|
51
|
+
let nextTaskId = 0;
|
|
51
52
|
export const runTask = async (task, callback = emptyTaskHandler)=>{
|
|
53
|
+
const taskId = nextTaskId++;
|
|
52
54
|
const task2 = {
|
|
53
55
|
...task,
|
|
56
|
+
id: taskId,
|
|
54
57
|
storageProofSize: task.storageProofSize ?? 0
|
|
55
58
|
};
|
|
56
59
|
const worker = await getWorker();
|
|
57
|
-
logger.trace(truncate(task2),
|
|
60
|
+
logger.trace(truncate(task2), `runTask #${taskId}`);
|
|
58
61
|
const response = await worker.remote.runTask(task2, Comlink.proxy(callback));
|
|
59
62
|
if ('Call' in response) {
|
|
60
|
-
logger.trace(truncate(response.Call),
|
|
63
|
+
logger.trace(truncate(response.Call), `taskResponse #${taskId}`);
|
|
61
64
|
} else {
|
|
62
65
|
logger.trace({
|
|
63
66
|
response
|
|
64
|
-
},
|
|
67
|
+
}, `taskResponse ${taskId}`);
|
|
65
68
|
}
|
|
66
69
|
return response;
|
|
67
70
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@acala-network/chopsticks-core",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"author": "Acala Developers <hello@acala.network>",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"depcheck": "npx depcheck"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@acala-network/chopsticks-executor": "1.0.
|
|
17
|
+
"@acala-network/chopsticks-executor": "1.0.5",
|
|
18
18
|
"@polkadot/rpc-provider": "^15.7.1",
|
|
19
19
|
"@polkadot/types": "^15.7.1",
|
|
20
20
|
"@polkadot/types-codec": "^15.7.1",
|