@typeberry/lib 0.5.4-9233977 → 0.5.4-b101fe6
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/package.json +1 -1
- package/packages/core/utils/compatibility.d.ts +0 -1
- package/packages/core/utils/compatibility.d.ts.map +1 -1
- package/packages/core/utils/compatibility.js +1 -2
- package/packages/core/utils/compatibility.test.js +6 -10
- package/packages/jam/database-lmdb/states.test.js +3 -5
- package/packages/jam/jam-host-calls/accumulate/bless.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/bless.js +6 -10
- package/packages/jam/jam-host-calls/accumulate/bless.test.js +32 -72
- package/packages/jam/jam-host-calls/accumulate/new.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/new.js +2 -4
- package/packages/jam/jam-host-calls/accumulate/new.test.js +4 -5
- package/packages/jam/jam-host-calls/general/fetch.d.ts +1 -57
- package/packages/jam/jam-host-calls/general/fetch.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/general/fetch.js +6 -29
- package/packages/jam/jam-host-calls/general/fetch.test.js +2 -58
- package/packages/jam/state/privileged-services.d.ts +1 -1
- package/packages/jam/state/privileged-services.d.ts.map +1 -1
- package/packages/jam/state/privileged-services.js +1 -6
- package/packages/jam/state/service.d.ts +1 -1
- package/packages/jam/state/service.d.ts.map +1 -1
- package/packages/jam/state/statistics.d.ts +0 -8
- package/packages/jam/state/statistics.d.ts.map +1 -1
- package/packages/jam/state/statistics.js +14 -44
- package/packages/jam/state/statistics.test.js +1 -8
- package/packages/jam/state/test.utils.d.ts +1 -1
- package/packages/jam/state/test.utils.d.ts.map +1 -1
- package/packages/jam/state/test.utils.js +4 -22
- package/packages/jam/state-json/accounts.d.ts +10 -0
- package/packages/jam/state-json/accounts.d.ts.map +1 -1
- package/packages/jam/state-json/accounts.js +47 -19
- package/packages/jam/state-json/dump.d.ts.map +1 -1
- package/packages/jam/state-json/dump.js +5 -9
- package/packages/jam/state-json/dump.test.js +2 -10
- package/packages/jam/state-json/statistics.d.ts +1 -1
- package/packages/jam/state-json/statistics.d.ts.map +1 -1
- package/packages/jam/state-json/statistics.js +1 -13
- package/packages/jam/state-merkleization/in-memory-state-codec.d.ts +0 -2
- package/packages/jam/state-merkleization/in-memory-state-codec.d.ts.map +1 -1
- package/packages/jam/state-merkleization/serialize.d.ts +4 -4
- package/packages/jam/state-merkleization/serialize.d.ts.map +1 -1
- package/packages/jam/state-merkleization/serialize.js +5 -8
- package/packages/jam/state-merkleization/serialized-state-view.d.ts.map +1 -1
- package/packages/jam/state-merkleization/state-entries.test.js +1 -7
- package/packages/jam/transition/accumulate/accumulate-state.d.ts +1 -2
- package/packages/jam/transition/accumulate/accumulate-state.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate-utils.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate-utils.js +2 -6
- package/packages/jam/transition/accumulate/accumulate-utils.test.js +2 -4
- package/packages/jam/transition/accumulate/accumulate.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate.js +11 -20
- package/packages/jam/transition/accumulate/index.d.ts +0 -1
- package/packages/jam/transition/accumulate/index.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/index.js +0 -1
- package/packages/jam/transition/chain-stf.d.ts +3 -5
- package/packages/jam/transition/chain-stf.d.ts.map +1 -1
- package/packages/jam/transition/chain-stf.js +5 -29
- package/packages/jam/transition/externalities/accumulate-externalities.d.ts.map +1 -1
- package/packages/jam/transition/externalities/accumulate-externalities.js +22 -49
- package/packages/jam/transition/externalities/accumulate-externalities.test.js +8 -72
- package/packages/jam/transition/externalities/fetch-externalities.d.ts +3 -22
- package/packages/jam/transition/externalities/fetch-externalities.d.ts.map +1 -1
- package/packages/jam/transition/externalities/fetch-externalities.js +3 -55
- package/packages/jam/transition/externalities/fetch-externalities.test.js +199 -112
- package/packages/jam/transition/statistics.d.ts +0 -7
- package/packages/jam/transition/statistics.d.ts.map +1 -1
- package/packages/jam/transition/statistics.js +2 -11
- package/packages/jam/transition/statistics.test.js +0 -40
- package/packages/jam/transition/accumulate/deferred-transfers.d.ts +0 -36
- package/packages/jam/transition/accumulate/deferred-transfers.d.ts.map +0 -1
- package/packages/jam/transition/accumulate/deferred-transfers.js +0 -94
|
@@ -6,7 +6,7 @@ import { AccumulationStateUpdate, clampU64ToU32, EjectError, ForgetPreimageError
|
|
|
6
6
|
import { Logger } from "#@typeberry/logger";
|
|
7
7
|
import { maxU64, sumU64, tryAsU32, tryAsU64 } from "#@typeberry/numbers";
|
|
8
8
|
import { LookupHistoryItem, PreimageItem, PrivilegedServices, ServiceAccountInfo, tryAsLookupHistorySlots, UpdatePreimage, } from "#@typeberry/state";
|
|
9
|
-
import { assertNever,
|
|
9
|
+
import { assertNever, check, OK, Result } from "#@typeberry/utils";
|
|
10
10
|
/**
|
|
11
11
|
* Number of storage items required for ejection of the service.
|
|
12
12
|
*
|
|
@@ -102,10 +102,7 @@ export class AccumulateExternalities {
|
|
|
102
102
|
/** `check`: https://graypaper.fluffylabs.dev/#/ab2cdbd/30c60330c603?v=0.7.2 */
|
|
103
103
|
getNextAvailableServiceId(serviceId) {
|
|
104
104
|
let currentServiceId = serviceId;
|
|
105
|
-
const mod =
|
|
106
|
-
? 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8
|
|
107
|
-
: 2 ** 32 - 2 ** 9;
|
|
108
|
-
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
105
|
+
const mod = 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8;
|
|
109
106
|
for (;;) {
|
|
110
107
|
const service = this.getServiceInfo(currentServiceId);
|
|
111
108
|
// we found an empty id
|
|
@@ -113,7 +110,7 @@ export class AccumulateExternalities {
|
|
|
113
110
|
return currentServiceId;
|
|
114
111
|
}
|
|
115
112
|
// keep trying
|
|
116
|
-
currentServiceId = tryAsServiceId(((currentServiceId -
|
|
113
|
+
currentServiceId = tryAsServiceId(((currentServiceId - MIN_PUBLIC_SERVICE_INDEX + 1 + mod) % mod) + MIN_PUBLIC_SERVICE_INDEX);
|
|
117
114
|
}
|
|
118
115
|
}
|
|
119
116
|
checkPreimageStatus(hash, length) {
|
|
@@ -304,25 +301,23 @@ export class AccumulateExternalities {
|
|
|
304
301
|
...currentService,
|
|
305
302
|
balance: tryAsU64(balanceLeftForCurrent),
|
|
306
303
|
});
|
|
307
|
-
if (
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
return Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken, () => `Service ID ${newServiceId} already taken`);
|
|
314
|
-
}
|
|
315
|
-
// add the new service with selected ID
|
|
316
|
-
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
|
|
317
|
-
this.updatedState.createService(newServiceId, newAccount, newLookupItem);
|
|
318
|
-
// update the balance of current service
|
|
319
|
-
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
|
|
320
|
-
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
321
|
-
return Result.ok(newServiceId);
|
|
304
|
+
if (wantedServiceId < MIN_PUBLIC_SERVICE_INDEX &&
|
|
305
|
+
this.currentServiceId === this.updatedState.getPrivilegedServices().registrar) {
|
|
306
|
+
// NOTE: It's safe to cast to `Number` here, bcs here service ID cannot be bigger than 2**16
|
|
307
|
+
const newServiceId = tryAsServiceId(Number(wantedServiceId));
|
|
308
|
+
if (this.getServiceInfo(newServiceId) !== null) {
|
|
309
|
+
return Result.error(NewServiceError.RegistrarServiceIdAlreadyTaken, () => `Service ID ${newServiceId} already taken`);
|
|
322
310
|
}
|
|
323
|
-
//
|
|
324
|
-
//
|
|
325
|
-
|
|
311
|
+
// add the new service with selected ID
|
|
312
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36be0336c003?v=0.7.2
|
|
313
|
+
this.updatedState.createService(newServiceId, newAccount, newLookupItem);
|
|
314
|
+
// update the balance of current service
|
|
315
|
+
// https://graypaper.fluffylabs.dev/#/ab2cdbd/36c20336c403?v=0.7.2
|
|
316
|
+
this.updatedState.updateServiceInfo(this.currentServiceId, updatedCurrentAccount);
|
|
317
|
+
return Result.ok(newServiceId);
|
|
318
|
+
}
|
|
319
|
+
// NOTE: in case the service is not a registrar or the requested serviceId is out of range,
|
|
320
|
+
// we completely ignore the `wantedServiceId` and assign a random one
|
|
326
321
|
const newServiceId = this.nextNewServiceId;
|
|
327
322
|
// add the new service
|
|
328
323
|
// https://graypaper.fluffylabs.dev/#/7e6ff6a/36cb0236cb02?v=0.6.7
|
|
@@ -367,7 +362,7 @@ export class AccumulateExternalities {
|
|
|
367
362
|
logger.trace `Current service id (${this.currentServiceId}) is not an auth manager of core ${coreIndex} (expected: ${currentAssigners}) and cannot update authorization queue.`;
|
|
368
363
|
return Result.error(UpdatePrivilegesError.UnprivilegedService, () => `Service ${this.currentServiceId} not assigner for core ${coreIndex} (expected: ${currentAssigners})`);
|
|
369
364
|
}
|
|
370
|
-
if (assigners === null
|
|
365
|
+
if (assigners === null) {
|
|
371
366
|
logger.trace `The new auth manager is not a valid service id.`;
|
|
372
367
|
return Result.error(UpdatePrivilegesError.InvalidServiceId, () => `New auth manager is null for core ${coreIndex}`);
|
|
373
368
|
}
|
|
@@ -375,25 +370,6 @@ export class AccumulateExternalities {
|
|
|
375
370
|
return Result.ok(OK);
|
|
376
371
|
}
|
|
377
372
|
updatePrivilegedServices(manager, assigners, delegator, registrar, autoAccumulateServices) {
|
|
378
|
-
if (!Compatibility.isGreaterOrEqual(GpVersion.V0_7_1)) {
|
|
379
|
-
/** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
|
|
380
|
-
const current = this.updatedState.getPrivilegedServices();
|
|
381
|
-
const isManager = current.manager === this.currentServiceId;
|
|
382
|
-
if (!isManager) {
|
|
383
|
-
return Result.error(UpdatePrivilegesError.UnprivilegedService, () => `Service ${this.currentServiceId} is not manager`);
|
|
384
|
-
}
|
|
385
|
-
if (manager === null || delegator === null) {
|
|
386
|
-
return Result.error(UpdatePrivilegesError.InvalidServiceId, () => "Either manager or delegator is not a valid service id.");
|
|
387
|
-
}
|
|
388
|
-
this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
|
|
389
|
-
manager,
|
|
390
|
-
assigners,
|
|
391
|
-
delegator,
|
|
392
|
-
registrar: registrar ?? tryAsServiceId(0),
|
|
393
|
-
autoAccumulateServices,
|
|
394
|
-
});
|
|
395
|
-
return Result.ok(OK);
|
|
396
|
-
}
|
|
397
373
|
if (manager === null || delegator === null || registrar === null) {
|
|
398
374
|
return Result.error(UpdatePrivilegesError.InvalidServiceId, () => "Either manager or delegator or registrar is not a valid service id.");
|
|
399
375
|
}
|
|
@@ -527,9 +503,6 @@ export class AccumulateExternalities {
|
|
|
527
503
|
}
|
|
528
504
|
}
|
|
529
505
|
function bumpServiceId(serviceId) {
|
|
530
|
-
const mod =
|
|
531
|
-
|
|
532
|
-
: 2 ** 32 - 2 ** 9;
|
|
533
|
-
const offset = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? MIN_PUBLIC_SERVICE_INDEX : 2 ** 8;
|
|
534
|
-
return tryAsServiceId(offset + ((serviceId - offset + 42 + mod) % mod));
|
|
506
|
+
const mod = 2 ** 32 - MIN_PUBLIC_SERVICE_INDEX - 2 ** 8;
|
|
507
|
+
return tryAsServiceId(MIN_PUBLIC_SERVICE_INDEX + ((serviceId - MIN_PUBLIC_SERVICE_INDEX + 42 + mod) % mod));
|
|
535
508
|
}
|
|
@@ -10,7 +10,7 @@ import { EjectError, ForgetPreimageError, NewServiceError, PartiallyUpdatedState
|
|
|
10
10
|
import { tryAsU32, tryAsU64 } from "#@typeberry/numbers";
|
|
11
11
|
import { AUTHORIZATION_QUEUE_SIZE, InMemoryService, InMemoryState, LookupHistoryItem, PreimageItem, PrivilegedServices, ServiceAccountInfo, StorageItem, tryAsLookupHistorySlots, tryAsPerCore, UpdatePreimage, UpdateService, VALIDATOR_META_BYTES, ValidatorData, } from "#@typeberry/state";
|
|
12
12
|
import { testState } from "#@typeberry/state/test.utils.js";
|
|
13
|
-
import { asOpaqueType,
|
|
13
|
+
import { asOpaqueType, deepEqual, OK, Result } from "#@typeberry/utils";
|
|
14
14
|
import { AccumulateExternalities } from "./accumulate-externalities.js";
|
|
15
15
|
let blake2b;
|
|
16
16
|
before(async () => {
|
|
@@ -19,9 +19,7 @@ before(async () => {
|
|
|
19
19
|
function partiallyUpdatedState() {
|
|
20
20
|
return new PartiallyUpdatedState(testState());
|
|
21
21
|
}
|
|
22
|
-
const INVALID_SERVICE_ID_ERROR =
|
|
23
|
-
? "Either manager or delegator or registrar is not a valid service id."
|
|
24
|
-
: "Either manager or delegator is not a valid service id.";
|
|
22
|
+
const INVALID_SERVICE_ID_ERROR = "Either manager or delegator or registrar is not a valid service id.";
|
|
25
23
|
describe("PartialState.checkPreimageStatus", () => {
|
|
26
24
|
it("should check preimage status from state", () => {
|
|
27
25
|
const state = partiallyUpdatedState();
|
|
@@ -342,7 +340,6 @@ describe("PartialState.forgetPreimage", () => {
|
|
|
342
340
|
});
|
|
343
341
|
});
|
|
344
342
|
describe("PartialState.newService", () => {
|
|
345
|
-
const itPost071 = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? it : it.skip;
|
|
346
343
|
it("should create a new service and update balance + next service ID", () => {
|
|
347
344
|
const state = partiallyUpdatedState();
|
|
348
345
|
const maybeService = state.state.services.get(tryAsServiceId(0));
|
|
@@ -398,14 +395,9 @@ describe("PartialState.newService", () => {
|
|
|
398
395
|
]));
|
|
399
396
|
assert.deepStrictEqual(state.stateUpdate.services.created, [expectedServiceId]);
|
|
400
397
|
// Verify next service ID bumped
|
|
401
|
-
|
|
402
|
-
assert.deepStrictEqual(partialState.getNextNewServiceId(), tryAsServiceId(4294901556));
|
|
403
|
-
}
|
|
404
|
-
else {
|
|
405
|
-
assert.deepStrictEqual(partialState.getNextNewServiceId(), tryAsServiceId(4294966836));
|
|
406
|
-
}
|
|
398
|
+
assert.deepStrictEqual(partialState.getNextNewServiceId(), tryAsServiceId(4294901556));
|
|
407
399
|
});
|
|
408
|
-
|
|
400
|
+
it("should create a new service with given id and update balance + not changed next service ID", () => {
|
|
409
401
|
const state = partiallyUpdatedState();
|
|
410
402
|
const serviceId = 0;
|
|
411
403
|
// setting registrar privileges for our service
|
|
@@ -534,7 +526,7 @@ describe("PartialState.newService", () => {
|
|
|
534
526
|
// Verify no side effects
|
|
535
527
|
assert.deepStrictEqual(state.stateUpdate.services.updated, new Map());
|
|
536
528
|
});
|
|
537
|
-
|
|
529
|
+
it("should return an error if attempting to create new service with selected id that already exists", () => {
|
|
538
530
|
const state = partiallyUpdatedState();
|
|
539
531
|
const serviceId = 0;
|
|
540
532
|
// setting registrar privileges for our service
|
|
@@ -562,7 +554,7 @@ describe("PartialState.newService", () => {
|
|
|
562
554
|
// Verify next service ID is not bumped
|
|
563
555
|
assert.deepStrictEqual(partialState.getNextNewServiceId(), tryAsServiceId(10));
|
|
564
556
|
});
|
|
565
|
-
|
|
557
|
+
it("should create a new service with random id if service is unprivileged to select new service id + next service id", () => {
|
|
566
558
|
const state = partiallyUpdatedState();
|
|
567
559
|
// setting different service than our privileged registrar
|
|
568
560
|
state.stateUpdate.privilegedServices = {
|
|
@@ -671,7 +663,6 @@ describe("PartialState.upgradeService", () => {
|
|
|
671
663
|
});
|
|
672
664
|
});
|
|
673
665
|
describe("PartialState.updateAuthorizationQueue", () => {
|
|
674
|
-
const itPost071 = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? it : it.skip;
|
|
675
666
|
it("should update the authorization queue for a given core index", () => {
|
|
676
667
|
const state = partiallyUpdatedState();
|
|
677
668
|
const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
|
|
@@ -683,7 +674,7 @@ describe("PartialState.updateAuthorizationQueue", () => {
|
|
|
683
674
|
// then
|
|
684
675
|
assert.deepStrictEqual(state.stateUpdate.authorizationQueues.get(coreIndex), queue);
|
|
685
676
|
});
|
|
686
|
-
|
|
677
|
+
it("should return InvalidServiceId when given auth manager is invalid", () => {
|
|
687
678
|
const state = partiallyUpdatedState();
|
|
688
679
|
const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
|
|
689
680
|
const coreIndex = tryAsCoreIndex(0);
|
|
@@ -729,7 +720,6 @@ describe("PartialState.updateAuthorizationQueue", () => {
|
|
|
729
720
|
});
|
|
730
721
|
});
|
|
731
722
|
describe("PartialState.updatePrivilegedServices", () => {
|
|
732
|
-
const [itPre071, itPost071] = Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) ? [it.skip, it] : [it, it.skip];
|
|
733
723
|
it("should update privileged services", () => {
|
|
734
724
|
const state = partiallyUpdatedState();
|
|
735
725
|
const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
|
|
@@ -753,60 +743,6 @@ describe("PartialState.updatePrivilegedServices", () => {
|
|
|
753
743
|
autoAccumulateServices,
|
|
754
744
|
}));
|
|
755
745
|
});
|
|
756
|
-
itPre071("should return UnprivilegedError when current service is unprivileged", () => {
|
|
757
|
-
const state = partiallyUpdatedState();
|
|
758
|
-
state.state.privilegedServices = { ...state.state.privilegedServices, manager: tryAsServiceId(1) };
|
|
759
|
-
const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
|
|
760
|
-
const manager = tryAsServiceId(1);
|
|
761
|
-
const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
|
|
762
|
-
const delegator = tryAsServiceId(3);
|
|
763
|
-
const registrar = tryAsServiceId(4);
|
|
764
|
-
const autoAccumulate = new Map([
|
|
765
|
-
[tryAsServiceId(4), tryAsServiceGas(10n)],
|
|
766
|
-
[tryAsServiceId(5), tryAsServiceGas(20n)],
|
|
767
|
-
]);
|
|
768
|
-
// when
|
|
769
|
-
const result = partialState.updatePrivilegedServices(manager, assigners, delegator, registrar, autoAccumulate);
|
|
770
|
-
// then
|
|
771
|
-
deepEqual(result, Result.error(UpdatePrivilegesError.UnprivilegedService, () => "Service 0 is not manager"));
|
|
772
|
-
assert.deepStrictEqual(state.stateUpdate.privilegedServices, null);
|
|
773
|
-
});
|
|
774
|
-
itPre071("should return UnprivilegedError when current service is unprivileged and manager is invalid service id", () => {
|
|
775
|
-
const state = partiallyUpdatedState();
|
|
776
|
-
state.state.privilegedServices = { ...state.state.privilegedServices, manager: tryAsServiceId(1) };
|
|
777
|
-
const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
|
|
778
|
-
const manager = null;
|
|
779
|
-
const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
|
|
780
|
-
const delegator = tryAsServiceId(3);
|
|
781
|
-
const registrar = tryAsServiceId(4);
|
|
782
|
-
const autoAccumulate = new Map([
|
|
783
|
-
[tryAsServiceId(4), tryAsServiceGas(10n)],
|
|
784
|
-
[tryAsServiceId(5), tryAsServiceGas(20n)],
|
|
785
|
-
]);
|
|
786
|
-
// when
|
|
787
|
-
const result = partialState.updatePrivilegedServices(manager, assigners, delegator, registrar, autoAccumulate);
|
|
788
|
-
// then
|
|
789
|
-
deepEqual(result, Result.error(UpdatePrivilegesError.UnprivilegedService, () => "Service 0 is not manager"));
|
|
790
|
-
assert.deepStrictEqual(state.stateUpdate.privilegedServices, null);
|
|
791
|
-
});
|
|
792
|
-
itPre071("should return UnprivilegedError when current service is unprivileged and validator is invalid service id", () => {
|
|
793
|
-
const state = partiallyUpdatedState();
|
|
794
|
-
state.state.privilegedServices = { ...state.state.privilegedServices, manager: tryAsServiceId(1) };
|
|
795
|
-
const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
|
|
796
|
-
const manager = tryAsServiceId(1);
|
|
797
|
-
const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
|
|
798
|
-
const delegator = null;
|
|
799
|
-
const registrar = tryAsServiceId(4);
|
|
800
|
-
const autoAccumulate = new Map([
|
|
801
|
-
[tryAsServiceId(4), tryAsServiceGas(10n)],
|
|
802
|
-
[tryAsServiceId(5), tryAsServiceGas(20n)],
|
|
803
|
-
]);
|
|
804
|
-
// when
|
|
805
|
-
const result = partialState.updatePrivilegedServices(manager, assigners, delegator, registrar, autoAccumulate);
|
|
806
|
-
// then
|
|
807
|
-
deepEqual(result, Result.error(UpdatePrivilegesError.UnprivilegedService, () => "Service 0 is not manager"));
|
|
808
|
-
assert.deepStrictEqual(state.stateUpdate.privilegedServices, null);
|
|
809
|
-
});
|
|
810
746
|
it("should return InvalidService when given manager is invalid service id", () => {
|
|
811
747
|
const state = partiallyUpdatedState();
|
|
812
748
|
const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
|
|
@@ -841,7 +777,7 @@ describe("PartialState.updatePrivilegedServices", () => {
|
|
|
841
777
|
deepEqual(result, Result.error(UpdatePrivilegesError.InvalidServiceId, () => INVALID_SERVICE_ID_ERROR));
|
|
842
778
|
assert.deepStrictEqual(state.stateUpdate.privilegedServices, null);
|
|
843
779
|
});
|
|
844
|
-
|
|
780
|
+
it("should return InvalidService when given registrar is invalid service id", () => {
|
|
845
781
|
const state = partiallyUpdatedState();
|
|
846
782
|
const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
|
|
847
783
|
const manager = tryAsServiceId(1);
|
|
@@ -4,7 +4,7 @@ import type { ChainSpec } from "#@typeberry/config";
|
|
|
4
4
|
import { type general, PendingTransfer } from "#@typeberry/jam-host-calls";
|
|
5
5
|
import { type U64 } from "#@typeberry/numbers";
|
|
6
6
|
import { Operand } from "../accumulate/operand.js";
|
|
7
|
-
declare enum TransferOperandKind {
|
|
7
|
+
export declare enum TransferOperandKind {
|
|
8
8
|
OPERAND = 0,
|
|
9
9
|
TRANSFER = 1
|
|
10
10
|
}
|
|
@@ -15,24 +15,11 @@ export type TransferOrOperand = {
|
|
|
15
15
|
kind: TransferOperandKind.TRANSFER;
|
|
16
16
|
value: PendingTransfer;
|
|
17
17
|
};
|
|
18
|
+
export declare const TRANSFER_OR_OPERAND: import("@typeberry/codec").Descriptor<TransferOrOperand, TransferOrOperand>;
|
|
18
19
|
declare enum FetchContext {
|
|
19
20
|
Accumulate = 0,
|
|
20
|
-
|
|
21
|
-
LegacyAccumulate = 1,
|
|
22
|
-
/** @deprecated since 0.7.1 */
|
|
23
|
-
LegacyOnTransfer = 2,
|
|
24
|
-
Refine = 3
|
|
21
|
+
Refine = 1
|
|
25
22
|
}
|
|
26
|
-
type LegacyAccumulateFetchData = {
|
|
27
|
-
context: FetchContext.LegacyAccumulate;
|
|
28
|
-
entropy: EntropyHash;
|
|
29
|
-
operands: Operand[];
|
|
30
|
-
};
|
|
31
|
-
type LegacyOnTransferFetchData = {
|
|
32
|
-
context: FetchContext.LegacyOnTransfer;
|
|
33
|
-
entropy: EntropyHash;
|
|
34
|
-
transfers: PendingTransfer[];
|
|
35
|
-
};
|
|
36
23
|
type AccumulateFetchData = {
|
|
37
24
|
context: FetchContext.Accumulate;
|
|
38
25
|
entropy: EntropyHash;
|
|
@@ -47,9 +34,7 @@ export declare class FetchExternalities implements general.IFetchExternalities {
|
|
|
47
34
|
private fetchData;
|
|
48
35
|
private chainSpec;
|
|
49
36
|
private constructor();
|
|
50
|
-
static createForPre071Accumulate(fetchData: Omit<LegacyAccumulateFetchData, "context">, chainSpec: ChainSpec): FetchExternalities;
|
|
51
37
|
static createForAccumulate(fetchData: Omit<AccumulateFetchData, "context">, chainSpec: ChainSpec): FetchExternalities;
|
|
52
|
-
static createForOnTransfer(fetchData: Omit<LegacyOnTransferFetchData, "context">, chainSpec: ChainSpec): FetchExternalities;
|
|
53
38
|
static createForRefine(fetchData: Omit<RefineFetchData, "context">, chainSpec: ChainSpec): FetchExternalities;
|
|
54
39
|
constants(): BytesBlob;
|
|
55
40
|
entropy(): BytesBlob | null;
|
|
@@ -63,10 +48,6 @@ export declare class FetchExternalities implements general.IFetchExternalities {
|
|
|
63
48
|
allWorkItems(): BytesBlob | null;
|
|
64
49
|
oneWorkItem(_workItem: U64): BytesBlob | null;
|
|
65
50
|
workItemPayload(_workItem: U64): BytesBlob | null;
|
|
66
|
-
allOperands(): BytesBlob | null;
|
|
67
|
-
oneOperand(operandIndex: U64): BytesBlob | null;
|
|
68
|
-
allTransfers(): BytesBlob | null;
|
|
69
|
-
oneTransfer(transferIndex: U64): BytesBlob | null;
|
|
70
51
|
allTransfersAndOperands(): BytesBlob | null;
|
|
71
52
|
oneTransferOrOperand(index: U64): BytesBlob | null;
|
|
72
53
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-externalities.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/transition/externalities/fetch-externalities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,KAAK,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAQ5E,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAInD,
|
|
1
|
+
{"version":3,"file":"fetch-externalities.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/transition/externalities/fetch-externalities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,KAAK,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC1E,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAQ5E,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAInD,oBAAY,mBAAmB;IAC7B,OAAO,IAAI;IACX,QAAQ,IAAI;CACb;AAED,MAAM,MAAM,iBAAiB,GACzB;IACE,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC;CAChB,GACD;IACE,IAAI,EAAE,mBAAmB,CAAC,QAAQ,CAAC;IACnC,KAAK,EAAE,eAAe,CAAC;CACxB,CAAC;AAEN,eAAO,MAAM,mBAAmB,6EAG9B,CAAC;AA2FH,aAAK,YAAY;IACf,UAAU,IAAI;IACd,MAAM,IAAI;CACX;AAED,KAAK,mBAAmB,GAAG;IACzB,OAAO,EAAE,YAAY,CAAC,UAAU,CAAC;IACjC,OAAO,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,eAAe,EAAE,CAAC;IAC7B,QAAQ,EAAE,OAAO,EAAE,CAAC;CACrB,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,OAAO,EAAE,YAAY,CAAC,MAAM,CAAC;IAE7B,OAAO,EAAE,SAAS,CAAC;CACpB,CAAC;AAOF,qBAAa,kBAAmB,YAAW,OAAO,CAAC,mBAAmB;IAElE,OAAO,CAAC,SAAS;IACjB,OAAO,CAAC,SAAS;IAFnB,OAAO;IAKP,MAAM,CAAC,mBAAmB,CACxB,SAAS,EAAE,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,EAC/C,SAAS,EAAE,SAAS,GACnB,kBAAkB;IAIrB,MAAM,CAAC,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,EAAE,SAAS,EAAE,SAAS,GAAG,kBAAkB;IAI7G,SAAS,IAAI,SAAS;IAItB,OAAO,IAAI,SAAS,GAAG,IAAI;IAS3B,eAAe,IAAI,SAAS,GAAG,IAAI;IAInC,iBAAiB,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAIvE,cAAc,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAIpE,WAAW,IAAI,SAAS,GAAG,IAAI;IAI/B,UAAU,IAAI,SAAS,GAAG,IAAI;IAI9B,kBAAkB,IAAI,SAAS,GAAG,IAAI;IAItC,aAAa,IAAI,SAAS,GAAG,IAAI;IAIjC,YAAY,IAAI,SAAS,GAAG,IAAI;IAIhC,WAAW,CAAC,SAAS,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAI7C,eAAe,CAAC,SAAS,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAIjD,uBAAuB,IAAI,SAAS,GAAG,IAAI;IAa3C,oBAAoB,CAAC,KAAK,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;CAuBnD"}
|
|
@@ -8,12 +8,12 @@ import { GAS_TO_INVOKE_WORK_REPORT } from "../accumulate/accumulate-state.js";
|
|
|
8
8
|
import { Operand } from "../accumulate/operand.js";
|
|
9
9
|
import { REPORT_TIMEOUT_GRACE_PERIOD } from "../assurances.js";
|
|
10
10
|
import { MAX_WORK_REPORT_SIZE_BYTES } from "../reports/verify-basic.js";
|
|
11
|
-
var TransferOperandKind;
|
|
11
|
+
export var TransferOperandKind;
|
|
12
12
|
(function (TransferOperandKind) {
|
|
13
13
|
TransferOperandKind[TransferOperandKind["OPERAND"] = 0] = "OPERAND";
|
|
14
14
|
TransferOperandKind[TransferOperandKind["TRANSFER"] = 1] = "TRANSFER";
|
|
15
15
|
})(TransferOperandKind || (TransferOperandKind = {}));
|
|
16
|
-
const TRANSFER_OR_OPERAND = codec.union("TransferOrOperand", {
|
|
16
|
+
export const TRANSFER_OR_OPERAND = codec.union("TransferOrOperand", {
|
|
17
17
|
[TransferOperandKind.OPERAND]: codec.object({ value: Operand.Codec }),
|
|
18
18
|
[TransferOperandKind.TRANSFER]: codec.object({ value: PendingTransfer.Codec }),
|
|
19
19
|
});
|
|
@@ -102,11 +102,7 @@ function getEncodedConstants(chainSpec) {
|
|
|
102
102
|
var FetchContext;
|
|
103
103
|
(function (FetchContext) {
|
|
104
104
|
FetchContext[FetchContext["Accumulate"] = 0] = "Accumulate";
|
|
105
|
-
|
|
106
|
-
FetchContext[FetchContext["LegacyAccumulate"] = 1] = "LegacyAccumulate";
|
|
107
|
-
/** @deprecated since 0.7.1 */
|
|
108
|
-
FetchContext[FetchContext["LegacyOnTransfer"] = 2] = "LegacyOnTransfer";
|
|
109
|
-
FetchContext[FetchContext["Refine"] = 3] = "Refine";
|
|
105
|
+
FetchContext[FetchContext["Refine"] = 1] = "Refine";
|
|
110
106
|
})(FetchContext || (FetchContext = {}));
|
|
111
107
|
export class FetchExternalities {
|
|
112
108
|
fetchData;
|
|
@@ -115,15 +111,9 @@ export class FetchExternalities {
|
|
|
115
111
|
this.fetchData = fetchData;
|
|
116
112
|
this.chainSpec = chainSpec;
|
|
117
113
|
}
|
|
118
|
-
static createForPre071Accumulate(fetchData, chainSpec) {
|
|
119
|
-
return new FetchExternalities({ context: FetchContext.LegacyAccumulate, ...fetchData }, chainSpec);
|
|
120
|
-
}
|
|
121
114
|
static createForAccumulate(fetchData, chainSpec) {
|
|
122
115
|
return new FetchExternalities({ context: FetchContext.Accumulate, ...fetchData }, chainSpec);
|
|
123
116
|
}
|
|
124
|
-
static createForOnTransfer(fetchData, chainSpec) {
|
|
125
|
-
return new FetchExternalities({ context: FetchContext.LegacyOnTransfer, ...fetchData }, chainSpec);
|
|
126
|
-
}
|
|
127
117
|
static createForRefine(fetchData, chainSpec) {
|
|
128
118
|
return new FetchExternalities({ context: FetchContext.Refine, ...fetchData }, chainSpec);
|
|
129
119
|
}
|
|
@@ -167,48 +157,6 @@ export class FetchExternalities {
|
|
|
167
157
|
workItemPayload(_workItem) {
|
|
168
158
|
return null;
|
|
169
159
|
}
|
|
170
|
-
allOperands() {
|
|
171
|
-
if (this.fetchData.context === FetchContext.LegacyAccumulate) {
|
|
172
|
-
const operands = this.fetchData.operands;
|
|
173
|
-
return Encoder.encodeObject(codec.sequenceVarLen(Operand.Codec), operands, this.chainSpec);
|
|
174
|
-
}
|
|
175
|
-
return null;
|
|
176
|
-
}
|
|
177
|
-
oneOperand(operandIndex) {
|
|
178
|
-
if (this.fetchData.context === FetchContext.LegacyAccumulate) {
|
|
179
|
-
const { operands } = this.fetchData;
|
|
180
|
-
if (operandIndex >= 2n ** 32n) {
|
|
181
|
-
return null;
|
|
182
|
-
}
|
|
183
|
-
const operand = operands[Number(operandIndex)];
|
|
184
|
-
if (operand === undefined) {
|
|
185
|
-
return null;
|
|
186
|
-
}
|
|
187
|
-
return Encoder.encodeObject(Operand.Codec, operand, this.chainSpec);
|
|
188
|
-
}
|
|
189
|
-
return null;
|
|
190
|
-
}
|
|
191
|
-
allTransfers() {
|
|
192
|
-
if (this.fetchData.context === FetchContext.LegacyOnTransfer) {
|
|
193
|
-
const { transfers } = this.fetchData;
|
|
194
|
-
return Encoder.encodeObject(codec.sequenceVarLen(PendingTransfer.Codec), transfers, this.chainSpec);
|
|
195
|
-
}
|
|
196
|
-
return null;
|
|
197
|
-
}
|
|
198
|
-
oneTransfer(transferIndex) {
|
|
199
|
-
if (this.fetchData.context === FetchContext.LegacyOnTransfer) {
|
|
200
|
-
const { transfers } = this.fetchData;
|
|
201
|
-
if (transferIndex >= 2n ** 32n) {
|
|
202
|
-
return null;
|
|
203
|
-
}
|
|
204
|
-
const transfer = transfers[Number(transferIndex)];
|
|
205
|
-
if (transfer === undefined) {
|
|
206
|
-
return null;
|
|
207
|
-
}
|
|
208
|
-
return Encoder.encodeObject(PendingTransfer.Codec, transfer, this.chainSpec);
|
|
209
|
-
}
|
|
210
|
-
return null;
|
|
211
|
-
}
|
|
212
160
|
allTransfersAndOperands() {
|
|
213
161
|
if (this.fetchData.context === FetchContext.Accumulate) {
|
|
214
162
|
const { transfers, operands } = this.fetchData;
|