@typeberry/lib 0.5.3 → 0.5.4-472e282
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/package.json +8 -4
- package/packages/core/hash/hash.d.ts.map +1 -1
- package/packages/core/hash/hash.js +1 -0
- package/packages/core/networking/certificate.d.ts.map +1 -1
- package/packages/core/networking/certificate.js +1 -0
- package/packages/core/networking/package.json +1 -1
- package/packages/core/networking/setup.d.ts.map +1 -1
- package/packages/core/networking/setup.js +16 -12
- package/packages/core/numbers/index.d.ts +4 -0
- package/packages/core/numbers/index.d.ts.map +1 -1
- package/packages/core/numbers/index.js +4 -4
- package/packages/core/pvm-host-calls/host-calls-executor.d.ts +23 -17
- package/packages/core/pvm-host-calls/host-calls-executor.d.ts.map +1 -1
- package/packages/core/pvm-host-calls/host-calls-executor.js +23 -31
- package/packages/core/pvm-interpreter/ops/math-consts.d.ts +2 -3
- package/packages/core/pvm-interpreter/ops/math-consts.d.ts.map +1 -1
- package/packages/core/pvm-interpreter/ops/math-consts.js +2 -3
- package/packages/core/pvm-interpreter/ops/math-ops.js +3 -3
- package/packages/core/pvm-interpreter/ops/math-utils.js +13 -13
- package/packages/core/pvm-interpreter/ops/math-utils.test.js +17 -16
- package/packages/core/telemetry/package.json +1 -1
- package/packages/core/utils/compatibility.d.ts +0 -1
- package/packages/core/utils/compatibility.d.ts.map +1 -1
- package/packages/core/utils/compatibility.js +1 -2
- package/packages/core/utils/compatibility.test.js +6 -10
- package/packages/extensions/ipc/jamnp/handler.d.ts +5 -4
- package/packages/extensions/ipc/jamnp/handler.d.ts.map +1 -1
- package/packages/extensions/ipc/jamnp/handler.js +59 -34
- package/packages/extensions/ipc/jamnp/stream.d.ts +6 -4
- package/packages/extensions/ipc/jamnp/stream.d.ts.map +1 -1
- package/packages/jam/block/index.d.ts +11 -11
- package/packages/jam/block/index.d.ts.map +1 -1
- package/packages/jam/block/index.js +11 -11
- package/packages/jam/block/work-item.d.ts +13 -4
- package/packages/jam/block/work-item.d.ts.map +1 -1
- package/packages/jam/block/work-package.d.ts +3 -1
- package/packages/jam/block/work-package.d.ts.map +1 -1
- package/packages/jam/block/work-package.js +6 -2
- package/packages/jam/block/work-result.d.ts +3 -5
- package/packages/jam/block/work-result.d.ts.map +1 -1
- package/packages/jam/block/work-result.js +6 -0
- package/packages/jam/block-json/block.d.ts +125 -0
- package/packages/jam/block-json/block.d.ts.map +1 -1
- package/packages/jam/block-json/block.js +9 -2
- package/packages/jam/block-json/work-result.d.ts.map +1 -1
- package/packages/jam/block-json/work-result.js +6 -6
- package/packages/jam/database-lmdb/states.test.js +2 -3
- package/packages/jam/executor/index.d.ts +4 -0
- package/packages/jam/executor/index.d.ts.map +1 -0
- package/packages/jam/executor/index.js +2 -0
- package/packages/jam/{transition/accumulate → executor}/pvm-executor.d.ts +19 -16
- package/packages/jam/executor/pvm-executor.d.ts.map +1 -0
- package/packages/jam/{transition/accumulate → executor}/pvm-executor.js +46 -3
- package/packages/jam/fuzz-proto/v1/handler.d.ts +1 -1
- package/packages/jam/fuzz-proto/v1/handler.d.ts.map +1 -1
- package/packages/jam/fuzz-proto/v1/handler.js +43 -19
- package/packages/jam/fuzz-proto/v1/types.d.ts +1 -1
- package/packages/jam/in-core/externalities/refine.d.ts +24 -0
- package/packages/jam/in-core/externalities/refine.d.ts.map +1 -0
- package/packages/jam/in-core/externalities/refine.js +36 -0
- package/packages/jam/in-core/in-core.d.ts +60 -0
- package/packages/jam/in-core/in-core.d.ts.map +1 -0
- package/packages/jam/in-core/in-core.js +294 -0
- package/packages/jam/in-core/in-core.test.d.ts +2 -0
- package/packages/jam/in-core/in-core.test.d.ts.map +1 -0
- package/packages/jam/in-core/in-core.test.js +81 -0
- package/packages/jam/in-core/index.d.ts +2 -0
- package/packages/jam/in-core/index.d.ts.map +1 -0
- package/packages/jam/in-core/index.js +1 -0
- package/packages/jam/jam-host-calls/accumulate/bless.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/bless.js +6 -10
- package/packages/jam/jam-host-calls/accumulate/bless.test.js +32 -73
- package/packages/jam/jam-host-calls/accumulate/new.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/accumulate/new.js +2 -4
- package/packages/jam/jam-host-calls/accumulate/new.test.js +4 -5
- package/packages/jam/jam-host-calls/general/fetch.d.ts +1 -57
- package/packages/jam/jam-host-calls/general/fetch.d.ts.map +1 -1
- package/packages/jam/jam-host-calls/general/fetch.js +6 -29
- package/packages/jam/jam-host-calls/general/fetch.test.js +2 -58
- package/packages/jam/jamnp-s/peers.d.ts.map +1 -1
- package/packages/jam/jamnp-s/peers.js +10 -0
- package/packages/jam/jamnp-s/protocol/ce-128-block-request.d.ts +1 -1
- package/packages/jam/jamnp-s/protocol/ce-128-block-request.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-128-block-request.js +10 -8
- package/packages/jam/jamnp-s/protocol/ce-129-state-request.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-129-state-request.js +11 -9
- package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.d.ts +3 -3
- package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.js +2 -2
- package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts +9 -9
- package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.js +2 -2
- package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.js +8 -6
- package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts +16 -16
- package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.js +2 -2
- package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.test.js +2 -2
- package/packages/jam/jamnp-s/protocol/stream.d.ts +13 -7
- package/packages/jam/jamnp-s/protocol/stream.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/stream.js +5 -4
- package/packages/jam/jamnp-s/protocol/test-utils.d.ts +1 -1
- package/packages/jam/jamnp-s/protocol/test-utils.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/test-utils.js +9 -12
- package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts +2 -2
- package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts.map +1 -1
- package/packages/jam/jamnp-s/protocol/up-0-block-announcement.js +1 -1
- package/packages/jam/jamnp-s/stream-manager.d.ts.map +1 -1
- package/packages/jam/jamnp-s/stream-manager.js +7 -5
- package/packages/jam/jamnp-s/stream-manager.test.js +8 -5
- package/packages/jam/jamnp-s/tasks/sync.js +1 -1
- package/packages/jam/node/jam-config.d.ts +4 -1
- package/packages/jam/node/jam-config.d.ts.map +1 -1
- package/packages/jam/node/jam-config.js +6 -2
- package/packages/jam/node/main.d.ts.map +1 -1
- package/packages/jam/node/main.js +5 -4
- package/packages/jam/node/package.json +1 -1
- package/packages/jam/node/reader.d.ts +25 -25
- package/packages/jam/node/workers.d.ts +183 -183
- package/packages/jam/rpc-validation/types.d.ts +7 -3
- package/packages/jam/rpc-validation/types.d.ts.map +1 -1
- package/packages/jam/rpc-validation/validation.d.ts +254 -36
- package/packages/jam/rpc-validation/validation.d.ts.map +1 -1
- package/packages/jam/rpc-validation/validation.js +20 -2
- package/packages/jam/state/accumulation-queue.d.ts +26 -26
- package/packages/jam/state/assurances.d.ts +26 -26
- package/packages/jam/state/in-memory-state.d.ts.map +1 -1
- package/packages/jam/state/in-memory-state.js +2 -3
- package/packages/jam/state/privileged-services.d.ts +1 -1
- package/packages/jam/state/privileged-services.d.ts.map +1 -1
- package/packages/jam/state/privileged-services.js +1 -6
- package/packages/jam/state/service.d.ts +1 -1
- package/packages/jam/state/service.d.ts.map +1 -1
- package/packages/jam/state/statistics.d.ts +0 -8
- package/packages/jam/state/statistics.d.ts.map +1 -1
- package/packages/jam/state/statistics.js +14 -44
- package/packages/jam/state/statistics.test.js +1 -8
- package/packages/jam/state/test.utils.d.ts +1 -1
- package/packages/jam/state/test.utils.d.ts.map +1 -1
- package/packages/jam/state/test.utils.js +6 -25
- package/packages/jam/state-json/accounts.d.ts +10 -0
- package/packages/jam/state-json/accounts.d.ts.map +1 -1
- package/packages/jam/state-json/accounts.js +47 -19
- package/packages/jam/state-json/dump.d.ts.map +1 -1
- package/packages/jam/state-json/dump.js +5 -9
- package/packages/jam/state-json/dump.test.js +2 -10
- package/packages/jam/state-json/statistics.d.ts +1 -1
- package/packages/jam/state-json/statistics.d.ts.map +1 -1
- package/packages/jam/state-json/statistics.js +1 -13
- package/packages/jam/state-merkleization/in-memory-state-codec.d.ts +29 -31
- package/packages/jam/state-merkleization/in-memory-state-codec.d.ts.map +1 -1
- package/packages/jam/state-merkleization/serialize.d.ts +4 -4
- package/packages/jam/state-merkleization/serialize.d.ts.map +1 -1
- package/packages/jam/state-merkleization/serialize.js +5 -8
- package/packages/jam/state-merkleization/serialized-state-view.d.ts.map +1 -1
- package/packages/jam/state-merkleization/state-entries.test.js +1 -7
- package/packages/jam/state-vectors/index.d.ts +377 -5
- package/packages/jam/state-vectors/index.d.ts.map +1 -1
- package/packages/jam/state-vectors/index.js +3 -3
- package/packages/jam/transition/accumulate/accumulate-data.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate-data.js +1 -2
- package/packages/jam/transition/accumulate/accumulate-queue.test.js +2 -2
- package/packages/jam/transition/accumulate/accumulate-state.d.ts +1 -2
- package/packages/jam/transition/accumulate/accumulate-state.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate-utils.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate-utils.js +2 -6
- package/packages/jam/transition/accumulate/accumulate-utils.test.js +4 -6
- package/packages/jam/transition/accumulate/accumulate.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulate.js +19 -33
- package/packages/jam/transition/accumulate/accumulate.test.js +2 -2
- package/packages/jam/transition/accumulate/accumulation-result-merge-utils.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/accumulation-result-merge-utils.js +1 -2
- package/packages/jam/transition/accumulate/accumulation-result-merge-utils.test.js +1 -2
- package/packages/jam/transition/accumulate/index.d.ts +0 -1
- package/packages/jam/transition/accumulate/index.d.ts.map +1 -1
- package/packages/jam/transition/accumulate/index.js +0 -1
- package/packages/jam/transition/accumulate/operand.d.ts +7 -7
- package/packages/jam/transition/chain-stf.d.ts +3 -5
- package/packages/jam/transition/chain-stf.d.ts.map +1 -1
- package/packages/jam/transition/chain-stf.js +5 -29
- package/packages/jam/transition/disputes/disputes.test.data2.d.ts +3 -3
- package/packages/jam/transition/disputes/disputes.test.data2.d.ts.map +1 -1
- package/packages/jam/transition/disputes/disputes.test.data2.js +2 -2
- package/packages/jam/transition/externalities/accumulate-externalities.d.ts.map +1 -1
- package/packages/jam/transition/externalities/accumulate-externalities.js +22 -49
- package/packages/jam/transition/externalities/accumulate-externalities.test.js +8 -72
- package/packages/jam/transition/externalities/fetch-externalities.d.ts +8 -21
- package/packages/jam/transition/externalities/fetch-externalities.d.ts.map +1 -1
- package/packages/jam/transition/externalities/fetch-externalities.js +5 -53
- package/packages/jam/transition/externalities/fetch-externalities.test.js +201 -114
- package/packages/jam/transition/hasher.test.js +2 -2
- package/packages/jam/transition/reports/error.d.ts +3 -1
- package/packages/jam/transition/reports/error.d.ts.map +1 -1
- package/packages/jam/transition/reports/error.js +2 -0
- package/packages/jam/transition/reports/test.utils.d.ts.map +1 -1
- package/packages/jam/transition/reports/test.utils.js +2 -2
- package/packages/jam/transition/reports/verify-basic.d.ts.map +1 -1
- package/packages/jam/transition/reports/verify-basic.js +10 -0
- package/packages/jam/transition/reports/verify-basic.test.js +29 -0
- package/packages/jam/transition/statistics.d.ts +0 -7
- package/packages/jam/transition/statistics.d.ts.map +1 -1
- package/packages/jam/transition/statistics.js +2 -11
- package/packages/jam/transition/statistics.test.js +0 -40
- package/packages/workers/block-authorship/generator.test.d.ts +2 -0
- package/packages/workers/block-authorship/generator.test.d.ts.map +1 -0
- package/packages/workers/block-authorship/generator.test.js +200 -0
- package/packages/workers/block-authorship/main.d.ts.map +1 -1
- package/packages/workers/block-authorship/main.js +23 -4
- package/packages/workers/block-authorship/package.json +1 -1
- package/packages/workers/block-authorship/protocol.d.ts +53 -51
- package/packages/workers/block-authorship/protocol.d.ts.map +1 -1
- package/packages/workers/block-authorship/protocol.js +6 -3
- package/packages/workers/importer/importer.d.ts.map +1 -1
- package/packages/workers/importer/importer.js +0 -1
- package/packages/workers/importer/package.json +1 -1
- package/packages/workers/importer/protocol.d.ts +54 -54
- package/packages/workers/jam-network/protocol.d.ts +79 -79
- package/packages/jam/transition/accumulate/deferred-transfers.d.ts +0 -36
- package/packages/jam/transition/accumulate/deferred-transfers.d.ts.map +0 -1
- package/packages/jam/transition/accumulate/deferred-transfers.js +0 -95
- package/packages/jam/transition/accumulate/pvm-executor.d.ts.map +0 -1
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type CoreIndex, type Segment, type SegmentIndex, type ServiceGas } from "#@typeberry/block";
|
|
2
|
+
import { type WorkPackageHash } from "#@typeberry/block/refine-context.js";
|
|
3
|
+
import type { WorkItemExtrinsic } from "#@typeberry/block/work-item.js";
|
|
4
|
+
import type { WorkPackage } from "#@typeberry/block/work-package.js";
|
|
5
|
+
import { WorkReport } from "#@typeberry/block/work-report.js";
|
|
6
|
+
import { WorkExecResult, WorkResult } from "#@typeberry/block/work-result.js";
|
|
7
|
+
import { type KnownSizeArray } from "#@typeberry/collections";
|
|
8
|
+
import type { ChainSpec, PvmBackend } from "#@typeberry/config";
|
|
9
|
+
import type { StatesDb } from "#@typeberry/database";
|
|
10
|
+
import { type ReturnValue } from "#@typeberry/executor";
|
|
11
|
+
import { type Blake2b, type WithHash } from "#@typeberry/hash";
|
|
12
|
+
import { Result } from "#@typeberry/utils";
|
|
13
|
+
export type RefineResult = {
|
|
14
|
+
report: WorkReport;
|
|
15
|
+
exports: PerWorkItem<Segment[]>;
|
|
16
|
+
};
|
|
17
|
+
export type RefineItemResult = {
|
|
18
|
+
result: WorkResult;
|
|
19
|
+
exports: Segment[];
|
|
20
|
+
};
|
|
21
|
+
export declare enum RefineError {
|
|
22
|
+
/** State for context anchor block or lookup anchor is not found in the DB. */
|
|
23
|
+
StateMissing = 0,
|
|
24
|
+
/** Posterior state root of context anchor block does not match the one in the DB. */
|
|
25
|
+
StateRootMismatch = 1,
|
|
26
|
+
/** Lookup anchor state-slot does not match the one given in context. */
|
|
27
|
+
InvalidLookupAnchorSlot = 2,
|
|
28
|
+
/** Authorization error. */
|
|
29
|
+
AuthorizationError = 3
|
|
30
|
+
}
|
|
31
|
+
export type PerWorkItem<T> = KnownSizeArray<T, "for each work item">;
|
|
32
|
+
export type ImportedSegment = {
|
|
33
|
+
index: SegmentIndex;
|
|
34
|
+
data: Segment;
|
|
35
|
+
};
|
|
36
|
+
export declare class InCore {
|
|
37
|
+
readonly chainSpec: ChainSpec;
|
|
38
|
+
private readonly states;
|
|
39
|
+
private readonly pvmBackend;
|
|
40
|
+
private readonly blake2b;
|
|
41
|
+
constructor(chainSpec: ChainSpec, states: StatesDb, pvmBackend: PvmBackend, blake2b: Blake2b);
|
|
42
|
+
/**
|
|
43
|
+
* Work-report computation function.
|
|
44
|
+
*
|
|
45
|
+
* Note this requires all of the imports and extrinsics to be already fetched
|
|
46
|
+
* and only performs the refinement.
|
|
47
|
+
*
|
|
48
|
+
* Any validation must be done externally!
|
|
49
|
+
*
|
|
50
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/1b7f021b7f02?v=0.7.2
|
|
51
|
+
*/
|
|
52
|
+
refine(workPackageAndHash: WithHash<WorkPackageHash, WorkPackage>, core: CoreIndex, imports: PerWorkItem<ImportedSegment[]>, extrinsics: PerWorkItem<WorkItemExtrinsic[]>): Promise<Result<RefineResult, RefineError>>;
|
|
53
|
+
private amalgamateWorkReport;
|
|
54
|
+
private authorizePackage;
|
|
55
|
+
private refineItem;
|
|
56
|
+
extractWorkResult(execResult: ReturnValue<ServiceGas>): WorkExecResult;
|
|
57
|
+
private getServiceCode;
|
|
58
|
+
private createRefineExternalities;
|
|
59
|
+
}
|
|
60
|
+
//# sourceMappingURL=in-core.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-core.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/in-core/in-core.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,OAAO,EACZ,KAAK,YAAY,EACjB,KAAK,UAAU,EAIhB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EAGL,KAAK,eAAe,EAErB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAY,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AACpE,OAAO,EAAmB,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC9E,OAAO,EAAE,cAAc,EAAsC,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAGjH,OAAO,EAA+B,KAAK,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC1F,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAA+D,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AACpH,OAAO,EAAE,KAAK,OAAO,EAAa,KAAK,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAKzE,OAAO,EAA4B,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAGpE,MAAM,MAAM,YAAY,GAAG;IACzB,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,WAAW,CAAC,OAAO,EAAE,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,UAAU,CAAC;IACnB,OAAO,EAAE,OAAO,EAAE,CAAC;CACpB,CAAC;AAEF,oBAAY,WAAW;IACrB,8EAA8E;IAC9E,YAAY,IAAI;IAChB,qFAAqF;IACrF,iBAAiB,IAAI;IACrB,wEAAwE;IACxE,uBAAuB,IAAI;IAC3B,2BAA2B;IAC3B,kBAAkB,IAAI;CACvB;AAqBD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,EAAE,oBAAoB,CAAC,CAAC;AAErE,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,YAAY,CAAC;IACpB,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAgBF,qBAAa,MAAM;aAEC,SAAS,EAAE,SAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBAHR,SAAS,EAAE,SAAS,EACnB,MAAM,EAAE,QAAQ,EAChB,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE,OAAO;IAGnC;;;;;;;;;OASG;IACG,MAAM,CACV,kBAAkB,EAAE,QAAQ,CAAC,eAAe,EAAE,WAAW,CAAC,EAC1D,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,WAAW,CAAC,eAAe,EAAE,CAAC,EACvC,UAAU,EAAE,WAAW,CAAC,iBAAiB,EAAE,CAAC,GAC3C,OAAO,CAAC,MAAM,CAAC,YAAY,EAAE,WAAW,CAAC,CAAC;IAmE7C,OAAO,CAAC,oBAAoB;YAuDd,gBAAgB;YAkBhB,UAAU;IAgGxB,iBAAiB,CAAC,UAAU,EAAE,WAAW,CAAC,UAAU,CAAC;IAiBrD,OAAO,CAAC,cAAc;IAyCtB,OAAO,CAAC,yBAAyB;CAoBlC"}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { tryAsCoreIndex, tryAsServiceGas, } from "#@typeberry/block";
|
|
2
|
+
import { W_C } from "#@typeberry/block/gp-constants.js";
|
|
3
|
+
import { WorkPackageInfo, } from "#@typeberry/block/refine-context.js";
|
|
4
|
+
import { WorkPackageSpec, WorkReport } from "#@typeberry/block/work-report.js";
|
|
5
|
+
import { WorkExecResult, WorkExecResultKind, WorkRefineLoad, WorkResult } from "#@typeberry/block/work-result.js";
|
|
6
|
+
import { Bytes, BytesBlob } from "#@typeberry/bytes";
|
|
7
|
+
import { codec, Encoder } from "#@typeberry/codec";
|
|
8
|
+
import { asKnownSize, FixedSizeArray } from "#@typeberry/collections";
|
|
9
|
+
import { PvmExecutor, ReturnStatus } from "#@typeberry/executor";
|
|
10
|
+
import { HASH_SIZE } from "#@typeberry/hash";
|
|
11
|
+
import { Logger } from "#@typeberry/logger";
|
|
12
|
+
import { tryAsU8, tryAsU16, tryAsU32 } from "#@typeberry/numbers";
|
|
13
|
+
import { FetchExternalities } from "#@typeberry/transition/externalities/fetch-externalities.js";
|
|
14
|
+
import { assertEmpty, assertNever, Result } from "#@typeberry/utils";
|
|
15
|
+
import { RefineExternalitiesImpl } from "./externalities/refine.js";
|
|
16
|
+
export var RefineError;
|
|
17
|
+
(function (RefineError) {
|
|
18
|
+
/** State for context anchor block or lookup anchor is not found in the DB. */
|
|
19
|
+
RefineError[RefineError["StateMissing"] = 0] = "StateMissing";
|
|
20
|
+
/** Posterior state root of context anchor block does not match the one in the DB. */
|
|
21
|
+
RefineError[RefineError["StateRootMismatch"] = 1] = "StateRootMismatch";
|
|
22
|
+
/** Lookup anchor state-slot does not match the one given in context. */
|
|
23
|
+
RefineError[RefineError["InvalidLookupAnchorSlot"] = 2] = "InvalidLookupAnchorSlot";
|
|
24
|
+
/** Authorization error. */
|
|
25
|
+
RefineError[RefineError["AuthorizationError"] = 3] = "AuthorizationError";
|
|
26
|
+
})(RefineError || (RefineError = {}));
|
|
27
|
+
var ServiceCodeError;
|
|
28
|
+
(function (ServiceCodeError) {
|
|
29
|
+
/** Service id is not found in the state. */
|
|
30
|
+
ServiceCodeError[ServiceCodeError["ServiceNotFound"] = 0] = "ServiceNotFound";
|
|
31
|
+
/** Expected service code does not match the state one. */
|
|
32
|
+
ServiceCodeError[ServiceCodeError["ServiceCodeMismatch"] = 1] = "ServiceCodeMismatch";
|
|
33
|
+
/** Code preimage missing. */
|
|
34
|
+
ServiceCodeError[ServiceCodeError["ServiceCodeMissing"] = 2] = "ServiceCodeMissing";
|
|
35
|
+
/** Code blob is too big. */
|
|
36
|
+
ServiceCodeError[ServiceCodeError["ServiceCodeTooBig"] = 3] = "ServiceCodeTooBig";
|
|
37
|
+
})(ServiceCodeError || (ServiceCodeError = {}));
|
|
38
|
+
var AuthorizationError;
|
|
39
|
+
(function (AuthorizationError) {
|
|
40
|
+
})(AuthorizationError || (AuthorizationError = {}));
|
|
41
|
+
const logger = Logger.new(import.meta.filename, "refine");
|
|
42
|
+
/** https://graypaper.fluffylabs.dev/#/ab2cdbd/2ffe002ffe00?v=0.7.2 */
|
|
43
|
+
const ARGS_CODEC = codec.object({
|
|
44
|
+
core: codec.varU32.convert((x) => tryAsU32(x), (x) => tryAsCoreIndex(x)),
|
|
45
|
+
workItemIndex: codec.varU32,
|
|
46
|
+
serviceId: codec.varU32.asOpaque(),
|
|
47
|
+
payloadLength: codec.varU32,
|
|
48
|
+
packageHash: codec.bytes(HASH_SIZE).asOpaque(),
|
|
49
|
+
});
|
|
50
|
+
export class InCore {
|
|
51
|
+
chainSpec;
|
|
52
|
+
states;
|
|
53
|
+
pvmBackend;
|
|
54
|
+
blake2b;
|
|
55
|
+
constructor(chainSpec, states, pvmBackend, blake2b) {
|
|
56
|
+
this.chainSpec = chainSpec;
|
|
57
|
+
this.states = states;
|
|
58
|
+
this.pvmBackend = pvmBackend;
|
|
59
|
+
this.blake2b = blake2b;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Work-report computation function.
|
|
63
|
+
*
|
|
64
|
+
* Note this requires all of the imports and extrinsics to be already fetched
|
|
65
|
+
* and only performs the refinement.
|
|
66
|
+
*
|
|
67
|
+
* Any validation must be done externally!
|
|
68
|
+
*
|
|
69
|
+
* https://graypaper.fluffylabs.dev/#/ab2cdbd/1b7f021b7f02?v=0.7.2
|
|
70
|
+
*/
|
|
71
|
+
async refine(workPackageAndHash, core, imports, extrinsics) {
|
|
72
|
+
const workPackageHash = workPackageAndHash.hash;
|
|
73
|
+
const { context, authorization, authCodeHash, authCodeHost, parametrization, items, ...rest } = workPackageAndHash.data;
|
|
74
|
+
assertEmpty(rest);
|
|
75
|
+
// TODO [ToDr] Verify BEEFY root
|
|
76
|
+
// TODO [ToDr] Verify prerequisites
|
|
77
|
+
logger.log `[core:${core}] Attempting to refine work package with ${items.length} items.`;
|
|
78
|
+
// TODO [ToDr] GP link
|
|
79
|
+
// Verify anchor block
|
|
80
|
+
const state = this.states.getState(context.anchor);
|
|
81
|
+
if (state === null) {
|
|
82
|
+
return Result.error(RefineError.StateMissing, () => `State at anchor block ${context.anchor} is missing.`);
|
|
83
|
+
}
|
|
84
|
+
const stateRoot = await this.states.getStateRoot(state);
|
|
85
|
+
if (!stateRoot.isEqualTo(context.stateRoot)) {
|
|
86
|
+
return Result.error(RefineError.StateRootMismatch, () => `State at ${context.anchor} does not match expected root hash. Ours: ${stateRoot}, expected: ${context.stateRoot}`);
|
|
87
|
+
}
|
|
88
|
+
// TODO [ToDr] GP link
|
|
89
|
+
// Verify lookup anchor state
|
|
90
|
+
const lookupState = this.states.getState(context.lookupAnchor);
|
|
91
|
+
if (lookupState === null) {
|
|
92
|
+
return Result.error(RefineError.StateMissing, () => `Lookup state at block ${context.lookupAnchor} is missing.`);
|
|
93
|
+
}
|
|
94
|
+
// TODO [ToDr] GP link
|
|
95
|
+
if (lookupState.timeslot !== context.lookupAnchorSlot) {
|
|
96
|
+
return Result.error(RefineError.InvalidLookupAnchorSlot, () => `Lookup anchor slot does not match the one is state. Ours: ${lookupState.timeslot}, expected: ${context.lookupAnchorSlot}`);
|
|
97
|
+
}
|
|
98
|
+
// Check authorization
|
|
99
|
+
const authResult = await this.authorizePackage(authorization, authCodeHost, authCodeHash, parametrization);
|
|
100
|
+
if (authResult.isError) {
|
|
101
|
+
return Result.error(RefineError.AuthorizationError, () => `Authorization error: ${AuthorizationError[authResult.error]}: ${authResult.details()}.`);
|
|
102
|
+
}
|
|
103
|
+
logger.log `[core:${core}] Authorized. Proceeding with work items verification. Anchor=${context.anchor}`;
|
|
104
|
+
// Verify the work items
|
|
105
|
+
const refineResults = [];
|
|
106
|
+
for (const [idx, item] of items.entries()) {
|
|
107
|
+
logger.info `[core:${core}][i:${idx}] Refining item for service ${item.service}.`;
|
|
108
|
+
refineResults.push(await this.refineItem(state, idx, item, imports, extrinsics, core, workPackageHash));
|
|
109
|
+
}
|
|
110
|
+
// amalgamate the work report now
|
|
111
|
+
return Result.ok(this.amalgamateWorkReport(asKnownSize(refineResults), authResult.ok, workPackageHash, context, core));
|
|
112
|
+
}
|
|
113
|
+
amalgamateWorkReport(refineResults, authResult, workPackageHash, context, coreIndex) {
|
|
114
|
+
// unzip exports and work results for each work item
|
|
115
|
+
const exports = refineResults.map((x) => x.exports);
|
|
116
|
+
const results = refineResults.map((x) => x.result);
|
|
117
|
+
const { authorizerHash, authorizationGasUsed, authorizationOutput, ...authRest } = authResult;
|
|
118
|
+
assertEmpty(authRest);
|
|
119
|
+
// TODO [ToDr] Compute erasure root
|
|
120
|
+
const erasureRoot = Bytes.zero(HASH_SIZE);
|
|
121
|
+
// TODO [ToDr] Compute exports root
|
|
122
|
+
const exportsRoot = Bytes.zero(HASH_SIZE).asOpaque();
|
|
123
|
+
const exportsCount = exports.reduce((acc, x) => acc + x.length, 0);
|
|
124
|
+
// TODO [ToDr] Segment root lookup computation?
|
|
125
|
+
const segmentRootLookup = [
|
|
126
|
+
WorkPackageInfo.create({
|
|
127
|
+
workPackageHash,
|
|
128
|
+
segmentTreeRoot: exportsRoot,
|
|
129
|
+
}),
|
|
130
|
+
];
|
|
131
|
+
// TODO [ToDr] Auditable work bundle length?
|
|
132
|
+
const workBundleLength = tryAsU32(0);
|
|
133
|
+
return {
|
|
134
|
+
report: WorkReport.create({
|
|
135
|
+
workPackageSpec: WorkPackageSpec.create({
|
|
136
|
+
length: workBundleLength,
|
|
137
|
+
hash: workPackageHash,
|
|
138
|
+
erasureRoot,
|
|
139
|
+
exportsRoot,
|
|
140
|
+
// safe to convert, since we have limit on number of
|
|
141
|
+
// exports per item and a limit for number of items
|
|
142
|
+
exportsCount: tryAsU16(exportsCount),
|
|
143
|
+
}),
|
|
144
|
+
context,
|
|
145
|
+
coreIndex,
|
|
146
|
+
authorizerHash,
|
|
147
|
+
authorizationGasUsed,
|
|
148
|
+
authorizationOutput,
|
|
149
|
+
segmentRootLookup,
|
|
150
|
+
// safe to convert, since we know that number of work items is limited
|
|
151
|
+
results: FixedSizeArray.new(results, tryAsU8(refineResults.length)),
|
|
152
|
+
}),
|
|
153
|
+
exports: asKnownSize(exports),
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
async authorizePackage(_authorization, _authCodeHost, _authCodeHash, _parametrization) {
|
|
157
|
+
// TODO [ToDr] Check authorization?
|
|
158
|
+
const authorizerHash = Bytes.zero(HASH_SIZE).asOpaque();
|
|
159
|
+
const authorizationGasUsed = tryAsServiceGas(0);
|
|
160
|
+
const authorizationOutput = BytesBlob.empty();
|
|
161
|
+
return Result.ok({
|
|
162
|
+
authorizerHash,
|
|
163
|
+
authorizationGasUsed,
|
|
164
|
+
authorizationOutput,
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
async refineItem(state, idx, item, allImports, allExtrinsics, coreIndex, workPackageHash) {
|
|
168
|
+
const payloadHash = this.blake2b.hashBytes(item.payload);
|
|
169
|
+
const baseResult = {
|
|
170
|
+
serviceId: item.service,
|
|
171
|
+
codeHash: item.codeHash,
|
|
172
|
+
payloadHash,
|
|
173
|
+
gas: item.refineGasLimit,
|
|
174
|
+
};
|
|
175
|
+
const imports = allImports[idx];
|
|
176
|
+
const extrinsics = allExtrinsics[idx];
|
|
177
|
+
const baseLoad = {
|
|
178
|
+
importedSegments: tryAsU32(imports.length),
|
|
179
|
+
extrinsicCount: tryAsU32(extrinsics.length),
|
|
180
|
+
extrinsicSize: tryAsU32(extrinsics.reduce((acc, x) => acc + x.length, 0)),
|
|
181
|
+
};
|
|
182
|
+
const maybeCode = this.getServiceCode(state, idx, item);
|
|
183
|
+
if (maybeCode.isError) {
|
|
184
|
+
const error = maybeCode.error === ServiceCodeError.ServiceCodeTooBig
|
|
185
|
+
? WorkExecResultKind.codeOversize
|
|
186
|
+
: WorkExecResultKind.badCode;
|
|
187
|
+
return {
|
|
188
|
+
exports: [],
|
|
189
|
+
result: WorkResult.create({
|
|
190
|
+
...baseResult,
|
|
191
|
+
result: WorkExecResult.error(error),
|
|
192
|
+
load: WorkRefineLoad.create({
|
|
193
|
+
...baseLoad,
|
|
194
|
+
gasUsed: tryAsServiceGas(item.refineGasLimit),
|
|
195
|
+
exportedSegments: tryAsU32(0),
|
|
196
|
+
}),
|
|
197
|
+
}),
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const code = maybeCode.ok;
|
|
201
|
+
const externalities = this.createRefineExternalities({
|
|
202
|
+
payload: item.payload,
|
|
203
|
+
imports: allImports,
|
|
204
|
+
extrinsics: allExtrinsics,
|
|
205
|
+
});
|
|
206
|
+
const executor = await PvmExecutor.createRefineExecutor(item.service, code, externalities, this.pvmBackend);
|
|
207
|
+
const args = Encoder.encodeObject(ARGS_CODEC, {
|
|
208
|
+
serviceId: item.service,
|
|
209
|
+
core: coreIndex,
|
|
210
|
+
workItemIndex: tryAsU32(idx),
|
|
211
|
+
payloadLength: tryAsU32(item.payload.length),
|
|
212
|
+
packageHash: workPackageHash,
|
|
213
|
+
});
|
|
214
|
+
const execResult = await executor.run(args, item.refineGasLimit);
|
|
215
|
+
// TODO [ToDr] get exports from externalities
|
|
216
|
+
const exports = [];
|
|
217
|
+
if (exports.length !== item.exportCount) {
|
|
218
|
+
return {
|
|
219
|
+
exports,
|
|
220
|
+
result: WorkResult.create({
|
|
221
|
+
...baseResult,
|
|
222
|
+
result: WorkExecResult.error(WorkExecResultKind.incorrectNumberOfExports),
|
|
223
|
+
load: WorkRefineLoad.create({
|
|
224
|
+
...baseLoad,
|
|
225
|
+
gasUsed: tryAsServiceGas(item.refineGasLimit),
|
|
226
|
+
exportedSegments: tryAsU32(0),
|
|
227
|
+
}),
|
|
228
|
+
}),
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
const result = this.extractWorkResult(execResult);
|
|
232
|
+
return {
|
|
233
|
+
exports,
|
|
234
|
+
result: WorkResult.create({
|
|
235
|
+
...baseResult,
|
|
236
|
+
result,
|
|
237
|
+
load: WorkRefineLoad.create({
|
|
238
|
+
...baseLoad,
|
|
239
|
+
gasUsed: tryAsServiceGas(execResult.consumedGas),
|
|
240
|
+
exportedSegments: tryAsU32(exports.length),
|
|
241
|
+
}),
|
|
242
|
+
}),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
extractWorkResult(execResult) {
|
|
246
|
+
if (execResult.status === ReturnStatus.OK) {
|
|
247
|
+
const slice = execResult.memorySlice;
|
|
248
|
+
// TODO [ToDr] Verify the output size and change digestTooBig?
|
|
249
|
+
return WorkExecResult.ok(BytesBlob.blobFrom(slice));
|
|
250
|
+
}
|
|
251
|
+
switch (execResult.status) {
|
|
252
|
+
case ReturnStatus.OOG:
|
|
253
|
+
return WorkExecResult.error(WorkExecResultKind.outOfGas);
|
|
254
|
+
case ReturnStatus.PANIC:
|
|
255
|
+
return WorkExecResult.error(WorkExecResultKind.panic);
|
|
256
|
+
default:
|
|
257
|
+
assertNever(execResult);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
getServiceCode(state, idx, item) {
|
|
261
|
+
const serviceId = item.service;
|
|
262
|
+
const service = state.getService(serviceId);
|
|
263
|
+
// TODO [ToDr] GP link
|
|
264
|
+
// missing service
|
|
265
|
+
if (service === null) {
|
|
266
|
+
return Result.error(ServiceCodeError.ServiceNotFound, () => `[i:${idx}] Service ${serviceId} is missing in state.`);
|
|
267
|
+
}
|
|
268
|
+
// TODO [ToDr] GP link
|
|
269
|
+
// TODO [ToDr] shall we rather use the old codehash instead
|
|
270
|
+
if (!service.getInfo().codeHash.isEqualTo(item.codeHash)) {
|
|
271
|
+
return Result.error(ServiceCodeError.ServiceCodeMismatch, () => `[i:${idx}] Service ${serviceId} has invalid code hash. Ours: ${service.getInfo().codeHash}, expected: ${item.codeHash}`);
|
|
272
|
+
}
|
|
273
|
+
const code = service.getPreimage(item.codeHash.asOpaque());
|
|
274
|
+
if (code === null) {
|
|
275
|
+
return Result.error(ServiceCodeError.ServiceCodeMissing, () => `[i:${idx}] Code ${item.codeHash} for service ${serviceId} was not found.`);
|
|
276
|
+
}
|
|
277
|
+
if (code.length > W_C) {
|
|
278
|
+
return Result.error(ServiceCodeError.ServiceCodeTooBig, () => `[i:${idx}] Code ${item.codeHash} for service ${serviceId} is too big! ${code.length} bytes vs ${W_C} bytes max.`);
|
|
279
|
+
}
|
|
280
|
+
return Result.ok(code);
|
|
281
|
+
}
|
|
282
|
+
createRefineExternalities(args) {
|
|
283
|
+
// TODO [ToDr] Pass all required fetch data
|
|
284
|
+
const fetchExternalities = FetchExternalities.createForRefine({
|
|
285
|
+
entropy: undefined,
|
|
286
|
+
...args,
|
|
287
|
+
}, this.chainSpec);
|
|
288
|
+
const refine = RefineExternalitiesImpl.create();
|
|
289
|
+
return {
|
|
290
|
+
fetchExternalities,
|
|
291
|
+
refine,
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"in-core.test.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/in-core/in-core.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { before, describe, it } from "node:test";
|
|
3
|
+
import { tryAsCoreIndex, tryAsServiceGas, tryAsServiceId, tryAsTimeSlot } from "#@typeberry/block";
|
|
4
|
+
import { RefineContext } from "#@typeberry/block/refine-context.js";
|
|
5
|
+
import { WorkItem } from "#@typeberry/block/work-item.js";
|
|
6
|
+
import { tryAsWorkItemsCount, WorkPackage } from "#@typeberry/block/work-package.js";
|
|
7
|
+
import { Bytes, BytesBlob } from "#@typeberry/bytes";
|
|
8
|
+
import { Encoder } from "#@typeberry/codec";
|
|
9
|
+
import { asKnownSize, FixedSizeArray } from "#@typeberry/collections";
|
|
10
|
+
import { PvmBackend, tinyChainSpec } from "#@typeberry/config";
|
|
11
|
+
import { InMemoryStates } from "#@typeberry/database";
|
|
12
|
+
import { Blake2b, HASH_SIZE, WithHash } from "#@typeberry/hash";
|
|
13
|
+
import { tryAsU16 } from "#@typeberry/numbers";
|
|
14
|
+
import { testState } from "#@typeberry/state/test.utils.js";
|
|
15
|
+
import { InCore, RefineError } from "./in-core.js";
|
|
16
|
+
let blake2b;
|
|
17
|
+
before(async () => {
|
|
18
|
+
blake2b = await Blake2b.createHasher();
|
|
19
|
+
});
|
|
20
|
+
function createWorkItem(serviceId = 1) {
|
|
21
|
+
return WorkItem.create({
|
|
22
|
+
service: tryAsServiceId(serviceId),
|
|
23
|
+
codeHash: Bytes.zero(HASH_SIZE).asOpaque(),
|
|
24
|
+
payload: BytesBlob.empty(),
|
|
25
|
+
refineGasLimit: tryAsServiceGas(1_000_000),
|
|
26
|
+
accumulateGasLimit: tryAsServiceGas(1_000_000),
|
|
27
|
+
importSegments: asKnownSize([]),
|
|
28
|
+
extrinsic: [],
|
|
29
|
+
exportCount: tryAsU16(0),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
function createWorkPackage(anchorHash, stateRoot, lookupAnchorSlot = 0) {
|
|
33
|
+
return WorkPackage.create({
|
|
34
|
+
authorization: BytesBlob.empty(),
|
|
35
|
+
authCodeHost: tryAsServiceId(1),
|
|
36
|
+
authCodeHash: Bytes.zero(HASH_SIZE).asOpaque(),
|
|
37
|
+
parametrization: BytesBlob.empty(),
|
|
38
|
+
context: RefineContext.create({
|
|
39
|
+
anchor: anchorHash,
|
|
40
|
+
stateRoot,
|
|
41
|
+
beefyRoot: Bytes.zero(HASH_SIZE).asOpaque(),
|
|
42
|
+
lookupAnchor: anchorHash,
|
|
43
|
+
lookupAnchorSlot: tryAsTimeSlot(lookupAnchorSlot),
|
|
44
|
+
prerequisites: [],
|
|
45
|
+
}),
|
|
46
|
+
items: FixedSizeArray.new([createWorkItem()], tryAsWorkItemsCount(1)),
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function hashWorkPackage(spec, workPackage) {
|
|
50
|
+
const workPackageHash = blake2b
|
|
51
|
+
.hashBytes(Encoder.encodeObject(WorkPackage.Codec, workPackage, spec))
|
|
52
|
+
.asOpaque();
|
|
53
|
+
return new WithHash(workPackageHash, workPackage);
|
|
54
|
+
}
|
|
55
|
+
describe("InCore", () => {
|
|
56
|
+
it("should return StateMissing error when anchor block state is not in DB", async () => {
|
|
57
|
+
const spec = tinyChainSpec;
|
|
58
|
+
const states = new InMemoryStates(spec);
|
|
59
|
+
const inCore = new InCore(spec, states, PvmBackend.BuiltIn, blake2b);
|
|
60
|
+
const anchorHash = Bytes.fill(HASH_SIZE, 1).asOpaque();
|
|
61
|
+
const stateRoot = Bytes.zero(HASH_SIZE).asOpaque();
|
|
62
|
+
const workPackage = createWorkPackage(anchorHash, stateRoot);
|
|
63
|
+
const result = await inCore.refine(hashWorkPackage(spec, workPackage), tryAsCoreIndex(0), asKnownSize([[]]), asKnownSize([[]]));
|
|
64
|
+
assert.strictEqual(result.isError, true);
|
|
65
|
+
assert.strictEqual(result.error, RefineError.StateMissing);
|
|
66
|
+
});
|
|
67
|
+
it("should refine work package and produce a report when state is set up", async () => {
|
|
68
|
+
const spec = tinyChainSpec;
|
|
69
|
+
const states = new InMemoryStates(spec);
|
|
70
|
+
const inCore = new InCore(spec, states, PvmBackend.BuiltIn, blake2b);
|
|
71
|
+
const anchorHash = Bytes.fill(HASH_SIZE, 1).asOpaque();
|
|
72
|
+
const state = testState();
|
|
73
|
+
await states.insertInitialState(anchorHash, state);
|
|
74
|
+
const correctStateRoot = await states.getStateRoot(state);
|
|
75
|
+
const workPackage = createWorkPackage(anchorHash, correctStateRoot, state.timeslot);
|
|
76
|
+
const result = await inCore.refine(hashWorkPackage(spec, workPackage), tryAsCoreIndex(0), asKnownSize([[]]), asKnownSize([[]]));
|
|
77
|
+
assert.strictEqual(result.isOk, true);
|
|
78
|
+
assert.strictEqual(result.ok.report.coreIndex, 0);
|
|
79
|
+
assert.strictEqual(result.ok.report.results.length, 1);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../packages/jam/in-core/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./in-core.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bless.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/jam-host-calls/accumulate/bless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,SAAS,
|
|
1
|
+
{"version":3,"file":"bless.d.ts","sourceRoot":"","sources":["../../../../../../packages/jam/jam-host-calls/accumulate/bless.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,KAAK,SAAS,EAAmB,MAAM,kBAAkB,CAAC;AAEpF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AACpG,OAAO,EAAE,YAAY,EAAsC,MAAM,2BAA2B,CAAC;AAC7F,OAAO,EAAE,KAAK,WAAW,EAAiB,MAAM,0BAA0B,CAAC;AAG3E,OAAO,EAAE,KAAK,YAAY,EAAyB,MAAM,mCAAmC,CAAC;AAkB7F;;;;GAIG;AACH,qBAAa,KAAM,YAAW,eAAe;aAMzB,gBAAgB,EAAE,SAAS;IAC3C,OAAO,CAAC,QAAQ,CAAC,YAAY;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAP5B,KAAK,iIAA0B;IAC/B,YAAY,4HAAqB;IACjC,eAAe,uEAAgD;gBAG7C,gBAAgB,EAAE,SAAS,EAC1B,YAAY,EAAE,YAAY,EAC1B,SAAS,EAAE,SAAS;IAGjC,OAAO,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,SAAS,GAAG,YAAY,CAAC;CAkFrH"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { tryAsServiceGas
|
|
1
|
+
import { tryAsServiceGas } from "#@typeberry/block";
|
|
2
2
|
import { codec, Decoder, tryAsExactBytes } from "#@typeberry/codec";
|
|
3
3
|
import { tryAsU64 } from "#@typeberry/numbers";
|
|
4
4
|
import { PvmExecution, traceRegisters, tryAsHostCallIndex } from "#@typeberry/pvm-host-calls";
|
|
5
5
|
import { tryAsSmallGas } from "#@typeberry/pvm-interface";
|
|
6
6
|
import { tryAsPerCore } from "#@typeberry/state";
|
|
7
|
-
import { asOpaqueType, assertNever,
|
|
7
|
+
import { asOpaqueType, assertNever, lazyInspect, safeAllocUint8Array } from "#@typeberry/utils";
|
|
8
8
|
import { UpdatePrivilegesError } from "../externalities/partial-state.js";
|
|
9
9
|
import { HostCallResult } from "../general/results.js";
|
|
10
10
|
import { logger } from "../logger.js";
|
|
@@ -25,9 +25,7 @@ export class Bless {
|
|
|
25
25
|
chainSpec;
|
|
26
26
|
index = tryAsHostCallIndex(14);
|
|
27
27
|
basicGasCost = tryAsSmallGas(10);
|
|
28
|
-
tracedRegisters =
|
|
29
|
-
? traceRegisters(IN_OUT_REG, 8, 9, 10, 11, 12)
|
|
30
|
-
: traceRegisters(IN_OUT_REG, 8, 9, 10, 11);
|
|
28
|
+
tracedRegisters = traceRegisters(IN_OUT_REG, 8, 9, 10, 11, 12);
|
|
31
29
|
constructor(currentServiceId, partialState, chainSpec) {
|
|
32
30
|
this.currentServiceId = currentServiceId;
|
|
33
31
|
this.partialState = partialState;
|
|
@@ -41,13 +39,11 @@ export class Bless {
|
|
|
41
39
|
// `v`: manages validator keys
|
|
42
40
|
const delegator = getServiceId(regs.get(9));
|
|
43
41
|
// `r`: manages creation of new services with id within protected range
|
|
44
|
-
const registrar =
|
|
45
|
-
? getServiceId(regs.get(10))
|
|
46
|
-
: tryAsServiceId(2 ** 32 - 1);
|
|
42
|
+
const registrar = getServiceId(regs.get(10));
|
|
47
43
|
// `o`: memory offset
|
|
48
|
-
const sourceStart =
|
|
44
|
+
const sourceStart = regs.get(11);
|
|
49
45
|
// `n`: number of items in the auto-accumulate dictionary
|
|
50
|
-
const numberOfItems =
|
|
46
|
+
const numberOfItems = regs.get(12);
|
|
51
47
|
/*
|
|
52
48
|
* `z`: array of key-value pairs serviceId -> gas that auto-accumulate every block
|
|
53
49
|
* https://graypaper.fluffylabs.dev/#/7e6ff6a/368100368100?v=0.6.7
|