@typeberry/jam 0.1.1-4a6ffa9 → 0.1.1-e48de40
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 +103 -94
- package/block-generator/index.js.map +1 -1
- package/importer/index.js +185 -176
- package/importer/index.js.map +1 -1
- package/index.js +342 -333
- package/index.js.map +1 -1
- package/jam-network/index.js +169 -162
- package/jam-network/index.js.map +1 -1
- package/package.json +1 -1
package/jam-network/index.js
CHANGED
|
@@ -32165,6 +32165,23 @@ function parseLevel(lvl) {
|
|
|
32165
32165
|
;// CONCATENATED MODULE: ./packages/core/logger/console.ts
|
|
32166
32166
|
// biome-ignore-all lint/suspicious/noConsole: logger
|
|
32167
32167
|
|
|
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
|
+
}
|
|
32168
32185
|
/** An optimized logger that ignores `TRACE`, `DEBUG` and `LOG` messages.
|
|
32169
32186
|
*
|
|
32170
32187
|
* Use the `create` method to instantiate the right instance of a more specialized logger.
|
|
@@ -32195,109 +32212,91 @@ class ConsoleTransport {
|
|
|
32195
32212
|
constructor(options) {
|
|
32196
32213
|
this.options = options;
|
|
32197
32214
|
}
|
|
32198
|
-
insane(
|
|
32215
|
+
insane(_levelAndName, _strings, _data) {
|
|
32199
32216
|
/* no-op */
|
|
32200
32217
|
}
|
|
32201
|
-
trace(
|
|
32218
|
+
trace(_levelAndName, _strings, _data) {
|
|
32202
32219
|
/* no-op */
|
|
32203
32220
|
}
|
|
32204
|
-
log(
|
|
32221
|
+
log(_levelAndName, _strings, _data) {
|
|
32205
32222
|
/* no-op */
|
|
32206
32223
|
}
|
|
32207
|
-
info(
|
|
32224
|
+
info(_levelAndName, _strings, _data) {
|
|
32208
32225
|
/* no-op */
|
|
32209
32226
|
}
|
|
32210
|
-
warn(
|
|
32211
|
-
|
|
32227
|
+
warn(levelAndName, strings, data) {
|
|
32228
|
+
print(Level.WARN, levelAndName, strings, data);
|
|
32212
32229
|
}
|
|
32213
|
-
error(
|
|
32214
|
-
|
|
32215
|
-
}
|
|
32216
|
-
push(level, moduleName, val) {
|
|
32217
|
-
const shortModule = moduleName.replace(this.options.workingDir, "");
|
|
32218
|
-
const configuredLevel = findLevel(this.options, moduleName);
|
|
32219
|
-
const lvlText = Level[level].padEnd(5);
|
|
32220
|
-
if (level < configuredLevel) {
|
|
32221
|
-
return;
|
|
32222
|
-
}
|
|
32223
|
-
const msg = `${lvlText} [${shortModule}] ${val}`;
|
|
32224
|
-
if (level === Level.WARN) {
|
|
32225
|
-
console.warn(msg);
|
|
32226
|
-
}
|
|
32227
|
-
else if (level === Level.ERROR) {
|
|
32228
|
-
console.error(msg);
|
|
32229
|
-
}
|
|
32230
|
-
else {
|
|
32231
|
-
console.info(msg);
|
|
32232
|
-
}
|
|
32230
|
+
error(levelAndName, strings, data) {
|
|
32231
|
+
print(Level.ERROR, levelAndName, strings, data);
|
|
32233
32232
|
}
|
|
32234
32233
|
}
|
|
32235
32234
|
/**
|
|
32236
32235
|
* Insane version of console logger - supports insane level.
|
|
32237
32236
|
*/
|
|
32238
32237
|
class InsaneConsoleLogger extends ConsoleTransport {
|
|
32239
|
-
insane(
|
|
32240
|
-
|
|
32238
|
+
insane(levelAndName, strings, data) {
|
|
32239
|
+
print(Level.INSANE, levelAndName, strings, data);
|
|
32241
32240
|
}
|
|
32242
|
-
trace(
|
|
32243
|
-
|
|
32241
|
+
trace(levelAndName, strings, data) {
|
|
32242
|
+
print(Level.TRACE, levelAndName, strings, data);
|
|
32244
32243
|
}
|
|
32245
|
-
log(
|
|
32246
|
-
|
|
32244
|
+
log(levelAndName, strings, data) {
|
|
32245
|
+
print(Level.LOG, levelAndName, strings, data);
|
|
32247
32246
|
}
|
|
32248
|
-
info(
|
|
32249
|
-
|
|
32247
|
+
info(levelAndName, strings, data) {
|
|
32248
|
+
print(Level.INFO, levelAndName, strings, data);
|
|
32250
32249
|
}
|
|
32251
32250
|
}
|
|
32252
32251
|
/**
|
|
32253
32252
|
* A basic version of console logger - printing everything.
|
|
32254
32253
|
*/
|
|
32255
32254
|
class TraceConsoleTransport extends ConsoleTransport {
|
|
32256
|
-
insane(
|
|
32255
|
+
insane(_levelAndName, _strings, _data) {
|
|
32257
32256
|
/* no-op */
|
|
32258
32257
|
}
|
|
32259
|
-
trace(
|
|
32260
|
-
|
|
32258
|
+
trace(levelAndName, strings, data) {
|
|
32259
|
+
print(Level.TRACE, levelAndName, strings, data);
|
|
32261
32260
|
}
|
|
32262
|
-
log(
|
|
32263
|
-
|
|
32261
|
+
log(levelAndName, strings, data) {
|
|
32262
|
+
print(Level.LOG, levelAndName, strings, data);
|
|
32264
32263
|
}
|
|
32265
|
-
info(
|
|
32266
|
-
|
|
32264
|
+
info(levelAndName, strings, data) {
|
|
32265
|
+
print(Level.INFO, levelAndName, strings, data);
|
|
32267
32266
|
}
|
|
32268
32267
|
}
|
|
32269
32268
|
/**
|
|
32270
32269
|
* An optimized version of the logger - completely ignores `TRACE` level calls.
|
|
32271
32270
|
*/
|
|
32272
32271
|
class LogConsoleTransport extends ConsoleTransport {
|
|
32273
|
-
insane(
|
|
32272
|
+
insane(_levelAndName, _strings, _data) {
|
|
32274
32273
|
/* no-op */
|
|
32275
32274
|
}
|
|
32276
|
-
trace(
|
|
32275
|
+
trace(_levelAndName, _strings, _data) {
|
|
32277
32276
|
/* no-op */
|
|
32278
32277
|
}
|
|
32279
|
-
log(
|
|
32280
|
-
|
|
32278
|
+
log(levelAndName, strings, data) {
|
|
32279
|
+
print(Level.LOG, levelAndName, strings, data);
|
|
32281
32280
|
}
|
|
32282
|
-
info(
|
|
32283
|
-
|
|
32281
|
+
info(levelAndName, strings, data) {
|
|
32282
|
+
print(Level.INFO, levelAndName, strings, data);
|
|
32284
32283
|
}
|
|
32285
32284
|
}
|
|
32286
32285
|
/**
|
|
32287
32286
|
* An optimized version of the logger - completely ignores `TRACE` & `DEBUG` level calls.
|
|
32288
32287
|
*/
|
|
32289
32288
|
class InfoConsoleTransport extends ConsoleTransport {
|
|
32290
|
-
insane(
|
|
32289
|
+
insane(_levelAndName, _strings, _data) {
|
|
32291
32290
|
/* no-op */
|
|
32292
32291
|
}
|
|
32293
|
-
trace(
|
|
32292
|
+
trace(_levelAndName, _strings, _data) {
|
|
32294
32293
|
/* no-op */
|
|
32295
32294
|
}
|
|
32296
|
-
log(
|
|
32295
|
+
log(_levelAndName, _strings, _data) {
|
|
32297
32296
|
/* no-op */
|
|
32298
32297
|
}
|
|
32299
|
-
info(
|
|
32300
|
-
|
|
32298
|
+
info(levelAndName, strings, data) {
|
|
32299
|
+
print(Level.INFO, levelAndName, strings, data);
|
|
32301
32300
|
}
|
|
32302
32301
|
}
|
|
32303
32302
|
|
|
@@ -32334,11 +32333,6 @@ class Logger {
|
|
|
32334
32333
|
const module = moduleName ?? fName;
|
|
32335
32334
|
return new Logger(module.padStart(8, " "), GLOBAL_CONFIG);
|
|
32336
32335
|
}
|
|
32337
|
-
/**
|
|
32338
|
-
* Return currently configured level for given module. */
|
|
32339
|
-
static getLevel(moduleName) {
|
|
32340
|
-
return findLevel(GLOBAL_CONFIG.options, moduleName);
|
|
32341
|
-
}
|
|
32342
32336
|
/**
|
|
32343
32337
|
* Global configuration of all loggers.
|
|
32344
32338
|
*
|
|
@@ -32369,33 +32363,46 @@ class Logger {
|
|
|
32369
32363
|
const options = parseLoggerOptions(input, defaultLevel, workingDir);
|
|
32370
32364
|
Logger.configureAllFromOptions(options);
|
|
32371
32365
|
}
|
|
32366
|
+
cachedLevelAndName;
|
|
32372
32367
|
constructor(moduleName, config) {
|
|
32373
32368
|
this.moduleName = moduleName;
|
|
32374
32369
|
this.config = config;
|
|
32375
32370
|
}
|
|
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
|
+
}
|
|
32376
32383
|
/** Log a message with `INSANE` level. */
|
|
32377
|
-
insane(
|
|
32378
|
-
this.config.transport.insane(this.
|
|
32384
|
+
insane(strings, ...data) {
|
|
32385
|
+
this.config.transport.insane(this.getLevelAndName(), strings, data);
|
|
32379
32386
|
}
|
|
32380
32387
|
/** Log a message with `TRACE` level. */
|
|
32381
|
-
trace(
|
|
32382
|
-
this.config.transport.trace(this.
|
|
32388
|
+
trace(strings, ...data) {
|
|
32389
|
+
this.config.transport.trace(this.getLevelAndName(), strings, data);
|
|
32383
32390
|
}
|
|
32384
32391
|
/** Log a message with `DEBUG`/`LOG` level. */
|
|
32385
|
-
log(
|
|
32386
|
-
this.config.transport.log(this.
|
|
32392
|
+
log(strings, ...data) {
|
|
32393
|
+
this.config.transport.log(this.getLevelAndName(), strings, data);
|
|
32387
32394
|
}
|
|
32388
32395
|
/** Log a message with `INFO` level. */
|
|
32389
|
-
info(
|
|
32390
|
-
this.config.transport.info(this.
|
|
32396
|
+
info(strings, ...data) {
|
|
32397
|
+
this.config.transport.info(this.getLevelAndName(), strings, data);
|
|
32391
32398
|
}
|
|
32392
32399
|
/** Log a message with `WARN` level. */
|
|
32393
|
-
warn(
|
|
32394
|
-
this.config.transport.warn(this.
|
|
32400
|
+
warn(strings, ...data) {
|
|
32401
|
+
this.config.transport.warn(this.getLevelAndName(), strings, data);
|
|
32395
32402
|
}
|
|
32396
32403
|
/** Log a message with `ERROR` level. */
|
|
32397
|
-
error(
|
|
32398
|
-
this.config.transport.error(this.
|
|
32404
|
+
error(strings, ...data) {
|
|
32405
|
+
this.config.transport.error(this.getLevelAndName(), strings, data);
|
|
32399
32406
|
}
|
|
32400
32407
|
}
|
|
32401
32408
|
|
|
@@ -32485,15 +32492,15 @@ class NodeConfiguration {
|
|
|
32485
32492
|
}
|
|
32486
32493
|
function loadConfig(configPath) {
|
|
32487
32494
|
if (configPath === DEFAULT_CONFIG) {
|
|
32488
|
-
logger.log
|
|
32495
|
+
logger.log `🔧 Loading DEFAULT config`;
|
|
32489
32496
|
return parseFromJson(configs.default, NodeConfiguration.fromJson);
|
|
32490
32497
|
}
|
|
32491
32498
|
if (configPath === DEV_CONFIG) {
|
|
32492
|
-
logger.log
|
|
32499
|
+
logger.log `🔧 Loading DEV config`;
|
|
32493
32500
|
return parseFromJson(configs.dev, NodeConfiguration.fromJson);
|
|
32494
32501
|
}
|
|
32495
32502
|
try {
|
|
32496
|
-
logger.log
|
|
32503
|
+
logger.log `🔧 Loading config from ${configPath}`;
|
|
32497
32504
|
const configFile = fs.readFileSync(configPath, "utf8");
|
|
32498
32505
|
const parsed = JSON.parse(configFile);
|
|
32499
32506
|
return parseFromJson(parsed, NodeConfiguration.fromJson);
|
|
@@ -36199,7 +36206,7 @@ class LmdbStates {
|
|
|
36199
36206
|
await Promise.all([valuesWrite, statesWrite]);
|
|
36200
36207
|
}
|
|
36201
36208
|
catch (e) {
|
|
36202
|
-
states_logger.error
|
|
36209
|
+
states_logger.error `${e}`;
|
|
36203
36210
|
return Result.error(StateUpdateError.Commit);
|
|
36204
36211
|
}
|
|
36205
36212
|
return Result.ok(OK);
|
|
@@ -36308,7 +36315,7 @@ class TypedPort {
|
|
|
36308
36315
|
this.dispatchPortMessage(msg);
|
|
36309
36316
|
}
|
|
36310
36317
|
catch (e) {
|
|
36311
|
-
port_logger.error
|
|
36318
|
+
port_logger.error `[${this.constructor.name}] Failed to dispatch a message: ${e}: ${msg}`;
|
|
36312
36319
|
throw e;
|
|
36313
36320
|
}
|
|
36314
36321
|
});
|
|
@@ -36382,7 +36389,7 @@ class TypedPort {
|
|
|
36382
36389
|
this.port.postMessage(msg, transferList);
|
|
36383
36390
|
}
|
|
36384
36391
|
catch (e) {
|
|
36385
|
-
port_logger.error
|
|
36392
|
+
port_logger.error `[${this.constructor.name}] Failed to post a message: ${e}: ${msg}`;
|
|
36386
36393
|
throw e;
|
|
36387
36394
|
}
|
|
36388
36395
|
}
|
|
@@ -36413,7 +36420,7 @@ class TypedPort {
|
|
|
36413
36420
|
cleanup(reason) {
|
|
36414
36421
|
// resolve all pending requests with an error.
|
|
36415
36422
|
const responseListeners = this.responseListeners.eventNames();
|
|
36416
|
-
for (const ev
|
|
36423
|
+
for (const ev of responseListeners) {
|
|
36417
36424
|
this.responseListeners.emit(ev, new Error(`port is ${reason}`));
|
|
36418
36425
|
}
|
|
36419
36426
|
}
|
|
@@ -36462,7 +36469,7 @@ class MessageChannelStateMachine {
|
|
|
36462
36469
|
this.dispatchSignal(name, data);
|
|
36463
36470
|
}
|
|
36464
36471
|
catch (e) {
|
|
36465
|
-
channel_logger.error
|
|
36472
|
+
channel_logger.error `[${this.constructor.name}] Unable to dispatch signal (${name}): ${e}. ${this.stateInfo(remoteState)}`;
|
|
36466
36473
|
throw e;
|
|
36467
36474
|
}
|
|
36468
36475
|
});
|
|
@@ -36471,7 +36478,7 @@ class MessageChannelStateMachine {
|
|
|
36471
36478
|
await this.dispatchRequest(name, data, msg);
|
|
36472
36479
|
}
|
|
36473
36480
|
catch (e) {
|
|
36474
|
-
channel_logger.error
|
|
36481
|
+
channel_logger.error `[${this.constructor.name}] Unable to dispatch request (${name}): ${e}. ${this.stateInfo(remoteState)}`;
|
|
36475
36482
|
throw e;
|
|
36476
36483
|
}
|
|
36477
36484
|
});
|
|
@@ -36557,7 +36564,7 @@ class MessageChannelStateMachine {
|
|
|
36557
36564
|
this.machine.transition(res.transitionTo.state, res.transitionTo.data);
|
|
36558
36565
|
}
|
|
36559
36566
|
if (didStateChangeInMeantime) {
|
|
36560
|
-
channel_logger.warn
|
|
36567
|
+
channel_logger.warn `Ignoring obsolete response for an old request: "${name}"`;
|
|
36561
36568
|
return;
|
|
36562
36569
|
}
|
|
36563
36570
|
return this.port.respond(prevState.stateName, msg, res.response);
|
|
@@ -36573,7 +36580,7 @@ class MessageChannelStateMachine {
|
|
|
36573
36580
|
}
|
|
36574
36581
|
}
|
|
36575
36582
|
transitionTo() {
|
|
36576
|
-
channel_logger.trace
|
|
36583
|
+
channel_logger.trace `[${this.machine.name}] transitioned to ${this.currentState()}`;
|
|
36577
36584
|
return this;
|
|
36578
36585
|
}
|
|
36579
36586
|
/**
|
|
@@ -36593,7 +36600,7 @@ class MessageChannelStateMachine {
|
|
|
36593
36600
|
await promise;
|
|
36594
36601
|
}
|
|
36595
36602
|
catch (e) {
|
|
36596
|
-
channel_logger.error
|
|
36603
|
+
channel_logger.error `${e}`;
|
|
36597
36604
|
}
|
|
36598
36605
|
return new MessageChannelStateMachine(machine, port);
|
|
36599
36606
|
}
|
|
@@ -36796,7 +36803,7 @@ class State {
|
|
|
36796
36803
|
* actions.
|
|
36797
36804
|
*/
|
|
36798
36805
|
onActivation(data) {
|
|
36799
|
-
state_logger.trace
|
|
36806
|
+
state_logger.trace `[${this.constructor.name}] Changing state to: ${this}`;
|
|
36800
36807
|
this.data = data;
|
|
36801
36808
|
}
|
|
36802
36809
|
/**
|
|
@@ -36894,7 +36901,7 @@ async function spawnWorkerGeneric(bootstrapPath, logger, mainReadyName, mainRead
|
|
|
36894
36901
|
const worker = new external_node_worker_threads_namespaceObject.Worker(bootstrapPath);
|
|
36895
36902
|
const machine = stateMachineMain(`main->${mainReadyName}`, mainReadyName, mainReadyState);
|
|
36896
36903
|
const channel = await MessageChannelStateMachine.createAndTransferChannel(machine, worker);
|
|
36897
|
-
logger.trace
|
|
36904
|
+
logger.trace `[${machine.name}] Worker spawned ${channel.currentState()}`;
|
|
36898
36905
|
return channel;
|
|
36899
36906
|
}
|
|
36900
36907
|
|
|
@@ -36991,11 +36998,11 @@ class PeersManagement {
|
|
|
36991
36998
|
_onPeerDisconnected = [];
|
|
36992
36999
|
peers = new Map();
|
|
36993
37000
|
peerConnected(peer) {
|
|
36994
|
-
peers_logger.info
|
|
37001
|
+
peers_logger.info `💡 Peer ${displayId(peer)} connected.`;
|
|
36995
37002
|
const oldPeerData = this.peers.get(peer.id);
|
|
36996
37003
|
if (oldPeerData !== undefined) {
|
|
36997
37004
|
// TODO [ToDr] replacing old connection?
|
|
36998
|
-
peers_logger.warn
|
|
37005
|
+
peers_logger.warn `Replacing older connection.`;
|
|
36999
37006
|
}
|
|
37000
37007
|
this.peers.set(peer.id, peer);
|
|
37001
37008
|
for (const callback of this._onPeerConnected) {
|
|
@@ -37003,7 +37010,7 @@ class PeersManagement {
|
|
|
37003
37010
|
}
|
|
37004
37011
|
}
|
|
37005
37012
|
peerDisconnected(peer) {
|
|
37006
|
-
peers_logger.info
|
|
37013
|
+
peers_logger.info `⚡︎Peer ${displayId(peer)} disconnected.`;
|
|
37007
37014
|
this.peers.delete(peer.id);
|
|
37008
37015
|
for (const callback of this._onPeerDisconnected) {
|
|
37009
37016
|
callback(peer);
|
|
@@ -45795,23 +45802,23 @@ var VerifyCertError;
|
|
|
45795
45802
|
VerifyCertError[VerifyCertError["IncorrectSignature"] = 4] = "IncorrectSignature";
|
|
45796
45803
|
})(VerifyCertError || (VerifyCertError = {}));
|
|
45797
45804
|
async function verifyCertificate(certs) {
|
|
45798
|
-
certificate_logger.log
|
|
45805
|
+
certificate_logger.log `Incoming peer. Verifying certificate`;
|
|
45799
45806
|
// Must present exactly one cert
|
|
45800
45807
|
if (certs.length !== 1) {
|
|
45801
|
-
certificate_logger.log
|
|
45808
|
+
certificate_logger.log `Rejecting peer: expected exactly one certificate, got: ${certs.length}`;
|
|
45802
45809
|
return result_Result.error(VerifyCertError.NoCertificate);
|
|
45803
45810
|
}
|
|
45804
45811
|
// Parse with Node's X509Certificate (accepts PEM or DER)
|
|
45805
45812
|
const xc = new (external_node_crypto_default()).X509Certificate(certs[0]);
|
|
45806
45813
|
// Must be Ed25519 key
|
|
45807
45814
|
if (xc.publicKey.asymmetricKeyType !== CURVE_NAME.toLowerCase()) {
|
|
45808
|
-
certificate_logger.log
|
|
45815
|
+
certificate_logger.log `Rejecting peer using non-ed25519 certificate: ${xc.publicKey.asymmetricKeyType}`;
|
|
45809
45816
|
return result_Result.error(VerifyCertError.NotEd25519);
|
|
45810
45817
|
}
|
|
45811
45818
|
// Extract raw public key via JWK export
|
|
45812
45819
|
const jwk = xc.publicKey.export({ format: "jwk" });
|
|
45813
45820
|
if (jwk.kty !== KEY_TYPE || jwk.crv !== CURVE_NAME) {
|
|
45814
|
-
certificate_logger.log
|
|
45821
|
+
certificate_logger.log `Public key type mismatch: ${jwk.kty}, ${jwk.crv}`;
|
|
45815
45822
|
return result_Result.error(VerifyCertError.PublicKeyTypeMismatch);
|
|
45816
45823
|
}
|
|
45817
45824
|
// SAN must be exactly 'e'+base32(rawPub)
|
|
@@ -45819,7 +45826,7 @@ async function verifyCertificate(certs) {
|
|
|
45819
45826
|
const sanField = xc.subjectAltName ?? "";
|
|
45820
45827
|
const m = sanField.match(/DNS:([^,]+)/);
|
|
45821
45828
|
if (m === null || m[1] !== expectedSan) {
|
|
45822
|
-
certificate_logger.log
|
|
45829
|
+
certificate_logger.log `AltName mismatch. Expected: '${expectedSan}', got: '${m?.[1]}'`;
|
|
45823
45830
|
return result_Result.error(VerifyCertError.AltNameMismatch);
|
|
45824
45831
|
}
|
|
45825
45832
|
const key = Buffer.from(jwk.x ?? "", "base64url");
|
|
@@ -46086,19 +46093,19 @@ class QuicNetwork {
|
|
|
46086
46093
|
}
|
|
46087
46094
|
this.started = true;
|
|
46088
46095
|
await this.socket.start({ host: this.listen.host, port: this.listen.port });
|
|
46089
|
-
quic_network_logger.info
|
|
46096
|
+
quic_network_logger.info `🛜 QUIC socket on ${this.socket.host}:${this.socket.port}`;
|
|
46090
46097
|
await this.server.start();
|
|
46091
|
-
quic_network_logger.log
|
|
46098
|
+
quic_network_logger.log `🛜 QUIC server listening`;
|
|
46092
46099
|
}
|
|
46093
46100
|
async stop() {
|
|
46094
46101
|
if (!this.started) {
|
|
46095
46102
|
throw new Error("Network not started yet!");
|
|
46096
46103
|
}
|
|
46097
|
-
quic_network_logger.info
|
|
46104
|
+
quic_network_logger.info `Stopping the networking.`;
|
|
46098
46105
|
await this.server.stop();
|
|
46099
46106
|
await this.socket.stop();
|
|
46100
46107
|
this.started = false;
|
|
46101
|
-
quic_network_logger.info
|
|
46108
|
+
quic_network_logger.info `Networking stopped.`;
|
|
46102
46109
|
}
|
|
46103
46110
|
get peers() {
|
|
46104
46111
|
return this._peers;
|
|
@@ -46119,7 +46126,7 @@ clazz, callback) {
|
|
|
46119
46126
|
await callback(ev);
|
|
46120
46127
|
}
|
|
46121
46128
|
catch (e) {
|
|
46122
|
-
quic_utils_logger.error
|
|
46129
|
+
quic_utils_logger.error `Unhandled exception in ${clazz.name} event handler: ${e}`;
|
|
46123
46130
|
}
|
|
46124
46131
|
});
|
|
46125
46132
|
}
|
|
@@ -46178,7 +46185,7 @@ class QuicPeer {
|
|
|
46178
46185
|
streamEvents = new (external_node_events_default())();
|
|
46179
46186
|
constructor(conn, peerInfo) {
|
|
46180
46187
|
this.conn = conn;
|
|
46181
|
-
quic_peer_logger.log
|
|
46188
|
+
quic_peer_logger.log `👥 [${peerInfo.id}] peer connected ${conn.remoteHost}:${conn.remotePort}`;
|
|
46182
46189
|
this.connectionId = conn.connectionIdShared.toString();
|
|
46183
46190
|
this.address = {
|
|
46184
46191
|
host: conn.remoteHost,
|
|
@@ -46188,11 +46195,11 @@ class QuicPeer {
|
|
|
46188
46195
|
this.key = peerInfo.key;
|
|
46189
46196
|
addEventListener(conn, EventQUICConnectionStream, (ev) => {
|
|
46190
46197
|
const stream = ev.detail;
|
|
46191
|
-
quic_peer_logger.log
|
|
46198
|
+
quic_peer_logger.log `🚰 [${this.id}] new stream: [${stream.streamId}]`;
|
|
46192
46199
|
this.streamEvents.emit("stream", new QuicStream(stream));
|
|
46193
46200
|
});
|
|
46194
46201
|
addEventListener(conn, EventQUICConnectionError, (err) => {
|
|
46195
|
-
quic_peer_logger.error
|
|
46202
|
+
quic_peer_logger.error `❌ [${this.id}] connection failed: ${err.detail}`;
|
|
46196
46203
|
});
|
|
46197
46204
|
}
|
|
46198
46205
|
addOnIncomingStream(streamCallback) {
|
|
@@ -46200,11 +46207,11 @@ class QuicPeer {
|
|
|
46200
46207
|
}
|
|
46201
46208
|
openStream() {
|
|
46202
46209
|
const stream = this.conn.newStream("bidi");
|
|
46203
|
-
quic_peer_logger.log
|
|
46210
|
+
quic_peer_logger.log `🚰 [${this.id}] opening stream: [${stream.streamId}]`;
|
|
46204
46211
|
return new QuicStream(stream);
|
|
46205
46212
|
}
|
|
46206
46213
|
async disconnect() {
|
|
46207
|
-
quic_peer_logger.log
|
|
46214
|
+
quic_peer_logger.log `👋 [${this.id}] disconnecting`;
|
|
46208
46215
|
await this.conn.stop({ isApp: true });
|
|
46209
46216
|
}
|
|
46210
46217
|
}
|
|
@@ -46225,7 +46232,7 @@ const setup_logger = Logger.new(import.meta.filename, "net");
|
|
|
46225
46232
|
class Quic {
|
|
46226
46233
|
/** Setup QUIC socket and start listening for connections. */
|
|
46227
46234
|
static async setup({ host, port, protocols, key }) {
|
|
46228
|
-
const quicLoggerLvl =
|
|
46235
|
+
const quicLoggerLvl = setup_logger.getLevel() > Level.TRACE ? LogLevel.WARN : LogLevel.DEBUG;
|
|
46229
46236
|
const quicLogger = new dist_Logger("quic", quicLoggerLvl, [
|
|
46230
46237
|
new handlers_StreamHandler(format `${level}:${keys}:${msg}`),
|
|
46231
46238
|
]);
|
|
@@ -46248,7 +46255,7 @@ class Quic {
|
|
|
46248
46255
|
verifyPeer: true,
|
|
46249
46256
|
verifyCallback: lastConnectedPeer.verifyCallback,
|
|
46250
46257
|
};
|
|
46251
|
-
setup_logger.info
|
|
46258
|
+
setup_logger.info `🆔 Peer id: ** ${altNameRaw(key.pubKey)}@${host}:${port} ** (pubkey: ${key.pubKey})`;
|
|
46252
46259
|
// Shared injected UDP socket
|
|
46253
46260
|
const socket = new dist_QUICSocket({
|
|
46254
46261
|
logger: quicLogger.getChild("socket"),
|
|
@@ -46263,8 +46270,8 @@ class Quic {
|
|
|
46263
46270
|
// peer management
|
|
46264
46271
|
const peers = new PeersManagement();
|
|
46265
46272
|
// basic error handling
|
|
46266
|
-
addEventListener(server, EventQUICServerError, (error) => setup_logger.error
|
|
46267
|
-
addEventListener(server, EventQUICServerClose, (ev) => setup_logger.error
|
|
46273
|
+
addEventListener(server, EventQUICServerError, (error) => setup_logger.error `🛜 Server error: ${error}`);
|
|
46274
|
+
addEventListener(server, EventQUICServerClose, (ev) => setup_logger.error `🛜 Server stopped: ${ev}`);
|
|
46268
46275
|
// handling incoming session
|
|
46269
46276
|
addEventListener(server, EventQUICServerConnection, async (ev) => {
|
|
46270
46277
|
const conn = ev.detail;
|
|
@@ -46273,16 +46280,16 @@ class Quic {
|
|
|
46273
46280
|
return;
|
|
46274
46281
|
}
|
|
46275
46282
|
if (lastConnectedPeer.info.key.isEqualTo(key.pubKey)) {
|
|
46276
|
-
setup_logger.log
|
|
46283
|
+
setup_logger.log `🛜 Rejecting connection from ourself from ${conn.remoteHost}:${conn.remotePort}`;
|
|
46277
46284
|
await conn.stop();
|
|
46278
46285
|
return;
|
|
46279
46286
|
}
|
|
46280
46287
|
if (peers.isConnected(lastConnectedPeer.info.id)) {
|
|
46281
|
-
setup_logger.log
|
|
46288
|
+
setup_logger.log `🛜 Rejecting duplicate connection with peer ${lastConnectedPeer.info.id} from ${conn.remoteHost}:${conn.remotePort}`;
|
|
46282
46289
|
await conn.stop();
|
|
46283
46290
|
return;
|
|
46284
46291
|
}
|
|
46285
|
-
setup_logger.log
|
|
46292
|
+
setup_logger.log `🛜 Server handshake with ${conn.remoteHost}:${conn.remotePort}`;
|
|
46286
46293
|
newPeer(conn, lastConnectedPeer.info);
|
|
46287
46294
|
lastConnectedPeer.info = null;
|
|
46288
46295
|
await conn.start();
|
|
@@ -46305,10 +46312,10 @@ class Quic {
|
|
|
46305
46312
|
});
|
|
46306
46313
|
const client = await clientLater;
|
|
46307
46314
|
addEventListener(client, EventQUICClientClose, () => {
|
|
46308
|
-
setup_logger.log
|
|
46315
|
+
setup_logger.log `⚰️ Client connection closed.`;
|
|
46309
46316
|
});
|
|
46310
46317
|
addEventListener(client, EventQUICClientError, (error) => {
|
|
46311
|
-
setup_logger.error
|
|
46318
|
+
setup_logger.error `🔴 Client error: ${error.detail}`;
|
|
46312
46319
|
});
|
|
46313
46320
|
if (peerDetails.info === null) {
|
|
46314
46321
|
throw new Error("Client connected, but there is no peer details!");
|
|
@@ -46316,7 +46323,7 @@ class Quic {
|
|
|
46316
46323
|
if (options.verifyName !== undefined && options.verifyName !== peerDetails.info.id) {
|
|
46317
46324
|
throw new Error(`Client connected, but the id didn't match. Expected: ${options.verifyName}, got: ${peerDetails.info.id}`);
|
|
46318
46325
|
}
|
|
46319
|
-
setup_logger.log
|
|
46326
|
+
setup_logger.log `🤝 Client handshake with: ${peer.host}:${peer.port}`;
|
|
46320
46327
|
return newPeer(client.connection, peerDetails.info);
|
|
46321
46328
|
}
|
|
46322
46329
|
function newPeer(conn, peerInfo) {
|
|
@@ -46436,10 +46443,10 @@ class Connections {
|
|
|
46436
46443
|
for (;;) {
|
|
46437
46444
|
// increase the reconnection counter
|
|
46438
46445
|
meta.currentRetry += 1;
|
|
46439
|
-
if (meta.currentRetry
|
|
46446
|
+
if (meta.currentRetry > meta.maxRetries) {
|
|
46440
46447
|
// reached max retries for a peer, remove it from tracking.
|
|
46441
46448
|
this.peerInfo.delete(id);
|
|
46442
|
-
jamnp_s_peers_logger.log
|
|
46449
|
+
jamnp_s_peers_logger.log `[${id}] max retries reached. Removing peer.`;
|
|
46443
46450
|
return;
|
|
46444
46451
|
}
|
|
46445
46452
|
// else attempt to connect to a node a bit later.
|
|
@@ -46458,7 +46465,7 @@ class Connections {
|
|
|
46458
46465
|
}
|
|
46459
46466
|
// attempt to connect to the peer
|
|
46460
46467
|
try {
|
|
46461
|
-
jamnp_s_peers_logger.trace
|
|
46468
|
+
jamnp_s_peers_logger.trace `[${id}] Attempting to connect to peer at ${meta.address.host}:${meta.address.port}.`;
|
|
46462
46469
|
await this.network.dial(meta.address, { signal, verifyName: meta.peerId });
|
|
46463
46470
|
return;
|
|
46464
46471
|
}
|
|
@@ -46467,7 +46474,7 @@ class Connections {
|
|
|
46467
46474
|
return;
|
|
46468
46475
|
}
|
|
46469
46476
|
// failing to connect, will retry.
|
|
46470
|
-
jamnp_s_peers_logger.trace
|
|
46477
|
+
jamnp_s_peers_logger.trace `[${id}] attempt failed. Will retry (${meta.currentRetry}/${meta.maxRetries})`;
|
|
46471
46478
|
}
|
|
46472
46479
|
}
|
|
46473
46480
|
}
|
|
@@ -46580,7 +46587,7 @@ class StreamManager {
|
|
|
46580
46587
|
// We expect a one-byte identifier first.
|
|
46581
46588
|
const data = await reader.read();
|
|
46582
46589
|
bytes = bytes_BytesBlob.blobFrom(data.value !== undefined ? data.value : new Uint8Array());
|
|
46583
|
-
stream_manager_logger.trace
|
|
46590
|
+
stream_manager_logger.trace `🚰 --> [${peer.id}:${streamId}] Initial data: ${bytes}`;
|
|
46584
46591
|
}
|
|
46585
46592
|
finally {
|
|
46586
46593
|
reader.releaseLock();
|
|
@@ -46594,7 +46601,7 @@ class StreamManager {
|
|
|
46594
46601
|
if (handler === undefined) {
|
|
46595
46602
|
throw new Error(`Unsupported stream kind: ${kind}`);
|
|
46596
46603
|
}
|
|
46597
|
-
stream_manager_logger.log
|
|
46604
|
+
stream_manager_logger.log `🚰 --> [${peer.id}:${stream.streamId}] Stream identified as: ${kind}`;
|
|
46598
46605
|
this.registerStream(peer, handler, stream, bytes_BytesBlob.blobFrom(bytes.raw.subarray(1)));
|
|
46599
46606
|
}
|
|
46600
46607
|
registerStream(peer, handler, stream, initialData) {
|
|
@@ -46604,7 +46611,7 @@ class StreamManager {
|
|
|
46604
46611
|
this.streams.delete(streamId);
|
|
46605
46612
|
this.backgroundTasks.delete(streamId);
|
|
46606
46613
|
if (kind === StreamErrorKind.Exception) {
|
|
46607
|
-
stream_manager_logger.error
|
|
46614
|
+
stream_manager_logger.error `🚰 --- [${peer.id}:${streamId}] Stream error: ${e}. Disconnecting peer.`;
|
|
46608
46615
|
}
|
|
46609
46616
|
if (kind !== StreamErrorKind.LocalClose) {
|
|
46610
46617
|
// whenever we have an error, we are going to inform the handler
|
|
@@ -46638,10 +46645,10 @@ async function readStreamForever(peer, handler, quicStream, initialData, reader)
|
|
|
46638
46645
|
let isDone = false;
|
|
46639
46646
|
const callback = handleMessageFragmentation((data) => {
|
|
46640
46647
|
const bytes = bytes_BytesBlob.blobFrom(new Uint8Array(data));
|
|
46641
|
-
stream_manager_logger.trace
|
|
46648
|
+
stream_manager_logger.trace `🚰 --> [${peer.id}:${quicStream.streamId}] ${bytes}`;
|
|
46642
46649
|
handler.onStreamMessage(quicStream, bytes);
|
|
46643
46650
|
}, () => {
|
|
46644
|
-
stream_manager_logger.error
|
|
46651
|
+
stream_manager_logger.error `🚰 --> [${peer.id}:${quicStream.streamId}] got too much data. Disconnecting.`;
|
|
46645
46652
|
peer.disconnect();
|
|
46646
46653
|
});
|
|
46647
46654
|
for (;;) {
|
|
@@ -46650,7 +46657,7 @@ async function readStreamForever(peer, handler, quicStream, initialData, reader)
|
|
|
46650
46657
|
// be a promise, so that we can make back pressure here.
|
|
46651
46658
|
callback(bytes.raw);
|
|
46652
46659
|
if (isDone) {
|
|
46653
|
-
stream_manager_logger.log
|
|
46660
|
+
stream_manager_logger.log `🚰 --> [${peer.id}:${quicStream.streamId}] remote finished.`;
|
|
46654
46661
|
return;
|
|
46655
46662
|
}
|
|
46656
46663
|
// await for more data
|
|
@@ -46693,7 +46700,7 @@ class QuicStreamSender {
|
|
|
46693
46700
|
return;
|
|
46694
46701
|
}
|
|
46695
46702
|
const { data, addPrefix } = chunk;
|
|
46696
|
-
stream_manager_logger.trace
|
|
46703
|
+
stream_manager_logger.trace `🚰 <-- [${this.streamId}] write: ${data}`;
|
|
46697
46704
|
if (addPrefix) {
|
|
46698
46705
|
await writer.write(encodeMessageLength(data.raw));
|
|
46699
46706
|
}
|
|
@@ -46710,7 +46717,7 @@ class QuicStreamSender {
|
|
|
46710
46717
|
}
|
|
46711
46718
|
close() {
|
|
46712
46719
|
handleAsyncErrors(async () => {
|
|
46713
|
-
stream_manager_logger.trace
|
|
46720
|
+
stream_manager_logger.trace `🚰 <-- [${this.streamId}] closing`;
|
|
46714
46721
|
if (this.currentWriterPromise !== null) {
|
|
46715
46722
|
await this.currentWriterPromise;
|
|
46716
46723
|
}
|
|
@@ -46796,7 +46803,7 @@ class ServerHandler {
|
|
|
46796
46803
|
}
|
|
46797
46804
|
onStreamMessage(sender, message) {
|
|
46798
46805
|
const request = decoder_Decoder.decodeObject(BlockRequest.Codec, message);
|
|
46799
|
-
ce_128_block_request_logger.log
|
|
46806
|
+
ce_128_block_request_logger.log `[${sender.streamId}] Client has requested: ${request}`;
|
|
46800
46807
|
const blocks = this.getBlockSequence(sender.streamId, request.headerHash, request.direction, request.maxBlocks);
|
|
46801
46808
|
sender.bufferAndSend(encoder_Encoder.encodeObject(descriptors_codec.sequenceFixLen(block_Block.Codec.View, blocks.length), blocks, this.chainSpec));
|
|
46802
46809
|
sender.close();
|
|
@@ -46816,7 +46823,7 @@ class ClientHandler {
|
|
|
46816
46823
|
throw new Error("Received an unexpected message from the server.");
|
|
46817
46824
|
}
|
|
46818
46825
|
const blocks = decoder_Decoder.decodeSequence(block_Block.Codec.View, message, this.chainSpec);
|
|
46819
|
-
ce_128_block_request_logger.log
|
|
46826
|
+
ce_128_block_request_logger.log `[${sender.streamId}] Server returned ${blocks.length} blocks in ${message.length} bytes of data.`;
|
|
46820
46827
|
this.promiseResolvers.get(sender.streamId)?.(blocks);
|
|
46821
46828
|
this.promiseResolvers.delete(sender.streamId);
|
|
46822
46829
|
}
|
|
@@ -46987,13 +46994,13 @@ class ce_129_state_request_Handler {
|
|
|
46987
46994
|
}
|
|
46988
46995
|
onStreamMessage(sender, message) {
|
|
46989
46996
|
if (this.isServer) {
|
|
46990
|
-
ce_129_state_request_logger.info
|
|
46997
|
+
ce_129_state_request_logger.info `[${sender.streamId}][server]: Received request.`;
|
|
46991
46998
|
if (this.getBoundaryNodes === undefined || this.getKeyValuePairs === undefined)
|
|
46992
46999
|
return;
|
|
46993
47000
|
const request = Decoder.decodeObject(StateRequest.Codec, message);
|
|
46994
47001
|
const boundaryNodes = this.getBoundaryNodes(request.headerHash, request.startKey, request.endKey);
|
|
46995
47002
|
const keyValuePairs = this.getKeyValuePairs(request.headerHash, request.startKey, request.endKey);
|
|
46996
|
-
ce_129_state_request_logger.info
|
|
47003
|
+
ce_129_state_request_logger.info `[${sender.streamId}][server]: <-- responding with boundary nodes and key value pairs.`;
|
|
46997
47004
|
sender.bufferAndSend(Encoder.encodeObject(codec.sequenceVarLen(trieNodeCodec), boundaryNodes));
|
|
46998
47005
|
sender.bufferAndSend(Encoder.encodeObject(StateResponse.Codec, StateResponse.create({ keyValuePairs })));
|
|
46999
47006
|
sender.close();
|
|
@@ -47001,11 +47008,11 @@ class ce_129_state_request_Handler {
|
|
|
47001
47008
|
}
|
|
47002
47009
|
if (!this.boundaryNodes.has(sender.streamId)) {
|
|
47003
47010
|
this.boundaryNodes.set(sender.streamId, Decoder.decodeObject(codec.sequenceVarLen(trieNodeCodec), message));
|
|
47004
|
-
ce_129_state_request_logger.info
|
|
47011
|
+
ce_129_state_request_logger.info `[${sender.streamId}][client]: Received boundary nodes.`;
|
|
47005
47012
|
return;
|
|
47006
47013
|
}
|
|
47007
47014
|
this.onResponse.get(sender.streamId)?.(Decoder.decodeObject(StateResponse.Codec, message));
|
|
47008
|
-
ce_129_state_request_logger.info
|
|
47015
|
+
ce_129_state_request_logger.info `[${sender.streamId}][client]: Received state values.`;
|
|
47009
47016
|
}
|
|
47010
47017
|
onClose(streamId) {
|
|
47011
47018
|
this.boundaryNodes.delete(streamId);
|
|
@@ -47062,7 +47069,7 @@ class ce_131_ce_132_safrole_ticket_distribution_ServerHandler {
|
|
|
47062
47069
|
}
|
|
47063
47070
|
onStreamMessage(sender, message) {
|
|
47064
47071
|
const ticketDistribution = Decoder.decodeObject(TicketDistributionRequest.Codec, message);
|
|
47065
|
-
ce_131_ce_132_safrole_ticket_distribution_logger.log
|
|
47072
|
+
ce_131_ce_132_safrole_ticket_distribution_logger.log `[${sender.streamId}][ce-${this.kind}] Received ticket for epoch ${ticketDistribution.epochIndex}`;
|
|
47066
47073
|
this.onTicketReceived(ticketDistribution.epochIndex, ticketDistribution.ticket);
|
|
47067
47074
|
sender.close();
|
|
47068
47075
|
}
|
|
@@ -47074,7 +47081,7 @@ class ce_131_ce_132_safrole_ticket_distribution_ClientHandler {
|
|
|
47074
47081
|
this.kind = kind;
|
|
47075
47082
|
}
|
|
47076
47083
|
onStreamMessage(sender) {
|
|
47077
|
-
ce_131_ce_132_safrole_ticket_distribution_logger.warn
|
|
47084
|
+
ce_131_ce_132_safrole_ticket_distribution_logger.warn `[${sender.streamId}][ce-${this.kind}] Unexpected message received. Closing.`;
|
|
47078
47085
|
sender.close();
|
|
47079
47086
|
}
|
|
47080
47087
|
onClose() { }
|
|
@@ -47147,15 +47154,15 @@ class ce_133_work_package_submission_ServerHandler {
|
|
|
47147
47154
|
class ce_133_work_package_submission_ClientHandler {
|
|
47148
47155
|
kind = ce_133_work_package_submission_STREAM_KIND;
|
|
47149
47156
|
onStreamMessage(sender) {
|
|
47150
|
-
ce_133_work_package_submission_logger.warn
|
|
47157
|
+
ce_133_work_package_submission_logger.warn `[${sender.streamId}] Got unexpected message on CE-133 stream. Closing.`;
|
|
47151
47158
|
sender.close();
|
|
47152
47159
|
}
|
|
47153
47160
|
onClose() { }
|
|
47154
47161
|
sendWorkPackage(sender, coreIndex, workPackage, extrinsic) {
|
|
47155
47162
|
const corePack = CoreWorkPackage.create({ coreIndex, workPackage });
|
|
47156
|
-
ce_133_work_package_submission_logger.trace
|
|
47163
|
+
ce_133_work_package_submission_logger.trace `[${sender.streamId}] Sending work package: ${corePack}`;
|
|
47157
47164
|
sender.bufferAndSend(Encoder.encodeObject(CoreWorkPackage.Codec, corePack));
|
|
47158
|
-
ce_133_work_package_submission_logger.trace
|
|
47165
|
+
ce_133_work_package_submission_logger.trace `[${sender.streamId}] Sending extrinsics: ${workPackage.items}`;
|
|
47159
47166
|
sender.bufferAndSend(Encoder.encodeObject(workItemExtrinsicsCodec(workPackage.items), extrinsic));
|
|
47160
47167
|
// now close the connection
|
|
47161
47168
|
sender.close();
|
|
@@ -47231,7 +47238,7 @@ class ce_134_work_package_sharing_ServerHandler {
|
|
|
47231
47238
|
ce_134_work_package_sharing_ServerHandler.sendWorkReport(sender, workReportHash, signature);
|
|
47232
47239
|
})
|
|
47233
47240
|
.catch((error) => {
|
|
47234
|
-
ce_134_work_package_sharing_logger.error
|
|
47241
|
+
ce_134_work_package_sharing_logger.error `[${streamId}] Error processing work package: ${error}`;
|
|
47235
47242
|
this.onClose(streamId);
|
|
47236
47243
|
});
|
|
47237
47244
|
}
|
|
@@ -47248,7 +47255,7 @@ class ce_134_work_package_sharing_ClientHandler {
|
|
|
47248
47255
|
throw new Error("Unexpected message received.");
|
|
47249
47256
|
}
|
|
47250
47257
|
const response = Decoder.decodeObject(WorkPackageSharingResponse.Codec, message);
|
|
47251
|
-
ce_134_work_package_sharing_logger.info
|
|
47258
|
+
ce_134_work_package_sharing_logger.info `[${sender.streamId}] Received work report hash and signature.`;
|
|
47252
47259
|
pendingRequest.resolve({ workReportHash: response.workReportHash, signature: response.signature });
|
|
47253
47260
|
sender.close();
|
|
47254
47261
|
}
|
|
@@ -47261,9 +47268,9 @@ class ce_134_work_package_sharing_ClientHandler {
|
|
|
47261
47268
|
}
|
|
47262
47269
|
async sendWorkPackage(sender, coreIndex, segmentsRootMappings, workPackageBundle) {
|
|
47263
47270
|
const request = WorkPackageSharingRequest.create({ coreIndex, segmentsRootMappings });
|
|
47264
|
-
ce_134_work_package_sharing_logger.trace
|
|
47271
|
+
ce_134_work_package_sharing_logger.trace `[${sender.streamId}] Sending core index and segments-root mappings.`;
|
|
47265
47272
|
sender.bufferAndSend(Encoder.encodeObject(WorkPackageSharingRequest.Codec, request));
|
|
47266
|
-
ce_134_work_package_sharing_logger.trace
|
|
47273
|
+
ce_134_work_package_sharing_logger.trace `[${sender.streamId}] Sending work package bundle.`;
|
|
47267
47274
|
sender.bufferAndSend(Encoder.encodeObject(WorkPackageBundleCodec, workPackageBundle));
|
|
47268
47275
|
return new Promise((resolve, reject) => {
|
|
47269
47276
|
this.pendingRequests.set(sender.streamId, { resolve, reject });
|
|
@@ -47323,7 +47330,7 @@ class ce_135_work_report_distribution_ServerHandler {
|
|
|
47323
47330
|
}
|
|
47324
47331
|
onStreamMessage(sender, message) {
|
|
47325
47332
|
const guaranteedWorkReport = Decoder.decodeObject(GuaranteedWorkReport.Codec, message, this.chainSpec);
|
|
47326
|
-
ce_135_work_report_distribution_logger.log
|
|
47333
|
+
ce_135_work_report_distribution_logger.log `[${sender.streamId}] Received guaranteed work report.`;
|
|
47327
47334
|
this.onWorkReport(guaranteedWorkReport);
|
|
47328
47335
|
sender.close();
|
|
47329
47336
|
}
|
|
@@ -47336,12 +47343,12 @@ class ce_135_work_report_distribution_ClientHandler {
|
|
|
47336
47343
|
this.chainSpec = chainSpec;
|
|
47337
47344
|
}
|
|
47338
47345
|
onStreamMessage(sender) {
|
|
47339
|
-
ce_135_work_report_distribution_logger.warn
|
|
47346
|
+
ce_135_work_report_distribution_logger.warn `[${sender.streamId}] Got unexpected message on CE-135 stream. Closing.`;
|
|
47340
47347
|
sender.close();
|
|
47341
47348
|
}
|
|
47342
47349
|
onClose() { }
|
|
47343
47350
|
sendWorkReport(sender, workReport) {
|
|
47344
|
-
ce_135_work_report_distribution_logger.trace
|
|
47351
|
+
ce_135_work_report_distribution_logger.trace `[${sender.streamId}] Sending guaranteed work report.`;
|
|
47345
47352
|
sender.bufferAndSend(Encoder.encodeObject(GuaranteedWorkReport.Codec, workReport, this.chainSpec));
|
|
47346
47353
|
sender.close();
|
|
47347
47354
|
}
|
|
@@ -47447,7 +47454,7 @@ class up_0_block_announcement_Handler {
|
|
|
47447
47454
|
this.handshakes.set(streamId, handshake);
|
|
47448
47455
|
// we didn't initiate this handshake, so let's respond
|
|
47449
47456
|
if (!this.pendingHandshakes.delete(streamId)) {
|
|
47450
|
-
up_0_block_announcement_logger.log
|
|
47457
|
+
up_0_block_announcement_logger.log `[${streamId}] <-- responding with a handshake.`;
|
|
47451
47458
|
sender.bufferAndSend(encoder_Encoder.encodeObject(Handshake.Codec, this.getHandshake()));
|
|
47452
47459
|
}
|
|
47453
47460
|
this.onHandshake(streamId, handshake);
|
|
@@ -47455,7 +47462,7 @@ class up_0_block_announcement_Handler {
|
|
|
47455
47462
|
}
|
|
47456
47463
|
// it's just an announcement
|
|
47457
47464
|
const annoucement = decoder_Decoder.decodeObject(Announcement.Codec, message, this.spec);
|
|
47458
|
-
up_0_block_announcement_logger.log
|
|
47465
|
+
up_0_block_announcement_logger.log `[${streamId}] --> got blocks announcement: ${annoucement.final}`;
|
|
47459
47466
|
this.onAnnouncement(streamId, annoucement);
|
|
47460
47467
|
}
|
|
47461
47468
|
onClose(streamId) {
|
|
@@ -47468,7 +47475,7 @@ class up_0_block_announcement_Handler {
|
|
|
47468
47475
|
return;
|
|
47469
47476
|
}
|
|
47470
47477
|
const handshake = this.getHandshake();
|
|
47471
|
-
up_0_block_announcement_logger.trace
|
|
47478
|
+
up_0_block_announcement_logger.trace `[${streamId}] <-- sending handshake`;
|
|
47472
47479
|
this.pendingHandshakes.set(sender.streamId, true);
|
|
47473
47480
|
sender.bufferAndSend(encoder_Encoder.encodeObject(Handshake.Codec, handshake));
|
|
47474
47481
|
}
|
|
@@ -47476,11 +47483,11 @@ class up_0_block_announcement_Handler {
|
|
|
47476
47483
|
const { streamId } = sender;
|
|
47477
47484
|
// only send announcement if we've handshaken
|
|
47478
47485
|
if (this.handshakes.has(streamId)) {
|
|
47479
|
-
up_0_block_announcement_logger.trace
|
|
47486
|
+
up_0_block_announcement_logger.trace `[${streamId}] <-- sending block announcement: ${annoucement.final}`;
|
|
47480
47487
|
sender.bufferAndSend(encoder_Encoder.encodeObject(Announcement.Codec, annoucement, this.spec));
|
|
47481
47488
|
}
|
|
47482
47489
|
else {
|
|
47483
|
-
up_0_block_announcement_logger.warn
|
|
47490
|
+
up_0_block_announcement_logger.warn `[${streamId}] <-- no handshake yet, skipping announcement.`;
|
|
47484
47491
|
}
|
|
47485
47492
|
}
|
|
47486
47493
|
}
|
|
@@ -47597,7 +47604,7 @@ class SyncTask {
|
|
|
47597
47604
|
onUp0Annoucement(peer, announcement) {
|
|
47598
47605
|
const { hash, slot } = announcement.final;
|
|
47599
47606
|
const bestHeader = hashHeader(announcement.header, this.spec);
|
|
47600
|
-
sync_logger.info
|
|
47607
|
+
sync_logger.info `[${peer.id}] --> Received new header #${announcement.header.timeSlotIndex}: ${bestHeader.hash}`;
|
|
47601
47608
|
// NOTE [ToDr] Instead of having `Connections` store aux data perhaps
|
|
47602
47609
|
// we should maintain that directly? However that would require
|
|
47603
47610
|
// listening to peers connected/disconnected to perfrom some cleanups
|
|
@@ -47672,7 +47679,7 @@ class SyncTask {
|
|
|
47672
47679
|
const peers = this.connections.getConnectedPeers();
|
|
47673
47680
|
for (const peerInfo of peers) {
|
|
47674
47681
|
this.streamManager.withStreamOfKind(peerInfo.peerId, up_0_block_announcement_STREAM_KIND, (handler, sender) => {
|
|
47675
|
-
sync_logger.log
|
|
47682
|
+
sync_logger.log `[${peerInfo.peerId}] <-- Broadcasting new header #${slot}: ${header.hash}`;
|
|
47676
47683
|
handler.sendAnnouncement(sender, annoucement);
|
|
47677
47684
|
return result_OK;
|
|
47678
47685
|
});
|
|
@@ -47686,13 +47693,13 @@ class SyncTask {
|
|
|
47686
47693
|
}
|
|
47687
47694
|
if (res.error === BlockSequenceError.BlockOnFork) {
|
|
47688
47695
|
// seems that peer is requesting syncing a fork from us, let's bail.
|
|
47689
|
-
sync_logger.warn
|
|
47696
|
+
sync_logger.warn `[${peer.id}] --> Invalid block sequence request: ${startHash} is on a fork.`;
|
|
47690
47697
|
return [];
|
|
47691
47698
|
}
|
|
47692
47699
|
if (res.error === BlockSequenceError.NoStartBlock) {
|
|
47693
47700
|
// we don't know about that block at all, so let's just bail.
|
|
47694
47701
|
// we should probably penalize the peer for sending BS?
|
|
47695
|
-
sync_logger.warn
|
|
47702
|
+
sync_logger.warn `[${peer.id}] --> Invalid block sequence request: ${startHash} missing header or extrinsic.`;
|
|
47696
47703
|
return [];
|
|
47697
47704
|
}
|
|
47698
47705
|
debug_assertNever(res.error);
|
|
@@ -47712,10 +47719,10 @@ class SyncTask {
|
|
|
47712
47719
|
// figure out where others are at
|
|
47713
47720
|
const othersBest = this.othersBest;
|
|
47714
47721
|
const blocksToSync = othersBest.slot - ourBestSlot;
|
|
47715
|
-
sync_logger.trace
|
|
47722
|
+
sync_logger.trace `Our best. ${ourBestSlot}. Best seen: ${othersBest.slot}`;
|
|
47716
47723
|
if (blocksToSync < 1) {
|
|
47717
47724
|
this.connections.getPeerCount();
|
|
47718
|
-
sync_logger.trace
|
|
47725
|
+
sync_logger.trace `No new blocks. ${peerCount} peers.`;
|
|
47719
47726
|
return {
|
|
47720
47727
|
kind: SyncResult.NoNewBlocks,
|
|
47721
47728
|
ours: ourBestSlot,
|
|
@@ -47723,7 +47730,7 @@ class SyncTask {
|
|
|
47723
47730
|
};
|
|
47724
47731
|
}
|
|
47725
47732
|
const requested = [];
|
|
47726
|
-
sync_logger.log
|
|
47733
|
+
sync_logger.log `Sync ${blocksToSync} blocks from ${peerCount} peers.`;
|
|
47727
47734
|
// NOTE [ToDr] We might be requesting the same blocks from many peers
|
|
47728
47735
|
// which isn't very optimal, but for now: 🤷
|
|
47729
47736
|
//
|
|
@@ -47749,12 +47756,12 @@ class SyncTask {
|
|
|
47749
47756
|
// request as much blocks from that peer as possible.
|
|
47750
47757
|
this.streamManager.withNewStream(peerInfo.peerRef, STREAM_KIND, (handler, sender) => {
|
|
47751
47758
|
handleAsyncErrors(async () => {
|
|
47752
|
-
sync_logger.log
|
|
47759
|
+
sync_logger.log `[${peerInfo.peerId}] <-- Fetching ${bestSlot - ourBestSlot} blocks (${bestHash})`;
|
|
47753
47760
|
const blocks = await handler.requestBlockSequence(sender, bestHash, Direction.DescIncl, numbers_tryAsU32(bestSlot - ourBestSlot));
|
|
47754
47761
|
blocks.reverse();
|
|
47755
47762
|
this.onNewBlocks(blocks, peerInfo.peerId);
|
|
47756
47763
|
}, (e) => {
|
|
47757
|
-
sync_logger.warn
|
|
47764
|
+
sync_logger.warn `[${peerInfo.peerId}] <-- requesting blocks to import: ${e}`;
|
|
47758
47765
|
});
|
|
47759
47766
|
return result_OK;
|
|
47760
47767
|
});
|
|
@@ -47828,7 +47835,7 @@ function setupPeerListeners(syncTask, network, streamManager) {
|
|
|
47828
47835
|
// whenever the peer wants to open a stream with us, let's handle that.
|
|
47829
47836
|
peer.addOnIncomingStream((stream) => {
|
|
47830
47837
|
handleAsyncErrors(() => streamManager.onIncomingStream(peer, stream), (e) => {
|
|
47831
|
-
network_logger.error
|
|
47838
|
+
network_logger.error `[${peer.id}:${stream.streamId}]🚰 Stream error: ${e}. Disconnecting peer.`;
|
|
47832
47839
|
peer.disconnect();
|
|
47833
47840
|
});
|
|
47834
47841
|
return result_OK;
|
|
@@ -47919,7 +47926,7 @@ class MainReady extends State {
|
|
|
47919
47926
|
this.onNewBlocks.emit(blocks);
|
|
47920
47927
|
}
|
|
47921
47928
|
else {
|
|
47922
|
-
state_machine_logger.error
|
|
47929
|
+
state_machine_logger.error `${this.constructor.name} got invalid signal type: ${JSON.stringify(block)}.`;
|
|
47923
47930
|
}
|
|
47924
47931
|
}
|
|
47925
47932
|
announceHeader(port, header) {
|
|
@@ -47957,7 +47964,7 @@ class NetworkReady extends State {
|
|
|
47957
47964
|
this.onNewHeader.emit(decoded);
|
|
47958
47965
|
}
|
|
47959
47966
|
else {
|
|
47960
|
-
state_machine_logger.error
|
|
47967
|
+
state_machine_logger.error `${this.constructor.name} got invalid signal type: ${JSON.stringify(header)}.`;
|
|
47961
47968
|
}
|
|
47962
47969
|
}
|
|
47963
47970
|
sendBlocks(port, blocks) {
|
|
@@ -47996,7 +48003,7 @@ if (!external_node_worker_threads_namespaceObject.isMainThread) {
|
|
|
47996
48003
|
Logger.configureAll(process.env.JAM_LOG ?? "", Level.LOG);
|
|
47997
48004
|
const machine = networkStateMachine();
|
|
47998
48005
|
const channel = MessageChannelStateMachine.receiveChannel(machine, external_node_worker_threads_namespaceObject.parentPort);
|
|
47999
|
-
channel.then((channel) => main(channel)).catch((e) => jam_network_logger.error
|
|
48006
|
+
channel.then((channel) => main(channel)).catch((e) => jam_network_logger.error `${e}`);
|
|
48000
48007
|
}
|
|
48001
48008
|
/**
|
|
48002
48009
|
* JAM networking worker.
|
|
@@ -48007,7 +48014,7 @@ if (!external_node_worker_threads_namespaceObject.isMainThread) {
|
|
|
48007
48014
|
*/
|
|
48008
48015
|
async function main(channel) {
|
|
48009
48016
|
await initAll();
|
|
48010
|
-
jam_network_logger.trace
|
|
48017
|
+
jam_network_logger.trace `🛜 Network starting ${channel.currentState()}`;
|
|
48011
48018
|
// Await the configuration object
|
|
48012
48019
|
// TODO [ToDr] The whole state machine needs to die.
|
|
48013
48020
|
const ready = channel.currentState().stateName !== "ready(network)"
|
|
@@ -48018,7 +48025,7 @@ async function main(channel) {
|
|
|
48018
48025
|
const key = await ed25519_privateKey(config.key);
|
|
48019
48026
|
const lmdb = new LmdbRoot(config.genericConfig.dbPath);
|
|
48020
48027
|
const blocks = new LmdbBlocks(config.genericConfig.chainSpec, lmdb);
|
|
48021
|
-
jam_network_logger.info
|
|
48028
|
+
jam_network_logger.info `🛜 Listening at ${config.host}:${config.port}`;
|
|
48022
48029
|
const network = await setup({
|
|
48023
48030
|
host: config.host,
|
|
48024
48031
|
port: config.port,
|
|
@@ -48031,7 +48038,7 @@ async function main(channel) {
|
|
|
48031
48038
|
ready.waitForState("finished").then(() => network.network.stop());
|
|
48032
48039
|
await network.network.start();
|
|
48033
48040
|
});
|
|
48034
|
-
jam_network_logger.info
|
|
48041
|
+
jam_network_logger.info `🛜 Network worker finished. Closing channel.`;
|
|
48035
48042
|
// Close the comms to gracefuly close the app.
|
|
48036
48043
|
finished.currentState().close(channel);
|
|
48037
48044
|
}
|