@typeberry/jam 0.0.5-1ef0e31 → 0.0.5-6e657f4

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/importer/index.js CHANGED
@@ -9984,6 +9984,7 @@ function legacyServiceNested(serviceId, hash) {
9984
9984
  ;// CONCATENATED MODULE: ./packages/jam/state/accumulation-output.ts
9985
9985
 
9986
9986
 
9987
+
9987
9988
  /**
9988
9989
  * Single service-indexed commitment to accumulation output
9989
9990
  *
@@ -10004,6 +10005,16 @@ class AccumulationOutput {
10004
10005
  this.output = output;
10005
10006
  }
10006
10007
  }
10008
+ function accumulationOutputComparator(a, b) {
10009
+ const result = a.serviceId - b.serviceId;
10010
+ if (result < 0) {
10011
+ return Ordering.Less;
10012
+ }
10013
+ if (result > 0) {
10014
+ return Ordering.Greater;
10015
+ }
10016
+ return Ordering.Equal;
10017
+ }
10007
10018
 
10008
10019
  ;// CONCATENATED MODULE: ./packages/jam/state/assurances.ts
10009
10020
 
@@ -11109,6 +11120,7 @@ class StatisticsData {
11109
11120
 
11110
11121
 
11111
11122
 
11123
+
11112
11124
 
11113
11125
  var in_memory_state_UpdateError;
11114
11126
  (function (UpdateError) {
@@ -11512,7 +11524,7 @@ class InMemoryState extends WithDebug {
11512
11524
  validatorsManager: tryAsServiceId(0),
11513
11525
  autoAccumulateServices: [],
11514
11526
  }),
11515
- accumulationOutputLog: [],
11527
+ accumulationOutputLog: SortedArray.fromArray(accumulationOutputComparator, []),
11516
11528
  services: new Map(),
11517
11529
  });
11518
11530
  }
@@ -11711,7 +11723,7 @@ var serialize;
11711
11723
  /** C(16): https://graypaper.fluffylabs.dev/#/38c4e62/3b46033b4603?v=0.7.0 */
11712
11724
  serialize.accumulationOutputLog = {
11713
11725
  key: stateKeys.index(StateKeyIdx.Theta),
11714
- Codec: descriptors_codec.sequenceVarLen(AccumulationOutput.Codec),
11726
+ Codec: descriptors_codec.sequenceVarLen(AccumulationOutput.Codec).convert((i) => i.array, (o) => SortedArray.fromSortedArray(accumulationOutputComparator, o)),
11715
11727
  extract: (s) => s.accumulationOutputLog,
11716
11728
  };
11717
11729
  /** C(255, s): https://graypaper.fluffylabs.dev/#/85129da/383103383103?v=0.6.3 */
@@ -20258,6 +20270,32 @@ class SafroleSeal {
20258
20270
 
20259
20271
 
20260
20272
 
20273
+ ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/accumulate-output.ts
20274
+
20275
+
20276
+
20277
+
20278
+
20279
+ class AccumulateOutput {
20280
+ async transition({ accumulationOutputLog }) {
20281
+ const rootHash = await getRootHash(accumulationOutputLog);
20282
+ return rootHash;
20283
+ }
20284
+ }
20285
+ /**
20286
+ * Returns a new root hash
20287
+ *
20288
+ * https://graypaper.fluffylabs.dev/#/38c4e62/3c9d013c9d01?v=0.7.0
20289
+ */
20290
+ async function getRootHash(yieldedRoots) {
20291
+ const keccakHasher = await KeccakHasher.create();
20292
+ const trieHasher = getKeccakTrieHasher(keccakHasher);
20293
+ const values = yieldedRoots.array.map(({ serviceId, output }) => {
20294
+ return bytes_BytesBlob.blobFromParts([numbers_u32AsLeBytes(serviceId), output.raw]);
20295
+ });
20296
+ return binaryMerkleization(values, trieHasher);
20297
+ }
20298
+
20261
20299
  ;// CONCATENATED MODULE: ./packages/jam/jam-host-calls/externalities/state-update.ts
20262
20300
 
20263
20301
 
@@ -23352,9 +23390,6 @@ class pvm_executor_PvmExecutor {
23352
23390
 
23353
23391
 
23354
23392
 
23355
-
23356
-
23357
-
23358
23393
 
23359
23394
 
23360
23395
 
@@ -23608,10 +23643,10 @@ class Accumulate {
23608
23643
  const { services, yieldedRoots, transfers, validatorsData, privilegedServices, authorizationQueues, ...stateUpdateRest } = state;
23609
23644
  assertEmpty(stateUpdateRest);
23610
23645
  const accStateUpdate = this.getAccumulationStateUpdate(accumulated, toAccumulateLater, slot, Array.from(statistics.keys()), services);
23611
- const accumulationOutput = Array.from(yieldedRoots.entries()).map(([serviceId, root]) => {
23646
+ const accumulationOutputUnsorted = Array.from(yieldedRoots.entries()).map(([serviceId, root]) => {
23612
23647
  return { serviceId, output: root.asOpaque() };
23613
23648
  });
23614
- const rootHash = await getRootHash(accumulationOutput);
23649
+ const accumulationOutput = SortedArray.fromArray(accumulationOutputComparator, accumulationOutputUnsorted);
23615
23650
  const authQueues = (() => {
23616
23651
  if (authorizationQueues.size === 0) {
23617
23652
  return {};
@@ -23623,7 +23658,6 @@ class Accumulate {
23623
23658
  return { authQueues: tryAsPerCore(updatedAuthQueues, this.chainSpec) };
23624
23659
  })();
23625
23660
  return result_Result.ok({
23626
- root: rootHash,
23627
23661
  stateUpdate: {
23628
23662
  ...accStateUpdate,
23629
23663
  ...(validatorsData === null ? {} : { designatedValidatorData: validatorsData }),
@@ -23636,20 +23670,6 @@ class Accumulate {
23636
23670
  });
23637
23671
  }
23638
23672
  }
23639
- /**
23640
- * Returns a new root hash
23641
- *
23642
- * https://graypaper.fluffylabs.dev/#/38c4e62/3c9d013c9d01?v=0.7.0
23643
- */
23644
- async function getRootHash(yieldedRoots) {
23645
- const keccakHasher = await KeccakHasher.create();
23646
- const trieHasher = getKeccakTrieHasher(keccakHasher);
23647
- const yieldedRootsSortedByServiceId = yieldedRoots.sort((a, b) => a.serviceId - b.serviceId);
23648
- const values = yieldedRootsSortedByServiceId.map(({ serviceId, output }) => {
23649
- return bytes_BytesBlob.blobFromParts([numbers_u32AsLeBytes(serviceId), output.raw]);
23650
- });
23651
- return binaryMerkleization(values, trieHasher);
23652
- }
23653
23673
 
23654
23674
  ;// CONCATENATED MODULE: ./packages/jam/transition/accumulate/deferred-transfers.ts
23655
23675
 
@@ -25045,6 +25065,7 @@ class Statistics {
25045
25065
 
25046
25066
 
25047
25067
 
25068
+
25048
25069
  class DbHeaderChain {
25049
25070
  blocks;
25050
25071
  constructor(blocks) {
@@ -25088,6 +25109,7 @@ class OnChain {
25088
25109
  assurances;
25089
25110
  // chapter 12: https://graypaper.fluffylabs.dev/#/68eaa1f/159f02159f02?v=0.6.4
25090
25111
  accumulate;
25112
+ accumulateOutput;
25091
25113
  // chapter 12.3: https://graypaper.fluffylabs.dev/#/68eaa1f/178203178203?v=0.6.4
25092
25114
  deferredTransfers;
25093
25115
  // chapter 12.4: https://graypaper.fluffylabs.dev/#/68eaa1f/18cc0018cc00?v=0.6.4
@@ -25112,6 +25134,7 @@ class OnChain {
25112
25134
  this.reports = new Reports(chainSpec, state, new DbHeaderChain(blocks));
25113
25135
  this.assurances = new Assurances(chainSpec, state);
25114
25136
  this.accumulate = new Accumulate(chainSpec, state);
25137
+ this.accumulateOutput = new AccumulateOutput();
25115
25138
  this.deferredTransfers = new DeferredTransfers(chainSpec, state);
25116
25139
  this.preimages = new Preimages(state);
25117
25140
  this.authorization = new Authorization(chainSpec, state);
@@ -25220,7 +25243,7 @@ class OnChain {
25220
25243
  if (accumulateResult.isError) {
25221
25244
  return stfError(StfErrorKind.Accumulate, accumulateResult);
25222
25245
  }
25223
- const { root: accumulateRoot, stateUpdate: accumulateUpdate, accumulationStatistics, pendingTransfers, accumulationOutputLog, ...accumulateRest } = accumulateResult.ok;
25246
+ const { stateUpdate: accumulateUpdate, accumulationStatistics, pendingTransfers, accumulationOutputLog, ...accumulateRest } = accumulateResult.ok;
25224
25247
  assertEmpty(accumulateRest);
25225
25248
  const { privilegedServices: maybePrivilegedServices, authQueues: maybeAuthorizationQueues, designatedValidatorData: maybeDesignatedValidatorData, preimages: accumulatePreimages, accumulationQueue, recentlyAccumulated, ...servicesUpdate } = accumulateUpdate;
25226
25249
  const deferredTransfersResult = await this.deferredTransfers.transition({
@@ -25234,8 +25257,9 @@ class OnChain {
25234
25257
  }
25235
25258
  const { servicesUpdate: newServicesUpdate, transferStatistics, ...deferredTransfersRest } = deferredTransfersResult.ok;
25236
25259
  assertEmpty(deferredTransfersRest);
25260
+ const accumulateRoot = await this.accumulateOutput.transition({ accumulationOutputLog });
25237
25261
  // recent history
25238
- const recentHistoryUpdate = this.recentHistory.transition({
25262
+ const recentHistoryUpdate = await this.recentHistory.transition({
25239
25263
  partial: recentHistoryPartialUpdate,
25240
25264
  headerHash,
25241
25265
  accumulateRoot,