@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-generator.mjs
CHANGED
|
@@ -3170,7 +3170,7 @@ function resultToString(res) {
|
|
|
3170
3170
|
if (res.isOk) {
|
|
3171
3171
|
return `OK: ${typeof res.ok === "symbol" ? res.ok.toString() : res.ok}`;
|
|
3172
3172
|
}
|
|
3173
|
-
return `${res.details}\nError: ${maybeTaggedErrorToString(res.error)}`;
|
|
3173
|
+
return `${res.details()}\nError: ${maybeTaggedErrorToString(res.error)}`;
|
|
3174
3174
|
}
|
|
3175
3175
|
/** An indication of two possible outcomes returned from a function. */
|
|
3176
3176
|
const result_Result = {
|
|
@@ -3184,7 +3184,7 @@ const result_Result = {
|
|
|
3184
3184
|
};
|
|
3185
3185
|
},
|
|
3186
3186
|
/** Create new [`Result`] with `Error` status. */
|
|
3187
|
-
error: (error, details
|
|
3187
|
+
error: (error, details) => {
|
|
3188
3188
|
debug_check `${error !== undefined} 'Error' type cannot be undefined.`;
|
|
3189
3189
|
return {
|
|
3190
3190
|
isOk: false,
|
|
@@ -3303,7 +3303,7 @@ function deepEqual(actual, expected, { context = [], errorsCollector, ignore = [
|
|
|
3303
3303
|
}
|
|
3304
3304
|
if (actual.isError && expected.isError) {
|
|
3305
3305
|
deepEqual(actual.error, expected.error, { context: ctx.concat(["error"]), errorsCollector: errors, ignore });
|
|
3306
|
-
deepEqual(actual.details, expected.details, {
|
|
3306
|
+
deepEqual(actual.details(), expected.details(), {
|
|
3307
3307
|
context: ctx.concat(["details"]),
|
|
3308
3308
|
errorsCollector: errors,
|
|
3309
3309
|
// display details when error does not match
|
|
@@ -9044,6 +9044,7 @@ function accumulationOutputComparator(a, b) {
|
|
|
9044
9044
|
|
|
9045
9045
|
;// CONCATENATED MODULE: ./packages/jam/block/gp-constants.ts
|
|
9046
9046
|
|
|
9047
|
+
|
|
9047
9048
|
/**
|
|
9048
9049
|
* This file lists all of the constants defined in the GrayPaper appendix.
|
|
9049
9050
|
*
|
|
@@ -9054,7 +9055,7 @@ function accumulationOutputComparator(a, b) {
|
|
|
9054
9055
|
* here are only temporarily for convenience. When we figure out better names
|
|
9055
9056
|
* and places for these this file will be eradicated.
|
|
9056
9057
|
*
|
|
9057
|
-
* https://graypaper.fluffylabs.dev/#/
|
|
9058
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/442300442300?v=0.7.2
|
|
9058
9059
|
*/
|
|
9059
9060
|
/** `G_I`: The gas allocated to invoke a work-package’s Is-Authorized logic. */
|
|
9060
9061
|
const G_I = 50_000_000;
|
|
@@ -9070,8 +9071,8 @@ const S = 1024;
|
|
|
9070
9071
|
const T = 128;
|
|
9071
9072
|
/** `W_A`: The maximum size of is-authorized code in octets. */
|
|
9072
9073
|
const W_A = 64_000;
|
|
9073
|
-
/** `W_B`: The maximum size of
|
|
9074
|
-
const W_B = 13_794_305;
|
|
9074
|
+
/** `W_B`: The maximum size of the concatenated variable-size blobs, extrinsics and imported segments of a work-package, in octets */
|
|
9075
|
+
const W_B = Compatibility.isGreaterOrEqual(GpVersion.V0_7_2) ? 13_791_360 : 13_794_305;
|
|
9075
9076
|
/** `W_C`: The maximum size of service code in octets. */
|
|
9076
9077
|
const W_C = 4_000_000;
|
|
9077
9078
|
/** `W_M`: The maximum number of imports in a work-package. */
|
|
@@ -10170,31 +10171,29 @@ var UpdatePreimageKind;
|
|
|
10170
10171
|
* 3. Update `LookupHistory` with given value.
|
|
10171
10172
|
*/
|
|
10172
10173
|
class state_update_UpdatePreimage {
|
|
10173
|
-
serviceId;
|
|
10174
10174
|
action;
|
|
10175
|
-
constructor(
|
|
10176
|
-
this.serviceId = serviceId;
|
|
10175
|
+
constructor(action) {
|
|
10177
10176
|
this.action = action;
|
|
10178
10177
|
}
|
|
10179
10178
|
/** A preimage is provided. We should update the lookuphistory and add the preimage to db. */
|
|
10180
|
-
static provide({
|
|
10181
|
-
return new state_update_UpdatePreimage(
|
|
10179
|
+
static provide({ preimage, slot }) {
|
|
10180
|
+
return new state_update_UpdatePreimage({
|
|
10182
10181
|
kind: UpdatePreimageKind.Provide,
|
|
10183
10182
|
preimage,
|
|
10184
10183
|
slot,
|
|
10185
10184
|
});
|
|
10186
10185
|
}
|
|
10187
10186
|
/** The preimage should be removed completely from the database. */
|
|
10188
|
-
static remove({
|
|
10189
|
-
return new state_update_UpdatePreimage(
|
|
10187
|
+
static remove({ hash, length }) {
|
|
10188
|
+
return new state_update_UpdatePreimage({
|
|
10190
10189
|
kind: UpdatePreimageKind.Remove,
|
|
10191
10190
|
hash,
|
|
10192
10191
|
length,
|
|
10193
10192
|
});
|
|
10194
10193
|
}
|
|
10195
10194
|
/** Update the lookup history of some preimage or add a new one (request). */
|
|
10196
|
-
static updateOrAdd({
|
|
10197
|
-
return new state_update_UpdatePreimage(
|
|
10195
|
+
static updateOrAdd({ lookupHistory }) {
|
|
10196
|
+
return new state_update_UpdatePreimage({
|
|
10198
10197
|
kind: UpdatePreimageKind.UpdateOrAdd,
|
|
10199
10198
|
item: lookupHistory,
|
|
10200
10199
|
});
|
|
@@ -10231,23 +10230,21 @@ var UpdateServiceKind;
|
|
|
10231
10230
|
UpdateServiceKind[UpdateServiceKind["Create"] = 1] = "Create";
|
|
10232
10231
|
})(UpdateServiceKind || (UpdateServiceKind = {}));
|
|
10233
10232
|
/**
|
|
10234
|
-
* Update service info
|
|
10233
|
+
* Update service info or create a new one.
|
|
10235
10234
|
*/
|
|
10236
10235
|
class UpdateService {
|
|
10237
|
-
serviceId;
|
|
10238
10236
|
action;
|
|
10239
|
-
constructor(
|
|
10240
|
-
this.serviceId = serviceId;
|
|
10237
|
+
constructor(action) {
|
|
10241
10238
|
this.action = action;
|
|
10242
10239
|
}
|
|
10243
|
-
static update({
|
|
10244
|
-
return new UpdateService(
|
|
10240
|
+
static update({ serviceInfo }) {
|
|
10241
|
+
return new UpdateService({
|
|
10245
10242
|
kind: UpdateServiceKind.Update,
|
|
10246
10243
|
account: serviceInfo,
|
|
10247
10244
|
});
|
|
10248
10245
|
}
|
|
10249
|
-
static create({
|
|
10250
|
-
return new UpdateService(
|
|
10246
|
+
static create({ serviceInfo, lookupHistory, }) {
|
|
10247
|
+
return new UpdateService({
|
|
10251
10248
|
kind: UpdateServiceKind.Create,
|
|
10252
10249
|
account: serviceInfo,
|
|
10253
10250
|
lookupHistory,
|
|
@@ -10268,17 +10265,15 @@ var UpdateStorageKind;
|
|
|
10268
10265
|
* Can either create/modify an entry or remove it.
|
|
10269
10266
|
*/
|
|
10270
10267
|
class UpdateStorage {
|
|
10271
|
-
serviceId;
|
|
10272
10268
|
action;
|
|
10273
|
-
constructor(
|
|
10274
|
-
this.serviceId = serviceId;
|
|
10269
|
+
constructor(action) {
|
|
10275
10270
|
this.action = action;
|
|
10276
10271
|
}
|
|
10277
|
-
static set({
|
|
10278
|
-
return new UpdateStorage(
|
|
10272
|
+
static set({ storage }) {
|
|
10273
|
+
return new UpdateStorage({ kind: UpdateStorageKind.Set, storage });
|
|
10279
10274
|
}
|
|
10280
|
-
static remove({
|
|
10281
|
-
return new UpdateStorage(
|
|
10275
|
+
static remove({ key }) {
|
|
10276
|
+
return new UpdateStorage({ kind: UpdateStorageKind.Remove, key });
|
|
10282
10277
|
}
|
|
10283
10278
|
get key() {
|
|
10284
10279
|
if (this.action.kind === UpdateStorageKind.Remove) {
|
|
@@ -10487,12 +10482,12 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
10487
10482
|
* Modify the state and apply a single state update.
|
|
10488
10483
|
*/
|
|
10489
10484
|
applyUpdate(update) {
|
|
10490
|
-
const {
|
|
10485
|
+
const { removed, created: _, updated, preimages, storage, ...rest } = update;
|
|
10491
10486
|
// just assign all other variables
|
|
10492
10487
|
Object.assign(this, rest);
|
|
10493
10488
|
// and update the services state
|
|
10494
10489
|
let result;
|
|
10495
|
-
result = this.updateServices(
|
|
10490
|
+
result = this.updateServices(updated);
|
|
10496
10491
|
if (result.isError) {
|
|
10497
10492
|
return result;
|
|
10498
10493
|
}
|
|
@@ -10504,7 +10499,7 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
10504
10499
|
if (result.isError) {
|
|
10505
10500
|
return result;
|
|
10506
10501
|
}
|
|
10507
|
-
this.removeServices(
|
|
10502
|
+
this.removeServices(removed);
|
|
10508
10503
|
return result_Result.ok(result_OK);
|
|
10509
10504
|
}
|
|
10510
10505
|
removeServices(servicesRemoved) {
|
|
@@ -10513,89 +10508,102 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
10513
10508
|
this.services.delete(serviceId);
|
|
10514
10509
|
}
|
|
10515
10510
|
}
|
|
10516
|
-
updateStorage(
|
|
10517
|
-
|
|
10518
|
-
|
|
10519
|
-
|
|
10520
|
-
|
|
10521
|
-
|
|
10522
|
-
|
|
10523
|
-
|
|
10524
|
-
|
|
10525
|
-
|
|
10526
|
-
|
|
10527
|
-
|
|
10528
|
-
|
|
10529
|
-
|
|
10511
|
+
updateStorage(storageUpdates) {
|
|
10512
|
+
if (storageUpdates === undefined) {
|
|
10513
|
+
return result_Result.ok(result_OK);
|
|
10514
|
+
}
|
|
10515
|
+
for (const [serviceId, updates] of storageUpdates.entries()) {
|
|
10516
|
+
for (const update of updates) {
|
|
10517
|
+
const { kind } = update.action;
|
|
10518
|
+
const service = this.services.get(serviceId);
|
|
10519
|
+
if (service === undefined) {
|
|
10520
|
+
return result_Result.error(in_memory_state_UpdateError.NoService, () => `Attempting to update storage of non-existing service: ${serviceId}`);
|
|
10521
|
+
}
|
|
10522
|
+
if (kind === UpdateStorageKind.Set) {
|
|
10523
|
+
const { key, value } = update.action.storage;
|
|
10524
|
+
service.data.storage.set(key.toString(), StorageItem.create({ key, value }));
|
|
10525
|
+
}
|
|
10526
|
+
else if (kind === UpdateStorageKind.Remove) {
|
|
10527
|
+
const { key } = update.action;
|
|
10528
|
+
debug_check `
|
|
10530
10529
|
${service.data.storage.has(key.toString())}
|
|
10531
|
-
Attempting to remove non-existing storage item at ${serviceId}: ${action.key}
|
|
10530
|
+
Attempting to remove non-existing storage item at ${serviceId}: ${update.action.key}
|
|
10532
10531
|
`;
|
|
10533
|
-
|
|
10534
|
-
|
|
10535
|
-
|
|
10536
|
-
|
|
10532
|
+
service.data.storage.delete(key.toString());
|
|
10533
|
+
}
|
|
10534
|
+
else {
|
|
10535
|
+
debug_assertNever(kind);
|
|
10536
|
+
}
|
|
10537
10537
|
}
|
|
10538
10538
|
}
|
|
10539
10539
|
return result_Result.ok(result_OK);
|
|
10540
10540
|
}
|
|
10541
|
-
updatePreimages(
|
|
10542
|
-
|
|
10541
|
+
updatePreimages(preimagesUpdates) {
|
|
10542
|
+
if (preimagesUpdates === undefined) {
|
|
10543
|
+
return result_Result.ok(result_OK);
|
|
10544
|
+
}
|
|
10545
|
+
for (const [serviceId, updates] of preimagesUpdates.entries()) {
|
|
10543
10546
|
const service = this.services.get(serviceId);
|
|
10544
10547
|
if (service === undefined) {
|
|
10545
|
-
return result_Result.error(in_memory_state_UpdateError.NoService, `Attempting to update preimage of non-existing service: ${serviceId}`);
|
|
10546
|
-
}
|
|
10547
|
-
const
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
service.data.preimages.set(preimage.hash, preimage);
|
|
10554
|
-
if (slot !== null) {
|
|
10555
|
-
const lookupHistory = service.data.lookupHistory.get(preimage.hash);
|
|
10556
|
-
const length = numbers_tryAsU32(preimage.blob.length);
|
|
10557
|
-
const lookup = new service_LookupHistoryItem(preimage.hash, length, tryAsLookupHistorySlots([slot]));
|
|
10558
|
-
if (lookupHistory === undefined) {
|
|
10559
|
-
// no lookup history for that preimage at all (edge case, should be requested)
|
|
10560
|
-
service.data.lookupHistory.set(preimage.hash, [lookup]);
|
|
10548
|
+
return result_Result.error(in_memory_state_UpdateError.NoService, () => `Attempting to update preimage of non-existing service: ${serviceId}`);
|
|
10549
|
+
}
|
|
10550
|
+
for (const update of updates) {
|
|
10551
|
+
const { kind } = update.action;
|
|
10552
|
+
if (kind === UpdatePreimageKind.Provide) {
|
|
10553
|
+
const { preimage, slot } = update.action;
|
|
10554
|
+
if (service.data.preimages.has(preimage.hash)) {
|
|
10555
|
+
return result_Result.error(in_memory_state_UpdateError.PreimageExists, () => `Overwriting existing preimage at ${serviceId}: ${preimage}`);
|
|
10561
10556
|
}
|
|
10562
|
-
|
|
10563
|
-
|
|
10564
|
-
const
|
|
10565
|
-
|
|
10557
|
+
service.data.preimages.set(preimage.hash, preimage);
|
|
10558
|
+
if (slot !== null) {
|
|
10559
|
+
const lookupHistory = service.data.lookupHistory.get(preimage.hash);
|
|
10560
|
+
const length = numbers_tryAsU32(preimage.blob.length);
|
|
10561
|
+
const lookup = new service_LookupHistoryItem(preimage.hash, length, tryAsLookupHistorySlots([slot]));
|
|
10562
|
+
if (lookupHistory === undefined) {
|
|
10563
|
+
// no lookup history for that preimage at all (edge case, should be requested)
|
|
10564
|
+
service.data.lookupHistory.set(preimage.hash, [lookup]);
|
|
10565
|
+
}
|
|
10566
|
+
else {
|
|
10567
|
+
// insert or replace exiting entry
|
|
10568
|
+
const index = lookupHistory.map((x) => x.length).indexOf(length);
|
|
10569
|
+
lookupHistory.splice(index, index === -1 ? 0 : 1, lookup);
|
|
10570
|
+
}
|
|
10566
10571
|
}
|
|
10567
10572
|
}
|
|
10568
|
-
|
|
10569
|
-
|
|
10570
|
-
|
|
10571
|
-
|
|
10572
|
-
|
|
10573
|
-
|
|
10574
|
-
|
|
10575
|
-
|
|
10573
|
+
else if (kind === UpdatePreimageKind.Remove) {
|
|
10574
|
+
const { hash, length } = update.action;
|
|
10575
|
+
service.data.preimages.delete(hash);
|
|
10576
|
+
const history = service.data.lookupHistory.get(hash) ?? [];
|
|
10577
|
+
const idx = history.map((x) => x.length).indexOf(length);
|
|
10578
|
+
if (idx !== -1) {
|
|
10579
|
+
history.splice(idx, 1);
|
|
10580
|
+
}
|
|
10581
|
+
}
|
|
10582
|
+
else if (kind === UpdatePreimageKind.UpdateOrAdd) {
|
|
10583
|
+
const { item } = update.action;
|
|
10584
|
+
const history = service.data.lookupHistory.get(item.hash) ?? [];
|
|
10585
|
+
const existingIdx = history.map((x) => x.length).indexOf(item.length);
|
|
10586
|
+
const removeCount = existingIdx === -1 ? 0 : 1;
|
|
10587
|
+
history.splice(existingIdx, removeCount, item);
|
|
10588
|
+
service.data.lookupHistory.set(item.hash, history);
|
|
10589
|
+
}
|
|
10590
|
+
else {
|
|
10591
|
+
debug_assertNever(kind);
|
|
10576
10592
|
}
|
|
10577
|
-
}
|
|
10578
|
-
else if (kind === UpdatePreimageKind.UpdateOrAdd) {
|
|
10579
|
-
const { item } = action;
|
|
10580
|
-
const history = service.data.lookupHistory.get(item.hash) ?? [];
|
|
10581
|
-
const existingIdx = history.map((x) => x.length).indexOf(item.length);
|
|
10582
|
-
const removeCount = existingIdx === -1 ? 0 : 1;
|
|
10583
|
-
history.splice(existingIdx, removeCount, item);
|
|
10584
|
-
service.data.lookupHistory.set(item.hash, history);
|
|
10585
|
-
}
|
|
10586
|
-
else {
|
|
10587
|
-
debug_assertNever(kind);
|
|
10588
10593
|
}
|
|
10589
10594
|
}
|
|
10590
10595
|
return result_Result.ok(result_OK);
|
|
10591
10596
|
}
|
|
10592
10597
|
updateServices(servicesUpdates) {
|
|
10593
|
-
|
|
10594
|
-
|
|
10598
|
+
if (servicesUpdates === undefined) {
|
|
10599
|
+
return result_Result.ok(result_OK);
|
|
10600
|
+
}
|
|
10601
|
+
for (const [serviceId, update] of servicesUpdates.entries()) {
|
|
10602
|
+
const { kind, account } = update.action;
|
|
10595
10603
|
if (kind === UpdateServiceKind.Create) {
|
|
10596
|
-
const { lookupHistory } = action;
|
|
10604
|
+
const { lookupHistory } = update.action;
|
|
10597
10605
|
if (this.services.has(serviceId)) {
|
|
10598
|
-
return result_Result.error(in_memory_state_UpdateError.DuplicateService, `${serviceId} already exists!`);
|
|
10606
|
+
return result_Result.error(in_memory_state_UpdateError.DuplicateService, () => `${serviceId} already exists!`);
|
|
10599
10607
|
}
|
|
10600
10608
|
this.services.set(serviceId, new InMemoryService(serviceId, {
|
|
10601
10609
|
info: account,
|
|
@@ -10607,7 +10615,7 @@ class in_memory_state_InMemoryState extends WithDebug {
|
|
|
10607
10615
|
else if (kind === UpdateServiceKind.Update) {
|
|
10608
10616
|
const existingService = this.services.get(serviceId);
|
|
10609
10617
|
if (existingService === undefined) {
|
|
10610
|
-
return result_Result.error(in_memory_state_UpdateError.NoService, `Cannot update ${serviceId} because it does not exist.`);
|
|
10618
|
+
return result_Result.error(in_memory_state_UpdateError.NoService, () => `Cannot update ${serviceId} because it does not exist.`);
|
|
10611
10619
|
}
|
|
10612
10620
|
existingService.data.info = account;
|
|
10613
10621
|
}
|
|
@@ -11854,7 +11862,6 @@ function getKeccakTrieHasher(hasher) {
|
|
|
11854
11862
|
|
|
11855
11863
|
|
|
11856
11864
|
|
|
11857
|
-
|
|
11858
11865
|
/** What should be done with that key? */
|
|
11859
11866
|
var StateEntryUpdateAction;
|
|
11860
11867
|
(function (StateEntryUpdateAction) {
|
|
@@ -11870,76 +11877,88 @@ function* serializeStateUpdate(spec, blake2b, update) {
|
|
|
11870
11877
|
yield* serializeBasicKeys(spec, update);
|
|
11871
11878
|
const encode = (codec, val) => encoder_Encoder.encodeObject(codec, val, spec);
|
|
11872
11879
|
// then let's proceed with service updates
|
|
11873
|
-
yield* serializeServiceUpdates(update.
|
|
11880
|
+
yield* serializeServiceUpdates(update.updated, encode, blake2b);
|
|
11874
11881
|
yield* serializePreimages(update.preimages, encode, blake2b);
|
|
11875
11882
|
yield* serializeStorage(update.storage, blake2b);
|
|
11876
|
-
yield* serializeRemovedServices(update.
|
|
11883
|
+
yield* serializeRemovedServices(update.removed);
|
|
11877
11884
|
}
|
|
11878
11885
|
function* serializeRemovedServices(servicesRemoved) {
|
|
11879
|
-
|
|
11886
|
+
if (servicesRemoved === undefined) {
|
|
11887
|
+
return;
|
|
11888
|
+
}
|
|
11889
|
+
for (const serviceId of servicesRemoved) {
|
|
11880
11890
|
// TODO [ToDr] what about all data associated with a service?
|
|
11881
11891
|
const codec = serialize_serialize.serviceData(serviceId);
|
|
11882
11892
|
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11883
11893
|
}
|
|
11884
11894
|
}
|
|
11885
|
-
function* serializeStorage(
|
|
11886
|
-
|
|
11887
|
-
|
|
11888
|
-
|
|
11889
|
-
|
|
11890
|
-
|
|
11891
|
-
|
|
11892
|
-
|
|
11893
|
-
|
|
11894
|
-
|
|
11895
|
-
|
|
11896
|
-
|
|
11897
|
-
|
|
11898
|
-
|
|
11895
|
+
function* serializeStorage(storageUpdates, blake2b) {
|
|
11896
|
+
if (storageUpdates === undefined) {
|
|
11897
|
+
return;
|
|
11898
|
+
}
|
|
11899
|
+
for (const [serviceId, updates] of storageUpdates.entries()) {
|
|
11900
|
+
for (const { action } of updates) {
|
|
11901
|
+
switch (action.kind) {
|
|
11902
|
+
case UpdateStorageKind.Set: {
|
|
11903
|
+
const key = action.storage.key;
|
|
11904
|
+
const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
|
|
11905
|
+
yield [StateEntryUpdateAction.Insert, codec.key, action.storage.value];
|
|
11906
|
+
break;
|
|
11907
|
+
}
|
|
11908
|
+
case UpdateStorageKind.Remove: {
|
|
11909
|
+
const key = action.key;
|
|
11910
|
+
const codec = serialize_serialize.serviceStorage(blake2b, serviceId, key);
|
|
11911
|
+
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11912
|
+
break;
|
|
11913
|
+
}
|
|
11899
11914
|
}
|
|
11900
|
-
default:
|
|
11901
|
-
debug_assertNever(action);
|
|
11902
11915
|
}
|
|
11903
11916
|
}
|
|
11904
11917
|
}
|
|
11905
|
-
function* serializePreimages(
|
|
11906
|
-
|
|
11907
|
-
|
|
11908
|
-
|
|
11909
|
-
|
|
11910
|
-
|
|
11911
|
-
|
|
11912
|
-
|
|
11913
|
-
const
|
|
11914
|
-
|
|
11915
|
-
|
|
11916
|
-
|
|
11917
|
-
|
|
11918
|
-
|
|
11918
|
+
function* serializePreimages(preimagesUpdates, encode, blake2b) {
|
|
11919
|
+
if (preimagesUpdates === undefined) {
|
|
11920
|
+
return;
|
|
11921
|
+
}
|
|
11922
|
+
for (const [serviceId, updates] of preimagesUpdates.entries()) {
|
|
11923
|
+
for (const { action } of updates) {
|
|
11924
|
+
switch (action.kind) {
|
|
11925
|
+
case UpdatePreimageKind.Provide: {
|
|
11926
|
+
const { hash, blob } = action.preimage;
|
|
11927
|
+
const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11928
|
+
yield [StateEntryUpdateAction.Insert, codec.key, blob];
|
|
11929
|
+
if (action.slot !== null) {
|
|
11930
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, numbers_tryAsU32(blob.length));
|
|
11931
|
+
yield [
|
|
11932
|
+
StateEntryUpdateAction.Insert,
|
|
11933
|
+
codec2.key,
|
|
11934
|
+
encode(codec2.Codec, tryAsLookupHistorySlots([action.slot])),
|
|
11935
|
+
];
|
|
11936
|
+
}
|
|
11937
|
+
break;
|
|
11938
|
+
}
|
|
11939
|
+
case UpdatePreimageKind.UpdateOrAdd: {
|
|
11940
|
+
const { hash, length, slots } = action.item;
|
|
11941
|
+
const codec = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11942
|
+
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
11943
|
+
break;
|
|
11944
|
+
}
|
|
11945
|
+
case UpdatePreimageKind.Remove: {
|
|
11946
|
+
const { hash, length } = action;
|
|
11947
|
+
const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11948
|
+
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11949
|
+
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11950
|
+
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
11951
|
+
break;
|
|
11919
11952
|
}
|
|
11920
|
-
break;
|
|
11921
|
-
}
|
|
11922
|
-
case UpdatePreimageKind.UpdateOrAdd: {
|
|
11923
|
-
const { hash, length, slots } = action.item;
|
|
11924
|
-
const codec = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11925
|
-
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, slots)];
|
|
11926
|
-
break;
|
|
11927
|
-
}
|
|
11928
|
-
case UpdatePreimageKind.Remove: {
|
|
11929
|
-
const { hash, length } = action;
|
|
11930
|
-
const codec = serialize_serialize.servicePreimages(blake2b, serviceId, hash);
|
|
11931
|
-
yield [StateEntryUpdateAction.Remove, codec.key, EMPTY_BLOB];
|
|
11932
|
-
const codec2 = serialize_serialize.serviceLookupHistory(blake2b, serviceId, hash, length);
|
|
11933
|
-
yield [StateEntryUpdateAction.Remove, codec2.key, EMPTY_BLOB];
|
|
11934
|
-
break;
|
|
11935
11953
|
}
|
|
11936
|
-
default:
|
|
11937
|
-
debug_assertNever(action);
|
|
11938
11954
|
}
|
|
11939
11955
|
}
|
|
11940
11956
|
}
|
|
11941
11957
|
function* serializeServiceUpdates(servicesUpdates, encode, blake2b) {
|
|
11942
|
-
|
|
11958
|
+
if (servicesUpdates === undefined) {
|
|
11959
|
+
return;
|
|
11960
|
+
}
|
|
11961
|
+
for (const [serviceId, { action }] of servicesUpdates.entries()) {
|
|
11943
11962
|
// new service being created or updated
|
|
11944
11963
|
const codec = serialize_serialize.serviceData(serviceId);
|
|
11945
11964
|
yield [StateEntryUpdateAction.Insert, codec.key, encode(codec.Codec, action.account)];
|
|
@@ -12226,13 +12245,13 @@ class LeafDb {
|
|
|
12226
12245
|
*/
|
|
12227
12246
|
static fromLeavesBlob(blob, db) {
|
|
12228
12247
|
if (blob.length % TRIE_NODE_BYTES !== 0) {
|
|
12229
|
-
return result_Result.error(LeafDbError.InvalidLeafData, `${blob.length} is not a multiply of ${TRIE_NODE_BYTES}: ${blob}`);
|
|
12248
|
+
return result_Result.error(LeafDbError.InvalidLeafData, () => `${blob.length} is not a multiply of ${TRIE_NODE_BYTES}: ${blob}`);
|
|
12230
12249
|
}
|
|
12231
12250
|
const leaves = SortedSet.fromArray(leafComparator, []);
|
|
12232
12251
|
for (const nodeData of blob.chunks(TRIE_NODE_BYTES)) {
|
|
12233
12252
|
const node = new TrieNode(nodeData.raw);
|
|
12234
12253
|
if (node.getNodeType() === NodeType.Branch) {
|
|
12235
|
-
return result_Result.error(LeafDbError.InvalidLeafData, `Branch node detected: ${nodeData}`);
|
|
12254
|
+
return result_Result.error(LeafDbError.InvalidLeafData, () => `Branch node detected: ${nodeData}`);
|
|
12236
12255
|
}
|
|
12237
12256
|
leaves.insert(node.asLeafNode());
|
|
12238
12257
|
}
|
|
@@ -12951,7 +12970,7 @@ class LmdbStates {
|
|
|
12951
12970
|
}
|
|
12952
12971
|
catch (e) {
|
|
12953
12972
|
logger.error `${e}`;
|
|
12954
|
-
return result_Result.error(StateUpdateError.Commit);
|
|
12973
|
+
return result_Result.error(StateUpdateError.Commit, () => `Failed to commit state update: ${e}`);
|
|
12955
12974
|
}
|
|
12956
12975
|
return result_Result.ok(result_OK);
|
|
12957
12976
|
}
|
|
@@ -13750,32 +13769,33 @@ class Preimages {
|
|
|
13750
13769
|
}
|
|
13751
13770
|
if (prevPreimage.requester > currPreimage.requester ||
|
|
13752
13771
|
currPreimage.blob.compare(prevPreimage.blob).isLessOrEqual()) {
|
|
13753
|
-
return Result.error(PreimagesErrorCode.PreimagesNotSortedUnique);
|
|
13772
|
+
return Result.error(PreimagesErrorCode.PreimagesNotSortedUnique, () => `Preimages not sorted/unique at index ${i}`);
|
|
13754
13773
|
}
|
|
13755
13774
|
}
|
|
13756
13775
|
const { preimages, slot } = input;
|
|
13757
|
-
const pendingChanges =
|
|
13776
|
+
const pendingChanges = new Map();
|
|
13758
13777
|
// select preimages for integration
|
|
13759
13778
|
for (const preimage of preimages) {
|
|
13760
13779
|
const { requester, blob } = preimage;
|
|
13761
13780
|
const hash = this.blake2b.hashBytes(blob).asOpaque();
|
|
13762
13781
|
const service = this.state.getService(requester);
|
|
13763
13782
|
if (service === null) {
|
|
13764
|
-
return Result.error(PreimagesErrorCode.AccountNotFound);
|
|
13783
|
+
return Result.error(PreimagesErrorCode.AccountNotFound, () => `Service not found: ${requester}`);
|
|
13765
13784
|
}
|
|
13766
13785
|
const hasPreimage = service.hasPreimage(hash);
|
|
13767
13786
|
const slots = service.getLookupHistory(hash, tryAsU32(blob.length));
|
|
13768
13787
|
// https://graypaper.fluffylabs.dev/#/5f542d7/181800181900
|
|
13769
13788
|
// https://graypaper.fluffylabs.dev/#/5f542d7/116f0011a500
|
|
13770
13789
|
if (hasPreimage || slots === null || !LookupHistoryItem.isRequested(slots)) {
|
|
13771
|
-
return Result.error(PreimagesErrorCode.PreimageUnneeded);
|
|
13790
|
+
return Result.error(PreimagesErrorCode.PreimageUnneeded, () => `Preimage unneeded: requester=${requester}, hash=${hash}, hasPreimage=${hasPreimage}, isRequested=${slots !== null && LookupHistoryItem.isRequested(slots)}`);
|
|
13772
13791
|
}
|
|
13773
13792
|
// https://graypaper.fluffylabs.dev/#/5f542d7/18c00018f300
|
|
13774
|
-
pendingChanges.
|
|
13775
|
-
|
|
13793
|
+
const updates = pendingChanges.get(requester) ?? [];
|
|
13794
|
+
updates.push(UpdatePreimage.provide({
|
|
13776
13795
|
preimage: PreimageItem.create({ hash, blob }),
|
|
13777
13796
|
slot,
|
|
13778
13797
|
}));
|
|
13798
|
+
pendingChanges.set(requester, updates);
|
|
13779
13799
|
}
|
|
13780
13800
|
return Result.ok({
|
|
13781
13801
|
preimages: pendingChanges,
|