@typeberry/lib 0.5.11-10b197e → 0.5.11

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 (40) hide show
  1. package/package.json +1 -1
  2. package/packages/jam/in-core/externalities/index.d.ts +4 -0
  3. package/packages/jam/in-core/externalities/index.d.ts.map +1 -0
  4. package/packages/jam/in-core/externalities/index.js +3 -0
  5. package/packages/jam/{transition/externalities/is-authorized-fetch-externalities.d.ts → in-core/externalities/is-authorized-fetch.d.ts} +7 -9
  6. package/packages/jam/in-core/externalities/is-authorized-fetch.d.ts.map +1 -0
  7. package/packages/jam/in-core/externalities/is-authorized-fetch.js +41 -0
  8. package/packages/jam/in-core/externalities/is-authorized-fetch.test.d.ts +2 -0
  9. package/packages/jam/in-core/externalities/is-authorized-fetch.test.d.ts.map +1 -0
  10. package/packages/jam/in-core/externalities/is-authorized-fetch.test.js +101 -0
  11. package/packages/jam/in-core/externalities/refine-fetch.d.ts +51 -0
  12. package/packages/jam/in-core/externalities/refine-fetch.d.ts.map +1 -0
  13. package/packages/jam/in-core/externalities/refine-fetch.js +80 -0
  14. package/packages/jam/in-core/externalities/refine-fetch.test.d.ts +2 -0
  15. package/packages/jam/in-core/externalities/refine-fetch.test.d.ts.map +1 -0
  16. package/packages/jam/in-core/externalities/refine-fetch.test.js +219 -0
  17. package/packages/jam/in-core/in-core.d.ts +2 -2
  18. package/packages/jam/in-core/in-core.d.ts.map +1 -1
  19. package/packages/jam/in-core/in-core.js +6 -4
  20. package/packages/jam/in-core/is-authorized.d.ts +3 -2
  21. package/packages/jam/in-core/is-authorized.d.ts.map +1 -1
  22. package/packages/jam/in-core/is-authorized.js +7 -6
  23. package/packages/jam/in-core/is-authorized.test.js +49 -7
  24. package/packages/jam/in-core/refine.d.ts +5 -8
  25. package/packages/jam/in-core/refine.d.ts.map +1 -1
  26. package/packages/jam/in-core/refine.js +12 -6
  27. package/packages/jam/transition/externalities/fetch-externalities.d.ts +55 -2
  28. package/packages/jam/transition/externalities/fetch-externalities.d.ts.map +1 -1
  29. package/packages/jam/transition/externalities/fetch-externalities.js +44 -2
  30. package/packages/jam/transition/externalities/index.d.ts +0 -2
  31. package/packages/jam/transition/externalities/index.d.ts.map +1 -1
  32. package/packages/jam/transition/externalities/index.js +0 -2
  33. package/packages/jam/transition/externalities/is-authorized-fetch-externalities.d.ts.map +0 -1
  34. package/packages/jam/transition/externalities/is-authorized-fetch-externalities.js +0 -41
  35. package/packages/jam/transition/externalities/refine-fetch-externalities.d.ts +0 -24
  36. package/packages/jam/transition/externalities/refine-fetch-externalities.d.ts.map +0 -1
  37. package/packages/jam/transition/externalities/refine-fetch-externalities.js +0 -59
  38. package/packages/jam/transition/externalities/refine-fetch-externalities.test.d.ts +0 -2
  39. package/packages/jam/transition/externalities/refine-fetch-externalities.test.d.ts.map +0 -1
  40. package/packages/jam/transition/externalities/refine-fetch-externalities.test.js +0 -32
@@ -1,9 +1,10 @@
1
- import { type CodeHash, type CoreIndex, type ServiceGas, type ServiceId } from "#@typeberry/block";
1
+ import { type CoreIndex, type ServiceGas } from "#@typeberry/block";
2
2
  import type { AuthorizerHash } from "#@typeberry/block/refine-context.js";
3
3
  import { BytesBlob } from "#@typeberry/bytes";
4
4
  import type { ChainSpec, PvmBackend } from "#@typeberry/config";
5
5
  import type { Blake2b } from "#@typeberry/hash";
6
6
  import type { State } from "#@typeberry/state";
7
+ import type { WorkPackageFetchData } from "#@typeberry/transition/externalities/fetch-externalities.js";
7
8
  import { Result } from "#@typeberry/utils";
