@typeberry/lib 0.1.2-753d258 → 0.1.2-7ebe1f6

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.cjs CHANGED
@@ -10,6 +10,7 @@ var GpVersion;
10
10
  GpVersion["V0_6_7"] = "0.6.7";
11
11
  GpVersion["V0_7_0"] = "0.7.0";
12
12
  GpVersion["V0_7_1"] = "0.7.1-preview";
13
+ GpVersion["V0_7_2"] = "0.7.2-preview";
13
14
  })(GpVersion || (GpVersion = {}));
14
15
  var TestSuite;
15
16
  (function (TestSuite) {
@@ -17,7 +18,7 @@ var TestSuite;
17
18
  TestSuite["JAMDUNA"] = "jamduna";
18
19
  })(TestSuite || (TestSuite = {}));
19
20
  const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
20
- const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1];
21
+ const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
21
22
  const env$1 = typeof process === "undefined" ? {} : process.env;
22
23
  const DEFAULT_VERSION = GpVersion.V0_7_0;
23
24
  let CURRENT_VERSION = parseCurrentVersion(env$1.GP_VERSION) ?? DEFAULT_VERSION;
@@ -26,20 +27,26 @@ function parseCurrentVersion(env) {
26
27
  if (env === undefined) {
27
28
  return undefined;
28
29
  }
29
- const version = env;
30
- if (!Object.values(GpVersion).includes(version)) {
31
- throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
30
+ switch (env) {
31
+ case GpVersion.V0_6_7:
32
+ case GpVersion.V0_7_0:
33
+ case GpVersion.V0_7_1:
34
+ case GpVersion.V0_7_2:
35
+ return env;
36
+ default:
37
+ throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
32
38
  }
33
- return version;
34
39
  }
35
40
  function parseCurrentSuite(env) {
36
41
  if (env === undefined)
37
42
  return undefined;
38
- const val = env;
39
- if (!Object.values(TestSuite).includes(val)) {
40
- throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
43
+ switch (env) {
44
+ case TestSuite.W3F_DAVXY:
45
+ case TestSuite.JAMDUNA:
46
+ return env;
47
+ default:
48
+ throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
41
49
  }
42
- return val;
43
50
  }
44
51
  class Compatibility {
45
52
  static override(version) {
@@ -5950,6 +5957,40 @@ var assurances = /*#__PURE__*/Object.freeze({
5950
5957
  assurancesExtrinsicCodec: assurancesExtrinsicCodec
5951
5958
  });
5952
5959
 
5960
+ /** Attempt to convert a number into `TimeSlot`. */
5961
+ const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
5962
+ /** Attempt to convert a number into `ValidatorIndex`. */
5963
+ const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
5964
+ /** Attempt to convert a number into `ServiceId`. */
5965
+ const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
5966
+ const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
5967
+ /** Attempt to convert a number into `CoreIndex`. */
5968
+ const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
5969
+ /** Attempt to convert a number into `Epoch`. */
5970
+ const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
5971
+ function tryAsPerValidator(array, spec) {
5972
+ check `
5973
+ ${array.length === spec.validatorsCount}
5974
+ Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
5975
+ `;
5976
+ return asKnownSize(array);
5977
+ }
5978
+ const codecPerValidator = (val) => codecWithContext((context) => {
5979
+ return codecKnownSizeArray(val, {
5980
+ fixedLength: context.validatorsCount,
5981
+ });
5982
+ });
5983
+ function tryAsPerEpochBlock(array, spec) {
5984
+ check `
5985
+ ${array.length === spec.epochLength}
5986
+ Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
5987
+ `;
5988
+ return asKnownSize(array);
5989
+ }
5990
+ const codecPerEpochBlock = (val) => codecWithContext((context) => {
5991
+ return codecKnownSizeArray(val, { fixedLength: context.epochLength });
5992
+ });
5993
+
5953
5994
  /**
5954
5995
  * Proof of signing a contradictory [`Judgement`] of a work report.
5955
5996
  */
@@ -6141,40 +6182,6 @@ var disputes = /*#__PURE__*/Object.freeze({
6141
6182
  Verdict: Verdict
6142
6183
  });
6143
6184
 
6144
- /** Attempt to convert a number into `TimeSlot`. */
6145
- const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
6146
- /** Attempt to convert a number into `ValidatorIndex`. */
6147
- const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
6148
- /** Attempt to convert a number into `ServiceId`. */
6149
- const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
6150
- const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
6151
- /** Attempt to convert a number into `CoreIndex`. */
6152
- const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
6153
- /** Attempt to convert a number into `Epoch`. */
6154
- const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
6155
- function tryAsPerValidator(array, spec) {
6156
- check `
6157
- ${array.length === spec.validatorsCount}
6158
- Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
6159
- `;
6160
- return asKnownSize(array);
6161
- }
6162
- const codecPerValidator = (val) => codecWithContext((context) => {
6163
- return codecKnownSizeArray(val, {
6164
- fixedLength: context.validatorsCount,
6165
- });
6166
- });
6167
- function tryAsPerEpochBlock(array, spec) {
6168
- check `
6169
- ${array.length === spec.epochLength}
6170
- Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
6171
- `;
6172
- return asKnownSize(array);
6173
- }
6174
- const codecPerEpochBlock = (val) => codecWithContext((context) => {
6175
- return codecKnownSizeArray(val, { fixedLength: context.epochLength });
6176
- });
6177
-
6178
6185
  /**
6179
6186
  * Mapping between work package hash and root hash of it's exports.
6180
6187
  *
@@ -7253,6 +7260,24 @@ class Block extends WithDebug {
7253
7260
  this.extrinsic = extrinsic;
7254
7261
  }
7255
7262
  }
7263
+ function emptyBlock(slot = tryAsTimeSlot(0)) {
7264
+ const header = Header.empty();
7265
+ header.timeSlotIndex = slot;
7266
+ return Block.create({
7267
+ header,
7268
+ extrinsic: Extrinsic.create({
7269
+ tickets: asKnownSize([]),
7270
+ preimages: [],
7271
+ assurances: asKnownSize([]),
7272
+ guarantees: asKnownSize([]),
7273
+ disputes: {
7274
+ verdicts: [],
7275
+ culprits: [],
7276
+ faults: [],
7277
+ },
7278
+ }),
7279
+ });
7280
+ }
7256
7281
 
7257
7282
  var index$j = /*#__PURE__*/Object.freeze({
7258
7283
  __proto__: null,
@@ -7269,6 +7294,7 @@ var index$j = /*#__PURE__*/Object.freeze({
7269
7294
  codecPerValidator: codecPerValidator,
7270
7295
  codecUtils: codec,
7271
7296
  disputes: disputes,
7297
+ emptyBlock: emptyBlock,
7272
7298
  encodeUnsealedHeader: encodeUnsealedHeader,
7273
7299
  guarantees: guarantees,
7274
7300
  headerViewWithHashCodec: headerViewWithHashCodec,
@@ -8045,8 +8071,8 @@ function print(level, levelAndName, strings, data) {
8045
8071
  return;
8046
8072
  }
8047
8073
  const lvlText = Level[level].padEnd(5);
8048
- const val = strings.map((v, idx) => `${v}${data[idx]}`);
8049
- const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
8074
+ const val = strings.map((v, idx) => `${v}${idx < data.length ? data[idx] : ""}`);
8075
+ const msg = `${lvlText} [${levelAndName[1]}] ${val.join("")}`;
8050
8076
  if (level === Level.WARN) {
8051
8077
  console.warn(msg);
8052
8078
  }
@@ -14118,6 +14144,17 @@ class PageRange {
14118
14144
  }
14119
14145
  return new PageRange(start, length);
14120
14146
  }
14147
+ /** Returns true if the page range is wrapped (`start` >= `end`) and is not empty */
14148
+ isWrapped() {
14149
+ return this.start >= this.end && !this.isEmpty();
14150
+ }
14151
+ /** Checks if given page number is within the range */
14152
+ isInRange(page) {
14153
+ if (this.isWrapped()) {
14154
+ return page >= this.start || page < this.end;
14155
+ }
14156
+ return page >= this.start && page < this.end;
14157
+ }
14121
14158
  /** Checks if a range is empty (`length === 0`) */
14122
14159
  isEmpty() {
14123
14160
  return this.length === 0;
@@ -14458,10 +14495,11 @@ class MemoryBuilder {
14458
14495
  startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
14459
14496
  `;
14460
14497
  this.ensureNotFinalized();
14461
- const range = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
14462
- const pages = PageRange.fromMemoryRange(range);
14463
- for (const pageNumber of pages) {
14464
- if (this.initialMemory.has(pageNumber)) {
14498
+ const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
14499
+ const heapPagesRange = PageRange.fromMemoryRange(heapRange);
14500
+ const initializedPageNumbers = Array.from(this.initialMemory.keys());
14501
+ for (const pageNumber of initializedPageNumbers) {
14502
+ if (heapPagesRange.isInRange(pageNumber)) {
14465
14503
  throw new IncorrectSbrkIndex();
14466
14504
  }
14467
14505
  }
package/index.d.ts CHANGED
@@ -2,6 +2,7 @@ declare enum GpVersion {
2
2
  V0_6_7 = "0.6.7",
3
3
  V0_7_0 = "0.7.0",
4
4
  V0_7_1 = "0.7.1-preview",
5
+ V0_7_2 = "0.7.2-preview",
5
6
  }
6
7
 
7
8
  declare enum TestSuite {
@@ -11,7 +12,7 @@ declare enum TestSuite {
11
12
 
12
13
  declare const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
13
14
 
14
- declare const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1];
15
+ declare const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
15
16
  declare const DEFAULT_VERSION = GpVersion.V0_7_0;
16
17
  declare let CURRENT_VERSION = parseCurrentVersion(env.GP_VERSION) ?? DEFAULT_VERSION;
17
18
  declare let CURRENT_SUITE = parseCurrentSuite(env.TEST_SUITE) ?? DEFAULT_SUITE;
@@ -20,24 +21,30 @@ declare function parseCurrentVersion(env?: string): GpVersion | undefined {
20
21
  if (env === undefined) {
21
22
  return undefined;
22
23
  }
23
- const version = env as GpVersion;
24
- if (!Object.values(GpVersion).includes(version)) {
25
- throw new Error(
26
- `Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`,
27
- );
24
+ switch (env) {
25
+ case GpVersion.V0_6_7:
26
+ case GpVersion.V0_7_0:
27
+ case GpVersion.V0_7_1:
28
+ case GpVersion.V0_7_2:
29
+ return env;
30
+ default:
31
+ throw new Error(
32
+ `Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`,
33
+ );
28
34
  }
29
- return version;
30
35
  }
31
36
 
32
37
  declare function parseCurrentSuite(env?: string): TestSuite | undefined {
33
38
  if (env === undefined) return undefined;
34
- const val = env as TestSuite;
35
- if (!Object.values(TestSuite).includes(val)) {
36
- throw new Error(
37
- `Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`,
38
- );
39
+ switch (env) {
40
+ case TestSuite.W3F_DAVXY:
41
+ case TestSuite.JAMDUNA:
42
+ return env;
43
+ default:
44
+ throw new Error(
45
+ `Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`,
46
+ );
39
47
  }
40
- return val;
41
48
  }
42
49
 
43
50
  declare class Compatibility {
@@ -6866,6 +6873,25 @@ declare class Block extends WithDebug {
6866
6873
  /** Undecoded View of a [`Block`]. */
6867
6874
  type BlockView = DescribedBy<typeof Block.Codec.View>;
6868
6875
 
6876
+ declare function emptyBlock(slot: TimeSlot = tryAsTimeSlot(0)) {
6877
+ const header = Header.empty();
6878
+ header.timeSlotIndex = slot;
6879
+ return Block.create({
6880
+ header,
6881
+ extrinsic: Extrinsic.create({
6882
+ tickets: asKnownSize([]),
6883
+ preimages: [],
6884
+ assurances: asKnownSize([]),
6885
+ guarantees: asKnownSize([]),
6886
+ disputes: {
6887
+ verdicts: [],
6888
+ culprits: [],
6889
+ faults: [],
6890
+ },
6891
+ }),
6892
+ });
6893
+ }
6894
+
6869
6895
  type index$j_Block = Block;
6870
6896
  declare const index$j_Block: typeof Block;
6871
6897
  type index$j_BlockView = BlockView;
@@ -6909,6 +6935,7 @@ declare const index$j_assurances: typeof assurances;
6909
6935
  declare const index$j_codecPerEpochBlock: typeof codecPerEpochBlock;
6910
6936
  declare const index$j_codecPerValidator: typeof codecPerValidator;
6911
6937
  declare const index$j_disputes: typeof disputes;
6938
+ declare const index$j_emptyBlock: typeof emptyBlock;
6912
6939
  declare const index$j_encodeUnsealedHeader: typeof encodeUnsealedHeader;
6913
6940
  declare const index$j_guarantees: typeof guarantees;
6914
6941
  declare const index$j_headerViewWithHashCodec: typeof headerViewWithHashCodec;
@@ -6930,7 +6957,7 @@ declare const index$j_workPackage: typeof workPackage;
6930
6957
  declare const index$j_workReport: typeof workReport;
6931
6958
  declare const index$j_workResult: typeof workResult;
6932
6959
  declare namespace index$j {
6933
- export { index$j_Block as Block, index$j_EpochMarker as EpochMarker, index$j_Extrinsic as Extrinsic, index$j_Header as Header, index$j_HeaderViewWithHash as HeaderViewWithHash, index$j_MAX_NUMBER_OF_SEGMENTS as MAX_NUMBER_OF_SEGMENTS, index$j_TicketsMarker as TicketsMarker, index$j_ValidatorKeys as ValidatorKeys, index$j_W_E as W_E, index$j_W_S as W_S, index$j_assurances as assurances, index$j_codecPerEpochBlock as codecPerEpochBlock, index$j_codecPerValidator as codecPerValidator, codec as codecUtils, index$j_disputes as disputes, index$j_encodeUnsealedHeader as encodeUnsealedHeader, index$j_guarantees as guarantees, index$j_headerViewWithHashCodec as headerViewWithHashCodec, index$j_legacyDescriptor as legacyDescriptor, index$j_preimage as preimage, index$j_refineContext as refineContext, index$j_tickets as tickets, index$j_tryAsCoreIndex as tryAsCoreIndex, index$j_tryAsEpoch as tryAsEpoch, index$j_tryAsPerEpochBlock as tryAsPerEpochBlock, index$j_tryAsPerValidator as tryAsPerValidator, index$j_tryAsSegmentIndex as tryAsSegmentIndex, index$j_tryAsServiceGas as tryAsServiceGas, index$j_tryAsServiceId as tryAsServiceId, index$j_tryAsTimeSlot as tryAsTimeSlot, index$j_tryAsValidatorIndex as tryAsValidatorIndex, index$j_workItem as workItem, index$j_workPackage as workPackage, index$j_workReport as workReport, index$j_workResult as workResult };
6960
+ export { index$j_Block as Block, index$j_EpochMarker as EpochMarker, index$j_Extrinsic as Extrinsic, index$j_Header as Header, index$j_HeaderViewWithHash as HeaderViewWithHash, index$j_MAX_NUMBER_OF_SEGMENTS as MAX_NUMBER_OF_SEGMENTS, index$j_TicketsMarker as TicketsMarker, index$j_ValidatorKeys as ValidatorKeys, index$j_W_E as W_E, index$j_W_S as W_S, index$j_assurances as assurances, index$j_codecPerEpochBlock as codecPerEpochBlock, index$j_codecPerValidator as codecPerValidator, codec as codecUtils, index$j_disputes as disputes, index$j_emptyBlock as emptyBlock, index$j_encodeUnsealedHeader as encodeUnsealedHeader, index$j_guarantees as guarantees, index$j_headerViewWithHashCodec as headerViewWithHashCodec, index$j_legacyDescriptor as legacyDescriptor, index$j_preimage as preimage, index$j_refineContext as refineContext, index$j_tickets as tickets, index$j_tryAsCoreIndex as tryAsCoreIndex, index$j_tryAsEpoch as tryAsEpoch, index$j_tryAsPerEpochBlock as tryAsPerEpochBlock, index$j_tryAsPerValidator as tryAsPerValidator, index$j_tryAsSegmentIndex as tryAsSegmentIndex, index$j_tryAsServiceGas as tryAsServiceGas, index$j_tryAsServiceId as tryAsServiceId, index$j_tryAsTimeSlot as tryAsTimeSlot, index$j_tryAsValidatorIndex as tryAsValidatorIndex, index$j_workItem as workItem, index$j_workPackage as workPackage, index$j_workReport as workReport, index$j_workResult as workResult };
6934
6961
  export type { index$j_BlockView as BlockView, index$j_CodeHash as CodeHash, index$j_CoreIndex as CoreIndex, index$j_EntropyHash as EntropyHash, index$j_Epoch as Epoch, index$j_EpochMarkerView as EpochMarkerView, index$j_ExtrinsicHash as ExtrinsicHash, index$j_ExtrinsicView as ExtrinsicView, index$j_HeaderHash as HeaderHash, index$j_HeaderView as HeaderView, index$j_PerEpochBlock as PerEpochBlock, index$j_PerValidator as PerValidator, index$j_SEGMENT_BYTES as SEGMENT_BYTES, index$j_Segment as Segment, index$j_SegmentIndex as SegmentIndex, index$j_ServiceGas as ServiceGas, index$j_ServiceId as ServiceId, index$j_StateRootHash as StateRootHash, index$j_TicketsMarkerView as TicketsMarkerView, index$j_TimeSlot as TimeSlot, index$j_ValidatorIndex as ValidatorIndex, index$j_WorkReportHash as WorkReportHash };
6935
6962
  }
6936
6963
 
@@ -14773,11 +14800,12 @@ declare class MemoryBuilder {
14773
14800
  `;
14774
14801
  this.ensureNotFinalized();
14775
14802
 
14776
- const range = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
14777
- const pages = PageRange.fromMemoryRange(range);
14803
+ const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
14804
+ const heapPagesRange = PageRange.fromMemoryRange(heapRange);
14805
+ const initializedPageNumbers = Array.from(this.initialMemory.keys());
14778
14806
 
14779
- for (const pageNumber of pages) {
14780
- if (this.initialMemory.has(pageNumber)) {
14807
+ for (const pageNumber of initializedPageNumbers) {
14808
+ if (heapPagesRange.isInRange(pageNumber)) {
14781
14809
  throw new IncorrectSbrkIndex();
14782
14810
  }
14783
14811
  }
package/index.js CHANGED
@@ -7,6 +7,7 @@ var GpVersion;
7
7
  GpVersion["V0_6_7"] = "0.6.7";
8
8
  GpVersion["V0_7_0"] = "0.7.0";
9
9
  GpVersion["V0_7_1"] = "0.7.1-preview";
10
+ GpVersion["V0_7_2"] = "0.7.2-preview";
10
11
  })(GpVersion || (GpVersion = {}));
11
12
  var TestSuite;
12
13
  (function (TestSuite) {
@@ -14,7 +15,7 @@ var TestSuite;
14
15
  TestSuite["JAMDUNA"] = "jamduna";
15
16
  })(TestSuite || (TestSuite = {}));
16
17
  const DEFAULT_SUITE = TestSuite.W3F_DAVXY;
17
- const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1];
18
+ const ALL_VERSIONS_IN_ORDER = [GpVersion.V0_6_7, GpVersion.V0_7_0, GpVersion.V0_7_1, GpVersion.V0_7_2];
18
19
  const env$1 = typeof process === "undefined" ? {} : process.env;
19
20
  const DEFAULT_VERSION = GpVersion.V0_7_0;
20
21
  let CURRENT_VERSION = parseCurrentVersion(env$1.GP_VERSION) ?? DEFAULT_VERSION;
@@ -23,20 +24,26 @@ function parseCurrentVersion(env) {
23
24
  if (env === undefined) {
24
25
  return undefined;
25
26
  }
26
- const version = env;
27
- if (!Object.values(GpVersion).includes(version)) {
28
- throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
27
+ switch (env) {
28
+ case GpVersion.V0_6_7:
29
+ case GpVersion.V0_7_0:
30
+ case GpVersion.V0_7_1:
31
+ case GpVersion.V0_7_2:
32
+ return env;
33
+ default:
34
+ throw new Error(`Configured environment variable GP_VERSION is unknown: '${env}'. Use one of: ${ALL_VERSIONS_IN_ORDER}`);
29
35
  }
30
- return version;
31
36
  }
32
37
  function parseCurrentSuite(env) {
33
38
  if (env === undefined)
34
39
  return undefined;
35
- const val = env;
36
- if (!Object.values(TestSuite).includes(val)) {
37
- throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
40
+ switch (env) {
41
+ case TestSuite.W3F_DAVXY:
42
+ case TestSuite.JAMDUNA:
43
+ return env;
44
+ default:
45
+ throw new Error(`Configured environment variable TEST_SUITE is unknown: '${env}'. Use one of: ${Object.values(TestSuite)}`);
38
46
  }
39
- return val;
40
47
  }
41
48
  class Compatibility {
42
49
  static override(version) {
@@ -5947,6 +5954,40 @@ var assurances = /*#__PURE__*/Object.freeze({
5947
5954
  assurancesExtrinsicCodec: assurancesExtrinsicCodec
5948
5955
  });
5949
5956
 
5957
+ /** Attempt to convert a number into `TimeSlot`. */
5958
+ const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
5959
+ /** Attempt to convert a number into `ValidatorIndex`. */
5960
+ const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
5961
+ /** Attempt to convert a number into `ServiceId`. */
5962
+ const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
5963
+ const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
5964
+ /** Attempt to convert a number into `CoreIndex`. */
5965
+ const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
5966
+ /** Attempt to convert a number into `Epoch`. */
5967
+ const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
5968
+ function tryAsPerValidator(array, spec) {
5969
+ check `
5970
+ ${array.length === spec.validatorsCount}
5971
+ Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
5972
+ `;
5973
+ return asKnownSize(array);
5974
+ }
5975
+ const codecPerValidator = (val) => codecWithContext((context) => {
5976
+ return codecKnownSizeArray(val, {
5977
+ fixedLength: context.validatorsCount,
5978
+ });
5979
+ });
5980
+ function tryAsPerEpochBlock(array, spec) {
5981
+ check `
5982
+ ${array.length === spec.epochLength}
5983
+ Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
5984
+ `;
5985
+ return asKnownSize(array);
5986
+ }
5987
+ const codecPerEpochBlock = (val) => codecWithContext((context) => {
5988
+ return codecKnownSizeArray(val, { fixedLength: context.epochLength });
5989
+ });
5990
+
5950
5991
  /**
5951
5992
  * Proof of signing a contradictory [`Judgement`] of a work report.
5952
5993
  */
@@ -6138,40 +6179,6 @@ var disputes = /*#__PURE__*/Object.freeze({
6138
6179
  Verdict: Verdict
6139
6180
  });
6140
6181
 
6141
- /** Attempt to convert a number into `TimeSlot`. */
6142
- const tryAsTimeSlot = (v) => asOpaqueType(tryAsU32(v));
6143
- /** Attempt to convert a number into `ValidatorIndex`. */
6144
- const tryAsValidatorIndex = (v) => asOpaqueType(tryAsU16(v));
6145
- /** Attempt to convert a number into `ServiceId`. */
6146
- const tryAsServiceId = (v) => asOpaqueType(tryAsU32(v));
6147
- const tryAsServiceGas = (v) => asOpaqueType(tryAsU64(v));
6148
- /** Attempt to convert a number into `CoreIndex`. */
6149
- const tryAsCoreIndex = (v) => asOpaqueType(tryAsU16(v));
6150
- /** Attempt to convert a number into `Epoch`. */
6151
- const tryAsEpoch = (v) => asOpaqueType(tryAsU32(v));
6152
- function tryAsPerValidator(array, spec) {
6153
- check `
6154
- ${array.length === spec.validatorsCount}
6155
- Invalid per-validator array length. Expected ${spec.validatorsCount}, got: ${array.length}
6156
- `;
6157
- return asKnownSize(array);
6158
- }
6159
- const codecPerValidator = (val) => codecWithContext((context) => {
6160
- return codecKnownSizeArray(val, {
6161
- fixedLength: context.validatorsCount,
6162
- });
6163
- });
6164
- function tryAsPerEpochBlock(array, spec) {
6165
- check `
6166
- ${array.length === spec.epochLength}
6167
- Invalid per-epoch-block array length. Expected ${spec.epochLength}, got: ${array.length}
6168
- `;
6169
- return asKnownSize(array);
6170
- }
6171
- const codecPerEpochBlock = (val) => codecWithContext((context) => {
6172
- return codecKnownSizeArray(val, { fixedLength: context.epochLength });
6173
- });
6174
-
6175
6182
  /**
6176
6183
  * Mapping between work package hash and root hash of it's exports.
6177
6184
  *
@@ -7250,6 +7257,24 @@ class Block extends WithDebug {
7250
7257
  this.extrinsic = extrinsic;
7251
7258
  }
7252
7259
  }
7260
+ function emptyBlock(slot = tryAsTimeSlot(0)) {
7261
+ const header = Header.empty();
7262
+ header.timeSlotIndex = slot;
7263
+ return Block.create({
7264
+ header,
7265
+ extrinsic: Extrinsic.create({
7266
+ tickets: asKnownSize([]),
7267
+ preimages: [],
7268
+ assurances: asKnownSize([]),
7269
+ guarantees: asKnownSize([]),
7270
+ disputes: {
7271
+ verdicts: [],
7272
+ culprits: [],
7273
+ faults: [],
7274
+ },
7275
+ }),
7276
+ });
7277
+ }
7253
7278
 
7254
7279
  var index$j = /*#__PURE__*/Object.freeze({
7255
7280
  __proto__: null,
@@ -7266,6 +7291,7 @@ var index$j = /*#__PURE__*/Object.freeze({
7266
7291
  codecPerValidator: codecPerValidator,
7267
7292
  codecUtils: codec,
7268
7293
  disputes: disputes,
7294
+ emptyBlock: emptyBlock,
7269
7295
  encodeUnsealedHeader: encodeUnsealedHeader,
7270
7296
  guarantees: guarantees,
7271
7297
  headerViewWithHashCodec: headerViewWithHashCodec,
@@ -8042,8 +8068,8 @@ function print(level, levelAndName, strings, data) {
8042
8068
  return;
8043
8069
  }
8044
8070
  const lvlText = Level[level].padEnd(5);
8045
- const val = strings.map((v, idx) => `${v}${data[idx]}`);
8046
- const msg = `${lvlText} [${levelAndName[1]}] ${val}`;
8071
+ const val = strings.map((v, idx) => `${v}${idx < data.length ? data[idx] : ""}`);
8072
+ const msg = `${lvlText} [${levelAndName[1]}] ${val.join("")}`;
8047
8073
  if (level === Level.WARN) {
8048
8074
  console.warn(msg);
8049
8075
  }
@@ -14115,6 +14141,17 @@ class PageRange {
14115
14141
  }
14116
14142
  return new PageRange(start, length);
14117
14143
  }
14144
+ /** Returns true if the page range is wrapped (`start` >= `end`) and is not empty */
14145
+ isWrapped() {
14146
+ return this.start >= this.end && !this.isEmpty();
14147
+ }
14148
+ /** Checks if given page number is within the range */
14149
+ isInRange(page) {
14150
+ if (this.isWrapped()) {
14151
+ return page >= this.start || page < this.end;
14152
+ }
14153
+ return page >= this.start && page < this.end;
14154
+ }
14118
14155
  /** Checks if a range is empty (`length === 0`) */
14119
14156
  isEmpty() {
14120
14157
  return this.length === 0;
@@ -14455,10 +14492,11 @@ class MemoryBuilder {
14455
14492
  startHeapIndex (${startHeapIndex}) has to be less than or equal to endHeapIndex (${endHeapIndex})
14456
14493
  `;
14457
14494
  this.ensureNotFinalized();
14458
- const range = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
14459
- const pages = PageRange.fromMemoryRange(range);
14460
- for (const pageNumber of pages) {
14461
- if (this.initialMemory.has(pageNumber)) {
14495
+ const heapRange = MemoryRange.fromStartAndLength(startHeapIndex, endHeapIndex - startHeapIndex);
14496
+ const heapPagesRange = PageRange.fromMemoryRange(heapRange);
14497
+ const initializedPageNumbers = Array.from(this.initialMemory.keys());
14498
+ for (const pageNumber of initializedPageNumbers) {
14499
+ if (heapPagesRange.isInRange(pageNumber)) {
14462
14500
  throw new IncorrectSbrkIndex();
14463
14501
  }
14464
14502
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@typeberry/lib",
3
- "version": "0.1.2-753d258",
3
+ "version": "0.1.2-7ebe1f6",
4
4
  "main": "index.js",
5
5
  "author": "Fluffy Labs",
6
6
  "license": "MPL-2.0",
@@ -1,29 +0,0 @@
1
- export * as block from "@typeberry/block";
2
- export * as block_json from "@typeberry/block-json";
3
- export * as bytes from "@typeberry/bytes";
4
- export * as codec from "@typeberry/codec";
5
- export * as collections from "@typeberry/collections";
6
- export * as config from "@typeberry/config";
7
- export * as config_node from "@typeberry/config-node";
8
- export * as crypto from "@typeberry/crypto";
9
- export * as database from "@typeberry/database";
10
- export * as erasure_coding from "@typeberry/erasure-coding";
11
- export * as hash from "@typeberry/hash";
12
- export * as jam_host_calls from "@typeberry/jam-host-calls";
13
- export * as json_parser from "@typeberry/json-parser";
14
- export * as logger from "@typeberry/logger";
15
- export * as mmr from "@typeberry/mmr";
16
- export * as numbers from "@typeberry/numbers";
17
- export * as ordering from "@typeberry/ordering";
18
- export * as pvm from "@typeberry/pvm-debugger-adapter";
19
- export * as pvm_host_calls from "@typeberry/pvm-host-calls";
20
- export * as pvm_interpreter from "@typeberry/pvm-interpreter";
21
- export * as pvm_program from "@typeberry/pvm-program";
22
- export * as pvm_spi_decoder from "@typeberry/pvm-spi-decoder";
23
- export * as shuffling from "@typeberry/shuffling";
24
- export * as state from "@typeberry/state";
25
- export * as state_json from "@typeberry/state-json";
26
- export * as state_merkleization from "@typeberry/state-merkleization";
27
- export * as transition from "@typeberry/transition";
28
- export * as trie from "@typeberry/trie";
29
- export * as utils from "@typeberry/utils";
@@ -1,76 +0,0 @@
1
- export declare const configs: {
2
- default: {
3
- $schema: string;
4
- version: number;
5
- flavor: string;
6
- authorship: {
7
- omit_seal_verification: boolean;
8
- };
9
- chain_spec: {
10
- id: string;
11
- bootnodes: string[];
12
- genesis_header: string;
13
- genesis_state: {
14
- "0b000000000000000000000000000000000000000000000000000000000000": string;
15
- "04000000000000000000000000000000000000000000000000000000000000": string;
16
- "08000000000000000000000000000000000000000000000000000000000000": string;
17
- "07000000000000000000000000000000000000000000000000000000000000": string;
18
- "00c500b600120062b94ad574028369bc6bd19a65f989134c022ea372cd4df6": string;
19
- "00ad0027003e003dc43472190923b0d2a1755796224bd5684c60fd0f6872c8": string;
20
- "008000c100e3000732d3152ca7f3bbf14ff40da18def60c6f78e93e4602f3d": string;
21
- "00f800e700990073c506a4ae6f6c368ca2c41dd8270472e9590c9ada0b87db": string;
22
- "09000000000000000000000000000000000000000000000000000000000000": string;
23
- ff000000000000000000000000000000000000000000000000000000000000: string;
24
- "0d000000000000000000000000000000000000000000000000000000000000": string;
25
- "01000000000000000000000000000000000000000000000000000000000000": string;
26
- "10000000000000000000000000000000000000000000000000000000000000": string;
27
- "0c000000000000000000000000000000000000000000000000000000000000": string;
28
- "06000000000000000000000000000000000000000000000000000000000000": string;
29
- "0a000000000000000000000000000000000000000000000000000000000000": string;
30
- "03000000000000000000000000000000000000000000000000000000000000": string;
31
- "0e000000000000000000000000000000000000000000000000000000000000": string;
32
- "0f000000000000000000000000000000000000000000000000000000000000": string;
33
- "02000000000000000000000000000000000000000000000000000000000000": string;
34
- "05000000000000000000000000000000000000000000000000000000000000": string;
35
- };
36
- };
37
- database_base_path: string;
38
- };
39
- dev: {
40
- $schema: string;
41
- version: number;
42
- flavor: string;
43
- authorship: {
44
- omit_seal_verification: boolean;
45
- };
46
- chain_spec: {
47
- id: string;
48
- bootnodes: string[];
49
- genesis_header: string;
50
- genesis_state: {
51
- "0b000000000000000000000000000000000000000000000000000000000000": string;
52
- "04000000000000000000000000000000000000000000000000000000000000": string;
53
- "08000000000000000000000000000000000000000000000000000000000000": string;
54
- "07000000000000000000000000000000000000000000000000000000000000": string;
55
- "00c500b600120062b94ad574028369bc6bd19a65f989134c022ea372cd4df6": string;
56
- "00ad0027003e003dc43472190923b0d2a1755796224bd5684c60fd0f6872c8": string;
57
- "008000c100e3000732d3152ca7f3bbf14ff40da18def60c6f78e93e4602f3d": string;
58
- "00f800e700990073c506a4ae6f6c368ca2c41dd8270472e9590c9ada0b87db": string;
59
- "09000000000000000000000000000000000000000000000000000000000000": string;
60
- ff000000000000000000000000000000000000000000000000000000000000: string;
61
- "0d000000000000000000000000000000000000000000000000000000000000": string;
62
- "01000000000000000000000000000000000000000000000000000000000000": string;
63
- "10000000000000000000000000000000000000000000000000000000000000": string;
64
- "0c000000000000000000000000000000000000000000000000000000000000": string;
65
- "06000000000000000000000000000000000000000000000000000000000000": string;
66
- "0a000000000000000000000000000000000000000000000000000000000000": string;
67
- "03000000000000000000000000000000000000000000000000000000000000": string;
68
- "0e000000000000000000000000000000000000000000000000000000000000": string;
69
- "0f000000000000000000000000000000000000000000000000000000000000": string;
70
- "02000000000000000000000000000000000000000000000000000000000000": string;
71
- "05000000000000000000000000000000000000000000000000000000000000": string;
72
- };
73
- };
74
- database_base_path: string;
75
- };
76
- };