@typeberry/jam 0.5.0-70ae055 → 0.5.0-7f94e30

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.
@@ -23884,12 +23884,15 @@ class Accumulate {
23884
23884
  chainSpec;
23885
23885
  blake2b;
23886
23886
  state;
23887
- pvm;
23888
- constructor(chainSpec, blake2b, state, pvm) {
23887
+ options;
23888
+ constructor(chainSpec, blake2b, state, options) {
23889
23889
  this.chainSpec = chainSpec;
23890
23890
  this.blake2b = blake2b;
23891
23891
  this.state = state;
23892
- this.pvm = pvm;
23892
+ this.options = options;
23893
+ if (options.accumulateSequentially === true) {
23894
+ accumulate_logger.warn `⚠️ Parallel accumulation is disabled. Running in sequential mode.`;
23895
+ }
23893
23896
  }
23894
23897
  /**
23895
23898
  * Returns an index that determines how many WorkReports can be processed before exceeding a given gasLimit.
@@ -23941,7 +23944,7 @@ class Accumulate {
23941
23944
  serviceExternalities: partialState,
23942
23945
  fetchExternalities,
23943
23946
  };
23944
- const executor = await PvmExecutor.createAccumulateExecutor(serviceId, code, externalities, this.chainSpec, this.pvm);
23947
+ const executor = await PvmExecutor.createAccumulateExecutor(serviceId, code, externalities, this.chainSpec, this.options.pvm);
23945
23948
  const invocationArgs = encoder_Encoder.encodeObject(ARGS_CODEC, {
23946
23949
  slot,
23947
23950
  serviceId,
@@ -24158,6 +24161,9 @@ class Accumulate {
24158
24161
  ];
24159
24162
  return resultEntry;
24160
24163
  });
24164
+ if (this.options.accumulateSequentially === true) {
24165
+ await promise;
24166
+ }
24161
24167
  resultPromises[serviceIndex] = promise;
24162
24168
  }
24163
24169
  return Promise.all(resultPromises).then((results) => new Map(results));
@@ -24389,6 +24395,7 @@ class DeferredTransfers {
24389
24395
 
24390
24396
 
24391
24397
 
24398
+
24392
24399
  ;// CONCATENATED MODULE: ./packages/jam/transition/authorization.ts
24393
24400
 
24394
24401
 
@@ -28418,22 +28425,23 @@ class Statistics {
28418
28425
  const newPreImagesSize = current[authorIndex].preImagesSize + preImagesSize;
28419
28426
  current[authorIndex].preImagesSize = numbers_tryAsU32(newPreImagesSize);
28420
28427
  /**
28421
- * * NOTE [MaSi] Please note I don't use Kappa' here. If I understand correctly we don't need it.
28422
- * Kappa' is not needed because we can use validator indexes directly from guarantees extrinsic.
28423
- * I asked a question to ensure it is true but I didn't get any response yet:
28424
- * https://github.com/w3f/jamtestvectors/pull/28#discussion_r190723700
28428
+ * Update guarantees
28425
28429
  *
28426
- * https://graypaper.fluffylabs.dev/#/1c979cb/19a00119a801?v=0.7.1
28430
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/19ea0119f201?v=0.7.2
28427
28431
  */
28428
- const incrementedGuarantors = new Set();
28429
- for (const guarantee of extrinsic.guarantees) {
28430
- for (const { validatorIndex } of guarantee.credentials) {
28431
- if (!incrementedGuarantors.has(validatorIndex)) {
28432
- const newGuaranteesCount = current[validatorIndex].guarantees + 1;
28433
- current[validatorIndex].guarantees = numbers_tryAsU32(newGuaranteesCount);
28434
- incrementedGuarantors.add(validatorIndex);
28435
- }
28432
+ const validatorKeys = input.currentValidatorData.map((v) => v.ed25519);
28433
+ for (const reporter of input.reporters) {
28434
+ const index = validatorKeys.findIndex((x) => x.isEqualTo(reporter));
28435
+ if (index === -1) {
28436
+ /**
28437
+ * it should never happen because:
28438
+ * 1. the extrinsic is verified in reports transition
28439
+ * 2. we use current validators set from safrole
28440
+ */
28441
+ continue;
28436
28442
  }
28443
+ const newGuaranteesCount = current[index].guarantees + 1;
28444
+ current[index].guarantees = numbers_tryAsU32(newGuaranteesCount);
28437
28445
  }
28438
28446
  for (const { validatorIndex } of extrinsic.assurances) {
28439
28447
  const newAssurancesCount = current[validatorIndex].assurances + 1;
@@ -28605,7 +28613,7 @@ class OnChain {
28605
28613
  // chapter 13: https://graypaper.fluffylabs.dev/#/68eaa1f/18b60118b601?v=0.6.4
28606
28614
  statistics;
28607
28615
  isReadyForNextEpoch = Promise.resolve(false);
28608
- constructor(chainSpec, state, hasher, pvm, headerChain) {
28616
+ constructor(chainSpec, state, hasher, options, headerChain) {
28609
28617
  this.chainSpec = chainSpec;
28610
28618
  this.state = state;
28611
28619
  this.hasher = hasher;
@@ -28617,9 +28625,9 @@ class OnChain {
28617
28625
  this.disputes = new Disputes(chainSpec, hasher.blake2b, state);
28618
28626
  this.reports = new Reports(chainSpec, hasher.blake2b, state, headerChain);
28619
28627
  this.assurances = new Assurances(chainSpec, state, hasher.blake2b);
28620
- this.accumulate = new Accumulate(chainSpec, hasher.blake2b, state, pvm);
28628
+ this.accumulate = new Accumulate(chainSpec, hasher.blake2b, state, options);
28621
28629
  this.accumulateOutput = new AccumulateOutput();
28622
- this.deferredTransfers = new DeferredTransfers(chainSpec, hasher.blake2b, state, pvm);
28630
+ this.deferredTransfers = new DeferredTransfers(chainSpec, hasher.blake2b, state, options.pvm);
28623
28631
  this.preimages = new Preimages(state, hasher.blake2b);
28624
28632
  this.authorization = new Authorization(chainSpec, state);
28625
28633
  }
@@ -28707,8 +28715,7 @@ class OnChain {
28707
28715
  if (reportsResult.isError) {
28708
28716
  return stfError(StfErrorKind.Reports, reportsResult);
28709
28717
  }
28710
- // NOTE `reporters` are unused
28711
- const { reported: workPackages, reporters: _, stateUpdate: reportsUpdate, ...reportsRest } = reportsResult.ok;
28718
+ const { reported: workPackages, reporters, stateUpdate: reportsUpdate, ...reportsRest } = reportsResult.ok;
28712
28719
  assertEmpty(reportsRest);
28713
28720
  const { availabilityAssignment: reportsAvailAssignment, ...reportsUpdateRest } = reportsUpdate;
28714
28721
  assertEmpty(reportsUpdateRest);
@@ -28722,7 +28729,7 @@ class OnChain {
28722
28729
  }
28723
28730
  const { preimages, ...preimagesRest } = preimagesResult.ok;
28724
28731
  assertEmpty(preimagesRest);
28725
- const timerAccumulate = measure(`import:accumulate (${PvmBackend[this.accumulate.pvm]})`);
28732
+ const timerAccumulate = measure(`import:accumulate (${PvmBackend[this.accumulate.options.pvm]})`);
28726
28733
  // accumulate
28727
28734
  const accumulateResult = await this.accumulate.transition({
28728
28735
  slot: timeSlot,
@@ -28782,6 +28789,8 @@ class OnChain {
28782
28789
  availableReports,
28783
28790
  accumulationStatistics,
28784
28791
  transferStatistics,
28792
+ reporters: reporters,
28793
+ currentValidatorData,
28785
28794
  });
28786
28795
  const { statistics, ...statisticsRest } = statisticsUpdate;
28787
28796
  assertEmpty(statisticsRest);
@@ -29033,7 +29042,7 @@ class Importer {
29033
29042
  throw new Error(`Unable to load best state from header hash: ${currentBestHeaderHash}.`);
29034
29043
  }
29035
29044
  this.verifier = new BlockVerifier(hasher, blocks);
29036
- this.stf = new OnChain(spec, state, hasher, pvm, DbHeaderChain.new(blocks));
29045
+ this.stf = new OnChain(spec, state, hasher, { pvm, accumulateSequentially: false }, DbHeaderChain.new(blocks));
29037
29046
  this.state = state;
29038
29047
  this.currentHash = currentBestHeaderHash;
29039
29048
  this.prepareForNextEpoch();
@@ -29186,11 +29195,11 @@ const blake2b = Blake2b.createHasher();
29186
29195
  async function createImporter(config) {
29187
29196
  const chainSpec = config.chainSpec;
29188
29197
  const db = config.openDatabase({ readonly: false });
29189
- const interpreter = config.workerParams.pvm;
29198
+ const pvm = config.workerParams.pvm;
29190
29199
  const blocks = db.getBlocksDb();
29191
29200
  const states = db.getStatesDb();
29192
29201
  const hasher = new TransitionHasher(await keccakHasher, await blake2b);
29193
- const importer = new Importer(chainSpec, interpreter, hasher, main_logger, blocks, states);
29202
+ const importer = new Importer(chainSpec, pvm, hasher, main_logger, blocks, states);
29194
29203
  return {
29195
29204
  importer,
29196
29205
  db,