@typeberry/jam 0.1.1 → 0.1.2-3178190
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/README.md +1 -0
- package/block-generator/index.js +164 -107
- package/block-generator/index.js.map +1 -1
- package/importer/index.js +273 -199
- package/importer/index.js.map +1 -1
- package/index.js +435 -365
- package/index.js.map +1 -1
- package/jam-network/index.js +214 -171
- package/jam-network/index.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
package/block-generator/index.js
CHANGED
|
@@ -3575,6 +3575,7 @@ var GpVersion;
|
|
|
3575
3575
|
GpVersion["V0_6_7"] = "0.6.7";
|
|
3576
3576
|
GpVersion["V0_7_0"] = "0.7.0";
|
|
3577
3577
|
GpVersion["V0_7_1"] = "0.7.1-preview";
|
|
3578
|
+
GpVersion["V0_7_2"] = "0.7.2-preview";
|
|
3578
3579
|
})(GpVersion || (GpVersion = {}));
|
|
3579
3580
|
var TestSuite;
|
|
3580
3581
|
(function (TestSuite) {
|
|
@@ -3582,7 +3583,7 @@ var TestSuite;
|
|
|
3582
3583
|
TestSuite["JAMDUNA"] = "jamduna";
|
|
3583
3584
|
})(TestSuite || (TestSuite = {}));
|
|
3584
3585
|
const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
|
|
3585
|
-
const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1];
|
|
3586
|
+
const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
|
|
3586
3587
|
const env = typeof process === "undefined" ? {} : process.env;
|
|
3587
3588
|
const DEFAULT_VERSION = GpVersion.V0_7_0;
|
|
3588
3589
|
let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
|
|
@@ -3591,20 +3592,26 @@ function parseCurrentVersion(env) {
|
|
|
3591
3592
|
if (env === undefined) {
|
|
3592
3593
|
return undefined;
|
|
3593
3594
|
}
|
|
3594
|
-
|
|
3595
|
-
|
|
3596
|
-
|
|
3595
|
+
switch (env) {
|
|
3596
|
+
case GpVersion.V0_6_7:
|
|
3597
|
+
case GpVersion.V0_7_0:
|
|
3598
|
+
case GpVersion.V0_7_1:
|
|
3599
|
+
case GpVersion.V0_7_2:
|
|
3600
|
+
return env;
|
|
3601
|
+
default:
|
|
3602
|
+
throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
|
|
3597
3603
|
}
|
|
3598
|
-
return version;
|
|
3599
3604
|
}
|
|
3600
3605
|
function parseCurrentSuite(env) {
|
|
3601
3606
|
if (env === undefined)
|
|
3602
3607
|
return undefined;
|
|
3603
|
-
|
|
3604
|
-
|
|
3605
|
-
|
|
3608
|
+
switch (env) {
|
|
3609
|
+
case TestSuite.W3F_DAVXY:
|
|
3610
|
+
case TestSuite.JAMDUNA:
|
|
3611
|
+
return env;
|
|
3612
|
+
default:
|
|
3613
|
+
throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
|
|
3606
3614
|
}
|
|
3607
|
-
return val;
|
|
3608
3615
|
}
|
|
3609
3616
|
class Compatibility {
|
|
3610
3617
|
static override(version) {
|
|
@@ -3766,6 +3773,34 @@ class WithDebug {
|
|
|
3766
3773
|
}
|
|
3767
3774
|
}
|
|
3768
3775
|
|
|
3776
|
+
;// CONCATENATED MODULE: ./packages/core/utils/dev.ts
|
|
3777
|
+
const dev_env = typeof process === "undefined" ? {} : process.env;
|
|
3778
|
+
/**
|
|
3779
|
+
* The function will produce relative path resolver that is adjusted
|
|
3780
|
+
* for package location within the workspace.
|
|
3781
|
+
*
|
|
3782
|
+
* Example:
|
|
3783
|
+
* $ npm start -w @typeberry/jam
|
|
3784
|
+
*
|
|
3785
|
+
* The above command will run `./bin/jam/index.js`, however we would
|
|
3786
|
+
* still want relative paths to be resolved according to top-level workspace
|
|
3787
|
+
* directory.
|
|
3788
|
+
*
|
|
3789
|
+
* So the caller, passes the absolute workspace path as argument and get's
|
|
3790
|
+
* a function that can properly resolve relative paths.
|
|
3791
|
+
*
|
|
3792
|
+
* NOTE: the translation happens only for development build! When
|
|
3793
|
+
* we build a single library from our project, we no longer mangle the paths.
|
|
3794
|
+
*/
|
|
3795
|
+
const workspacePathFix = dev_env.NODE_ENV === "development"
|
|
3796
|
+
? (workspacePath) => (p) => {
|
|
3797
|
+
if (p.startsWith("/")) {
|
|
3798
|
+
return p;
|
|
3799
|
+
}
|
|
3800
|
+
return `${workspacePath}/${p}`;
|
|
3801
|
+
}
|
|
3802
|
+
: () => (p) => p;
|
|
3803
|
+
|
|
3769
3804
|
;// CONCATENATED MODULE: ./packages/core/utils/opaque.ts
|
|
3770
3805
|
/**
|
|
3771
3806
|
* @fileoverview `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
|
|
@@ -4109,6 +4144,7 @@ function isResult(x) {
|
|
|
4109
4144
|
|
|
4110
4145
|
|
|
4111
4146
|
|
|
4147
|
+
|
|
4112
4148
|
;// CONCATENATED MODULE: ./packages/core/bytes/bitvec.ts
|
|
4113
4149
|
|
|
4114
4150
|
/**
|
|
@@ -12946,6 +12982,23 @@ function parseLevel(lvl) {
|
|
|
12946
12982
|
;// CONCATENATED MODULE: ./packages/core/logger/console.ts
|
|
12947
12983
|
// biome-ignore-all lint/suspicious/noConsole: logger
|
|
12948
12984
|
|
|
12985
|
+
function print(level, levelAndName, strings, data) {
|
|
12986
|
+
if (level < levelAndName[0]) {
|
|
12987
|
+
return;
|
|
12988
|
+
}
|
|
12989
|
+
const lvlText = Level[level].padEnd(5);
|
|
12990
|
+
const val = strings.map((v, idx) => `${v}${idx < data.length ? data[idx] : ""}`);
|
|
12991
|
+
const msg = `${lvlText} [${levelAndName[1]}] ${val.join("")}`;
|
|
12992
|
+
if (level === Level.WARN) {
|
|
12993
|
+
console.warn(msg);
|
|
12994
|
+
}
|
|
12995
|
+
else if (level === Level.ERROR) {
|
|
12996
|
+
console.error(msg);
|
|
12997
|
+
}
|
|
12998
|
+
else {
|
|
12999
|
+
console.info(msg);
|
|
13000
|
+
}
|
|
13001
|
+
}
|
|
12949
13002
|
/** An optimized logger that ignores `TRACE`, `DEBUG` and `LOG` messages.
|
|
12950
13003
|
*
|
|
12951
13004
|
* Use the `create` method to instantiate the right instance of a more specialized logger.
|
|
@@ -12976,109 +13029,91 @@ class ConsoleTransport {
|
|
|
12976
13029
|
constructor(options) {
|
|
12977
13030
|
this.options = options;
|
|
12978
13031
|
}
|
|
12979
|
-
insane(
|
|
13032
|
+
insane(_levelAndName, _strings, _data) {
|
|
12980
13033
|
/* no-op */
|
|
12981
13034
|
}
|
|
12982
|
-
trace(
|
|
13035
|
+
trace(_levelAndName, _strings, _data) {
|
|
12983
13036
|
/* no-op */
|
|
12984
13037
|
}
|
|
12985
|
-
log(
|
|
13038
|
+
log(_levelAndName, _strings, _data) {
|
|
12986
13039
|
/* no-op */
|
|
12987
13040
|
}
|
|
12988
|
-
info(
|
|
13041
|
+
info(_levelAndName, _strings, _data) {
|
|
12989
13042
|
/* no-op */
|
|
12990
13043
|
}
|
|
12991
|
-
warn(
|
|
12992
|
-
|
|
13044
|
+
warn(levelAndName, strings, data) {
|
|
13045
|
+
print(Level.WARN, levelAndName, strings, data);
|
|
12993
13046
|
}
|
|
12994
|
-
error(
|
|
12995
|
-
|
|
12996
|
-
}
|
|
12997
|
-
push(level, moduleName, val) {
|
|
12998
|
-
const shortModule = moduleName.replace(this.options.workingDir, "");
|
|
12999
|
-
const configuredLevel = findLevel(this.options, moduleName);
|
|
13000
|
-
const lvlText = Level[level].padEnd(5);
|
|
13001
|
-
if (level < configuredLevel) {
|
|
13002
|
-
return;
|
|
13003
|
-
}
|
|
13004
|
-
const msg = `${lvlText} [${shortModule}] ${val}`;
|
|
13005
|
-
if (level === Level.WARN) {
|
|
13006
|
-
console.warn(msg);
|
|
13007
|
-
}
|
|
13008
|
-
else if (level === Level.ERROR) {
|
|
13009
|
-
console.error(msg);
|
|
13010
|
-
}
|
|
13011
|
-
else {
|
|
13012
|
-
console.info(msg);
|
|
13013
|
-
}
|
|
13047
|
+
error(levelAndName, strings, data) {
|
|
13048
|
+
print(Level.ERROR, levelAndName, strings, data);
|
|
13014
13049
|
}
|
|
13015
13050
|
}
|
|
13016
13051
|
/**
|
|
13017
13052
|
* Insane version of console logger - supports insane level.
|
|
13018
13053
|
*/
|
|
13019
13054
|
class InsaneConsoleLogger extends ConsoleTransport {
|
|
13020
|
-
insane(
|
|
13021
|
-
|
|
13055
|
+
insane(levelAndName, strings, data) {
|
|
13056
|
+
print(Level.INSANE, levelAndName, strings, data);
|
|
13022
13057
|
}
|
|
13023
|
-
trace(
|
|
13024
|
-
|
|
13058
|
+
trace(levelAndName, strings, data) {
|
|
13059
|
+
print(Level.TRACE, levelAndName, strings, data);
|
|
13025
13060
|
}
|
|
13026
|
-
log(
|
|
13027
|
-
|
|
13061
|
+
log(levelAndName, strings, data) {
|
|
13062
|
+
print(Level.LOG, levelAndName, strings, data);
|
|
13028
13063
|
}
|
|
13029
|
-
info(
|
|
13030
|
-
|
|
13064
|
+
info(levelAndName, strings, data) {
|
|
13065
|
+
print(Level.INFO, levelAndName, strings, data);
|
|
13031
13066
|
}
|
|
13032
13067
|
}
|
|
13033
13068
|
/**
|
|
13034
13069
|
* A basic version of console logger - printing everything.
|
|
13035
13070
|
*/
|
|
13036
13071
|
class TraceConsoleTransport extends ConsoleTransport {
|
|
13037
|
-
insane(
|
|
13072
|
+
insane(_levelAndName, _strings, _data) {
|
|
13038
13073
|
/* no-op */
|
|
13039
13074
|
}
|
|
13040
|
-
trace(
|
|
13041
|
-
|
|
13075
|
+
trace(levelAndName, strings, data) {
|
|
13076
|
+
print(Level.TRACE, levelAndName, strings, data);
|
|
13042
13077
|
}
|
|
13043
|
-
log(
|
|
13044
|
-
|
|
13078
|
+
log(levelAndName, strings, data) {
|
|
13079
|
+
print(Level.LOG, levelAndName, strings, data);
|
|
13045
13080
|
}
|
|
13046
|
-
info(
|
|
13047
|
-
|
|
13081
|
+
info(levelAndName, strings, data) {
|
|
13082
|
+
print(Level.INFO, levelAndName, strings, data);
|
|
13048
13083
|
}
|
|
13049
13084
|
}
|
|
13050
13085
|
/**
|
|
13051
13086
|
* An optimized version of the logger - completely ignores `TRACE` level calls.
|
|
13052
13087
|
*/
|
|
13053
13088
|
class LogConsoleTransport extends ConsoleTransport {
|
|
13054
|
-
insane(
|
|
13089
|
+
insane(_levelAndName, _strings, _data) {
|
|
13055
13090
|
/* no-op */
|
|
13056
13091
|
}
|
|
13057
|
-
trace(
|
|
13092
|
+
trace(_levelAndName, _strings, _data) {
|
|
13058
13093
|
/* no-op */
|
|
13059
13094
|
}
|
|
13060
|
-
log(
|
|
13061
|
-
|
|
13095
|
+
log(levelAndName, strings, data) {
|
|
13096
|
+
print(Level.LOG, levelAndName, strings, data);
|
|
13062
13097
|
}
|
|
13063
|
-
info(
|
|
13064
|
-
|
|
13098
|
+
info(levelAndName, strings, data) {
|
|
13099
|
+
print(Level.INFO, levelAndName, strings, data);
|
|
13065
13100
|
}
|
|
13066
13101
|
}
|
|
13067
13102
|
/**
|
|
13068
13103
|
* An optimized version of the logger - completely ignores `TRACE` & `DEBUG` level calls.
|
|
13069
13104
|
*/
|
|
13070
13105
|
class InfoConsoleTransport extends ConsoleTransport {
|
|
13071
|
-
insane(
|
|
13106
|
+
insane(_levelAndName, _strings, _data) {
|
|
13072
13107
|
/* no-op */
|
|
13073
13108
|
}
|
|
13074
|
-
trace(
|
|
13109
|
+
trace(_levelAndName, _strings, _data) {
|
|
13075
13110
|
/* no-op */
|
|
13076
13111
|
}
|
|
13077
|
-
log(
|
|
13112
|
+
log(_levelAndName, _strings, _data) {
|
|
13078
13113
|
/* no-op */
|
|
13079
13114
|
}
|
|
13080
|
-
info(
|
|
13081
|
-
|
|
13115
|
+
info(levelAndName, strings, data) {
|
|
13116
|
+
print(Level.INFO, levelAndName, strings, data);
|
|
13082
13117
|
}
|
|
13083
13118
|
}
|
|
13084
13119
|
|
|
@@ -13115,11 +13150,6 @@ class Logger {
|
|
|
13115
13150
|
const module = moduleName ?? fName;
|
|
13116
13151
|
return new Logger(module.padStart(8, " "), GLOBAL_CONFIG);
|
|
13117
13152
|
}
|
|
13118
|
-
/**
|
|
13119
|
-
* Return currently configured level for given module. */
|
|
13120
|
-
static getLevel(moduleName) {
|
|
13121
|
-
return findLevel(GLOBAL_CONFIG.options, moduleName);
|
|
13122
|
-
}
|
|
13123
13153
|
/**
|
|
13124
13154
|
* Global configuration of all loggers.
|
|
13125
13155
|
*
|
|
@@ -13150,33 +13180,46 @@ class Logger {
|
|
|
13150
13180
|
const options = parseLoggerOptions(input, defaultLevel, workingDir);
|
|
13151
13181
|
Logger.configureAllFromOptions(options);
|
|
13152
13182
|
}
|
|
13183
|
+
cachedLevelAndName;
|
|
13153
13184
|
constructor(moduleName, config) {
|
|
13154
13185
|
this.moduleName = moduleName;
|
|
13155
13186
|
this.config = config;
|
|
13156
13187
|
}
|
|
13188
|
+
/** Return currently configured level for given module. */
|
|
13189
|
+
getLevel() {
|
|
13190
|
+
return this.getLevelAndName()[0];
|
|
13191
|
+
}
|
|
13192
|
+
getLevelAndName() {
|
|
13193
|
+
if (this.cachedLevelAndName === undefined) {
|
|
13194
|
+
const level = findLevel(this.config.options, this.moduleName);
|
|
13195
|
+
const shortName = this.moduleName.replace(this.config.options.workingDir, "");
|
|
13196
|
+
this.cachedLevelAndName = [level, shortName];
|
|
13197
|
+
}
|
|
13198
|
+
return this.cachedLevelAndName;
|
|
13199
|
+
}
|
|
13157
13200
|
/** Log a message with `INSANE` level. */
|
|
13158
|
-
insane(
|
|
13159
|
-
this.config.transport.insane(this.
|
|
13201
|
+
insane(strings, ...data) {
|
|
13202
|
+
this.config.transport.insane(this.getLevelAndName(), strings, data);
|
|
13160
13203
|
}
|
|
13161
13204
|
/** Log a message with `TRACE` level. */
|
|
13162
|
-
trace(
|
|
13163
|
-
this.config.transport.trace(this.
|
|
13205
|
+
trace(strings, ...data) {
|
|
13206
|
+
this.config.transport.trace(this.getLevelAndName(), strings, data);
|
|
13164
13207
|
}
|
|
13165
13208
|
/** Log a message with `DEBUG`/`LOG` level. */
|
|
13166
|
-
log(
|
|
13167
|
-
this.config.transport.log(this.
|
|
13209
|
+
log(strings, ...data) {
|
|
13210
|
+
this.config.transport.log(this.getLevelAndName(), strings, data);
|
|
13168
13211
|
}
|
|
13169
13212
|
/** Log a message with `INFO` level. */
|
|
13170
|
-
info(
|
|
13171
|
-
this.config.transport.info(this.
|
|
13213
|
+
info(strings, ...data) {
|
|
13214
|
+
this.config.transport.info(this.getLevelAndName(), strings, data);
|
|
13172
13215
|
}
|
|
13173
13216
|
/** Log a message with `WARN` level. */
|
|
13174
|
-
warn(
|
|
13175
|
-
this.config.transport.warn(this.
|
|
13217
|
+
warn(strings, ...data) {
|
|
13218
|
+
this.config.transport.warn(this.getLevelAndName(), strings, data);
|
|
13176
13219
|
}
|
|
13177
13220
|
/** Log a message with `ERROR` level. */
|
|
13178
|
-
error(
|
|
13179
|
-
this.config.transport.error(this.
|
|
13221
|
+
error(strings, ...data) {
|
|
13222
|
+
this.config.transport.error(this.getLevelAndName(), strings, data);
|
|
13180
13223
|
}
|
|
13181
13224
|
}
|
|
13182
13225
|
|
|
@@ -13291,7 +13334,7 @@ class LmdbStates {
|
|
|
13291
13334
|
await Promise.all([valuesWrite, statesWrite]);
|
|
13292
13335
|
}
|
|
13293
13336
|
catch (e) {
|
|
13294
|
-
logger.error
|
|
13337
|
+
logger.error `${e}`;
|
|
13295
13338
|
return result_Result.error(StateUpdateError.Commit);
|
|
13296
13339
|
}
|
|
13297
13340
|
return result_Result.ok(result_OK);
|
|
@@ -13399,7 +13442,7 @@ class TypedPort {
|
|
|
13399
13442
|
this.dispatchPortMessage(msg);
|
|
13400
13443
|
}
|
|
13401
13444
|
catch (e) {
|
|
13402
|
-
port_logger.error
|
|
13445
|
+
port_logger.error `[${this.constructor.name}] Failed to dispatch a message: ${e}: ${msg}`;
|
|
13403
13446
|
throw e;
|
|
13404
13447
|
}
|
|
13405
13448
|
});
|
|
@@ -13473,7 +13516,7 @@ class TypedPort {
|
|
|
13473
13516
|
this.port.postMessage(msg, transferList);
|
|
13474
13517
|
}
|
|
13475
13518
|
catch (e) {
|
|
13476
|
-
port_logger.error
|
|
13519
|
+
port_logger.error `[${this.constructor.name}] Failed to post a message: ${e}: ${msg}`;
|
|
13477
13520
|
throw e;
|
|
13478
13521
|
}
|
|
13479
13522
|
}
|
|
@@ -13504,7 +13547,7 @@ class TypedPort {
|
|
|
13504
13547
|
cleanup(reason) {
|
|
13505
13548
|
// resolve all pending requests with an error.
|
|
13506
13549
|
const responseListeners = this.responseListeners.eventNames();
|
|
13507
|
-
for (const ev
|
|
13550
|
+
for (const ev of responseListeners) {
|
|
13508
13551
|
this.responseListeners.emit(ev, new Error(`port is ${reason}`));
|
|
13509
13552
|
}
|
|
13510
13553
|
}
|
|
@@ -13553,7 +13596,7 @@ class MessageChannelStateMachine {
|
|
|
13553
13596
|
this.dispatchSignal(name, data);
|
|
13554
13597
|
}
|
|
13555
13598
|
catch (e) {
|
|
13556
|
-
channel_logger.error
|
|
13599
|
+
channel_logger.error `[${this.constructor.name}] Unable to dispatch signal (${name}): ${e}. ${this.stateInfo(remoteState)}`;
|
|
13557
13600
|
throw e;
|
|
13558
13601
|
}
|
|
13559
13602
|
});
|
|
@@ -13562,7 +13605,7 @@ class MessageChannelStateMachine {
|
|
|
13562
13605
|
await this.dispatchRequest(name, data, msg);
|
|
13563
13606
|
}
|
|
13564
13607
|
catch (e) {
|
|
13565
|
-
channel_logger.error
|
|
13608
|
+
channel_logger.error `[${this.constructor.name}] Unable to dispatch request (${name}): ${e}. ${this.stateInfo(remoteState)}`;
|
|
13566
13609
|
throw e;
|
|
13567
13610
|
}
|
|
13568
13611
|
});
|
|
@@ -13648,7 +13691,7 @@ class MessageChannelStateMachine {
|
|
|
13648
13691
|
this.machine.transition(res.transitionTo.state, res.transitionTo.data);
|
|
13649
13692
|
}
|
|
13650
13693
|
if (didStateChangeInMeantime) {
|
|
13651
|
-
channel_logger.warn
|
|
13694
|
+
channel_logger.warn `Ignoring obsolete response for an old request: "${name}"`;
|
|
13652
13695
|
return;
|
|
13653
13696
|
}
|
|
13654
13697
|
return this.port.respond(prevState.stateName, msg, res.response);
|
|
@@ -13664,7 +13707,7 @@ class MessageChannelStateMachine {
|
|
|
13664
13707
|
}
|
|
13665
13708
|
}
|
|
13666
13709
|
transitionTo() {
|
|
13667
|
-
channel_logger.trace
|
|
13710
|
+
channel_logger.trace `[${this.machine.name}] transitioned to ${this.currentState()}`;
|
|
13668
13711
|
return this;
|
|
13669
13712
|
}
|
|
13670
13713
|
/**
|
|
@@ -13684,7 +13727,7 @@ class MessageChannelStateMachine {
|
|
|
13684
13727
|
await promise;
|
|
13685
13728
|
}
|
|
13686
13729
|
catch (e) {
|
|
13687
|
-
channel_logger.error
|
|
13730
|
+
channel_logger.error `${e}`;
|
|
13688
13731
|
}
|
|
13689
13732
|
return new MessageChannelStateMachine(machine, port);
|
|
13690
13733
|
}
|
|
@@ -13887,7 +13930,7 @@ class State {
|
|
|
13887
13930
|
* actions.
|
|
13888
13931
|
*/
|
|
13889
13932
|
onActivation(data) {
|
|
13890
|
-
state_logger.trace
|
|
13933
|
+
state_logger.trace `[${this.constructor.name}] Changing state to: ${this}`;
|
|
13891
13934
|
this.data = data;
|
|
13892
13935
|
}
|
|
13893
13936
|
/**
|
|
@@ -13985,7 +14028,7 @@ async function spawnWorkerGeneric(bootstrapPath, logger, mainReadyName, mainRead
|
|
|
13985
14028
|
const worker = new external_node_worker_threads_namespaceObject.Worker(bootstrapPath);
|
|
13986
14029
|
const machine = stateMachineMain(`main->${mainReadyName}`, mainReadyName, mainReadyState);
|
|
13987
14030
|
const channel = await MessageChannelStateMachine.createAndTransferChannel(machine, worker);
|
|
13988
|
-
logger.trace
|
|
14031
|
+
logger.trace `[${machine.name}] Worker spawned ${channel.currentState()}`;
|
|
13989
14032
|
return channel;
|
|
13990
14033
|
}
|
|
13991
14034
|
|
|
@@ -15435,6 +15478,17 @@ class page_range_PageRange {
|
|
|
15435
15478
|
}
|
|
15436
15479
|
return new page_range_PageRange(start, length);
|
|
15437
15480
|
}
|
|
15481
|
+
/** Returns true if the page range is wrapped (`start` >= `end`) and is not empty */
|
|
15482
|
+
isWrapped() {
|
|
15483
|
+
return this.start >= this.end && !this.isEmpty();
|
|
15484
|
+
}
|
|
15485
|
+
/** Checks if given page number is within the range */
|
|
15486
|
+
isInRange(page) {
|
|
15487
|
+
if (this.isWrapped()) {
|
|
15488
|
+
return page >= this.start || page < this.end;
|
|
15489
|
+
}
|
|
15490
|
+
return page >= this.start && page < this.end;
|
|
15491
|
+
}
|
|
15438
15492
|
/** Checks if a range is empty (`length === 0`) */
|
|
15439
15493
|
isEmpty() {
|
|
15440
15494
|
return this.length === 0;
|
|
@@ -15563,12 +15617,14 @@ class writeable_page_WriteablePage extends MemoryPage {
|
|
|
15563
15617
|
|
|
15564
15618
|
|
|
15565
15619
|
|
|
15620
|
+
|
|
15621
|
+
|
|
15566
15622
|
var AccessType;
|
|
15567
15623
|
(function (AccessType) {
|
|
15568
15624
|
AccessType[AccessType["READ"] = 0] = "READ";
|
|
15569
15625
|
AccessType[AccessType["WRITE"] = 1] = "WRITE";
|
|
15570
15626
|
})(AccessType || (AccessType = {}));
|
|
15571
|
-
|
|
15627
|
+
const memory_logger = Logger.new(import.meta.filename, "pvm:mem");
|
|
15572
15628
|
class memory_Memory {
|
|
15573
15629
|
sbrkIndex;
|
|
15574
15630
|
virtualSbrkIndex;
|
|
@@ -15599,7 +15655,7 @@ class memory_Memory {
|
|
|
15599
15655
|
if (bytes.length === 0) {
|
|
15600
15656
|
return Result.ok(OK);
|
|
15601
15657
|
}
|
|
15602
|
-
|
|
15658
|
+
memory_logger.insane `MEM[${address}] <- ${BytesBlob.blobFrom(bytes)}`;
|
|
15603
15659
|
const pagesResult = this.getPages(address, bytes.length, AccessType.WRITE);
|
|
15604
15660
|
if (pagesResult.isError) {
|
|
15605
15661
|
return Result.error(pagesResult.error);
|
|
@@ -15666,7 +15722,7 @@ class memory_Memory {
|
|
|
15666
15722
|
currentPosition += bytesToRead;
|
|
15667
15723
|
bytesLeft -= bytesToRead;
|
|
15668
15724
|
}
|
|
15669
|
-
|
|
15725
|
+
memory_logger.insane `MEM[${startAddress}] => ${BytesBlob.blobFrom(result)}`;
|
|
15670
15726
|
return Result.ok(OK);
|
|
15671
15727
|
}
|
|
15672
15728
|
sbrk(length) {
|
|
@@ -15812,10 +15868,11 @@ class memory_builder_MemoryBuilder {
|
|
|
15812
15868
|
startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
|
|
15813
15869
|
`;
|
|
15814
15870
|
this.ensureNotFinalized();
|
|
15815
|
-
const
|
|
15816
|
-
const
|
|
15817
|
-
|
|
15818
|
-
|
|
15871
|
+
const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
|
|
15872
|
+
const heapPagesRange = PageRange.fromMemoryRange(heapRange);
|
|
15873
|
+
const initializedPageNumbers = Array.from(this.initialMemory.keys());
|
|
15874
|
+
for (const pageNumber of initializedPageNumbers) {
|
|
15875
|
+
if (heapPagesRange.isInRange(pageNumber)) {
|
|
15819
15876
|
throw new IncorrectSbrkIndex();
|
|
15820
15877
|
}
|
|
15821
15878
|
}
|
|
@@ -17403,7 +17460,7 @@ class program_decoder_ProgramDecoder {
|
|
|
17403
17460
|
return Result.ok(new program_decoder_ProgramDecoder(program));
|
|
17404
17461
|
}
|
|
17405
17462
|
catch (e) {
|
|
17406
|
-
program_decoder_logger.error
|
|
17463
|
+
program_decoder_logger.error `Invalid program: ${e}`;
|
|
17407
17464
|
return Result.error(ProgramDecoderError.InvalidProgramError);
|
|
17408
17465
|
}
|
|
17409
17466
|
}
|
|
@@ -17569,7 +17626,7 @@ class interpreter_Interpreter {
|
|
|
17569
17626
|
const argsType = instructionArgumentTypeMap[currentInstruction] ?? ArgumentType.NO_ARGUMENTS;
|
|
17570
17627
|
const argsResult = this.argsDecodingResults[argsType];
|
|
17571
17628
|
this.argsDecoder.fillArgs(this.pc, argsResult);
|
|
17572
|
-
interpreter_logger.insane
|
|
17629
|
+
interpreter_logger.insane `[PC: ${this.pc}] ${Instruction[currentInstruction]}`;
|
|
17573
17630
|
if (!isValidInstruction) {
|
|
17574
17631
|
this.instructionResult.status = Result.PANIC;
|
|
17575
17632
|
}
|
|
@@ -17641,7 +17698,7 @@ class interpreter_Interpreter {
|
|
|
17641
17698
|
this.status = Status.HOST;
|
|
17642
17699
|
break;
|
|
17643
17700
|
}
|
|
17644
|
-
interpreter_logger.insane
|
|
17701
|
+
interpreter_logger.insane `[PC: ${this.pc}] Status: ${Result[this.instructionResult.status]}`;
|
|
17645
17702
|
return this.status;
|
|
17646
17703
|
}
|
|
17647
17704
|
this.pc = this.instructionResult.nextPc;
|
|
@@ -17888,7 +17945,7 @@ class host_calls_manager_HostCallsManager {
|
|
|
17888
17945
|
return `r${idx}=${value} (0x${value.toString(16)})`;
|
|
17889
17946
|
})
|
|
17890
17947
|
.join(", ");
|
|
17891
|
-
host_calls_manager_logger.insane
|
|
17948
|
+
host_calls_manager_logger.insane `[${currentServiceId}] ${context} ${name}${requested}. Gas: ${gas}. Regs: ${registerValues}.`;
|
|
17892
17949
|
}
|
|
17893
17950
|
}
|
|
17894
17951
|
class NoopMissing {
|
|
@@ -18475,7 +18532,7 @@ class MainReady extends State {
|
|
|
18475
18532
|
this.onBlock.emit(block);
|
|
18476
18533
|
}
|
|
18477
18534
|
else {
|
|
18478
|
-
state_machine_logger.error
|
|
18535
|
+
state_machine_logger.error `${this.constructor.name} got invalid signal type: ${JSON.stringify(block)}.`;
|
|
18479
18536
|
}
|
|
18480
18537
|
}
|
|
18481
18538
|
finish(channel) {
|
|
@@ -18530,12 +18587,12 @@ if (!external_node_worker_threads_namespaceObject.isMainThread) {
|
|
|
18530
18587
|
channel
|
|
18531
18588
|
.then((channel) => main(channel))
|
|
18532
18589
|
.catch((e) => {
|
|
18533
|
-
block_generator_logger.error
|
|
18590
|
+
block_generator_logger.error `${e}`;
|
|
18534
18591
|
if (e.stack !== undefined) {
|
|
18535
|
-
block_generator_logger.error
|
|
18592
|
+
block_generator_logger.error `${e.stack}`;
|
|
18536
18593
|
}
|
|
18537
18594
|
if (e.cause !== undefined) {
|
|
18538
|
-
block_generator_logger.error
|
|
18595
|
+
block_generator_logger.error `${e.cause}`;
|
|
18539
18596
|
}
|
|
18540
18597
|
});
|
|
18541
18598
|
}
|
|
@@ -18543,7 +18600,7 @@ if (!external_node_worker_threads_namespaceObject.isMainThread) {
|
|
|
18543
18600
|
* The `BlockGenerator` should periodically create new blocks and send them as signals to the main thread.
|
|
18544
18601
|
*/
|
|
18545
18602
|
async function main(channel) {
|
|
18546
|
-
block_generator_logger.info
|
|
18603
|
+
block_generator_logger.info `🎁 Block Generator running ${channel.currentState()}`;
|
|
18547
18604
|
// Await the configuration object
|
|
18548
18605
|
const ready = await channel.waitForState("ready(generator)");
|
|
18549
18606
|
const config = ready.currentState().getConfig();
|
|
@@ -18558,11 +18615,11 @@ async function main(channel) {
|
|
|
18558
18615
|
await (0,promises_namespaceObject.setTimeout)(config.chainSpec.slotDuration * 1000);
|
|
18559
18616
|
counter += 1;
|
|
18560
18617
|
const newBlock = await generator.nextEncodedBlock();
|
|
18561
|
-
block_generator_logger.trace
|
|
18618
|
+
block_generator_logger.trace `Sending block ${counter}`;
|
|
18562
18619
|
worker.sendBlock(port, newBlock);
|
|
18563
18620
|
}
|
|
18564
18621
|
});
|
|
18565
|
-
block_generator_logger.info
|
|
18622
|
+
block_generator_logger.info `Block Generator finished. Closing channel.`;
|
|
18566
18623
|
// Close the comms to gracefully close the app.
|
|
18567
18624
|
finished.currentState().close(channel);
|
|
18568
18625
|
}
|