@typeberry/jam 0.2.0-74f246e → 0.2.0-adde0dd
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/bootstrap-generator.mjs +179 -159
- package/bootstrap-generator.mjs.map +1 -1
- package/bootstrap-importer.mjs +402 -368
- package/bootstrap-importer.mjs.map +1 -1
- package/bootstrap-network.mjs +179 -160
- package/bootstrap-network.mjs.map +1 -1
- package/index.js +413 -379
- package/index.js.map +1 -1
- package/package.json +1 -1
package/bootstrap-network.mjs
CHANGED
|
@@ -24333,7 +24333,7 @@ function result_resultToString(res) {
|
|
|
24333
24333
|
if (res.isOk) {
|
|
24334
24334
|
return `OK: ${typeof res.ok === "symbol" ? res.ok.toString() : res.ok}`;
|
|
24335
24335
|
}
|
|
24336
|
-
return `${res.details}\nError: ${maybeTaggedErrorToString(res.error)}`;
|
|
24336
|
+
return `${res.details()}\nError: ${maybeTaggedErrorToString(res.error)}`;
|
|
24337
24337
|
}
|
|
24338
24338
|
/** An indication of two possible outcomes returned from a function. */
|
|
24339
24339
|
const result_Result = {
|
|
@@ -24347,7 +24347,7 @@ const result_Result = {
|
|
|
24347
24347
|
};
|
|
24348
24348
|
},
|
|
24349
24349
|
/** Create new [`Result`] with `Error` status. */
|
|
24350
|
-
error: (error, details
|
|
24350
|
+
error: (error, details) => {
|
|
24351
24351
|
debug_check `${error !== undefined} 'Error' type cannot be undefined.`;
|
|
24352
24352
|
return {
|
|
24353
24353
|
isOk: false,
|
|
@@ -24466,7 +24466,7 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
|
|
|
24466
24466
|
}
|
|
24467
24467
|
if (actual.isError && expected.isError) {
|
|
24468
24468
|
deepEqual(actual.error, expected.error, { context: ctx.concat(["error"]), errorsCollector: errors, ignore });
|
|
24469
|
-
deepEqual(actual.details, expected.details, {
|
|
24469
|
+
deepEqual(actual.details(), expected.details(), {
|
|
24470
24470
|
context: ctx.concat(["details"]),
|
|
24471
24471
|
errorsCollector: errors,
|
|
24472
24472
|
// display details when error does not match
|
|
@@ -31755,6 +31755,7 @@ function accumulationOutputComparator(a, b) {
|
|
|
31755
31755
|
|
|
31756
31756
|
;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
|
|
31757
31757
|
|
|
31758
|
+
|
|
31758
31759
|
/**
|
|
31759
31760
|
* This file lists all of the constants defined in the GrayPaper appendix.
|
|
31760
31761
|
*
|
|
@@ -31765,7 +31766,7 @@ function accumulationOutputComparator(a, b) {
|
|
|
31765
31766
|
* here are only temporarily for convenience. When we figure out better names
|
|
31766
31767
|
* and places for these this file will be eradicated.
|
|
31767
31768
|
*
|
|
31768
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
31769
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/442300442300?v=0.7.2
|
|
31769
31770
|
*/
|
|
31770
31771
|
/** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
|
|
31771
31772
|
const G_I = 50_000_000;
|
|
@@ -31781,8 +31782,8 @@ const S = 1024;
|
|
|
31781
31782
|
const T = 128;
|
|
31782
31783
|
/** `W_A`: The maximum size of is-authorized code in octets. */
|
|
31783
31784
|
const W_A = 64_000;
|
|
31784
|
-
/** `W_B`: The maximum size of
|
|
31785
|
-
const W_B = 13_794_305;
|
|
31785
|
+
/** `W_B`: The maximum size of the concatenated variable-size blobs, extrinsics and imported segments of a work-package, in octets */
|
|
31786
|
+
const W_B = compatibility_Compatibility.isGreaterOrEqual(compatibility_GpVersion.V0_7_2) ? 13_791_360 : 13_794_305;
|
|
31786
31787
|
/** `W_C`: The maximum size of service code in octets. */
|
|
31787
31788
|
const W_C = 4_000_000;
|
|
31788
31789
|
/** `W_M`: The maximum number of imports in a work-package. */
|
|
@@ -32881,31 +32882,29 @@ var state_update_UpdatePreimageKind;
|
|
|
32881
32882
|
* 3. Update `LookupHistory` with given value.
|
|
32882
32883
|
*/
|
|
32883
32884
|
class UpdatePreimage {
|
|
32884
|
-
serviceId;
|
|
32885
32885
|
action;
|
|
32886
|
-
constructor(
|
|
32887
|
-
this.serviceId = serviceId;
|
|
32886
|
+
constructor(action) {
|
|
32888
32887
|
this.action = action;
|
|
32889
32888
|
}
|
|
32890
32889
|
/** A preimage is provided. We should update the lookuphistory and add the preimage to db. */
|
|
32891
|
-
static provide({
|
|
32892
|
-
return new UpdatePreimage(
|
|
32890
|
+
static provide({ preimage, slot }) {
|
|
32891
|
+
return new UpdatePreimage({
|
|
32893
32892
|
kind: state_update_UpdatePreimageKind.Provide,
|
|
32894
32893
|
preimage,
|
|
32895
32894
|
slot,
|
|
32896
32895
|
});
|
|
32897
32896
|
}
|
|
32898
32897
|
/** The preimage should be removed completely from the database. */
|
|
32899
|
-
static remove({
|
|
32900
|
-
return new UpdatePreimage(
|
|
32898
|
+
static remove({ hash, length }) {
|
|
32899
|
+
return new UpdatePreimage({
|
|
32901
32900
|
kind: state_update_UpdatePreimageKind.Remove,
|
|
32902
32901
|
hash,
|
|
32903
32902
|
length,
|
|
32904
32903
|
});
|
|
32905
32904
|
}
|
|
32906
32905
|
/** Update the lookup history of some preimage or add a new one (request). */
|
|
32907
|
-
static updateOrAdd({
|
|
32908
|
-
return new UpdatePreimage(
|
|
32906
|
+
static updateOrAdd({ lookupHistory }) {
|
|
32907
|
+
return new UpdatePreimage({
|
|
32909
32908
|
kind: state_update_UpdatePreimageKind.UpdateOrAdd,
|
|
32910
32909
|
item: lookupHistory,
|
|
32911
32910
|
});
|
|
@@ -32942,23 +32941,21 @@ var state_update_UpdateServiceKind;
|
|
|
32942
32941
|
UpdateServiceKind[UpdateServiceKind["Create"] = 1] = "Create";
|
|
32943
32942
|
})(state_update_UpdateServiceKind || (state_update_UpdateServiceKind = {}));
|
|
32944
32943
|
/**
|
|
32945
|
-
* Update service info
|
|
32944
|
+
* Update service info or create a new one.
|
|
32946
32945
|
*/
|
|
32947
32946
|
class UpdateService {
|
|
32948
|
-
serviceId;
|
|
32949
32947
|
action;
|
|
32950
|
-
constructor(
|
|
32951
|
-
this.serviceId = serviceId;
|
|
32948
|
+
constructor(action) {
|
|
32952
32949
|
this.action = action;
|
|
32953
32950
|
}
|
|
32954
|
-
static update({
|
|
32955
|
-
return new UpdateService(
|
|
32951
|
+
static update({ serviceInfo }) {
|
|
32952
|
+
return new UpdateService({
|
|
32956
32953
|
kind: state_update_UpdateServiceKind.Update,
|
|
32957
32954
|
account: serviceInfo,
|
|
32958
32955
|
});
|
|
32959
32956
|
}
|
|
32960
|
-
static create({
|
|
32961
|
-
return new UpdateService(
|
|
32957
|
+
static create({ serviceInfo, lookupHistory, }) {
|
|
32958
|
+
return new UpdateService({
|
|
32962
32959
|
kind: state_update_UpdateServiceKind.Create,
|
|
32963
32960
|
account: serviceInfo,
|
|
32964
32961
|
lookupHistory,
|
|
@@ -32979,17 +32976,15 @@ var state_update_UpdateStorageKind;
|
|
|
32979
32976
|
* Can either create/modify an entry or remove it.
|
|
32980
32977
|
*/
|
|
32981
32978
|
class UpdateStorage {
|
|
32982
|
-
serviceId;
|
|
32983
32979
|
action;
|
|
32984
|
-
constructor(
|
|
32985
|
-
this.serviceId = serviceId;
|
|
32980
|
+
constructor(action) {
|
|
32986
32981
|
this.action = action;
|
|
32987
32982
|
}
|
|
32988
|
-
static set({
|
|
32989
|
-
return new UpdateStorage(
|
|
32983
|
+
static set({ storage }) {
|
|
32984
|
+
return new UpdateStorage({ kind: state_update_UpdateStorageKind.Set, storage });
|
|
32990
32985
|
}
|
|
32991
|
-
static remove({
|
|
32992
|
-
return new UpdateStorage(
|
|
32986
|
+
static remove({ key }) {
|
|
32987
|
+
return new UpdateStorage({ kind: state_update_UpdateStorageKind.Remove, key });
|
|
32993
32988
|
}
|
|
32994
32989
|
get key() {
|
|
32995
32990
|
if (this.action.kind === state_update_UpdateStorageKind.Remove) {
|
|
@@ -33198,12 +33193,12 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
33198
33193
|
* Modify the state and apply a single state update.
|
|
33199
33194
|
*/
|
|
33200
33195
|
applyUpdate(update) {
|
|
33201
|
-
const {
|
|
33196
|
+
const { removed, created: _, updated, preimages, storage, ...rest } = update;
|
|
33202
33197
|
// just assign all other variables
|
|
33203
33198
|
Object.assign(this, rest);
|
|
33204
33199
|
// and update the services state
|
|
33205
33200
|
let result;
|
|
33206
|
-
result = this.updateServices(
|
|
33201
|
+
result = this.updateServices(updated);
|
|
33207
33202
|
if (result.isError) {
|
|
33208
33203
|
return result;
|
|
33209
33204
|
}
|
|
@@ -33215,7 +33210,7 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
33215
33210
|
if (result.isError) {
|
|
33216
33211
|
return result;
|
|
33217
33212
|
}
|
|
33218
|
-
this.removeServices(
|
|
33213
|
+
this.removeServices(removed);
|
|
33219
33214
|
return result_Result.ok(result_OK);
|
|
33220
33215
|
}
|
|
33221
33216
|
removeServices(servicesRemoved) {
|
|
@@ -33224,89 +33219,102 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
33224
33219
|
this.services.delete(serviceId);
|
|
33225
33220
|
}
|
|
33226
33221
|
}
|
|
33227
|
-
updateStorage(
|
|
33228
|
-
|
|
33229
|
-
|
|
33230
|
-
|
|
33231
|
-
|
|
33232
|
-
|
|
33233
|
-
|
|
33234
|
-
|
|
33235
|
-
|
|
33236
|
-
|
|
33237
|
-
|
|
33238
|
-
|
|
33239
|
-
|
|
33240
|
-
|
|
33222
|
+
updateStorage(storageUpdates) {
|
|
33223
|
+
if (storageUpdates === undefined) {
|
|
33224
|
+
return result_Result.ok(result_OK);
|
|
33225
|
+
}
|
|
33226
|
+
for (const [serviceId, updates] of storageUpdates.entries()) {
|
|
33227
|
+
for (const update of updates) {
|
|
33228
|
+
const { kind } = update.action;
|
|
33229
|
+
const service = this.services.get(serviceId);
|
|
33230
|
+
if (service === undefined) {
|
|
33231
|
+
return result_Result.error(in_memory_state_UpdateError.NoService, () => `Attempting to update storage of non-existing service: ${serviceId}`);
|
|
33232
|
+
}
|
|
33233
|
+
if (kind === state_update_UpdateStorageKind.Set) {
|
|
33234
|
+
const { key, value } = update.action.storage;
|
|
33235
|
+
service.data.storage.set(key.toString(), StorageItem.create({ key, value }));
|
|
33236
|
+
}
|
|
33237
|
+
else if (kind === state_update_UpdateStorageKind.Remove) {
|
|
33238
|
+
const { key } = update.action;
|
|
33239
|
+
debug_check `
|
|
33241
33240
|
${service.data.storage.has(key.toString())}
|
|
33242
|
-
Attempting to remove non-existing storage item at ${serviceId}: ${action.key}
|
|
33241
|
+
Attempting to remove non-existing storage item at ${serviceId}: ${update.action.key}
|
|
33243
33242
|
`;
|
|
33244
|
-
|
|
33245
|
-
|
|
33246
|
-
|
|
33247
|
-
|
|
33243
|
+
service.data.storage.delete(key.toString());
|
|
33244
|
+
}
|
|
33245
|
+
else {
|
|
33246
|
+
debug_assertNever(kind);
|
|
33247
|
+
}
|
|
33248
33248
|
}
|
|
33249
33249
|
}
|
|
33250
33250
|
return result_Result.ok(result_OK);
|
|
33251
33251
|
}
|
|
33252
|
-
updatePreimages(
|
|
33253
|
-
|
|
33252
|
+
updatePreimages(preimagesUpdates) {
|
|
33253
|
+
if (preimagesUpdates === undefined) {
|
|
33254
|
+
return result_Result.ok(result_OK);
|
|
33255
|
+
}
|
|
33256
|
+
for (const [serviceId, updates] of preimagesUpdates.entries()) {
|
|
33254
33257
|
const service = this.services.get(serviceId);
|
|
33255
33258
|
if (service === undefined) {
|
|
33256
|
-
return result_Result.error(in_memory_state_UpdateError.NoService, `Attempting to update preimage of non-existing service: ${serviceId}`);
|
|
33257
|
-
}
|
|
33258
|
-
const
|
|
33259
|
-
|
|
33260
|
-
|
|
33261
|
-
|
|
33262
|
-
|
|
33263
|
-
|
|
33264
|
-
service.data.preimages.set(preimage.hash, preimage);
|
|
33265
|
-
if (slot !== null) {
|
|
33266
|
-
const lookupHistory = service.data.lookupHistory.get(preimage.hash);
|
|
33267
|
-
const length = numbers_tryAsU32(preimage.blob.length);
|
|
33268
|
-
const lookup = new LookupHistoryItem(preimage.hash, length, service_tryAsLookupHistorySlots([slot]));
|
|
33269
|
-
if (lookupHistory === undefined) {
|
|
33270
|
-
// no lookup history for that preimage at all (edge case, should be requested)
|
|
33271
|
-
service.data.lookupHistory.set(preimage.hash, [lookup]);
|
|
33259
|
+
return result_Result.error(in_memory_state_UpdateError.NoService, () => `Attempting to update preimage of non-existing service: ${serviceId}`);
|
|
33260
|
+
}
|
|
33261
|
+
for (const update of updates) {
|
|
33262
|
+
const { kind } = update.action;
|
|
33263
|
+
if (kind === state_update_UpdatePreimageKind.Provide) {
|
|
33264
|
+
const { preimage, slot } = update.action;
|
|
33265
|
+
if (service.data.preimages.has(preimage.hash)) {
|
|
33266
|
+
return result_Result.error(in_memory_state_UpdateError.PreimageExists, () => `Overwriting existing preimage at ${serviceId}: ${preimage}`);
|
|
33272
33267
|
}
|
|
33273
|
-
|
|
33274
|
-
|
|
33275
|
-
const
|
|
33276
|
-
|
|
33268
|
+
service.data.preimages.set(preimage.hash, preimage);
|
|
33269
|
+
if (slot !== null) {
|
|
33270
|
+
const lookupHistory = service.data.lookupHistory.get(preimage.hash);
|
|
33271
|
+
const length = numbers_tryAsU32(preimage.blob.length);
|
|
33272
|
+
const lookup = new LookupHistoryItem(preimage.hash, length, service_tryAsLookupHistorySlots([slot]));
|
|
33273
|
+
if (lookupHistory === undefined) {
|
|
33274
|
+
// no lookup history for that preimage at all (edge case, should be requested)
|
|
33275
|
+
service.data.lookupHistory.set(preimage.hash, [lookup]);
|
|
33276
|
+
}
|
|
33277
|
+
else {
|
|
33278
|
+
// insert or replace exiting entry
|
|
33279
|
+
const index = lookupHistory.map((x) => x.length).indexOf(length);
|
|
33280
|
+
lookupHistory.splice(index, index === -1 ? 0 : 1, lookup);
|
|
33281
|
+
}
|
|
33277
33282
|
}
|
|
33278
33283
|
}
|
|
33279
|
-
|
|
33280
|
-
|
|
33281
|
-
|
|
33282
|
-
|
|
33283
|
-
|
|
33284
|
-
|
|
33285
|
-
|
|
33286
|
-
|
|
33284
|
+
else if (kind === state_update_UpdatePreimageKind.Remove) {
|
|
33285
|
+
const { hash, length } = update.action;
|
|
33286
|
+
service.data.preimages.delete(hash);
|
|
33287
|
+
const history = service.data.lookupHistory.get(hash) ?? [];
|
|
33288
|
+
const idx = history.map((x) => x.length).indexOf(length);
|
|
33289
|
+
if (idx !== -1) {
|
|
33290
|
+
history.splice(idx, 1);
|
|
33291
|
+
}
|
|
33292
|
+
}
|
|
33293
|
+
else if (kind === state_update_UpdatePreimageKind.UpdateOrAdd) {
|
|
33294
|
+
const { item } = update.action;
|
|
33295
|
+
const history = service.data.lookupHistory.get(item.hash) ?? [];
|
|
33296
|
+
const existingIdx = history.map((x) => x.length).indexOf(item.length);
|
|
33297
|
+
const removeCount = existingIdx === -1 ? 0 : 1;
|
|
33298
|
+
history.splice(existingIdx, removeCount, item);
|
|
33299
|
+
service.data.lookupHistory.set(item.hash, history);
|
|
33300
|
+
}
|
|
33301
|
+
else {
|
|
33302
|
+
debug_assertNever(kind);
|
|
33287
33303
|
}
|
|
33288
|
-
}
|
|
33289
|
-
else if (kind === state_update_UpdatePreimageKind.UpdateOrAdd) {
|
|
33290
|
-
const { item } = action;
|
|
33291
|
-
const history = service.data.lookupHistory.get(item.hash) ?? [];
|
|
33292
|
-
const existingIdx = history.map((x) => x.length).indexOf(item.length);
|
|
33293
|
-
const removeCount = existingIdx === -1 ? 0 : 1;
|
|
33294
|
-
history.splice(existingIdx, removeCount, item);
|
|
33295
|
-
service.data.lookupHistory.set(item.hash, history);
|
|
33296
|
-
}
|
|
33297
|
-
else {
|
|
33298
|
-
debug_assertNever(kind);
|
|
33299
33304
|
}
|
|
33300
33305
|
}
|
|
33301
33306
|
return result_Result.ok(result_OK);
|
|
33302
33307
|
}
|
|
33303
33308
|
updateServices(servicesUpdates) {
|
|
33304
|
-
|
|
33305
|
-
|
|
33309
|
+
if (servicesUpdates === undefined) {
|
|
33310
|
+
return result_Result.ok(result_OK);
|
|
33311
|
+
}
|
|
33312
|
+
for (const [serviceId, update] of servicesUpdates.entries()) {
|
|
33313
|
+
const { kind, account } = update.action;
|
|
33306
33314
|
if (kind === state_update_UpdateServiceKind.Create) {
|
|
33307
|
-
const { lookupHistory } = action;
|
|
33315
|
+
const { lookupHistory } = update.action;
|
|
33308
33316
|
if (this.services.has(serviceId)) {
|
|
33309
|
-
return result_Result.error(in_memory_state_UpdateError.DuplicateService, `${serviceId} already exists!`);
|
|
33317
|
+
return result_Result.error(in_memory_state_UpdateError.DuplicateService, () => `${serviceId} already exists!`);
|
|
33310
33318
|
}
|
|
33311
33319
|
this.services.set(serviceId, new InMemoryService(serviceId, {
|
|
33312
33320
|
info: account,
|
|
@@ -33318,7 +33326,7 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
33318
33326
|
else if (kind === state_update_UpdateServiceKind.Update) {
|
|
33319
33327
|
const existingService = this.services.get(serviceId);
|
|
33320
33328
|
if (existingService === undefined) {
|
|
33321
|
-
return result_Result.error(in_memory_state_UpdateError.NoService, `Cannot update ${serviceId} because it does not exist.`);
|
|
33329
|
+
return result_Result.error(in_memory_state_UpdateError.NoService, () => `Cannot update ${serviceId} because it does not exist.`);
|
|
33322
33330
|
}
|
|
33323
33331
|
existingService.data.info = account;
|
|
33324
33332
|
}
|
|
@@ -34565,7 +34573,6 @@ function getKeccakTrieHasher(hasher) {
|
|
|
34565
34573
|
|
|
34566
34574
|
|
|
34567
34575
|
|
|
34568
|
-
|
|
34569
34576
|
/** What should be done with that key? */
|
|
34570
34577
|
var serialize_state_update_StateEntryUpdateAction;
|
|
34571
34578
|
(function (StateEntryUpdateAction) {
|
|
@@ -34581,76 +34588,88 @@ function* serialize_state_update_serializeStateUpdate(spec, blake2b, update) {
|
|
|
34581
34588
|
yield* serializeBasicKeys(spec, update);
|
|
34582
34589
|
const encode = (codec, val) => Encoder.encodeObject(codec, val, spec);
|
|
34583
34590
|
// then let's proceed with service updates
|
|
34584
|
-
yield* serializeServiceUpdates(update.
|
|
34591
|
+
yield* serializeServiceUpdates(update.updated, encode, blake2b);
|
|
34585
34592
|
yield* serializePreimages(update.preimages, encode, blake2b);
|
|
34586
34593
|
yield* serializeStorage(update.storage, blake2b);
|
|
34587
|
-
yield* serializeRemovedServices(update.
|
|
34594
|
+
yield* serializeRemovedServices(update.removed);
|
|
34588
34595
|
}
|
|
34589
34596
|
function* serializeRemovedServices(servicesRemoved) {
|
|
34590
|
-
|
|
34597
|
+
if (servicesRemoved === undefined) {
|
|
34598
|
+
return;
|
|
34599
|
+
}
|
|
34600
|
+
for (const serviceId of servicesRemoved) {
|
|
34591
34601
|
// TODO [ToDr] what about all data associated with a service?
|
|
34592
34602
|
const codec = serialize.serviceData(serviceId);
|
|
34593
34603
|
yield [serialize_state_update_StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
34594
34604
|
}
|
|
34595
34605
|
}
|
|
34596
|
-
function* serializeStorage(
|
|
34597
|
-
|
|
34598
|
-
|
|
34599
|
-
|
|
34600
|
-
|
|
34601
|
-
|
|
34602
|
-
|
|
34603
|
-
|
|
34604
|
-
|
|
34605
|
-
|
|
34606
|
-
|
|
34607
|
-
|
|
34608
|
-
|
|
34609
|
-
|
|
34606
|
+
function* serializeStorage(storageUpdates, blake2b) {
|
|
34607
|
+
if (storageUpdates === undefined) {
|
|
34608
|
+
return;
|
|
34609
|
+
}
|
|
34610
|
+
for (const [serviceId, updates] of storageUpdates.entries()) {
|
|
34611
|
+
for (const { action } of updates) {
|
|
34612
|
+
switch (action.kind) {
|
|
34613
|
+
case UpdateStorageKind.Set: {
|
|
34614
|
+
const key = action.storage.key;
|
|
34615
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
34616
|
+
yield [serialize_state_update_StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
34617
|
+
break;
|
|
34618
|
+
}
|
|
34619
|
+
case UpdateStorageKind.Remove: {
|
|
34620
|
+
const key = action.key;
|
|
34621
|
+
const codec = serialize.serviceStorage(blake2b, serviceId, key);
|
|
34622
|
+
yield [serialize_state_update_StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
34623
|
+
break;
|
|
34624
|
+
}
|
|
34610
34625
|
}
|
|
34611
|
-
default:
|
|
34612
|
-
assertNever(action);
|
|
34613
34626
|
}
|
|
34614
34627
|
}
|
|
34615
34628
|
}
|
|
34616
|
-
function* serializePreimages(
|
|
34617
|
-
|
|
34618
|
-
|
|
34619
|
-
|
|
34620
|
-
|
|
34621
|
-
|
|
34622
|
-
|
|
34623
|
-
|
|
34624
|
-
const
|
|
34625
|
-
|
|
34626
|
-
|
|
34627
|
-
|
|
34628
|
-
|
|
34629
|
-
|
|
34629
|
+
function* serializePreimages(preimagesUpdates, encode, blake2b) {
|
|
34630
|
+
if (preimagesUpdates === undefined) {
|
|
34631
|
+
return;
|
|
34632
|
+
}
|
|
34633
|
+
for (const [serviceId, updates] of preimagesUpdates.entries()) {
|
|
34634
|
+
for (const { action } of updates) {
|
|
34635
|
+
switch (action.kind) {
|
|
34636
|
+
case UpdatePreimageKind.Provide: {
|
|
34637
|
+
const { hash, blob } = action.preimage;
|
|
34638
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
34639
|
+
yield [serialize_state_update_StateEntryUpdateAction.Insert, codec.key, blob];
|
|
34640
|
+
if (action.slot !== null) {
|
|
34641
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, tryAsU32(blob.length));
|
|
34642
|
+
yield [
|
|
34643
|
+
serialize_state_update_StateEntryUpdateAction.Insert,
|
|
34644
|
+
codec2.key,
|
|
34645
|
+
encode(codec2.Codec, tryAsLookupHistorySlots([action.slot])),
|
|
34646
|
+
];
|
|
34647
|
+
}
|
|
34648
|
+
break;
|
|
34649
|
+
}
|
|
34650
|
+
case UpdatePreimageKind.UpdateOrAdd: {
|
|
34651
|
+
const { hash, length, slots } = action.item;
|
|
34652
|
+
const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
34653
|
+
yield [serialize_state_update_StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
34654
|
+
break;
|
|
34655
|
+
}
|
|
34656
|
+
case UpdatePreimageKind.Remove: {
|
|
34657
|
+
const { hash, length } = action;
|
|
34658
|
+
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
34659
|
+
yield [serialize_state_update_StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
34660
|
+
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
34661
|
+
yield [serialize_state_update_StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
34662
|
+
break;
|
|
34630
34663
|
}
|
|
34631
|
-
break;
|
|
34632
|
-
}
|
|
34633
|
-
case UpdatePreimageKind.UpdateOrAdd: {
|
|
34634
|
-
const { hash, length, slots } = action.item;
|
|
34635
|
-
const codec = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
34636
|
-
yield [serialize_state_update_StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
34637
|
-
break;
|
|
34638
|
-
}
|
|
34639
|
-
case UpdatePreimageKind.Remove: {
|
|
34640
|
-
const { hash, length } = action;
|
|
34641
|
-
const codec = serialize.servicePreimages(blake2b, serviceId, hash);
|
|
34642
|
-
yield [serialize_state_update_StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
34643
|
-
const codec2 = serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
34644
|
-
yield [serialize_state_update_StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
34645
|
-
break;
|
|
34646
34664
|
}
|
|
34647
|
-
default:
|
|
34648
|
-
assertNever(action);
|
|
34649
34665
|
}
|
|
34650
34666
|
}
|
|
34651
34667
|
}
|
|
34652
34668
|
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
34653
|
-
|
|
34669
|
+
if (servicesUpdates === undefined) {
|
|
34670
|
+
return;
|
|
34671
|
+
}
|
|
34672
|
+
for (const [serviceId, { action }] of servicesUpdates.entries()) {
|
|
34654
34673
|
// new service being created or updated
|
|
34655
34674
|
const codec = serialize.serviceData(serviceId);
|
|
34656
34675
|
yield [serialize_state_update_StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, action.account)];
|
|
@@ -34937,13 +34956,13 @@ class leaf_db_LeafDb {
|
|
|
34937
34956
|
*/
|
|
34938
34957
|
static fromLeavesBlob(blob, db) {
|
|
34939
34958
|
if (blob.length % TRIE_NODE_BYTES !== 0) {
|
|
34940
|
-
return Result.error(LeafDbError.InvalidLeafData, `${blob.length} is not a multiply of ${TRIE_NODE_BYTES}: ${blob}`);
|
|
34959
|
+
return Result.error(LeafDbError.InvalidLeafData, () => `${blob.length} is not a multiply of ${TRIE_NODE_BYTES}: ${blob}`);
|
|
34941
34960
|
}
|
|
34942
34961
|
const leaves = SortedSet.fromArray(leafComparator, []);
|
|
34943
34962
|
for (const nodeData of blob.chunks(TRIE_NODE_BYTES)) {
|
|
34944
34963
|
const node = new TrieNode(nodeData.raw);
|
|
34945
34964
|
if (node.getNodeType() === NodeType.Branch) {
|
|
34946
|
-
return Result.error(LeafDbError.InvalidLeafData, `Branch node detected: ${nodeData}`);
|
|
34965
|
+
return Result.error(LeafDbError.InvalidLeafData, () => `Branch node detected: ${nodeData}`);
|
|
34947
34966
|
}
|
|
34948
34967
|
leaves.insert(node.asLeafNode());
|
|
34949
34968
|
}
|
|
@@ -35336,7 +35355,7 @@ class LmdbStates {
|
|
|
35336
35355
|
}
|
|
35337
35356
|
catch (e) {
|
|
35338
35357
|
states_logger.error `${e}`;
|
|
35339
|
-
return Result.error(StateUpdateError.Commit);
|
|
35358
|
+
return Result.error(StateUpdateError.Commit, () => `Failed to commit state update: ${e}`);
|
|
35340
35359
|
}
|
|
35341
35360
|
return Result.ok(OK);
|
|
35342
35361
|
}
|
|
@@ -36603,20 +36622,20 @@ async function verifyCertificate(certs) {
|
|
|
36603
36622
|
// Must present exactly one cert
|
|
36604
36623
|
if (certs.length !== 1) {
|
|
36605
36624
|
certificate_logger.log `Rejecting peer: expected exactly one certificate, got: ${certs.length}`;
|
|
36606
|
-
return result_Result.error(VerifyCertError.NoCertificate);
|
|
36625
|
+
return result_Result.error(VerifyCertError.NoCertificate, () => `Certificate validation failed: expected exactly one certificate, got ${certs.length}`);
|
|
36607
36626
|
}
|
|
36608
36627
|
// Parse with Node's X509Certificate (accepts PEM or DER)
|
|
36609
36628
|
const xc = new (external_node_crypto_default()).X509Certificate(certs[0]);
|
|
36610
36629
|
// Must be Ed25519 key
|
|
36611
36630
|
if (xc.publicKey.asymmetricKeyType !== CURVE_NAME.toLowerCase()) {
|
|
36612
36631
|
certificate_logger.log `Rejecting peer using non-ed25519 certificate: ${xc.publicKey.asymmetricKeyType}`;
|
|
36613
|
-
return result_Result.error(VerifyCertError.NotEd25519);
|
|
36632
|
+
return result_Result.error(VerifyCertError.NotEd25519, () => `Certificate validation failed: expected Ed25519 key, got ${xc.publicKey.asymmetricKeyType}`);
|
|
36614
36633
|
}
|
|
36615
36634
|
// Extract raw public key via JWK export
|
|
36616
36635
|
const jwk = xc.publicKey.export({ format: "jwk" });
|
|
36617
36636
|
if (jwk.kty !== KEY_TYPE || jwk.crv !== CURVE_NAME) {
|
|
36618
36637
|
certificate_logger.log `Public key type mismatch: ${jwk.kty}, ${jwk.crv}`;
|
|
36619
|
-
return result_Result.error(VerifyCertError.PublicKeyTypeMismatch);
|
|
36638
|
+
return result_Result.error(VerifyCertError.PublicKeyTypeMismatch, () => `Certificate validation failed: public key type mismatch (kty: ${jwk.kty}, crv: ${jwk.crv})`);
|
|
36620
36639
|
}
|
|
36621
36640
|
// SAN must be exactly 'e'+base32(rawPub)
|
|
36622
36641
|
const expectedSan = altNameJwk(jwk);
|
|
@@ -36624,11 +36643,11 @@ async function verifyCertificate(certs) {
|
|
|
36624
36643
|
const m = sanField.match(/DNS:([^,]+)/);
|
|
36625
36644
|
if (m === null || m[1] !== expectedSan) {
|
|
36626
36645
|
certificate_logger.log `AltName mismatch. Expected: '${expectedSan}', got: '${m?.[1]}'`;
|
|
36627
|
-
return result_Result.error(VerifyCertError.AltNameMismatch);
|
|
36646
|
+
return result_Result.error(VerifyCertError.AltNameMismatch, () => `Certificate validation failed: altName mismatch (expected: ${expectedSan}, got: ${m?.[1] ?? "none"})`);
|
|
36628
36647
|
}
|
|
36629
36648
|
const key = Buffer.from(jwk.x ?? "", "base64url");
|
|
36630
36649
|
if (!xc.verify(xc.publicKey)) {
|
|
36631
|
-
return result_Result.error(VerifyCertError.IncorrectSignature);
|
|
36650
|
+
return result_Result.error(VerifyCertError.IncorrectSignature, () => "Certificate validation failed: incorrect signature");
|
|
36632
36651
|
}
|
|
36633
36652
|
const publicKey = bytes_Bytes.fromBlob(new Uint8Array(key), ED25519_KEY_BYTES);
|
|
36634
36653
|
return result_Result.ok({
|
|
@@ -37662,7 +37681,7 @@ function handleGetBlockSequence(chainSpec, blocks, startHash, direction, limit)
|
|
|
37662
37681
|
};
|
|
37663
37682
|
const startBlock = getBlockView(startHash);
|
|
37664
37683
|
if (startBlock === null) {
|
|
37665
|
-
return result_Result.error(BlockSequenceError.NoStartBlock);
|
|
37684
|
+
return result_Result.error(BlockSequenceError.NoStartBlock, () => `Block sequence error: start block ${startHash} not found`);
|
|
37666
37685
|
}
|
|
37667
37686
|
if (direction === Direction.AscExcl) {
|
|
37668
37687
|
// Since we don't have an index of all blocks, we need to start from
|
|
@@ -37674,7 +37693,7 @@ function handleGetBlockSequence(chainSpec, blocks, startHash, direction, limit)
|
|
|
37674
37693
|
const currentHeader = blocks.getHeader(currentHash);
|
|
37675
37694
|
// some errornuous situation, we didn't really reach the block?
|
|
37676
37695
|
if (currentHeader === null || currentHeader.timeSlotIndex.materialize() < startIndex) {
|
|
37677
|
-
return result_Result.error(BlockSequenceError.BlockOnFork);
|
|
37696
|
+
return result_Result.error(BlockSequenceError.BlockOnFork, () => `Block sequence error: start block ${startHash} appears to be on a fork`);
|
|
37678
37697
|
}
|
|
37679
37698
|
// we have everything we need, let's return it now
|
|
37680
37699
|
if (startHash.isEqualTo(currentHash)) {
|