@typeberry/jam 0.1.3-0eba10b → 0.1.3-2fdafd6

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/index.js CHANGED
@@ -46750,24 +46750,78 @@ class AccumulateExternalities {
46750
46750
  this.updatedState.stateUpdate.authorizationQueues.set(coreIndex, authQueue);
46751
46751
  return result_Result.ok(result_OK);
46752
46752
  }
46753
+ updatePrivilegedServiceId(
46754
+ // The id that privileged service wants to be updated to
46755
+ newId,
46756
+ // Current id of privileged service (updated state)
46757
+ currentId, {
46758
+ // is current service id a manager (can update anything)
46759
+ isManager,
46760
+ // is current service attempting to update itself (privileged are owned)
46761
+ isSelf,
46762
+ // is the service id already changed in this block
46763
+ isAlreadyChanged, }) {
46764
+ if (isManager) {
46765
+ return newId;
46766
+ }
46767
+ // current service can update itself, only if it was a privileged
46768
+ // service at the start of the block. I.e. owned privileges cannot
46769
+ // be transfered multiple times in a block.
46770
+ if (isSelf && !isAlreadyChanged) {
46771
+ return newId;
46772
+ }
46773
+ return currentId;
46774
+ }
46753
46775
  updatePrivilegedServices(manager, authorizers, delegator, registrar, autoAccumulate) {
46754
46776
  /** https://graypaper.fluffylabs.dev/#/7e6ff6a/36d90036de00?v=0.6.7 */
46755
- const currentManager = this.updatedState.getPrivilegedServices().manager;
46756
- if (currentManager !== this.currentServiceId) {
46757
- return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
46758
- }
46759
- if (manager === null || delegator === null) {
46760
- return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not valid service id.");
46777
+ const current = this.updatedState.getPrivilegedServices();
46778
+ const isManager = current.manager === this.currentServiceId;
46779
+ if (Compatibility.isLessThan(GpVersion.V0_7_1)) {
46780
+ if (!isManager) {
46781
+ return result_Result.error(UpdatePrivilegesError.UnprivilegedService);
46782
+ }
46783
+ if (manager === null || delegator === null) {
46784
+ return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator is not a valid service id.");
46785
+ }
46786
+ this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
46787
+ manager,
46788
+ assigners: authorizers,
46789
+ delegator: delegator,
46790
+ registrar: registrar ?? tryAsServiceId(0),
46791
+ autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
46792
+ });
46793
+ return result_Result.ok(result_OK);
46761
46794
  }
46762
- if (Compatibility.isGreaterOrEqual(GpVersion.V0_7_1) && registrar === null) {
46763
- return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Register manager is not valid service id.");
46795
+ const original = this.updatedState.state.privilegedServices;
46796
+ if (manager === null || delegator === null || registrar === null) {
46797
+ return result_Result.error(UpdatePrivilegesError.InvalidServiceId, "Either manager or delegator or registrar is not a valid service id.");
46764
46798
  }
46799
+ const newDelegator = this.updatePrivilegedServiceId(delegator, current.delegator, {
46800
+ isManager,
46801
+ isSelf: this.currentServiceId === current.delegator,
46802
+ isAlreadyChanged: current.delegator !== original.delegator,
46803
+ });
46804
+ const newRegistrar = this.updatePrivilegedServiceId(registrar, current.registrar, {
46805
+ isManager,
46806
+ isSelf: this.currentServiceId === current.registrar,
46807
+ isAlreadyChanged: current.registrar !== original.registrar,
46808
+ });
46809
+ const newAssigners = current.assigners.map((currentAssigner, index) => this.updatePrivilegedServiceId(authorizers[index], currentAssigner, {
46810
+ isManager,
46811
+ isSelf: this.currentServiceId === currentAssigner,
46812
+ isAlreadyChanged: currentAssigner !== original.assigners[index],
46813
+ }));
46814
+ const newManager = isManager ? manager : current.manager;
46815
+ const newAutoAccumulateServices = isManager
46816
+ ? autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit }))
46817
+ : current.autoAccumulateServices;
46818
+ // finally update the privileges
46765
46819
  this.updatedState.stateUpdate.privilegedServices = PrivilegedServices.create({
46766
- manager,
46767
- assigners: authorizers,
46768
- delegator,
46769
- registrar: registrar ?? tryAsServiceId(0), // introduced in 0.7.1
46770
- autoAccumulateServices: autoAccumulate.map(([service, gasLimit]) => AutoAccumulate.create({ service, gasLimit })),
46820
+ manager: newManager,
46821
+ assigners: tryAsPerCore(newAssigners, this.chainSpec),
46822
+ delegator: newDelegator,
46823
+ registrar: newRegistrar,
46824
+ autoAccumulateServices: newAutoAccumulateServices,
46771
46825
  });
46772
46826
  return result_Result.ok(result_OK);
46773
46827
  }
@@ -48126,6 +48180,7 @@ class Bless {
48126
48180
  return;
48127
48181
  }
48128
48182
  const e = updateResult.error;
48183
+ // NOTE: `UpdatePrivilegesError.UnprivilegedService` won't happen in 0.7.1+
48129
48184
  if (e === UpdatePrivilegesError.UnprivilegedService) {
48130
48185
  logger_logger.trace `BLESS(${manager}, ${authorizers}, ${delegator}, ${registrar}, ${autoAccumulateEntries}) <- HUH`;
48131
48186
  regs.set(bless_IN_OUT_REG, HostCallResult.HUH);