@typeberry/jam 0.1.1-e48de40 → 0.1.1
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/block-generator/index.js +94 -132
- package/block-generator/index.js.map +1 -1
- package/importer/index.js +177 -234
- package/importer/index.js.map +1 -1
- package/index.js +341 -394
- package/index.js.map +1 -1
- package/jam-network/index.js +162 -198
- package/jam-network/index.js.map +1 -1
- package/package.json +2 -4
package/jam-network/index.js
CHANGED
|
@@ -25425,34 +25425,6 @@ class WithDebug {
|
|
|
25425
25425
|
}
|
|
25426
25426
|
}
|
|
25427
25427
|
|
|
25428
|
-
;// CONCATENATED MODULE: ./packages/core/utils/dev.ts
|
|
25429
|
-
const dev_env = typeof process === "undefined" ? {} : process.env;
|
|
25430
|
-
/**
|
|
25431
|
-
* The function will produce relative path resolver that is adjusted
|
|
25432
|
-
* for package location within the workspace.
|
|
25433
|
-
*
|
|
25434
|
-
* Example:
|
|
25435
|
-
* $ npm start -w @typeberry/jam
|
|
25436
|
-
*
|
|
25437
|
-
* The above command will run `./bin/jam/index.js`, however we would
|
|
25438
|
-
* still want relative paths to be resolved according to top-level workspace
|
|
25439
|
-
* directory.
|
|
25440
|
-
*
|
|
25441
|
-
* So the caller, passes the absolute workspace path as argument and get's
|
|
25442
|
-
* a function that can properly resolve relative paths.
|
|
25443
|
-
*
|
|
25444
|
-
* NOTE: the translation happens only for development build! When
|
|
25445
|
-
* we build a single library from our project, we no longer mangle the paths.
|
|
25446
|
-
*/
|
|
25447
|
-
const workspacePathFix = dev_env.NODE_ENV === "development"
|
|
25448
|
-
? (workspacePath) => (p) => {
|
|
25449
|
-
if (p.startsWith("/")) {
|
|
25450
|
-
return p;
|
|
25451
|
-
}
|
|
25452
|
-
return `${workspacePath}/${p}`;
|
|
25453
|
-
}
|
|
25454
|
-
: () => (p) => p;
|
|
25455
|
-
|
|
25456
25428
|
;// CONCATENATED MODULE: ./packages/core/utils/opaque.ts
|
|
25457
25429
|
/**
|
|
25458
25430
|
* @fileoverview `Opaque<Type, Token>` constructs a unique type which is a subset of Type with a
|
|
@@ -25796,7 +25768,6 @@ function isResult(x) {
|
|
|
25796
25768
|
|
|
25797
25769
|
|
|
25798
25770
|
|
|
25799
|
-
|
|
25800
25771
|
;// CONCATENATED MODULE: ./packages/core/bytes/bitvec.ts
|
|
25801
25772
|
|
|
25802
25773
|
/**
|
|
@@ -32165,23 +32136,6 @@ function parseLevel(lvl) {
|
|
|
32165
32136
|
;// CONCATENATED MODULE: ./packages/core/logger/console.ts
|
|
32166
32137
|
// biome-ignore-all lint/suspicious/noConsole: logger
|
|
32167
32138
|
|
|
32168
|
-
function print(level, levelAndName, strings, data) {
|
|
32169
|
-
if (level < levelAndName[0]) {
|
|
32170
|
-
return;
|
|
32171
|
-
}
|
|
32172
|
-
const lvlText = Level[level].padEnd(5);
|
|
32173
|
-
const val = strings.map((v, idx) => `${v}${data[idx]}`);
|
|
32174
|
-
const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
|
|
32175
|
-
if (level === Level.WARN) {
|
|
32176
|
-
console.warn(msg);
|
|
32177
|
-
}
|
|
32178
|
-
else if (level === Level.ERROR) {
|
|
32179
|
-
console.error(msg);
|
|
32180
|
-
}
|
|
32181
|
-
else {
|
|
32182
|
-
console.info(msg);
|
|
32183
|
-
}
|
|
32184
|
-
}
|
|
32185
32139
|
/** An optimized logger that ignores `TRACE`, `DEBUG` and `LOG` messages.
|
|
32186
32140
|
*
|
|
32187
32141
|
* Use the `create` method to instantiate the right instance of a more specialized logger.
|
|
@@ -32212,91 +32166,109 @@ class ConsoleTransport {
|
|
|
32212
32166
|
constructor(options) {
|
|
32213
32167
|
this.options = options;
|
|
32214
32168
|
}
|
|
32215
|
-
insane(
|
|
32169
|
+
insane(_moduleName, _val) {
|
|
32216
32170
|
/* no-op */
|
|
32217
32171
|
}
|
|
32218
|
-
trace(
|
|
32172
|
+
trace(_moduleName, _val) {
|
|
32219
32173
|
/* no-op */
|
|
32220
32174
|
}
|
|
32221
|
-
log(
|
|
32175
|
+
log(_moduleName, _val) {
|
|
32222
32176
|
/* no-op */
|
|
32223
32177
|
}
|
|
32224
|
-
info(
|
|
32178
|
+
info(_moduleName, _val) {
|
|
32225
32179
|
/* no-op */
|
|
32226
32180
|
}
|
|
32227
|
-
warn(
|
|
32228
|
-
|
|
32181
|
+
warn(moduleName, val) {
|
|
32182
|
+
this.push(Level.WARN, moduleName, val);
|
|
32229
32183
|
}
|
|
32230
|
-
error(
|
|
32231
|
-
|
|
32184
|
+
error(moduleName, val) {
|
|
32185
|
+
this.push(Level.ERROR, moduleName, val);
|
|
32186
|
+
}
|
|
32187
|
+
push(level, moduleName, val) {
|
|
32188
|
+
const shortModule = moduleName.replace(this.options.workingDir, "");
|
|
32189
|
+
const configuredLevel = findLevel(this.options, moduleName);
|
|
32190
|
+
const lvlText = Level[level].padEnd(5);
|
|
32191
|
+
if (level < configuredLevel) {
|
|
32192
|
+
return;
|
|
32193
|
+
}
|
|
32194
|
+
const msg = `${lvlText} [${shortModule}] ${val}`;
|
|
32195
|
+
if (level === Level.WARN) {
|
|
32196
|
+
console.warn(msg);
|
|
32197
|
+
}
|
|
32198
|
+
else if (level === Level.ERROR) {
|
|
32199
|
+
console.error(msg);
|
|
32200
|
+
}
|
|
32201
|
+
else {
|
|
32202
|
+
console.info(msg);
|
|
32203
|
+
}
|
|
32232
32204
|
}
|
|
32233
32205
|
}
|
|
32234
32206
|
/**
|
|
32235
32207
|
* Insane version of console logger - supports insane level.
|
|
32236
32208
|
*/
|
|
32237
32209
|
class InsaneConsoleLogger extends ConsoleTransport {
|
|
32238
|
-
insane(
|
|
32239
|
-
|
|
32210
|
+
insane(moduleName, val) {
|
|
32211
|
+
this.push(Level.INSANE, moduleName, val);
|
|
32240
32212
|
}
|
|
32241
|
-
trace(
|
|
32242
|
-
|
|
32213
|
+
trace(moduleName, val) {
|
|
32214
|
+
this.push(Level.TRACE, moduleName, val);
|
|
32243
32215
|
}
|
|
32244
|
-
log(
|
|
32245
|
-
|
|
32216
|
+
log(moduleName, val) {
|
|
32217
|
+
this.push(Level.LOG, moduleName, val);
|
|
32246
32218
|
}
|
|
32247
|
-
info(
|
|
32248
|
-
|
|
32219
|
+
info(moduleName, val) {
|
|
32220
|
+
this.push(Level.INFO, moduleName, val);
|
|
32249
32221
|
}
|
|
32250
32222
|
}
|
|
32251
32223
|
/**
|
|
32252
32224
|
* A basic version of console logger - printing everything.
|
|
32253
32225
|
*/
|
|
32254
32226
|
class TraceConsoleTransport extends ConsoleTransport {
|
|
32255
|
-
insane(
|
|
32227
|
+
insane(_moduleName, _val) {
|
|
32256
32228
|
/* no-op */
|
|
32257
32229
|
}
|
|
32258
|
-
trace(
|
|
32259
|
-
|
|
32230
|
+
trace(moduleName, val) {
|
|
32231
|
+
this.push(Level.TRACE, moduleName, val);
|
|
32260
32232
|
}
|
|
32261
|
-
log(
|
|
32262
|
-
|
|
32233
|
+
log(moduleName, val) {
|
|
32234
|
+
this.push(Level.LOG, moduleName, val);
|
|
32263
32235
|
}
|
|
32264
|
-
info(
|
|
32265
|
-
|
|
32236
|
+
info(moduleName, val) {
|
|
32237
|
+
this.push(Level.INFO, moduleName, val);
|
|
32266
32238
|
}
|
|
32267
32239
|
}
|
|
32268
32240
|
/**
|
|
32269
32241
|
* An optimized version of the logger - completely ignores `TRACE` level calls.
|
|
32270
32242
|
*/
|
|
32271
32243
|
class LogConsoleTransport extends ConsoleTransport {
|
|
32272
|
-
insane(
|
|
32244
|
+
insane(_moduleName, _val) {
|
|
32273
32245
|
/* no-op */
|
|
32274
32246
|
}
|
|
32275
|
-
trace(
|
|
32247
|
+
trace(_moduleName, _val) {
|
|
32276
32248
|
/* no-op */
|
|
32277
32249
|
}
|
|
32278
|
-
log(
|
|
32279
|
-
|
|
32250
|
+
log(moduleName, val) {
|
|
32251
|
+
this.push(Level.LOG, moduleName, val);
|
|
32280
32252
|
}
|
|
32281
|
-
info(
|
|
32282
|
-
|
|
32253
|
+
info(moduleName, val) {
|
|
32254
|
+
this.push(Level.INFO, moduleName, val);
|
|
32283
32255
|
}
|
|
32284
32256
|
}
|
|
32285
32257
|
/**
|
|
32286
32258
|
* An optimized version of the logger - completely ignores `TRACE` & `DEBUG` level calls.
|
|
32287
32259
|
*/
|
|
32288
32260
|
class InfoConsoleTransport extends ConsoleTransport {
|
|
32289
|
-
insane(
|
|
32261
|
+
insane(_moduleName, _val) {
|
|
32290
32262
|
/* no-op */
|
|
32291
32263
|
}
|
|
32292
|
-
trace(
|
|
32264
|
+
trace(_moduleName, _val) {
|
|
32293
32265
|
/* no-op */
|
|
32294
32266
|
}
|
|
32295
|
-
log(
|
|
32267
|
+
log(_moduleName, _val) {
|
|
32296
32268
|
/* no-op */
|
|
32297
32269
|
}
|
|
32298
|
-
info(
|
|
32299
|
-
|
|
32270
|
+
info(moduleName, val) {
|
|
32271
|
+
this.push(Level.INFO, moduleName, val);
|
|
32300
32272
|
}
|
|
32301
32273
|
}
|
|
32302
32274
|
|
|
@@ -32333,6 +32305,11 @@ class Logger {
|
|
|
32333
32305
|
const module = moduleName ?? fName;
|
|
32334
32306
|
return new Logger(module.padStart(8, " "), GLOBAL_CONFIG);
|
|
32335
32307
|
}
|
|
32308
|
+
/**
|
|
32309
|
+
* Return currently configured level for given module. */
|
|
32310
|
+
static getLevel(moduleName) {
|
|
32311
|
+
return findLevel(GLOBAL_CONFIG.options, moduleName);
|
|
32312
|
+
}
|
|
32336
32313
|
/**
|
|
32337
32314
|
* Global configuration of all loggers.
|
|
32338
32315
|
*
|
|
@@ -32363,46 +32340,33 @@ class Logger {
|
|
|
32363
32340
|
const options = parseLoggerOptions(input, defaultLevel, workingDir);
|
|
32364
32341
|
Logger.configureAllFromOptions(options);
|
|
32365
32342
|
}
|
|
32366
|
-
cachedLevelAndName;
|
|
32367
32343
|
constructor(moduleName, config) {
|
|
32368
32344
|
this.moduleName = moduleName;
|
|
32369
32345
|
this.config = config;
|
|
32370
32346
|
}
|
|
32371
|
-
/** Return currently configured level for given module. */
|
|
32372
|
-
getLevel() {
|
|
32373
|
-
return this.getLevelAndName()[0];
|
|
32374
|
-
}
|
|
32375
|
-
getLevelAndName() {
|
|
32376
|
-
if (this.cachedLevelAndName === undefined) {
|
|
32377
|
-
const level = findLevel(this.config.options, this.moduleName);
|
|
32378
|
-
const shortName = this.moduleName.replace(this.config.options.workingDir, "");
|
|
32379
|
-
this.cachedLevelAndName = [level, shortName];
|
|
32380
|
-
}
|
|
32381
|
-
return this.cachedLevelAndName;
|
|
32382
|
-
}
|
|
32383
32347
|
/** Log a message with `INSANE` level. */
|
|
32384
|
-
insane(
|
|
32385
|
-
this.config.transport.insane(this.
|
|
32348
|
+
insane(val) {
|
|
32349
|
+
this.config.transport.insane(this.moduleName, val);
|
|
32386
32350
|
}
|
|
32387
32351
|
/** Log a message with `TRACE` level. */
|
|
32388
|
-
trace(
|
|
32389
|
-
this.config.transport.trace(this.
|
|
32352
|
+
trace(val) {
|
|
32353
|
+
this.config.transport.trace(this.moduleName, val);
|
|
32390
32354
|
}
|
|
32391
32355
|
/** Log a message with `DEBUG`/`LOG` level. */
|
|
32392
|
-
log(
|
|
32393
|
-
this.config.transport.log(this.
|
|
32356
|
+
log(val) {
|
|
32357
|
+
this.config.transport.log(this.moduleName, val);
|
|
32394
32358
|
}
|
|
32395
32359
|
/** Log a message with `INFO` level. */
|
|
32396
|
-
info(
|
|
32397
|
-
this.config.transport.info(this.
|
|
32360
|
+
info(val) {
|
|
32361
|
+
this.config.transport.info(this.moduleName, val);
|
|
32398
32362
|
}
|
|
32399
32363
|
/** Log a message with `WARN` level. */
|
|
32400
|
-
warn(
|
|
32401
|
-
this.config.transport.warn(this.
|
|
32364
|
+
warn(val) {
|
|
32365
|
+
this.config.transport.warn(this.moduleName, val);
|
|
32402
32366
|
}
|
|
32403
32367
|
/** Log a message with `ERROR` level. */
|
|
32404
|
-
error(
|
|
32405
|
-
this.config.transport.error(this.
|
|
32368
|
+
error(val) {
|
|
32369
|
+
this.config.transport.error(this.moduleName, val);
|
|
32406
32370
|
}
|
|
32407
32371
|
}
|
|
32408
32372
|
|
|
@@ -32492,15 +32456,15 @@ class NodeConfiguration {
|
|
|
32492
32456
|
}
|
|
32493
32457
|
function loadConfig(configPath) {
|
|
32494
32458
|
if (configPath === DEFAULT_CONFIG) {
|
|
32495
|
-
logger.log
|
|
32459
|
+
logger.log("🔧 Loading DEFAULT config");
|
|
32496
32460
|
return parseFromJson(configs.default, NodeConfiguration.fromJson);
|
|
32497
32461
|
}
|
|
32498
32462
|
if (configPath === DEV_CONFIG) {
|
|
32499
|
-
logger.log
|
|
32463
|
+
logger.log("🔧 Loading DEV config");
|
|
32500
32464
|
return parseFromJson(configs.dev, NodeConfiguration.fromJson);
|
|
32501
32465
|
}
|
|
32502
32466
|
try {
|
|
32503
|
-
logger.log
|
|
32467
|
+
logger.log(`🔧 Loading config from ${configPath}`);
|
|
32504
32468
|
const configFile = fs.readFileSync(configPath, "utf8");
|
|
32505
32469
|
const parsed = JSON.parse(configFile);
|
|
32506
32470
|
return parseFromJson(parsed, NodeConfiguration.fromJson);
|
|
@@ -36206,7 +36170,7 @@ class LmdbStates {
|
|
|
36206
36170
|
await Promise.all([valuesWrite, statesWrite]);
|
|
36207
36171
|
}
|
|
36208
36172
|
catch (e) {
|
|
36209
|
-
states_logger.error
|
|
36173
|
+
states_logger.error(`${e}`);
|
|
36210
36174
|
return Result.error(StateUpdateError.Commit);
|
|
36211
36175
|
}
|
|
36212
36176
|
return Result.ok(OK);
|
|
@@ -36315,7 +36279,7 @@ class TypedPort {
|
|
|
36315
36279
|
this.dispatchPortMessage(msg);
|
|
36316
36280
|
}
|
|
36317
36281
|
catch (e) {
|
|
36318
|
-
port_logger.error
|
|
36282
|
+
port_logger.error(`[${this.constructor.name}] Failed to dispatch a message: ${e}: ${JSON.stringify(msg)}`);
|
|
36319
36283
|
throw e;
|
|
36320
36284
|
}
|
|
36321
36285
|
});
|
|
@@ -36389,7 +36353,7 @@ class TypedPort {
|
|
|
36389
36353
|
this.port.postMessage(msg, transferList);
|
|
36390
36354
|
}
|
|
36391
36355
|
catch (e) {
|
|
36392
|
-
port_logger.error
|
|
36356
|
+
port_logger.error(`[${this.constructor.name}] Failed to post a message: ${e}: ${JSON.stringify(msg)}`);
|
|
36393
36357
|
throw e;
|
|
36394
36358
|
}
|
|
36395
36359
|
}
|
|
@@ -36420,7 +36384,7 @@ class TypedPort {
|
|
|
36420
36384
|
cleanup(reason) {
|
|
36421
36385
|
// resolve all pending requests with an error.
|
|
36422
36386
|
const responseListeners = this.responseListeners.eventNames();
|
|
36423
|
-
for (const ev
|
|
36387
|
+
for (const ev in responseListeners) {
|
|
36424
36388
|
this.responseListeners.emit(ev, new Error(`port is ${reason}`));
|
|
36425
36389
|
}
|
|
36426
36390
|
}
|
|
@@ -36469,7 +36433,7 @@ class MessageChannelStateMachine {
|
|
|
36469
36433
|
this.dispatchSignal(name, data);
|
|
36470
36434
|
}
|
|
36471
36435
|
catch (e) {
|
|
36472
|
-
channel_logger.error
|
|
36436
|
+
channel_logger.error(`[${this.constructor.name}] Unable to dispatch signal (${name}): ${e}. ${this.stateInfo(remoteState)}`);
|
|
36473
36437
|
throw e;
|
|
36474
36438
|
}
|
|
36475
36439
|
});
|
|
@@ -36478,7 +36442,7 @@ class MessageChannelStateMachine {
|
|
|
36478
36442
|
await this.dispatchRequest(name, data, msg);
|
|
36479
36443
|
}
|
|
36480
36444
|
catch (e) {
|
|
36481
|
-
channel_logger.error
|
|
36445
|
+
channel_logger.error(`[${this.constructor.name}] Unable to dispatch request (${name}): ${e}. ${this.stateInfo(remoteState)}`);
|
|
36482
36446
|
throw e;
|
|
36483
36447
|
}
|
|
36484
36448
|
});
|
|
@@ -36564,7 +36528,7 @@ class MessageChannelStateMachine {
|
|
|
36564
36528
|
this.machine.transition(res.transitionTo.state, res.transitionTo.data);
|
|
36565
36529
|
}
|
|
36566
36530
|
if (didStateChangeInMeantime) {
|
|
36567
|
-
channel_logger.warn
|
|
36531
|
+
channel_logger.warn(`Ignoring obsolete response for an old request: "${name}"`);
|
|
36568
36532
|
return;
|
|
36569
36533
|
}
|
|
36570
36534
|
return this.port.respond(prevState.stateName, msg, res.response);
|
|
@@ -36580,7 +36544,7 @@ class MessageChannelStateMachine {
|
|
|
36580
36544
|
}
|
|
36581
36545
|
}
|
|
36582
36546
|
transitionTo() {
|
|
36583
|
-
channel_logger.trace
|
|
36547
|
+
channel_logger.trace(`[${this.machine.name}] transitioned to ${this.currentState()}`);
|
|
36584
36548
|
return this;
|
|
36585
36549
|
}
|
|
36586
36550
|
/**
|
|
@@ -36600,7 +36564,7 @@ class MessageChannelStateMachine {
|
|
|
36600
36564
|
await promise;
|
|
36601
36565
|
}
|
|
36602
36566
|
catch (e) {
|
|
36603
|
-
channel_logger.error
|
|
36567
|
+
channel_logger.error(JSON.stringify(e));
|
|
36604
36568
|
}
|
|
36605
36569
|
return new MessageChannelStateMachine(machine, port);
|
|
36606
36570
|
}
|
|
@@ -36803,7 +36767,7 @@ class State {
|
|
|
36803
36767
|
* actions.
|
|
36804
36768
|
*/
|
|
36805
36769
|
onActivation(data) {
|
|
36806
|
-
state_logger.trace
|
|
36770
|
+
state_logger.trace(`[${this.constructor.name}] Changing state to: ${this}`);
|
|
36807
36771
|
this.data = data;
|
|
36808
36772
|
}
|
|
36809
36773
|
/**
|
|
@@ -36901,7 +36865,7 @@ async function spawnWorkerGeneric(bootstrapPath, logger, mainReadyName, mainRead
|
|
|
36901
36865
|
const worker = new external_node_worker_threads_namespaceObject.Worker(bootstrapPath);
|
|
36902
36866
|
const machine = stateMachineMain(`main->${mainReadyName}`, mainReadyName, mainReadyState);
|
|
36903
36867
|
const channel = await MessageChannelStateMachine.createAndTransferChannel(machine, worker);
|
|
36904
|
-
logger.trace
|
|
36868
|
+
logger.trace(`[${machine.name}] Worker spawned ${channel.currentState()}`);
|
|
36905
36869
|
return channel;
|
|
36906
36870
|
}
|
|
36907
36871
|
|
|
@@ -36998,11 +36962,11 @@ class PeersManagement {
|
|
|
36998
36962
|
_onPeerDisconnected = [];
|
|
36999
36963
|
peers = new Map();
|
|
37000
36964
|
peerConnected(peer) {
|
|
37001
|
-
peers_logger.info
|
|
36965
|
+
peers_logger.info(`💡 Peer ${displayId(peer)} connected.`);
|
|
37002
36966
|
const oldPeerData = this.peers.get(peer.id);
|
|
37003
36967
|
if (oldPeerData !== undefined) {
|
|
37004
36968
|
// TODO [ToDr] replacing old connection?
|
|
37005
|
-
peers_logger.warn
|
|
36969
|
+
peers_logger.warn("Replacing older connection.");
|
|
37006
36970
|
}
|
|
37007
36971
|
this.peers.set(peer.id, peer);
|
|
37008
36972
|
for (const callback of this._onPeerConnected) {
|
|
@@ -37010,7 +36974,7 @@ class PeersManagement {
|
|
|
37010
36974
|
}
|
|
37011
36975
|
}
|
|
37012
36976
|
peerDisconnected(peer) {
|
|
37013
|
-
peers_logger.info
|
|
36977
|
+
peers_logger.info(`⚡︎Peer ${displayId(peer)} disconnected.`);
|
|
37014
36978
|
this.peers.delete(peer.id);
|
|
37015
36979
|
for (const callback of this._onPeerDisconnected) {
|
|
37016
36980
|
callback(peer);
|
|
@@ -45802,23 +45766,23 @@ var VerifyCertError;
|
|
|
45802
45766
|
VerifyCertError[VerifyCertError["IncorrectSignature"] = 4] = "IncorrectSignature";
|
|
45803
45767
|
})(VerifyCertError || (VerifyCertError = {}));
|
|
45804
45768
|
async function verifyCertificate(certs) {
|
|
45805
|
-
certificate_logger.log
|
|
45769
|
+
certificate_logger.log("Incoming peer. Verifying certificate");
|
|
45806
45770
|
// Must present exactly one cert
|
|
45807
45771
|
if (certs.length !== 1) {
|
|
45808
|
-
certificate_logger.log
|
|
45772
|
+
certificate_logger.log("Rejecting peer with no certificates.");
|
|
45809
45773
|
return result_Result.error(VerifyCertError.NoCertificate);
|
|
45810
45774
|
}
|
|
45811
45775
|
// Parse with Node's X509Certificate (accepts PEM or DER)
|
|
45812
45776
|
const xc = new (external_node_crypto_default()).X509Certificate(certs[0]);
|
|
45813
45777
|
// Must be Ed25519 key
|
|
45814
45778
|
if (xc.publicKey.asymmetricKeyType !== CURVE_NAME.toLowerCase()) {
|
|
45815
|
-
certificate_logger.log
|
|
45779
|
+
certificate_logger.log(`Rejecting peer using non-ed25519 certificate: ${xc.publicKey.asymmetricKeyType}`);
|
|
45816
45780
|
return result_Result.error(VerifyCertError.NotEd25519);
|
|
45817
45781
|
}
|
|
45818
45782
|
// Extract raw public key via JWK export
|
|
45819
45783
|
const jwk = xc.publicKey.export({ format: "jwk" });
|
|
45820
45784
|
if (jwk.kty !== KEY_TYPE || jwk.crv !== CURVE_NAME) {
|
|
45821
|
-
certificate_logger.log
|
|
45785
|
+
certificate_logger.log(`Public key type mismatch: ${jwk.kty}, ${jwk.crv}`);
|
|
45822
45786
|
return result_Result.error(VerifyCertError.PublicKeyTypeMismatch);
|
|
45823
45787
|
}
|
|
45824
45788
|
// SAN must be exactly 'e'+base32(rawPub)
|
|
@@ -45826,7 +45790,7 @@ async function verifyCertificate(certs) {
|
|
|
45826
45790
|
const sanField = xc.subjectAltName ?? "";
|
|
45827
45791
|
const m = sanField.match(/DNS:([^,]+)/);
|
|
45828
45792
|
if (m === null || m[1] !== expectedSan) {
|
|
45829
|
-
certificate_logger.log
|
|
45793
|
+
certificate_logger.log(`AltName mismatch. Expected: '${expectedSan}', got: '${m?.[1]}'`);
|
|
45830
45794
|
return result_Result.error(VerifyCertError.AltNameMismatch);
|
|
45831
45795
|
}
|
|
45832
45796
|
const key = Buffer.from(jwk.x ?? "", "base64url");
|
|
@@ -46093,19 +46057,19 @@ class QuicNetwork {
|
|
|
46093
46057
|
}
|
|
46094
46058
|
this.started = true;
|
|
46095
46059
|
await this.socket.start({ host: this.listen.host, port: this.listen.port });
|
|
46096
|
-
quic_network_logger.info
|
|
46060
|
+
quic_network_logger.info(`🛜 QUIC socket on ${this.socket.host}:${this.socket.port}`);
|
|
46097
46061
|
await this.server.start();
|
|
46098
|
-
quic_network_logger.log
|
|
46062
|
+
quic_network_logger.log("🛜 QUIC server listening");
|
|
46099
46063
|
}
|
|
46100
46064
|
async stop() {
|
|
46101
46065
|
if (!this.started) {
|
|
46102
46066
|
throw new Error("Network not started yet!");
|
|
46103
46067
|
}
|
|
46104
|
-
quic_network_logger.info
|
|
46068
|
+
quic_network_logger.info("Stopping the networking.");
|
|
46105
46069
|
await this.server.stop();
|
|
46106
46070
|
await this.socket.stop();
|
|
46107
46071
|
this.started = false;
|
|
46108
|
-
quic_network_logger.info
|
|
46072
|
+
quic_network_logger.info("Networking stopped.");
|
|
46109
46073
|
}
|
|
46110
46074
|
get peers() {
|
|
46111
46075
|
return this._peers;
|
|
@@ -46126,7 +46090,7 @@ clazz, callback) {
|
|
|
46126
46090
|
await callback(ev);
|
|
46127
46091
|
}
|
|
46128
46092
|
catch (e) {
|
|
46129
|
-
quic_utils_logger.error
|
|
46093
|
+
quic_utils_logger.error(`Unhandled exception in ${clazz.name} event handler: ${e}`);
|
|
46130
46094
|
}
|
|
46131
46095
|
});
|
|
46132
46096
|
}
|
|
@@ -46185,7 +46149,7 @@ class QuicPeer {
|
|
|
46185
46149
|
streamEvents = new (external_node_events_default())();
|
|
46186
46150
|
constructor(conn, peerInfo) {
|
|
46187
46151
|
this.conn = conn;
|
|
46188
|
-
quic_peer_logger.log
|
|
46152
|
+
quic_peer_logger.log(`👥 [${peerInfo.id}] peer connected ${conn.remoteHost}:${conn.remotePort}`);
|
|
46189
46153
|
this.connectionId = conn.connectionIdShared.toString();
|
|
46190
46154
|
this.address = {
|
|
46191
46155
|
host: conn.remoteHost,
|
|
@@ -46195,11 +46159,11 @@ class QuicPeer {
|
|
|
46195
46159
|
this.key = peerInfo.key;
|
|
46196
46160
|
addEventListener(conn, EventQUICConnectionStream, (ev) => {
|
|
46197
46161
|
const stream = ev.detail;
|
|
46198
|
-
quic_peer_logger.log
|
|
46162
|
+
quic_peer_logger.log(`🚰 [${this.id}] new stream: [${stream.streamId}]`);
|
|
46199
46163
|
this.streamEvents.emit("stream", new QuicStream(stream));
|
|
46200
46164
|
});
|
|
46201
46165
|
addEventListener(conn, EventQUICConnectionError, (err) => {
|
|
46202
|
-
quic_peer_logger.error
|
|
46166
|
+
quic_peer_logger.error(`❌ [${this.id}] connection failed: ${err.detail}`);
|
|
46203
46167
|
});
|
|
46204
46168
|
}
|
|
46205
46169
|
addOnIncomingStream(streamCallback) {
|
|
@@ -46207,11 +46171,11 @@ class QuicPeer {
|
|
|
46207
46171
|
}
|
|
46208
46172
|
openStream() {
|
|
46209
46173
|
const stream = this.conn.newStream("bidi");
|
|
46210
|
-
quic_peer_logger.log
|
|
46174
|
+
quic_peer_logger.log(`🚰 [${this.id}] opening stream: [${stream.streamId}]`);
|
|
46211
46175
|
return new QuicStream(stream);
|
|
46212
46176
|
}
|
|
46213
46177
|
async disconnect() {
|
|
46214
|
-
quic_peer_logger.log
|
|
46178
|
+
quic_peer_logger.log(`👋 [${this.id}] disconnecting`);
|
|
46215
46179
|
await this.conn.stop({ isApp: true });
|
|
46216
46180
|
}
|
|
46217
46181
|
}
|
|
@@ -46232,7 +46196,7 @@ const setup_logger = Logger.new(import.meta.filename, "net");
|
|
|
46232
46196
|
class Quic {
|
|
46233
46197
|
/** Setup QUIC socket and start listening for connections. */
|
|
46234
46198
|
static async setup({ host, port, protocols, key }) {
|
|
46235
|
-
const quicLoggerLvl =
|
|
46199
|
+
const quicLoggerLvl = Logger.getLevel("net") > Level.TRACE ? LogLevel.WARN : LogLevel.DEBUG;
|
|
46236
46200
|
const quicLogger = new dist_Logger("quic", quicLoggerLvl, [
|
|
46237
46201
|
new handlers_StreamHandler(format `${level}:${keys}:${msg}`),
|
|
46238
46202
|
]);
|
|
@@ -46255,7 +46219,7 @@ class Quic {
|
|
|
46255
46219
|
verifyPeer: true,
|
|
46256
46220
|
verifyCallback: lastConnectedPeer.verifyCallback,
|
|
46257
46221
|
};
|
|
46258
|
-
setup_logger.info
|
|
46222
|
+
setup_logger.info(`🆔 Peer id: ** ${altNameRaw(key.pubKey)}@${host}:${port} ** (pubkey: ${key.pubKey})`);
|
|
46259
46223
|
// Shared injected UDP socket
|
|
46260
46224
|
const socket = new dist_QUICSocket({
|
|
46261
46225
|
logger: quicLogger.getChild("socket"),
|
|
@@ -46270,8 +46234,8 @@ class Quic {
|
|
|
46270
46234
|
// peer management
|
|
46271
46235
|
const peers = new PeersManagement();
|
|
46272
46236
|
// basic error handling
|
|
46273
|
-
addEventListener(server, EventQUICServerError, (error) => setup_logger.error
|
|
46274
|
-
addEventListener(server, EventQUICServerClose, (ev) => setup_logger.error
|
|
46237
|
+
addEventListener(server, EventQUICServerError, (error) => setup_logger.error(`🛜 Server error: ${error}`));
|
|
46238
|
+
addEventListener(server, EventQUICServerClose, (ev) => setup_logger.error(`🛜 Server stopped: ${ev}`));
|
|
46275
46239
|
// handling incoming session
|
|
46276
46240
|
addEventListener(server, EventQUICServerConnection, async (ev) => {
|
|
46277
46241
|
const conn = ev.detail;
|
|
@@ -46280,16 +46244,16 @@ class Quic {
|
|
|
46280
46244
|
return;
|
|
46281
46245
|
}
|
|
46282
46246
|
if (lastConnectedPeer.info.key.isEqualTo(key.pubKey)) {
|
|
46283
|
-
setup_logger.log
|
|
46247
|
+
setup_logger.log(`🛜 Rejecting connection from ourself from ${conn.remoteHost}:${conn.remotePort}`);
|
|
46284
46248
|
await conn.stop();
|
|
46285
46249
|
return;
|
|
46286
46250
|
}
|
|
46287
46251
|
if (peers.isConnected(lastConnectedPeer.info.id)) {
|
|
46288
|
-
setup_logger.log
|
|
46252
|
+
setup_logger.log(`🛜 Rejecting duplicate connection with peer ${lastConnectedPeer.info.id} from ${conn.remoteHost}:${conn.remotePort}`);
|
|
46289
46253
|
await conn.stop();
|
|
46290
46254
|
return;
|
|
46291
46255
|
}
|
|
46292
|
-
setup_logger.log
|
|
46256
|
+
setup_logger.log(`🛜 Server handshake with ${conn.remoteHost}:${conn.remotePort}`);
|
|
46293
46257
|
newPeer(conn, lastConnectedPeer.info);
|
|
46294
46258
|
lastConnectedPeer.info = null;
|
|
46295
46259
|
await conn.start();
|
|
@@ -46312,10 +46276,10 @@ class Quic {
|
|
|
46312
46276
|
});
|
|
46313
46277
|
const client = await clientLater;
|
|
46314
46278
|
addEventListener(client, EventQUICClientClose, () => {
|
|
46315
|
-
setup_logger.log
|
|
46279
|
+
setup_logger.log("⚰️ Client connection closed.");
|
|
46316
46280
|
});
|
|
46317
46281
|
addEventListener(client, EventQUICClientError, (error) => {
|
|
46318
|
-
setup_logger.error
|
|
46282
|
+
setup_logger.error(`🔴 Client error: ${error.detail}`);
|
|
46319
46283
|
});
|
|
46320
46284
|
if (peerDetails.info === null) {
|
|
46321
46285
|
throw new Error("Client connected, but there is no peer details!");
|
|
@@ -46323,7 +46287,7 @@ class Quic {
|
|
|
46323
46287
|
if (options.verifyName !== undefined && options.verifyName !== peerDetails.info.id) {
|
|
46324
46288
|
throw new Error(`Client connected, but the id didn't match. Expected: ${options.verifyName}, got: ${peerDetails.info.id}`);
|
|
46325
46289
|
}
|
|
46326
|
-
setup_logger.log
|
|
46290
|
+
setup_logger.log(`🤝 Client handshake with: ${peer.host}:${peer.port}`);
|
|
46327
46291
|
return newPeer(client.connection, peerDetails.info);
|
|
46328
46292
|
}
|
|
46329
46293
|
function newPeer(conn, peerInfo) {
|
|
@@ -46443,10 +46407,10 @@ class Connections {
|
|
|
46443
46407
|
for (;;) {
|
|
46444
46408
|
// increase the reconnection counter
|
|
46445
46409
|
meta.currentRetry += 1;
|
|
46446
|
-
if (meta.currentRetry
|
|
46410
|
+
if (meta.currentRetry >= meta.maxRetries) {
|
|
46447
46411
|
// reached max retries for a peer, remove it from tracking.
|
|
46448
46412
|
this.peerInfo.delete(id);
|
|
46449
|
-
jamnp_s_peers_logger.log
|
|
46413
|
+
jamnp_s_peers_logger.log(`[${id}] max retries reached. Removing peer.`);
|
|
46450
46414
|
return;
|
|
46451
46415
|
}
|
|
46452
46416
|
// else attempt to connect to a node a bit later.
|
|
@@ -46465,7 +46429,7 @@ class Connections {
|
|
|
46465
46429
|
}
|
|
46466
46430
|
// attempt to connect to the peer
|
|
46467
46431
|
try {
|
|
46468
|
-
jamnp_s_peers_logger.trace
|
|
46432
|
+
jamnp_s_peers_logger.trace(`[${id}] Attempting to connect to peer at ${meta.address.host}:${meta.address.port}.`);
|
|
46469
46433
|
await this.network.dial(meta.address, { signal, verifyName: meta.peerId });
|
|
46470
46434
|
return;
|
|
46471
46435
|
}
|
|
@@ -46474,7 +46438,7 @@ class Connections {
|
|
|
46474
46438
|
return;
|
|
46475
46439
|
}
|
|
46476
46440
|
// failing to connect, will retry.
|
|
46477
|
-
jamnp_s_peers_logger.trace
|
|
46441
|
+
jamnp_s_peers_logger.trace(`[${id}] attempt failed. Will retry (${meta.currentRetry}/${meta.maxRetries})`);
|
|
46478
46442
|
}
|
|
46479
46443
|
}
|
|
46480
46444
|
}
|
|
@@ -46587,7 +46551,7 @@ class StreamManager {
|
|
|
46587
46551
|
// We expect a one-byte identifier first.
|
|
46588
46552
|
const data = await reader.read();
|
|
46589
46553
|
bytes = bytes_BytesBlob.blobFrom(data.value !== undefined ? data.value : new Uint8Array());
|
|
46590
|
-
stream_manager_logger.trace
|
|
46554
|
+
stream_manager_logger.trace(`🚰 --> [${peer.id}:${streamId}] Initial data: ${bytes}`);
|
|
46591
46555
|
}
|
|
46592
46556
|
finally {
|
|
46593
46557
|
reader.releaseLock();
|
|
@@ -46601,7 +46565,7 @@ class StreamManager {
|
|
|
46601
46565
|
if (handler === undefined) {
|
|
46602
46566
|
throw new Error(`Unsupported stream kind: ${kind}`);
|
|
46603
46567
|
}
|
|
46604
|
-
stream_manager_logger.log
|
|
46568
|
+
stream_manager_logger.log(`🚰 --> [${peer.id}:${stream.streamId}] Stream identified as: ${kind}`);
|
|
46605
46569
|
this.registerStream(peer, handler, stream, bytes_BytesBlob.blobFrom(bytes.raw.subarray(1)));
|
|
46606
46570
|
}
|
|
46607
46571
|
registerStream(peer, handler, stream, initialData) {
|
|
@@ -46611,7 +46575,7 @@ class StreamManager {
|
|
|
46611
46575
|
this.streams.delete(streamId);
|
|
46612
46576
|
this.backgroundTasks.delete(streamId);
|
|
46613
46577
|
if (kind === StreamErrorKind.Exception) {
|
|
46614
|
-
stream_manager_logger.error
|
|
46578
|
+
stream_manager_logger.error(`🚰 --- [${peer.id}:${streamId}] Stream error: ${e}. Disconnecting peer.`);
|
|
46615
46579
|
}
|
|
46616
46580
|
if (kind !== StreamErrorKind.LocalClose) {
|
|
46617
46581
|
// whenever we have an error, we are going to inform the handler
|
|
@@ -46645,10 +46609,10 @@ async function readStreamForever(peer, handler, quicStream, initialData, reader)
|
|
|
46645
46609
|
let isDone = false;
|
|
46646
46610
|
const callback = handleMessageFragmentation((data) => {
|
|
46647
46611
|
const bytes = bytes_BytesBlob.blobFrom(new Uint8Array(data));
|
|
46648
|
-
stream_manager_logger.trace
|
|
46612
|
+
stream_manager_logger.trace(`🚰 --> [${peer.id}:${quicStream.streamId}] ${bytes}`);
|
|
46649
46613
|
handler.onStreamMessage(quicStream, bytes);
|
|
46650
46614
|
}, () => {
|
|
46651
|
-
stream_manager_logger.error
|
|
46615
|
+
stream_manager_logger.error(`🚰 --> [${peer.id}:${quicStream.streamId}] got too much data. Disconnecting.`);
|
|
46652
46616
|
peer.disconnect();
|
|
46653
46617
|
});
|
|
46654
46618
|
for (;;) {
|
|
@@ -46657,7 +46621,7 @@ async function readStreamForever(peer, handler, quicStream, initialData, reader)
|
|
|
46657
46621
|
// be a promise, so that we can make back pressure here.
|
|
46658
46622
|
callback(bytes.raw);
|
|
46659
46623
|
if (isDone) {
|
|
46660
|
-
stream_manager_logger.log
|
|
46624
|
+
stream_manager_logger.log(`🚰 --> [${peer.id}:${quicStream.streamId}] remote finished.`);
|
|
46661
46625
|
return;
|
|
46662
46626
|
}
|
|
46663
46627
|
// await for more data
|
|
@@ -46700,7 +46664,7 @@ class QuicStreamSender {
|
|
|
46700
46664
|
return;
|
|
46701
46665
|
}
|
|
46702
46666
|
const { data, addPrefix } = chunk;
|
|
46703
|
-
stream_manager_logger.trace
|
|
46667
|
+
stream_manager_logger.trace(`🚰 <-- [${this.streamId}] write: ${data}`);
|
|
46704
46668
|
if (addPrefix) {
|
|
46705
46669
|
await writer.write(encodeMessageLength(data.raw));
|
|
46706
46670
|
}
|
|
@@ -46717,7 +46681,7 @@ class QuicStreamSender {
|
|
|
46717
46681
|
}
|
|
46718
46682
|
close() {
|
|
46719
46683
|
handleAsyncErrors(async () => {
|
|
46720
|
-
stream_manager_logger.trace
|
|
46684
|
+
stream_manager_logger.trace(`🚰 <-- [${this.streamId}] closing`);
|
|
46721
46685
|
if (this.currentWriterPromise !== null) {
|
|
46722
46686
|
await this.currentWriterPromise;
|
|
46723
46687
|
}
|
|
@@ -46803,7 +46767,7 @@ class ServerHandler {
|
|
|
46803
46767
|
}
|
|
46804
46768
|
onStreamMessage(sender, message) {
|
|
46805
46769
|
const request = decoder_Decoder.decodeObject(BlockRequest.Codec, message);
|
|
46806
|
-
ce_128_block_request_logger.log
|
|
46770
|
+
ce_128_block_request_logger.log(`[${sender.streamId}] Client has requested: ${request}`);
|
|
46807
46771
|
const blocks = this.getBlockSequence(sender.streamId, request.headerHash, request.direction, request.maxBlocks);
|
|
46808
46772
|
sender.bufferAndSend(encoder_Encoder.encodeObject(descriptors_codec.sequenceFixLen(block_Block.Codec.View, blocks.length), blocks, this.chainSpec));
|
|
46809
46773
|
sender.close();
|
|
@@ -46823,7 +46787,7 @@ class ClientHandler {
|
|
|
46823
46787
|
throw new Error("Received an unexpected message from the server.");
|
|
46824
46788
|
}
|
|
46825
46789
|
const blocks = decoder_Decoder.decodeSequence(block_Block.Codec.View, message, this.chainSpec);
|
|
46826
|
-
ce_128_block_request_logger.log
|
|
46790
|
+
ce_128_block_request_logger.log(`[${sender.streamId}] Server returned ${blocks.length} blocks in ${message.length} bytes of data.`);
|
|
46827
46791
|
this.promiseResolvers.get(sender.streamId)?.(blocks);
|
|
46828
46792
|
this.promiseResolvers.delete(sender.streamId);
|
|
46829
46793
|
}
|
|
@@ -46994,13 +46958,13 @@ class ce_129_state_request_Handler {
|
|
|
46994
46958
|
}
|
|
46995
46959
|
onStreamMessage(sender, message) {
|
|
46996
46960
|
if (this.isServer) {
|
|
46997
|
-
ce_129_state_request_logger.info
|
|
46961
|
+
ce_129_state_request_logger.info(`[${sender.streamId}][server]: Received request.`);
|
|
46998
46962
|
if (this.getBoundaryNodes === undefined || this.getKeyValuePairs === undefined)
|
|
46999
46963
|
return;
|
|
47000
46964
|
const request = Decoder.decodeObject(StateRequest.Codec, message);
|
|
47001
46965
|
const boundaryNodes = this.getBoundaryNodes(request.headerHash, request.startKey, request.endKey);
|
|
47002
46966
|
const keyValuePairs = this.getKeyValuePairs(request.headerHash, request.startKey, request.endKey);
|
|
47003
|
-
ce_129_state_request_logger.info
|
|
46967
|
+
ce_129_state_request_logger.info(`[${sender.streamId}][server]: <-- responding with boundary nodes and key value pairs.`);
|
|
47004
46968
|
sender.bufferAndSend(Encoder.encodeObject(codec.sequenceVarLen(trieNodeCodec), boundaryNodes));
|
|
47005
46969
|
sender.bufferAndSend(Encoder.encodeObject(StateResponse.Codec, StateResponse.create({ keyValuePairs })));
|
|
47006
46970
|
sender.close();
|
|
@@ -47008,11 +46972,11 @@ class ce_129_state_request_Handler {
|
|
|
47008
46972
|
}
|
|
47009
46973
|
if (!this.boundaryNodes.has(sender.streamId)) {
|
|
47010
46974
|
this.boundaryNodes.set(sender.streamId, Decoder.decodeObject(codec.sequenceVarLen(trieNodeCodec), message));
|
|
47011
|
-
ce_129_state_request_logger.info
|
|
46975
|
+
ce_129_state_request_logger.info(`[${sender.streamId}][client]: Received boundary nodes.`);
|
|
47012
46976
|
return;
|
|
47013
46977
|
}
|
|
47014
46978
|
this.onResponse.get(sender.streamId)?.(Decoder.decodeObject(StateResponse.Codec, message));
|
|
47015
|
-
ce_129_state_request_logger.info
|
|
46979
|
+
ce_129_state_request_logger.info(`[${sender.streamId}][client]: Received state values.`);
|
|
47016
46980
|
}
|
|
47017
46981
|
onClose(streamId) {
|
|
47018
46982
|
this.boundaryNodes.delete(streamId);
|
|
@@ -47069,7 +47033,7 @@ class ce_131_ce_132_safrole_ticket_distribution_ServerHandler {
|
|
|
47069
47033
|
}
|
|
47070
47034
|
onStreamMessage(sender, message) {
|
|
47071
47035
|
const ticketDistribution = Decoder.decodeObject(TicketDistributionRequest.Codec, message);
|
|
47072
|
-
ce_131_ce_132_safrole_ticket_distribution_logger.log
|
|
47036
|
+
ce_131_ce_132_safrole_ticket_distribution_logger.log(`[${sender.streamId}][ce-${this.kind}] Received ticket for epoch ${ticketDistribution.epochIndex}`);
|
|
47073
47037
|
this.onTicketReceived(ticketDistribution.epochIndex, ticketDistribution.ticket);
|
|
47074
47038
|
sender.close();
|
|
47075
47039
|
}
|
|
@@ -47081,7 +47045,7 @@ class ce_131_ce_132_safrole_ticket_distribution_ClientHandler {
|
|
|
47081
47045
|
this.kind = kind;
|
|
47082
47046
|
}
|
|
47083
47047
|
onStreamMessage(sender) {
|
|
47084
|
-
ce_131_ce_132_safrole_ticket_distribution_logger.warn
|
|
47048
|
+
ce_131_ce_132_safrole_ticket_distribution_logger.warn(`[${sender.streamId}][ce-${this.kind}] Unexpected message received. Closing.`);
|
|
47085
47049
|
sender.close();
|
|
47086
47050
|
}
|
|
47087
47051
|
onClose() { }
|
|
@@ -47154,15 +47118,15 @@ class ce_133_work_package_submission_ServerHandler {
|
|
|
47154
47118
|
class ce_133_work_package_submission_ClientHandler {
|
|
47155
47119
|
kind = ce_133_work_package_submission_STREAM_KIND;
|
|
47156
47120
|
onStreamMessage(sender) {
|
|
47157
|
-
ce_133_work_package_submission_logger.warn
|
|
47121
|
+
ce_133_work_package_submission_logger.warn(`[${sender.streamId}] Got unexpected message on CE-133 stream. Closing.`);
|
|
47158
47122
|
sender.close();
|
|
47159
47123
|
}
|
|
47160
47124
|
onClose() { }
|
|
47161
47125
|
sendWorkPackage(sender, coreIndex, workPackage, extrinsic) {
|
|
47162
47126
|
const corePack = CoreWorkPackage.create({ coreIndex, workPackage });
|
|
47163
|
-
ce_133_work_package_submission_logger.trace
|
|
47127
|
+
ce_133_work_package_submission_logger.trace(`[${sender.streamId}] Sending work package: ${corePack}`);
|
|
47164
47128
|
sender.bufferAndSend(Encoder.encodeObject(CoreWorkPackage.Codec, corePack));
|
|
47165
|
-
ce_133_work_package_submission_logger.trace
|
|
47129
|
+
ce_133_work_package_submission_logger.trace(`[${sender.streamId}] Sending extrinsics: ${workPackage.items}`);
|
|
47166
47130
|
sender.bufferAndSend(Encoder.encodeObject(workItemExtrinsicsCodec(workPackage.items), extrinsic));
|
|
47167
47131
|
// now close the connection
|
|
47168
47132
|
sender.close();
|
|
@@ -47238,7 +47202,7 @@ class ce_134_work_package_sharing_ServerHandler {
|
|
|
47238
47202
|
ce_134_work_package_sharing_ServerHandler.sendWorkReport(sender, workReportHash, signature);
|
|
47239
47203
|
})
|
|
47240
47204
|
.catch((error) => {
|
|
47241
|
-
ce_134_work_package_sharing_logger.error
|
|
47205
|
+
ce_134_work_package_sharing_logger.error(`[${streamId}] Error processing work package: ${error}`);
|
|
47242
47206
|
this.onClose(streamId);
|
|
47243
47207
|
});
|
|
47244
47208
|
}
|
|
@@ -47255,7 +47219,7 @@ class ce_134_work_package_sharing_ClientHandler {
|
|
|
47255
47219
|
throw new Error("Unexpected message received.");
|
|
47256
47220
|
}
|
|
47257
47221
|
const response = Decoder.decodeObject(WorkPackageSharingResponse.Codec, message);
|
|
47258
|
-
ce_134_work_package_sharing_logger.info
|
|
47222
|
+
ce_134_work_package_sharing_logger.info(`[${sender.streamId}] Received work report hash and signature.`);
|
|
47259
47223
|
pendingRequest.resolve({ workReportHash: response.workReportHash, signature: response.signature });
|
|
47260
47224
|
sender.close();
|
|
47261
47225
|
}
|
|
@@ -47268,9 +47232,9 @@ class ce_134_work_package_sharing_ClientHandler {
|
|
|
47268
47232
|
}
|
|
47269
47233
|
async sendWorkPackage(sender, coreIndex, segmentsRootMappings, workPackageBundle) {
|
|
47270
47234
|
const request = WorkPackageSharingRequest.create({ coreIndex, segmentsRootMappings });
|
|
47271
|
-
ce_134_work_package_sharing_logger.trace
|
|
47235
|
+
ce_134_work_package_sharing_logger.trace(`[${sender.streamId}] Sending core index and segments-root mappings.`);
|
|
47272
47236
|
sender.bufferAndSend(Encoder.encodeObject(WorkPackageSharingRequest.Codec, request));
|
|
47273
|
-
ce_134_work_package_sharing_logger.trace
|
|
47237
|
+
ce_134_work_package_sharing_logger.trace(`[${sender.streamId}] Sending work package bundle.`);
|
|
47274
47238
|
sender.bufferAndSend(Encoder.encodeObject(WorkPackageBundleCodec, workPackageBundle));
|
|
47275
47239
|
return new Promise((resolve, reject) => {
|
|
47276
47240
|
this.pendingRequests.set(sender.streamId, { resolve, reject });
|
|
@@ -47330,7 +47294,7 @@ class ce_135_work_report_distribution_ServerHandler {
|
|
|
47330
47294
|
}
|
|
47331
47295
|
onStreamMessage(sender, message) {
|
|
47332
47296
|
const guaranteedWorkReport = Decoder.decodeObject(GuaranteedWorkReport.Codec, message, this.chainSpec);
|
|
47333
|
-
ce_135_work_report_distribution_logger.log
|
|
47297
|
+
ce_135_work_report_distribution_logger.log(`[${sender.streamId}] Received guaranteed work report.`);
|
|
47334
47298
|
this.onWorkReport(guaranteedWorkReport);
|
|
47335
47299
|
sender.close();
|
|
47336
47300
|
}
|
|
@@ -47343,12 +47307,12 @@ class ce_135_work_report_distribution_ClientHandler {
|
|
|
47343
47307
|
this.chainSpec = chainSpec;
|
|
47344
47308
|
}
|
|
47345
47309
|
onStreamMessage(sender) {
|
|
47346
|
-
ce_135_work_report_distribution_logger.warn
|
|
47310
|
+
ce_135_work_report_distribution_logger.warn(`[${sender.streamId}] Got unexpected message on CE-135 stream. Closing.`);
|
|
47347
47311
|
sender.close();
|
|
47348
47312
|
}
|
|
47349
47313
|
onClose() { }
|
|
47350
47314
|
sendWorkReport(sender, workReport) {
|
|
47351
|
-
ce_135_work_report_distribution_logger.trace
|
|
47315
|
+
ce_135_work_report_distribution_logger.trace(`[${sender.streamId}] Sending guaranteed work report.`);
|
|
47352
47316
|
sender.bufferAndSend(Encoder.encodeObject(GuaranteedWorkReport.Codec, workReport, this.chainSpec));
|
|
47353
47317
|
sender.close();
|
|
47354
47318
|
}
|
|
@@ -47454,7 +47418,7 @@ class up_0_block_announcement_Handler {
|
|
|
47454
47418
|
this.handshakes.set(streamId, handshake);
|
|
47455
47419
|
// we didn't initiate this handshake, so let's respond
|
|
47456
47420
|
if (!this.pendingHandshakes.delete(streamId)) {
|
|
47457
|
-
up_0_block_announcement_logger.log
|
|
47421
|
+
up_0_block_announcement_logger.log(`[${streamId}] <-- responding with a handshake.`);
|
|
47458
47422
|
sender.bufferAndSend(encoder_Encoder.encodeObject(Handshake.Codec, this.getHandshake()));
|
|
47459
47423
|
}
|
|
47460
47424
|
this.onHandshake(streamId, handshake);
|
|
@@ -47462,7 +47426,7 @@ class up_0_block_announcement_Handler {
|
|
|
47462
47426
|
}
|
|
47463
47427
|
// it's just an announcement
|
|
47464
47428
|
const annoucement = decoder_Decoder.decodeObject(Announcement.Codec, message, this.spec);
|
|
47465
|
-
up_0_block_announcement_logger.log
|
|
47429
|
+
up_0_block_announcement_logger.log(`[${streamId}] --> got blocks announcement: ${annoucement.final}`);
|
|
47466
47430
|
this.onAnnouncement(streamId, annoucement);
|
|
47467
47431
|
}
|
|
47468
47432
|
onClose(streamId) {
|
|
@@ -47475,7 +47439,7 @@ class up_0_block_announcement_Handler {
|
|
|
47475
47439
|
return;
|
|
47476
47440
|
}
|
|
47477
47441
|
const handshake = this.getHandshake();
|
|
47478
|
-
up_0_block_announcement_logger.trace
|
|
47442
|
+
up_0_block_announcement_logger.trace(`[${streamId}] <-- sending handshake`);
|
|
47479
47443
|
this.pendingHandshakes.set(sender.streamId, true);
|
|
47480
47444
|
sender.bufferAndSend(encoder_Encoder.encodeObject(Handshake.Codec, handshake));
|
|
47481
47445
|
}
|
|
@@ -47483,11 +47447,11 @@ class up_0_block_announcement_Handler {
|
|
|
47483
47447
|
const { streamId } = sender;
|
|
47484
47448
|
// only send announcement if we've handshaken
|
|
47485
47449
|
if (this.handshakes.has(streamId)) {
|
|
47486
|
-
up_0_block_announcement_logger.trace
|
|
47450
|
+
up_0_block_announcement_logger.trace(`[${streamId}] <-- sending block announcement: ${annoucement.final}`);
|
|
47487
47451
|
sender.bufferAndSend(encoder_Encoder.encodeObject(Announcement.Codec, annoucement, this.spec));
|
|
47488
47452
|
}
|
|
47489
47453
|
else {
|
|
47490
|
-
up_0_block_announcement_logger.warn
|
|
47454
|
+
up_0_block_announcement_logger.warn(`[${streamId}] <-- no handshake yet, skipping announcement.`);
|
|
47491
47455
|
}
|
|
47492
47456
|
}
|
|
47493
47457
|
}
|
|
@@ -47604,7 +47568,7 @@ class SyncTask {
|
|
|
47604
47568
|
onUp0Annoucement(peer, announcement) {
|
|
47605
47569
|
const { hash, slot } = announcement.final;
|
|
47606
47570
|
const bestHeader = hashHeader(announcement.header, this.spec);
|
|
47607
|
-
sync_logger.info
|
|
47571
|
+
sync_logger.info(`[${peer.id}] --> Received new header #${announcement.header.timeSlotIndex}: ${bestHeader.hash}`);
|
|
47608
47572
|
// NOTE [ToDr] Instead of having `Connections` store aux data perhaps
|
|
47609
47573
|
// we should maintain that directly? However that would require
|
|
47610
47574
|
// listening to peers connected/disconnected to perfrom some cleanups
|
|
@@ -47679,7 +47643,7 @@ class SyncTask {
|
|
|
47679
47643
|
const peers = this.connections.getConnectedPeers();
|
|
47680
47644
|
for (const peerInfo of peers) {
|
|
47681
47645
|
this.streamManager.withStreamOfKind(peerInfo.peerId, up_0_block_announcement_STREAM_KIND, (handler, sender) => {
|
|
47682
|
-
sync_logger.log
|
|
47646
|
+
sync_logger.log(`[${peerInfo.peerId}] <-- Broadcasting new header #${slot}: ${header.hash}`);
|
|
47683
47647
|
handler.sendAnnouncement(sender, annoucement);
|
|
47684
47648
|
return result_OK;
|
|
47685
47649
|
});
|
|
@@ -47693,13 +47657,13 @@ class SyncTask {
|
|
|
47693
47657
|
}
|
|
47694
47658
|
if (res.error === BlockSequenceError.BlockOnFork) {
|
|
47695
47659
|
// seems that peer is requesting syncing a fork from us, let's bail.
|
|
47696
|
-
sync_logger.warn
|
|
47660
|
+
sync_logger.warn(`[${peer.id}] <-- Invalid block sequence request: ${startHash} is on a fork.`);
|
|
47697
47661
|
return [];
|
|
47698
47662
|
}
|
|
47699
47663
|
if (res.error === BlockSequenceError.NoStartBlock) {
|
|
47700
47664
|
// we don't know about that block at all, so let's just bail.
|
|
47701
47665
|
// we should probably penalize the peer for sending BS?
|
|
47702
|
-
sync_logger.warn
|
|
47666
|
+
sync_logger.warn(`[${peer.id}] <-- Invalid block sequence request: ${startHash} missing header or extrinsic.`);
|
|
47703
47667
|
return [];
|
|
47704
47668
|
}
|
|
47705
47669
|
debug_assertNever(res.error);
|
|
@@ -47719,10 +47683,10 @@ class SyncTask {
|
|
|
47719
47683
|
// figure out where others are at
|
|
47720
47684
|
const othersBest = this.othersBest;
|
|
47721
47685
|
const blocksToSync = othersBest.slot - ourBestSlot;
|
|
47722
|
-
sync_logger.trace
|
|
47686
|
+
sync_logger.trace(`Our best. ${ourBestSlot}. Best seen: ${othersBest.slot}`);
|
|
47723
47687
|
if (blocksToSync < 1) {
|
|
47724
47688
|
this.connections.getPeerCount();
|
|
47725
|
-
sync_logger.trace
|
|
47689
|
+
sync_logger.trace(`No new blocks. ${peerCount} peers.`);
|
|
47726
47690
|
return {
|
|
47727
47691
|
kind: SyncResult.NoNewBlocks,
|
|
47728
47692
|
ours: ourBestSlot,
|
|
@@ -47730,7 +47694,7 @@ class SyncTask {
|
|
|
47730
47694
|
};
|
|
47731
47695
|
}
|
|
47732
47696
|
const requested = [];
|
|
47733
|
-
sync_logger.log
|
|
47697
|
+
sync_logger.log(`Sync ${blocksToSync} blocks from ${peerCount} peers.`);
|
|
47734
47698
|
// NOTE [ToDr] We might be requesting the same blocks from many peers
|
|
47735
47699
|
// which isn't very optimal, but for now: 🤷
|
|
47736
47700
|
//
|
|
@@ -47756,12 +47720,12 @@ class SyncTask {
|
|
|
47756
47720
|
// request as much blocks from that peer as possible.
|
|
47757
47721
|
this.streamManager.withNewStream(peerInfo.peerRef, STREAM_KIND, (handler, sender) => {
|
|
47758
47722
|
handleAsyncErrors(async () => {
|
|
47759
|
-
sync_logger.log
|
|
47723
|
+
sync_logger.log(`Fetching blocks from ${peerInfo.peerId}.`);
|
|
47760
47724
|
const blocks = await handler.requestBlockSequence(sender, bestHash, Direction.DescIncl, numbers_tryAsU32(bestSlot - ourBestSlot));
|
|
47761
47725
|
blocks.reverse();
|
|
47762
47726
|
this.onNewBlocks(blocks, peerInfo.peerId);
|
|
47763
47727
|
}, (e) => {
|
|
47764
|
-
sync_logger.warn
|
|
47728
|
+
sync_logger.warn(`[${peerInfo.peerId}] --> requesting blocks to import: ${e}`);
|
|
47765
47729
|
});
|
|
47766
47730
|
return result_OK;
|
|
47767
47731
|
});
|
|
@@ -47835,7 +47799,7 @@ function setupPeerListeners(syncTask, network, streamManager) {
|
|
|
47835
47799
|
// whenever the peer wants to open a stream with us, let's handle that.
|
|
47836
47800
|
peer.addOnIncomingStream((stream) => {
|
|
47837
47801
|
handleAsyncErrors(() => streamManager.onIncomingStream(peer, stream), (e) => {
|
|
47838
|
-
network_logger.error
|
|
47802
|
+
network_logger.error(`[${peer.id}:${stream.streamId}]🚰 Stream error: ${e}. Disconnecting peer.`);
|
|
47839
47803
|
peer.disconnect();
|
|
47840
47804
|
});
|
|
47841
47805
|
return result_OK;
|
|
@@ -47926,7 +47890,7 @@ class MainReady extends State {
|
|
|
47926
47890
|
this.onNewBlocks.emit(blocks);
|
|
47927
47891
|
}
|
|
47928
47892
|
else {
|
|
47929
|
-
state_machine_logger.error
|
|
47893
|
+
state_machine_logger.error(`${this.constructor.name} got invalid signal type: ${JSON.stringify(block)}.`);
|
|
47930
47894
|
}
|
|
47931
47895
|
}
|
|
47932
47896
|
announceHeader(port, header) {
|
|
@@ -47964,7 +47928,7 @@ class NetworkReady extends State {
|
|
|
47964
47928
|
this.onNewHeader.emit(decoded);
|
|
47965
47929
|
}
|
|
47966
47930
|
else {
|
|
47967
|
-
state_machine_logger.error
|
|
47931
|
+
state_machine_logger.error(`${this.constructor.name} got invalid signal type: ${JSON.stringify(header)}.`);
|
|
47968
47932
|
}
|
|
47969
47933
|
}
|
|
47970
47934
|
sendBlocks(port, blocks) {
|
|
@@ -48003,7 +47967,7 @@ if (!external_node_worker_threads_namespaceObject.isMainThread) {
|
|
|
48003
47967
|
Logger.configureAll(process.env.JAM_LOG ?? "", Level.LOG);
|
|
48004
47968
|
const machine = networkStateMachine();
|
|
48005
47969
|
const channel = MessageChannelStateMachine.receiveChannel(machine, external_node_worker_threads_namespaceObject.parentPort);
|
|
48006
|
-
channel.then((channel) => main(channel)).catch((e) => jam_network_logger.error
|
|
47970
|
+
channel.then((channel) => main(channel)).catch((e) => jam_network_logger.error(e));
|
|
48007
47971
|
}
|
|
48008
47972
|
/**
|
|
48009
47973
|
* JAM networking worker.
|
|
@@ -48014,7 +47978,7 @@ if (!external_node_worker_threads_namespaceObject.isMainThread) {
|
|
|
48014
47978
|
*/
|
|
48015
47979
|
async function main(channel) {
|
|
48016
47980
|
await initAll();
|
|
48017
|
-
jam_network_logger.trace
|
|
47981
|
+
jam_network_logger.trace(`🛜 Network starting ${channel.currentState()}`);
|
|
48018
47982
|
// Await the configuration object
|
|
48019
47983
|
// TODO [ToDr] The whole state machine needs to die.
|
|
48020
47984
|
const ready = channel.currentState().stateName !== "ready(network)"
|
|
@@ -48025,7 +47989,7 @@ async function main(channel) {
|
|
|
48025
47989
|
const key = await ed25519_privateKey(config.key);
|
|
48026
47990
|
const lmdb = new LmdbRoot(config.genericConfig.dbPath);
|
|
48027
47991
|
const blocks = new LmdbBlocks(config.genericConfig.chainSpec, lmdb);
|
|
48028
|
-
jam_network_logger.info
|
|
47992
|
+
jam_network_logger.info(`🛜 Listening at ${config.host}:${config.port}`);
|
|
48029
47993
|
const network = await setup({
|
|
48030
47994
|
host: config.host,
|
|
48031
47995
|
port: config.port,
|
|
@@ -48038,7 +48002,7 @@ async function main(channel) {
|
|
|
48038
48002
|
ready.waitForState("finished").then(() => network.network.stop());
|
|
48039
48003
|
await network.network.start();
|
|
48040
48004
|
});
|
|
48041
|
-
jam_network_logger.info
|
|
48005
|
+
jam_network_logger.info("🛜 Network worker finished. Closing channel.");
|
|
48042
48006
|
// Close the comms to gracefuly close the app.
|
|
48043
48007
|
finished.currentState().close(channel);
|
|
48044
48008
|
}
|