@typeberry/convert 0.1.3-6edad4a → 0.1.3-af70ed0

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.
Files changed (3) hide show
  1. package/index.js +38 -19
  2. package/index.js.map +1 -1
  3. package/package.json +1 -1
package/index.js CHANGED
@@ -12190,6 +12190,10 @@ class disputes_DisputesRecords {
12190
12190
  static create({ goodSet, badSet, wonkySet, punishSet }) {
12191
12191
  return new disputes_DisputesRecords(goodSet, badSet, wonkySet, punishSet);
12192
12192
  }
12193
+ goodSetDict;
12194
+ badSetDict;
12195
+ wonkySetDict;
12196
+ punishSetDict;
12193
12197
  constructor(
12194
12198
  /** `goodSet`: all work-reports hashes which were judged to be correct */
12195
12199
  goodSet,
@@ -12203,6 +12207,18 @@ class disputes_DisputesRecords {
12203
12207
  this.badSet = badSet;
12204
12208
  this.wonkySet = wonkySet;
12205
12209
  this.punishSet = punishSet;
12210
+ this.goodSetDict = hash_set_HashSet.from(goodSet.array);
12211
+ this.badSetDict = hash_set_HashSet.from(badSet.array);
12212
+ this.wonkySetDict = hash_set_HashSet.from(wonkySet.array);
12213
+ this.punishSetDict = hash_set_HashSet.from(punishSet.array);
12214
+ }
12215
+ asDictionaries() {
12216
+ return {
12217
+ goodSet: this.goodSetDict,
12218
+ badSet: this.badSetDict,
12219
+ wonkySet: this.wonkySetDict,
12220
+ punishSet: this.punishSetDict,
12221
+ };
12206
12222
  }
12207
12223
  static fromSortedArrays({ goodSet, badSet, wonkySet, punishSet, }) {
12208
12224
  return new disputes_DisputesRecords(sorted_set_SortedSet.fromSortedArray(disputes_hashComparator, goodSet), sorted_set_SortedSet.fromSortedArray(disputes_hashComparator, badSet), sorted_set_SortedSet.fromSortedArray(disputes_hashComparator, wonkySet), sorted_set_SortedSet.fromSortedArray(disputes_hashComparator, punishSet));
@@ -20434,7 +20450,7 @@ class disputes_Disputes {
20434
20450
  const { key, workReportHash } = disputes.culprits[i];
20435
20451
  // check if some offenders weren't reported earlier
20436
20452
  // https://graypaper.fluffylabs.dev/#/579bd12/125501125501
20437
- const isInPunishSet = this.state.disputesRecords.punishSet.findExact(key) !== undefined;
20453
+ const isInPunishSet = this.state.disputesRecords.asDictionaries().punishSet.has(key);
20438
20454
  if (isInPunishSet) {
20439
20455
  return Result.error(DisputesErrorCode.OffenderAlreadyReported);
20440
20456
  }
@@ -20445,8 +20461,8 @@ class disputes_Disputes {
20445
20461
  }
20446
20462
  // verify if the culprit will be in new bad set
20447
20463
  // https://graypaper.fluffylabs.dev/#/579bd12/124601124601
20448
- const isInNewBadSet = newItems.toAddToBadSet.findExact(workReportHash);
20449
- if (isInNewBadSet === undefined) {
20464
+ const isInNewBadSet = newItems.asDictionaries().badSet.has(workReportHash);
20465
+ if (!isInNewBadSet) {
20450
20466
  return Result.error(DisputesErrorCode.CulpritsVerdictNotBad);
20451
20467
  }
20452
20468
  // verify culprit signature
@@ -20469,7 +20485,7 @@ class disputes_Disputes {
20469
20485
  const { key, workReportHash, wasConsideredValid } = disputes.faults[i];
20470
20486
  // check if some offenders weren't reported earlier
20471
20487
  // https://graypaper.fluffylabs.dev/#/579bd12/12a20112a201
20472
- const isInPunishSet = this.state.disputesRecords.punishSet.findExact(key) !== undefined;
20488
+ const isInPunishSet = this.state.disputesRecords.asDictionaries().punishSet.has(key);
20473
20489
  if (isInPunishSet) {
20474
20490
  return Result.error(DisputesErrorCode.OffenderAlreadyReported);
20475
20491
  }
@@ -20484,9 +20500,10 @@ class disputes_Disputes {
20484
20500
  // but it does not pass the tests
20485
20501
  // https://graypaper.fluffylabs.dev/#/579bd12/128a01129601
20486
20502
  if (wasConsideredValid) {
20487
- const isInNewGoodSet = newItems.toAddToGoodSet.findExact(workReportHash);
20488
- const isInNewBadSet = newItems.toAddToBadSet.findExact(workReportHash);
20489
- if (isInNewGoodSet !== undefined || isInNewBadSet === undefined) {
20503
+ const { goodSet, badSet } = newItems.asDictionaries();
20504
+ const isInNewGoodSet = goodSet.has(workReportHash);
20505
+ const isInNewBadSet = badSet.has(workReportHash);
20506
+ if (isInNewGoodSet || !isInNewBadSet) {
20490
20507
  return Result.error(DisputesErrorCode.FaultVerdictWrong);
20491
20508
  }
20492
20509
  }
@@ -20539,10 +20556,11 @@ class disputes_Disputes {
20539
20556
  for (const verdict of disputes.verdicts) {
20540
20557
  // current verdicts should not be reported earlier
20541
20558
  // https://graypaper.fluffylabs.dev/#/579bd12/122202122202
20542
- const isInGoodSet = this.state.disputesRecords.goodSet.findExact(verdict.workReportHash);
20543
- const isInBadSet = this.state.disputesRecords.badSet.findExact(verdict.workReportHash);
20544
- const isInWonkySet = this.state.disputesRecords.wonkySet.findExact(verdict.workReportHash);
20545
- if (isInGoodSet !== undefined || isInBadSet !== undefined || isInWonkySet !== undefined) {
20559
+ const { goodSet, badSet, wonkySet } = this.state.disputesRecords.asDictionaries();
20560
+ const isInGoodSet = goodSet.has(verdict.workReportHash);
20561
+ const isInBadSet = badSet.has(verdict.workReportHash);
20562
+ const isInWonkySet = wonkySet.has(verdict.workReportHash);
20563
+ if (isInGoodSet || isInBadSet || isInWonkySet) {
20546
20564
  return Result.error(DisputesErrorCode.AlreadyJudged);
20547
20565
  }
20548
20566
  }
@@ -20612,11 +20630,12 @@ class disputes_Disputes {
20612
20630
  toAddToWonkySet.push(r);
20613
20631
  }
20614
20632
  }
20615
- return {
20616
- toAddToGoodSet: SortedSet.fromArrayUnique(hashComparator, toAddToGoodSet),
20617
- toAddToBadSet: SortedSet.fromArrayUnique(hashComparator, toAddToBadSet),
20618
- toAddToWonkySet: SortedSet.fromArrayUnique(hashComparator, toAddToWonkySet),
20619
- };
20633
+ return DisputesRecords.create({
20634
+ goodSet: SortedSet.fromArrayUnique(hashComparator, toAddToGoodSet),
20635
+ badSet: SortedSet.fromArrayUnique(hashComparator, toAddToBadSet),
20636
+ wonkySet: SortedSet.fromArrayUnique(hashComparator, toAddToWonkySet),
20637
+ punishSet: SortedSet.fromArray(hashComparator, []),
20638
+ });
20620
20639
  }
20621
20640
  getClearedCoreAssignment(v) {
20622
20641
  /**
@@ -20651,9 +20670,9 @@ class disputes_Disputes {
20651
20670
  const toAddToPunishSet = SortedArray.fromArray(hashComparator, Array.from(offenders));
20652
20671
  return DisputesRecords.create({
20653
20672
  // https://graypaper.fluffylabs.dev/#/579bd12/12690312bc03
20654
- goodSet: SortedSet.fromTwoSortedCollections(this.state.disputesRecords.goodSet, newItems.toAddToGoodSet),
20655
- badSet: SortedSet.fromTwoSortedCollections(this.state.disputesRecords.badSet, newItems.toAddToBadSet),
20656
- wonkySet: SortedSet.fromTwoSortedCollections(this.state.disputesRecords.wonkySet, newItems.toAddToWonkySet),
20673
+ goodSet: SortedSet.fromTwoSortedCollections(this.state.disputesRecords.goodSet, newItems.goodSet),
20674
+ badSet: SortedSet.fromTwoSortedCollections(this.state.disputesRecords.badSet, newItems.badSet),
20675
+ wonkySet: SortedSet.fromTwoSortedCollections(this.state.disputesRecords.wonkySet, newItems.wonkySet),
20657
20676
  punishSet: SortedSet.fromTwoSortedCollections(this.state.disputesRecords.punishSet, toAddToPunishSet),
20658
20677
  });
20659
20678
  }