8
9
  export declare enum AuthorizationError {
9
10
  /** BAD: authorizer code not found (service or preimage missing). */
@@ -28,6 +29,6 @@ export declare class IsAuthorized {
28
29
  private readonly pvmBackend;
29
30
  private readonly blake2b;
30
31
  constructor(chainSpec: ChainSpec, pvmBackend: PvmBackend, blake2b: Blake2b);
31
- invoke(state: State, coreIndex: CoreIndex, authToken: BytesBlob, authCodeHost: ServiceId, authCodeHash: CodeHash, authConfiguration: BytesBlob): Promise<Result<AuthorizationOk, AuthorizationError>>;
32
+ invoke(state: State, coreIndex: CoreIndex, packageFetchData: WorkPackageFetchData): Promise<Result<AuthorizationOk, AuthorizationError>>;
32
33
  }
33
34
  //# sourceMappingURL=is-authorized.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"is-authorized.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/in-core/is-authorized.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,SAAS,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAmB,MAAM,kBAAkB,CAAC;AAEnH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAE9C,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAE1C,oBAAY,kBAAkB;IAC5B,oEAAoE;IACpE,YAAY,IAAI;IAChB,8CAA8C;IAC9C,UAAU,IAAI;IACd,uCAAuC;IACvC,SAAS,IAAI;CACd;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,cAAc,EAAE,cAAc,CAAC;IAC/B,oBAAoB,EAAE,UAAU,CAAC;IACjC,mBAAmB,EAAE,SAAS,CAAC;CAChC,CAAC;AAMF;;;;GAIG;AACH,qBAAa,YAAY;IAErB,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAFP,SAAS,EAAE,SAAS,EACpB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO;IAG7B,MAAM,CACV,KAA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EAAE,UAAU,EACtB,OAAO,EAAE,OAAO;IAG7B,MAAM,CACV,KAAK,EAAE,KAAK,EACZ,SAAS,EAAE,SAAS,EACpB,gBAAgB,EAAE,oBAAoB,GACrC,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,kBAAkB,CAAC,CAAC;CAiExD"}
@@ -3,8 +3,8 @@ import { G_I, W_A } from "#@typeberry/block/gp-constants.js";
3
3
  import { BytesBlob } from "#@typeberry/bytes";
4
4
  import { codec, Encoder } from "#@typeberry/codec";
5
5
  import { PvmExecutor, ReturnStatus } from "#@typeberry/executor";
6
- import { IsAuthorizedFetchExternalities } from "#@typeberry/transition/externalities/is-authorized-fetch-externalities.js";
7
6
  import { Result } from "#@typeberry/utils";
7
+ import { IsAuthorizedFetchExternalities } from "./externalities/index.js";
8
8
  export var AuthorizationError;
9
9
  (function (AuthorizationError) {
10
10
  /** BAD: authorizer code not found (service or preimage missing). */
@@ -31,7 +31,11 @@ export class IsAuthorized {
31
31
  this.pvmBackend = pvmBackend;
32
32
  this.blake2b = blake2b;
33
33
  }
34
- async invoke(state, coreIndex, authToken, authCodeHost, authCodeHash, authConfiguration) {
34
+ async invoke(state, coreIndex, packageFetchData) {
35
+ const packageView = packageFetchData.packageView;
36
+ const authCodeHost = packageView.authCodeHost.materialize();
37
+ const authCodeHash = packageView.authCodeHash.materialize();
38
+ const authConfiguration = packageView.authConfiguration.materialize();
35
39
  // Look up the authorizer code from the auth code host service
36
40
  const service = state.getService(authCodeHost);
37
41
  // https://graypaper.fluffylabs.dev/#/ab2cdbd/2eca002eca00?v=0.7.2
@@ -48,10 +52,7 @@ export class IsAuthorized {
48
52
  return Result.error(AuthorizationError.CodeTooBig, () => `Auth code is too big: ${code.length} bytes vs ${W_A} max.`);
49
53
  }
50
54
  // Prepare fetch externalities and executor
51
- const fetchExternalities = new IsAuthorizedFetchExternalities(this.chainSpec, {
52
- authToken,
53
- authConfiguration,
54
- });
55
+ const fetchExternalities = new IsAuthorizedFetchExternalities(this.chainSpec, packageFetchData);
55
56
  const executor = await PvmExecutor.createIsAuthorizedExecutor(authCodeHost, code, { fetchExternalities }, this.pvmBackend);
56
57
  const args = Encoder.encodeObject(AUTH_ARGS_CODEC, {
57
58
  coreIndex,
@@ -3,13 +3,50 @@ import { readFileSync } from "node:fs";
3
3
  import { resolve } from "node:path";
4
4
  import { before, describe, it } from "node:test";
5
5
  import { tryAsCoreIndex, tryAsServiceGas, tryAsServiceId, tryAsTimeSlot } from "#@typeberry/block";
6
+ import { RefineContext } from "#@typeberry/block/refine-context.js";
7
+ import { WorkItem } from "#@typeberry/block/work-item.js";
8
+ import { tryAsWorkItemsCount, WorkPackage } from "#@typeberry/block/work-package.js";
6
9
  import { Bytes, BytesBlob } from "#@typeberry/bytes";
7
- import { HashDictionary } from "#@typeberry/collections";
10
+ import { asKnownSize, FixedSizeArray, HashDictionary } from "#@typeberry/collections";
8
11
  import { PvmBackend, tinyChainSpec } from "#@typeberry/config";
9
12
  import { Blake2b, HASH_SIZE } from "#@typeberry/hash";
10
- import { tryAsU32, tryAsU64 } from "#@typeberry/numbers";
13
+ import { tryAsU16, tryAsU32, tryAsU64 } from "#@typeberry/numbers";
11
14
  import { InMemoryService, InMemoryState, PreimageItem, ServiceAccountInfo } from "#@typeberry/state";
15
+ import { buildWorkPackageFetchData } from "#@typeberry/transition/externalities/fetch-externalities.js";
12
16
  import { AuthorizationError, IsAuthorized } from "./is-authorized.js";
17
+ function buildPackageAndFetchData(authCodeHash, authToken, authConfiguration) {
18
+ const pkg = buildPackage(authCodeHash, authToken, authConfiguration);
19
+ return { pkg, fetchData: buildWorkPackageFetchData(tinyChainSpec, pkg) };
20
+ }
21
+ function buildPackage(authCodeHash, authToken, authConfiguration) {
22
+ const items = [
23
+ WorkItem.create({
24
+ service: tryAsServiceId(1),
25
+ codeHash: Bytes.zero(HASH_SIZE).asOpaque(),
26
+ refineGasLimit: tryAsServiceGas(1_000_000),
27
+ accumulateGasLimit: tryAsServiceGas(1_000_000),
28
+ exportCount: tryAsU16(0),
29
+ payload: BytesBlob.empty(),
30
+ importSegments: asKnownSize([]),
31
+ extrinsic: [],
32
+ }),
33
+ ];
34
+ return WorkPackage.create({
35
+ authToken,
36
+ authCodeHost: AUTH_SERVICE_ID,
37
+ authCodeHash,
38
+ authConfiguration,
39
+ context: RefineContext.create({
40
+ anchor: Bytes.zero(HASH_SIZE).asOpaque(),
41
+ stateRoot: Bytes.zero(HASH_SIZE).asOpaque(),
42
+ beefyRoot: Bytes.zero(HASH_SIZE).asOpaque(),
43
+ lookupAnchor: Bytes.zero(HASH_SIZE).asOpaque(),
44
+ lookupAnchorSlot: tryAsTimeSlot(16),
45
+ prerequisites: [],
46
+ }),
47
+ items: FixedSizeArray.new(items, tryAsWorkItemsCount(1)),
48
+ });
49
+ }
13
50
  let blake2b;
14
51
  before(async () => {
15
52
  blake2b = await Blake2b.createHasher();
@@ -54,7 +91,8 @@ describe("IsAuthorized", () => {
54
91
  const state = createStateWithService(authCodeHash, AUTHORIZER_PVM);
55
92
  const isAuthorized = new IsAuthorized(spec, PvmBackend.BuiltIn, blake2b);
56
93
  const token = BytesBlob.blobFromString("hello");
57
- const result = await isAuthorized.invoke(state, tryAsCoreIndex(0), token, AUTH_SERVICE_ID, authCodeHash, token);
94
+ const { fetchData } = buildPackageAndFetchData(authCodeHash, token, token);
95
+ const result = await isAuthorized.invoke(state, tryAsCoreIndex(0), fetchData);
58
96
  assert.strictEqual(result.isOk, true, `Expected OK but got error: ${result.isError ? result.details() : ""}`);
59
97
  // Verify the authorization output starts with "Auth=<hello>"
60
98
  const outputStr = Buffer.from(result.ok.authorizationOutput.raw).toString("utf8");
@@ -69,7 +107,8 @@ describe("IsAuthorized", () => {
69
107
  const authCodeHash = getAuthCodeHash();
70
108
  const state = createStateWithService(authCodeHash, AUTHORIZER_PVM);
71
109
  const isAuthorized = new IsAuthorized(spec, PvmBackend.BuiltIn, blake2b);
72
- const result = await isAuthorized.invoke(state, tryAsCoreIndex(0), BytesBlob.empty(), AUTH_SERVICE_ID, authCodeHash, BytesBlob.empty());
110
+ const empty = buildPackageAndFetchData(authCodeHash, BytesBlob.empty(), BytesBlob.empty());
111
+ const result = await isAuthorized.invoke(state, tryAsCoreIndex(0), empty.fetchData);
73
112
  assert.strictEqual(result.isOk, true, `Expected OK but got error: ${result.isError ? result.details() : ""}`);
74
113
  const outputStr = Buffer.from(result.ok.authorizationOutput.raw).toString("utf8");
75
114
  assert.ok(outputStr.startsWith("Auth=<>"), `Expected "Auth=<>" prefix but got "${outputStr.slice(0, 30)}"`);
@@ -78,7 +117,8 @@ describe("IsAuthorized", () => {
78
117
  const authCodeHash = getAuthCodeHash();
79
118
  const state = createStateWithService(authCodeHash, AUTHORIZER_PVM);
80
119
  const isAuthorized = new IsAuthorized(spec, PvmBackend.BuiltIn, blake2b);
81
- const result = await isAuthorized.invoke(state, tryAsCoreIndex(0), BytesBlob.blobFromString("wrong"), AUTH_SERVICE_ID, authCodeHash, BytesBlob.blobFromString("right"));
120
+ const mismatch = buildPackageAndFetchData(authCodeHash, BytesBlob.blobFromString("wrong"), BytesBlob.blobFromString("right"));
121
+ const result = await isAuthorized.invoke(state, tryAsCoreIndex(0), mismatch.fetchData);
82
122
  assert.strictEqual(result.isError, true);
83
123
  assert.strictEqual(result.error, AuthorizationError.PvmFailed);
84
124
  });
@@ -89,7 +129,8 @@ describe("IsAuthorized", () => {
89
129
  services: new Map(),
90
130
  });
91
131
  const isAuthorized = new IsAuthorized(spec, PvmBackend.BuiltIn, blake2b);
92
- const result = await isAuthorized.invoke(state, tryAsCoreIndex(0), BytesBlob.empty(), AUTH_SERVICE_ID, authCodeHash, BytesBlob.empty());
132
+ const missing = buildPackageAndFetchData(authCodeHash, BytesBlob.empty(), BytesBlob.empty());
133
+ const result = await isAuthorized.invoke(state, tryAsCoreIndex(0), missing.fetchData);
93
134
  assert.strictEqual(result.isError, true);
94
135
  assert.strictEqual(result.error, AuthorizationError.CodeNotFound);
95
136
  });
@@ -118,7 +159,8 @@ describe("IsAuthorized", () => {
118
159
  services: new Map([[AUTH_SERVICE_ID, emptyService]]),
119
160
  });
120
161
  const isAuthorized = new IsAuthorized(spec, PvmBackend.BuiltIn, blake2b);
121
- const result = await isAuthorized.invoke(state, tryAsCoreIndex(0), BytesBlob.empty(), AUTH_SERVICE_ID, authCodeHash, BytesBlob.empty());
162
+ const emptyPreimage = buildPackageAndFetchData(authCodeHash, BytesBlob.empty(), BytesBlob.empty());
163
+ const result = await isAuthorized.invoke(state, tryAsCoreIndex(0), emptyPreimage.fetchData);
122
164
  assert.strictEqual(result.isError, true);
123
165
  assert.strictEqual(result.error, AuthorizationError.CodeNotFound);
124
166
  });
@@ -1,21 +1,18 @@
1
- import { type CoreIndex, type Segment, type SegmentIndex, type ServiceGas } from "#@typeberry/block";
1
+ import { type CoreIndex, type Segment, type ServiceGas } from "#@typeberry/block";
2
2
  import type { WorkPackageHash } from "#@typeberry/block/refine-context.js";
3
3
  import type { WorkItem, WorkItemExtrinsic } from "#@typeberry/block/work-item.js";
4
4
  import { WorkExecResult, WorkResult } from "#@typeberry/block/work-result.js";
5
- import type { KnownSizeArray } from "#@typeberry/collections";
5
+ import { BytesBlob } from "#@typeberry/bytes";
6
6
  import type { ChainSpec, PvmBackend } from "#@typeberry/config";
7
7
  import { type ReturnValue } from "#@typeberry/executor";
8
8
  import { type Blake2b } from "#@typeberry/hash";
9
9
  import type { State } from "#@typeberry/state";
10
+ import type { WorkPackageFetchData } from "#@typeberry/transition/externalities/fetch-externalities.js";
11
+ import { type ImportedSegment, type PerWorkItem } from "./externalities/index.js";
10
12
  export type RefineItemResult = {
11
13
  result: WorkResult;
12
14
  exports: readonly Segment[];
13
15
  };
14
- export type PerWorkItem<T> = KnownSizeArray<T, "for each work item">;
15
- export type ImportedSegment = {
16
- index: SegmentIndex;
17
- data: Segment;
18
- };
19
16
  /**
20
17
  * Refine PVM invocation (Psi_R).
21
18
  *
@@ -26,7 +23,7 @@ export declare class Refine {
26
23
  private readonly pvmBackend;
27
24
  private readonly blake2b;
28
25
  constructor(chainSpec: ChainSpec, pvmBackend: PvmBackend, blake2b: Blake2b);
29
- invoke(state: State, lookupState: State, idx: number, item: WorkItem, allImports: PerWorkItem<ImportedSegment[]>, allExtrinsics: PerWorkItem<WorkItemExtrinsic[]>, coreIndex: CoreIndex, workPackageHash: WorkPackageHash, exportOffset: number): Promise<RefineItemResult>;
26
+ invoke(state: State, lookupState: State, packageFetchData: WorkPackageFetchData, idx: number, item: WorkItem, allImports: PerWorkItem<ImportedSegment[]>, allExtrinsics: PerWorkItem<WorkItemExtrinsic[]>, coreIndex: CoreIndex, workPackageHash: WorkPackageHash, exportOffset: number, authorizerTrace: BytesBlob): Promise<RefineItemResult>;
30
27
  static extractWorkResult(execResult: ReturnValue<ServiceGas>): WorkExecResult;
31
28
  private getServiceCode;
32
29
  private createRefineExternalities;
@@ -1 +1 @@
1
- {"version":3,"file":"refine.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/in-core/refine.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,UAAU,EAIhB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,EAAE,cAAc,EAAsC,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAGjH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EAA+D,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACpH,OAAO,EAAE,KAAK,OAAO,EAAa,MAAM,iBAAiB,CAAC;AAE1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,kBAAk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ACzB,OAAO,CAAC,gBAAgB,CAAC;IA4F5B,MAAM,CAAC,iBAAiB,CAAC,UAAU,EAAE,WAAW,CAAC,UAAU,CAAC;IAiB5D,OAAO,CAAC,cAAc;IAyCtB,OAAO,CAAC,yBAAyB;CA6BlC"}
@@ -6,9 +6,8 @@ import { codec, Encoder } from "#@typeberry/codec";
6
6
  import { PvmExecutor, ReturnStatus } from "#@typeberry/executor";
7
7
  import { HASH_SIZE } from "#@typeberry/hash";
8
8
  import { tryAsU32 } from "#@typeberry/numbers";
9
- import { RefineFetchExternalities } from "#@typeberry/transition/externalities/refine-fetch-externalities.js";
10
9
  import { assertNever, Result } from "#@typeberry/utils";
11
- import { RefineExternalitiesImpl } from "./externalities/refine.js";
10
+ import { RefineExternalitiesImpl, RefineFetchExternalities, } from "./externalities/index.js";
12
11
  var ServiceCodeError;
13
12
  (function (ServiceCodeError) {
14
13
  /** Service id is not found in the state. */
@@ -42,7 +41,7 @@ export class Refine {
42
41
  this.pvmBackend = pvmBackend;
43
42
  this.blake2b = blake2b;
44
43
  }
45
- async invoke(state, lookupState, idx, item, allImports, allExtrinsics, coreIndex, workPackageHash, exportOffset) {
44
+ async invoke(state, lookupState, packageFetchData, idx, item, allImports, allExtrinsics, coreIndex, workPackageHash, exportOffset, authorizerTrace) {
46
45
  const payloadHash = this.blake2b.hashBytes(item.payload);
47
46
  const baseResult = {
48
47
  serviceId: item.service,
@@ -77,12 +76,14 @@ export class Refine {
77
76
  }
78
77
  const code = maybeCode.ok;
79
78
  const externalities = this.createRefineExternalities({
80
- payload: item.payload,
79
+ packageFetchData,
80
+ currentWorkItemIndex: idx,
81
81
  imports: allImports,
82
82
  extrinsics: allExtrinsics,
83
83
  currentServiceId: item.service,
84
84
  lookupState,
85
85
  exportOffset,
86
+ authorizerTrace,
86
87
  });
87
88
  const executor = await PvmExecutor.createRefineExecutor(item.service, code, externalities, this.pvmBackend);
88
89
  const args = Encoder.encodeObject(REFINE_ARGS_CODEC, {
@@ -160,8 +161,13 @@ export class Refine {
160
161
  return Result.ok(code);
161
162
  }
162
163
  createRefineExternalities(args) {
163
- // TODO [ToDr] Pass all required fetch data
164
- const fetchExternalities = RefineFetchExternalities.new(this.chainSpec);
164
+ const fetchExternalities = new RefineFetchExternalities(this.chainSpec, {
165
+ packageData: args.packageFetchData,
166
+ currentWorkItemIndex: args.currentWorkItemIndex,
167
+ imports: args.imports,
168
+ extrinsics: args.extrinsics,
169
+ authorizerTrace: args.authorizerTrace,
170
+ });
165
171
  const refine = RefineExternalitiesImpl.create({
166
172
  currentServiceId: args.currentServiceId,
167
173
  lookupState: args.lookupState,
@@ -1,6 +1,10 @@
1
- import type { BytesBlob } from "#@typeberry/bytes";
1
+ import type { WorkItem } from "#@typeberry/block/work-item.js";
2
+ import { WorkPackage, type WorkPackageView } from "#@typeberry/block/work-package.js";
3
+ import { BytesBlob } from "#@typeberry/bytes";
4
+ import { type DescribedBy, SequenceView } from "#@typeberry/codec";
2
5
  import type { ChainSpec } from "#@typeberry/config";
3
6
  import { PendingTransfer } from "#@typeberry/jam-host-calls";
7
+ import { type U64 } from "#@typeberry/numbers";
4
8
  import { Operand } from "../accumulate/operand.js";
5
9
  export declare enum TransferOperandKind {
6
10
  OPERAND = 0,
@@ -14,6 +18,55 @@ export type TransferOrOperand = {
14
18
  value: PendingTransfer;
15
19
  };
16
20
  export declare const TRANSFER_OR_OPERAND: import("@typeberry/codec").Descriptor<TransferOrOperand, TransferOrOperand>;
17
- export declare const TRANSFERS_AND_OPERANDS: import("@typeberry/codec").Descriptor<TransferOrOperand[], import("@typeberry/codec").SequenceView<TransferOrOperand, TransferOrOperand>>;
21
+ export declare const TRANSFERS_AND_OPERANDS: import("@typeberry/codec").Descriptor<TransferOrOperand[], SequenceView<TransferOrOperand, TransferOrOperand>>;
18
22
  export declare function getEncodedConstants(chainSpec: ChainSpec): BytesBlob;
23
+ /**
24
+ * `S(w)` — work-item summary used by fetch in both the IsAuthorized
25
+ * and Refine contexts.
26
+ *
27
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31fc0231fc02?v=0.7.2
28
+ */
29
+ declare const WORK_ITEM_SUMMARY_CODEC: import("@typeberry/codec").Descriptor<{
30
+ service: number & import("@typeberry/numbers").WithBytesRepresentation<4> & import("@typeberry/utils").WithOpaque<"ServiceId[u32]">;
31
+ codeHash: import("@typeberry/bytes").Bytes<32> & import("@typeberry/utils").WithOpaque<"CodeHash">;
32
+ refineGasLimit: bigint & import("@typeberry/numbers").WithBytesRepresentation<8> & import("@typeberry/utils").WithOpaque<"ServiceGas[u64]">;
33
+ accumulateGasLimit: bigint & import("@typeberry/numbers").WithBytesRepresentation<8> & import("@typeberry/utils").WithOpaque<"ServiceGas[u64]">;
34
+ exportCount: import("@typeberry/numbers").U16;
35
+ importSegmentsCount: import("@typeberry/numbers").U16;
36
+ extrinsicCount: import("@typeberry/numbers").U16;
37
+ payloadLength: import("@typeberry/numbers").U32;
38
+ }, import("@typeberry/codec").ViewOf<{
39
+ service: number & import("@typeberry/numbers").WithBytesRepresentation<4> & import("@typeberry/utils").WithOpaque<"ServiceId[u32]">;
40
+ codeHash: import("@typeberry/bytes").Bytes<32> & import("@typeberry/utils").WithOpaque<"CodeHash">;
41
+ refineGasLimit: bigint & import("@typeberry/numbers").WithBytesRepresentation<8> & import("@typeberry/utils").WithOpaque<"ServiceGas[u64]">;
42
+ accumulateGasLimit: bigint & import("@typeberry/numbers").WithBytesRepresentation<8> & import("@typeberry/utils").WithOpaque<"ServiceGas[u64]">;
43
+ exportCount: import("@typeberry/numbers").U16;
44
+ importSegmentsCount: import("@typeberry/numbers").U16;
45
+ extrinsicCount: import("@typeberry/numbers").U16;
46
+ payloadLength: import("@typeberry/numbers").U32;
47
+ }, import("@typeberry/codec").SimpleDescriptorRecord<{
48
+ service: number & import("@typeberry/numbers").WithBytesRepresentation<4> & import("@typeberry/utils").WithOpaque<"ServiceId[u32]">;
49
+ codeHash: import("@typeberry/bytes").Bytes<32> & import("@typeberry/utils").WithOpaque<"CodeHash">;
50
+ refineGasLimit: bigint & import("@typeberry/numbers").WithBytesRepresentation<8> & import("@typeberry/utils").WithOpaque<"ServiceGas[u64]">;
51
+ accumulateGasLimit: bigint & import("@typeberry/numbers").WithBytesRepresentation<8> & import("@typeberry/utils").WithOpaque<"ServiceGas[u64]">;
52
+ exportCount: import("@typeberry/numbers").U16;
53
+ importSegmentsCount: import("@typeberry/numbers").U16;
54
+ extrinsicCount: import("@typeberry/numbers").U16;
55
+ payloadLength: import("@typeberry/numbers").U32;
56
+ }>>>;
57
+ type WorkItemSummary = DescribedBy<typeof WORK_ITEM_SUMMARY_CODEC>;
58
+ type WorkItemSummaryView = DescribedBy<typeof WORK_ITEM_SUMMARY_CODEC.View>;
59
+ export declare function encodeWorkItemSummary(item: WorkItem): BytesBlob;
60
+ /** Encoded work package data for fetch, shared between `IsAuthorized` and `Refine` fetchers. */
61
+ export type WorkPackageFetchData = {
62
+ /** Lazy view over the encoded work package. */
63
+ packageView: WorkPackageView;
64
+ /** SequenceView over the concatenated S(w) summaries. */
65
+ workItemSummaries: SequenceView<WorkItemSummary, WorkItemSummaryView>;
66
+ };
67
+ /** Eagerly build the per-package fetch views. */
68
+ export declare function buildWorkPackageFetchData(chainSpec: ChainSpec, workPackage: WorkPackage): WorkPackageFetchData;
69
+ /** Converts u64 value taken from a register into valid index of array of given `length`. */
70
+ export declare function u64ToArrayIndex(v: U64, len: number): number | null;
71
+ export {};
19
72
  //# sourceMappingURL=fetch-externalities.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-externalities.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/transition/externalities/fetch-externalities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAElD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAS5D,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAInD,oBAAY,mBAAmB;IAC7B,OAAO,IAAI;IACX,QAAQ,IAAI;CACb;AAED,MAAM,MAAM,iBAAiB,GACzB;IACE,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC;CAChB,GACD;IACE,IAAI,EAAE,mBAAmB,CAAC,QAAQ,CAAC;IACnC,KAAK,EAAE,eAAe,CAAC;CACxB,CAAC;AAEN,eAAO,MAAM,mBAAmB,6EAG9B,CAAC;AAEH,eAAO,MAAM,sBAAsB,2IAA4C,CAAC;AA0ChF,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,SAAS,aA6CvD"}
1
+ {"version":3,"file":"fetch-externalities.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/transition/externalities/fetch-externalities.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AAC9D,OAAO,EAA4B,WAAW,EAAE,KAAK,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAC/G,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAkB,KAAK,WAAW,EAAW,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EAAgC,KAAK,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAQ5E,OAAO,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAInD,oBAAY,mBAAmB;IAC7B,OAAO,IAAI;IACX,QAAQ,IAAI;CACb;AAED,MAAM,MAAM,iBAAiB,GACzB;IACE,IAAI,EAAE,mBAAmB,CAAC,OAAO,CAAC;IAClC,KAAK,EAAE,OAAO,CAAC;CAChB,GACD;IACE,IAAI,EAAE,mBAAmB,CAAC,QAAQ,CAAC;IACnC,KAAK,EAAE,eAAe,CAAC;CACxB,CAAC;AAEN,eAAO,MAAM,mBAAmB,6EAG9B,CAAC;AAEH,eAAO,MAAM,sBAAsB,gHAA4C,CAAC;AA0ChF,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,SAAS,aA6CvD;AAED;;;;;GAKG;AACH,QAAA,MAAM,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;;;;;IAS3B,CAAC;AACH,KAAK,eAAe,GAAG,WAAW,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACnE,KAAK,mBAAmB,GAAG,WAAW,CAAC,OAAO,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAE5E,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAW/D;AAED,gGAAgG;AAChG,MAAM,MAAM,oBAAoB,GAAG;IACjC,+CAA+C;IAC/C,WAAW,EAAE,eAAe,CAAC;IAC7B,yDAAyD;IACzD,iBAAiB,EAAE,YAAY,CAAC,eAAe,EAAE,mBAAmB,CAAC,CAAC;CACvE,CAAC;AAEF,iDAAiD;AACjD,wBAAgB,yBAAyB,CAAC,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,GAAG,oBAAoB,CAY9G;AAED,4FAA4F;AAC5F,wBAAgB,eAAe,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAElE"}
@@ -1,6 +1,9 @@
1
+ import { reencodeAsView } from "#@typeberry/block";
1
2
  import { G_I, MAX_REPORT_DEPENDENCIES, O, Q, T, W_A, W_B, W_C, W_M, W_T, W_X } from "#@typeberry/block/gp-constants.js";
2
- import { MAX_NUMBER_OF_WORK_ITEMS } from "#@typeberry/block/work-package.js";
3
- import { codec, Encoder } from "#@typeberry/codec";
3
+ import { MAX_NUMBER_OF_WORK_ITEMS, WorkPackage } from "#@typeberry/block/work-package.js";
4
+ import { BytesBlob } from "#@typeberry/bytes";
5
+ import { codec, Decoder, Encoder, SequenceView } from "#@typeberry/codec";
6
+ import { HASH_SIZE } from "#@typeberry/hash";
4
7
  import { PendingTransfer } from "#@typeberry/jam-host-calls";
5
8
  import { tryAsU16, tryAsU32, tryAsU64 } from "#@typeberry/numbers";
6
9
  import { BASE_SERVICE_BALANCE, ELECTIVE_BYTE_BALANCE, ELECTIVE_ITEM_BALANCE, MAX_RECENT_HISTORY, } from "#@typeberry/state";
@@ -99,3 +102,42 @@ export function getEncodedConstants(chainSpec) {
99
102
  encodedConstantsCache.set(chainSpec, encodedConsts);
100
103
  return encodedConsts;
101
104
  }
105
+ /**
106
+ * `S(w)` — work-item summary used by fetch in both the IsAuthorized
107
+ * and Refine contexts.
108
+ *
109
+ * https://graypaper.fluffylabs.dev/#/ab2cdbd/31fc0231fc02?v=0.7.2
110
+ */
111
+ const WORK_ITEM_SUMMARY_CODEC = codec.object({
112
+ service: codec.u32.asOpaque(),
113
+ codeHash: codec.bytes(HASH_SIZE).asOpaque(),
114
+ refineGasLimit: codec.u64.asOpaque(),
115
+ accumulateGasLimit: codec.u64.asOpaque(),
116
+ exportCount: codec.u16,
117
+ importSegmentsCount: codec.u16,
118
+ extrinsicCount: codec.u16,
119
+ payloadLength: codec.u32,
120
+ });
121
+ export function encodeWorkItemSummary(item) {
122
+ return Encoder.encodeObject(WORK_ITEM_SUMMARY_CODEC, {
123
+ service: item.service,
124
+ codeHash: item.codeHash,
125
+ refineGasLimit: item.refineGasLimit,
126
+ accumulateGasLimit: item.accumulateGasLimit,
127
+ exportCount: item.exportCount,
128
+ importSegmentsCount: tryAsU16(item.importSegments.length),
129
+ extrinsicCount: tryAsU16(item.extrinsic.length),
130
+ payloadLength: tryAsU32(item.payload.length),
131
+ });
132
+ }
133
+ /** Eagerly build the per-package fetch views. */
134
+ export function buildWorkPackageFetchData(chainSpec, workPackage) {
135
+ const packageView = reencodeAsView(WorkPackage.Codec, workPackage, chainSpec);
136
+ const summariesBlob = BytesBlob.blobFromParts(workPackage.items.map((i) => encodeWorkItemSummary(i).raw));
137
+ const workItemSummaries = new SequenceView(Decoder.fromBytesBlob(summariesBlob), WORK_ITEM_SUMMARY_CODEC, workPackage.items.length);
138
+ return { packageView, workItemSummaries };
139
+ }
140
+ /** Converts u64 value taken from a register into valid index of array of given `length`. */
141
+ export function u64ToArrayIndex(v, len) {
142
+ return v < BigInt(len) ? Number(v) : null;
143
+ }
@@ -1,6 +1,4 @@
1
1
  export * from "./accumulate-externalities.js";
2
2
  export * from "./accumulate-fetch-externalities.js";
3
3
  export * from "./fetch-externalities.js";
4
- export * from "./is-authorized-fetch-externalities.js";
5
- export * from "./refine-fetch-externalities.js";
6
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/transition/externalities/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,0BAA0B,CAAC;AACzC,cAAc,wCAAwC,CAAC;AACvD,cAAc,iCAAiC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/transition/externalities/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,0BAA0B,CAAC"}
@@ -1,5 +1,3 @@
1
1
  export * from "./accumulate-externalities.js";
2
2
  export * from "./accumulate-fetch-externalities.js";
3
3
  export * from "./fetch-externalities.js";
4
- export * from "./is-authorized-fetch-externalities.js";
5
- export * from "./refine-fetch-externalities.js";
@@ -1 +0,0 @@
1
- {"version":3,"file":"is-authorized-fetch-externalities.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/transition/externalities/is-authorized-fetch-externalities.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAG9C,qBAAa,8BAA+B,YAAW,OAAO,CAAC,kBAAkB;IAI7E,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJzB,QAAQ,CAAC,OAAO,qCAAqC;gBAGlC,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE;QACvB,SAAS,EAAE,SAAS,CAAC;QACrB,iBAAiB,EAAE,SAAS,CAAC;KAC9B;IAGH,SAAS,IAAI,SAAS;IAKtB,WAAW,IAAI,SAAS;IAIxB,iBAAiB,IAAI,SAAS;IAI9B,SAAS,IAAI,SAAS;IAKtB,aAAa,IAAI,SAAS;IAK1B,YAAY,IAAI,SAAS;IAKzB,WAAW,CAAC,SAAS,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAK7C,eAAe,CAAC,SAAS,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;CAGlD"}
@@ -1,41 +0,0 @@
1
- import { BytesBlob } from "#@typeberry/bytes";
2
- import { general } from "#@typeberry/jam-host-calls";
3
- import { getEncodedConstants } from "./fetch-externalities.js";
4
- export class IsAuthorizedFetchExternalities {
5
- chainSpec;
6
- params;
7
- context = general.FetchContext.IsAuthorized;
8
- constructor(chainSpec, params) {
9
- this.chainSpec = chainSpec;
10
- this.params = params;
11
- }
12
- constants() {
13
- return getEncodedConstants(this.chainSpec);
14
- }
15
- // TODO [ToDr] Return encoded work package E(p)
16
- workPackage() {
17
- return BytesBlob.empty();
18
- }
19
- authConfiguration() {
20
- return this.params.authConfiguration;
21
- }
22
- authToken() {
23
- return this.params.authToken;
24
- }
25
- // TODO [ToDr] Return encoded refinement context
26
- refineContext() {
27
- return BytesBlob.empty();
28
- }
29
- // TODO [ToDr] Return encoded work items
30
- allWorkItems() {
31
- return BytesBlob.empty();
32
- }
33
- // TODO [ToDr] Return single work item summary
34
- oneWorkItem(_workItem) {
35
- return null;
36
- }
37
- // TODO [ToDr] Return work item payload
38
- workItemPayload(_workItem) {
39
- return null;
40
- }
41
- }
@@ -1,24 +0,0 @@
1
- import type { EntropyHash } from "#@typeberry/block";
2
- import { BytesBlob } from "#@typeberry/bytes";
3
- import type { ChainSpec } from "#@typeberry/config";
4
- import { general } from "#@typeberry/jam-host-calls";
5
- import type { U64 } from "#@typeberry/numbers";
6
- export declare class RefineFetchExternalities implements general.IRefineFetch {
7
- private readonly chainSpec;
8
- readonly context = general.FetchContext.Refine;
9
- static new(chainSpec: ChainSpec): RefineFetchExternalities;
10
- private constructor();
11
- constants(): BytesBlob;
12
- entropy(): EntropyHash;
13
- authorizerTrace(): BytesBlob;
14
- workItemExtrinsic(_workItem: U64 | null, _index: U64): BytesBlob | null;
15
- workItemImport(_workItem: U64 | null, _index: U64): BytesBlob | null;
16
- workPackage(): BytesBlob;
17
- authConfiguration(): BytesBlob;
18
- authToken(): BytesBlob;
19
- refineContext(): BytesBlob;
20
- allWorkItems(): BytesBlob;
21
- oneWorkItem(_workItem: U64): BytesBlob | null;
22
- workItemPayload(_workItem: U64): BytesBlob | null;
23
- }
24
- //# sourceMappingURL=refine-fetch-externalities.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"refine-fetch-externalities.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/transition/externalities/refine-fetch-externalities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAS,SAAS,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AACpD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,oBAAoB,CAAC;AAG9C,qBAAa,wBAAyB,YAAW,OAAO,CAAC,YAAY;IAO/C,OAAO,CAAC,QAAQ,CAAC,SAAS;IAN9C,QAAQ,CAAC,OAAO,+BAA+B;IAE/C,MAAM,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS;IAI/B,OAAO;IAEP,SAAS,IAAI,SAAS;IAKtB,OAAO,IAAI,WAAW;IAKtB,eAAe,IAAI,SAAS;IAK5B,iBAAiB,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAKvE,cAAc,CAAC,SAAS,EAAE,GAAG,GAAG,IAAI,EAAE,MAAM,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAKpE,WAAW,IAAI,SAAS;IAKxB,iBAAiB,IAAI,SAAS;IAK9B,SAAS,IAAI,SAAS;IAKtB,aAAa,IAAI,SAAS;IAK1B,YAAY,IAAI,SAAS;IAIzB,WAAW,CAAC,SAAS,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;IAI7C,eAAe,CAAC,SAAS,EAAE,GAAG,GAAG,SAAS,GAAG,IAAI;CAGlD"}
@@ -1,59 +0,0 @@
1
- import { Bytes, BytesBlob } from "#@typeberry/bytes";
2
- import { HASH_SIZE } from "#@typeberry/hash";
3
- import { general } from "#@typeberry/jam-host-calls";
4
- import { getEncodedConstants } from "./fetch-externalities.js";
5
- export class RefineFetchExternalities {
6
- chainSpec;
7
- context = general.FetchContext.Refine;
8
- static new(chainSpec) {
9
- return new RefineFetchExternalities(chainSpec);
10
- }
11
- constructor(chainSpec) {
12
- this.chainSpec = chainSpec;
13
- }
14
- constants() {
15
- return getEncodedConstants(this.chainSpec);
16
- }
17
- // Returns H₀ (zero hash)
18
- entropy() {
19
- return Bytes.zero(HASH_SIZE).asOpaque();
20
- }
21
- // TODO [ToDr] implement
22
- authorizerTrace() {
23
- return BytesBlob.empty();
24
- }
25
- // TODO [ToDr] implement
26
- workItemExtrinsic(_workItem, _index) {
27
- return null;
28
- }
29
- // TODO [ToDr] implement
30
- workItemImport(_workItem, _index) {
31
- return null;
32
- }
33
- // TODO [ToDr] implement
34
- workPackage() {
35
- return BytesBlob.empty();
36
- }
37
- // TODO [ToDr] implement
38
- authConfiguration() {
39
- return BytesBlob.empty();
40
- }
41
- // TODO [ToDr] implement
42
- authToken() {
43
- return BytesBlob.empty();
44
- }
45
- // TODO [ToDr] implement
46
- refineContext() {
47
- return BytesBlob.empty();
48
- }
49
- // TODO [ToDr] implement
50
- allWorkItems() {
51
- return BytesBlob.empty();
52
- }
53
- oneWorkItem(_workItem) {
54
- return null;
55
- }
56
- workItemPayload(_workItem) {
57
- return null;
58
- }
59
- }
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=refine-fetch-externalities.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"refine-fetch-externalities.test.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/transition/externalities/refine-fetch-externalities.test.ts"],"names":[],"mappings":""}
@@ -1,32 +0,0 @@
1
- import assert from "node:assert";
2
- import { describe, it } from "node:test";
3
- import { fullChainSpec, tinyChainSpec } from "#@typeberry/config";
4
- import { RefineFetchExternalities } from "./refine-fetch-externalities.js";
5
- describe("RefineFetchExternalities", () => {
6
- const prepareRefineData = ({ chainSpec } = {}) => {
7
- const defaultChainSpec = tinyChainSpec;
8
- return RefineFetchExternalities.new(chainSpec ?? defaultChainSpec);
9
- };
10
- it("should return different constants for different chain specs", () => {
11
- const tinyFetchExternalities = prepareRefineData({ chainSpec: tinyChainSpec });
12
- const fullFetchExternalities = prepareRefineData({ chainSpec: fullChainSpec });
13
- const tinyConstants = tinyFetchExternalities.constants();
14
- const fullConstants = fullFetchExternalities.constants();
15
- assert.notStrictEqual(tinyConstants.length, 0);
16
- assert.notStrictEqual(fullConstants.length, 0);
17
- assert.notDeepStrictEqual(tinyConstants, fullConstants);
18
- });
19
- // Pending implementation — these should assert against real fixture values once
20
- // RefineFetchExternalities accepts and exposes the required refine inputs.
21
- it.todo("should return entropy (H₀ header hash of anchor block)");
22
- it.todo("should return authorizer trace");
23
- it.todo("should return work item extrinsic");
24
- it.todo("should return work item import");
25
- it.todo("should return work package");
26
- it.todo("should return authorizer");
27
- it.todo("should return authorization token");
28
- it.todo("should return refine context");
29
- it.todo("should return all work items");
30
- it.todo("should return one work item");
31
- it.todo("should return work item payload");
32
- });