Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ JAM Prize requirements
- [x] Performance optimisations
- [ ] Milestone 2
- [x] Networking (partial)
- [x] Fast PVM (ananas)
- [x] Fast PVM (ananas, lite)
- [ ] Milestone 3
- [ ] PVM Recompiler
- [ ] Milestone 4
Expand Down Expand Up @@ -107,6 +107,7 @@ $ npm start -w @typeberry/rpc
- [PVM Debugger](https://github.com/fluffylabs/pvm-debugger) - load & inspect a PVM program
- [Gray Paper Reader](https://github.com/fluffylabs/graypaper-reader) - view the Gray Paper
- [Ananas](https://github.com/tomusdrw/anan-as) - AssemblyScript PVM interpreter
- [Lite](https://www.npmjs.com/package/@fluffylabs/pvm-interpreter-lite) - Lightweight TypeScript PVM interpreter

### Formatting & linting

Expand Down Expand Up @@ -171,7 +172,7 @@ cases by altering the glob pattern in the path.

#### Selecting PVM Backend

By default, test vectors are run with both PVM backends (built-in and Ananas).
By default, test vectors are run with all PVM backends (built-in, Ananas, and Lite).
You can select a specific PVM backend using the `--pvm` option:

```bash
Expand All @@ -181,7 +182,10 @@ $ npm run w3f-davxy:0.7.1 -w @typeberry/test-runner -- --pvm builtin
# Run tests with Ananas PVM only
$ npm run w3f-davxy:0.7.1 -w @typeberry/test-runner -- --pvm ananas

# Run tests with both PVMs (default)
# Run tests with Lite PVM only
$ npm run w3f-davxy:0.7.1 -w @typeberry/test-runner -- --pvm lite

# Run tests with all PVMs (default)
$ npm run w3f-davxy:0.7.1 -w @typeberry/test-runner
```

Expand Down
4 changes: 2 additions & 2 deletions bin/jam/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ jam --config=custom-config.json

### `--pvm`

Select the PVM (Polkavm) backend to use. Available options: `wasmtime`, `interpreter`, `ananas`.
Select the PVM (Polkavm) backend to use. Available options: `built-in`, `ananas`, `lite`.

Default: `ananas`

```bash
jam --pvm=wasmtime
jam --pvm=lite
```

## Environment Variables
Expand Down
15 changes: 10 additions & 5 deletions bin/test-runner/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe("test runner common", () => {
initialFiles: ["file1.json", "file2.json"],
pvms: [SelectedPvm.Ananas],
accumulateSequentially: false,
accumulateWorkers: 1,
});
});

Expand All @@ -23,8 +24,9 @@ describe("test runner common", () => {

deepEqual(result, {
initialFiles: ["file1.json", "file2.json"],
pvms: [SelectedPvm.Ananas, SelectedPvm.Builtin],
pvms: [SelectedPvm.Ananas, SelectedPvm.Builtin, SelectedPvm.Lite],
accumulateSequentially: false,
accumulateWorkers: 1,
});
});

Expand All @@ -36,7 +38,7 @@ describe("test runner common", () => {
const _result = parseArgs(args);
},
{
message: "Unknown pvm value: invalid. Use one of ananas, builtin.",
message: "Unknown pvm value: invalid. Use one of ananas, builtin, lite.",
},
);
});
Expand All @@ -48,8 +50,9 @@ describe("test runner common", () => {

deepEqual(result, {
initialFiles: ["file1.json"],
pvms: [SelectedPvm.Ananas, SelectedPvm.Builtin],
pvms: [SelectedPvm.Ananas, SelectedPvm.Builtin, SelectedPvm.Lite],
accumulateSequentially: true,
accumulateWorkers: 1,
});
});

Expand All @@ -60,8 +63,9 @@ describe("test runner common", () => {

deepEqual(result, {
initialFiles: ["file1.json"],
pvms: [SelectedPvm.Ananas, SelectedPvm.Builtin],
pvms: [SelectedPvm.Ananas, SelectedPvm.Builtin, SelectedPvm.Lite],
accumulateSequentially: true,
accumulateWorkers: 1,
});
});

Expand All @@ -72,8 +76,9 @@ describe("test runner common", () => {

deepEqual(result, {
initialFiles: ["file1.json"],
pvms: [SelectedPvm.Ananas, SelectedPvm.Builtin],
pvms: [SelectedPvm.Ananas, SelectedPvm.Builtin, SelectedPvm.Lite],
accumulateSequentially: false,
accumulateWorkers: 1,
});
});

Expand Down
20 changes: 18 additions & 2 deletions bin/test-runner/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ export const logger = Logger.new(import.meta.filename, "test-runner");
export enum SelectedPvm {
Ananas = "ananas",
Builtin = "builtin",
Lite = "lite",
}
export const ALL_PVMS = [SelectedPvm.Ananas, SelectedPvm.Builtin];
export const ALL_PVMS = [SelectedPvm.Ananas, SelectedPvm.Builtin, SelectedPvm.Lite];
export function selectedPvmToBackend(pvm: SelectedPvm): PvmBackend {
switch (pvm) {
case SelectedPvm.Ananas:
return PvmBackend.Ananas;
case SelectedPvm.Builtin:
return PvmBackend.BuiltIn;
case SelectedPvm.Lite:
return PvmBackend.Lite;
default:
assertNever(pvm);
}
Expand All @@ -35,6 +38,7 @@ export function selectedPvmToBackend(pvm: SelectedPvm): PvmBackend {
export type GlobalsOptions = {
pvms: SelectedPvm[];
accumulateSequentially: boolean;
accumulateWorkers: number;
};

export class RunnerBuilder<T, V> implements Runner<T, V> {
Expand Down Expand Up @@ -97,6 +101,7 @@ export type RunOptions = {
chainSpec: ChainSpec;
path: string;
accumulateSequentially: boolean;
accumulateWorkers: number;
};

export type RunFunction<T, V> = (test: T, options: RunOptions, variant: V) => Promise<void>;
Expand Down Expand Up @@ -138,6 +143,7 @@ export namespace testFile {

const PVM_OPTION = "pvm";
const ACCUMULATE_SEQUENTIALLY_OPTION = "accumulate-sequentially";
const ACCUMULATE_WORKERS_OPTION = "accumulate-workers";
const HELP_OPTION = "help";
export const HELP_MESSAGE = `
Usage: test-runner [options] [files...]
Expand All @@ -150,6 +156,10 @@ Options:
--accumulate-sequentially Run accumulation sequentially instead of in parallel.
Default: false

--accumulate-workers <N> Number of worker threads for accumulation.
0 = no workers (current behavior), 1+ = worker threads.
Default: 0

-h, --help Show this help message.

Examples:
Expand All @@ -163,7 +173,7 @@ export function parseArgs(argv: string[]) {
const parsed = minimist(argv, {
boolean: [ACCUMULATE_SEQUENTIALLY_OPTION, HELP_OPTION],
alias: { h: HELP_OPTION },
default: { [ACCUMULATE_SEQUENTIALLY_OPTION]: false },
default: { [ACCUMULATE_SEQUENTIALLY_OPTION]: false, [ACCUMULATE_WORKERS_OPTION]: 1 },
});

const shouldShowHelp = getBooleanOption(parsed[HELP_OPTION]);
Expand All @@ -175,11 +185,13 @@ export function parseArgs(argv: string[]) {

const pvms = getPvms(parsed[PVM_OPTION]);
const accumulateSequentially = getBooleanOption(parsed[ACCUMULATE_SEQUENTIALLY_OPTION]);
const accumulateWorkers = Number(parsed[ACCUMULATE_WORKERS_OPTION]) || 0;

return {
initialFiles: parsed._,
pvms,
accumulateSequentially,
accumulateWorkers,
};

function getBooleanOption(value: unknown): boolean {
Expand Down Expand Up @@ -218,13 +230,15 @@ export async function main(
initialFiles,
pvms,
accumulateSequentially,
accumulateWorkers,
patterns = [testFile.bin, testFile.json],
accepted,
ignored,
}: {
initialFiles: string[];
pvms: SelectedPvm[];
accumulateSequentially: boolean;
accumulateWorkers: number;
patterns?: (testFile.bin | testFile.json)[];
accepted?: {
[testFile.bin]?: string[];
Expand Down Expand Up @@ -284,6 +298,7 @@ export async function main(
const testVariants = prepareTest(runners, testFileContent, testFilePath, absolutePath, {
pvms,
accumulateSequentially,
accumulateWorkers,
});
for (const test of testVariants) {
test.shouldSkip = !isAccepted;
Expand Down Expand Up @@ -464,6 +479,7 @@ function prepareTest<T, V>(
path: fullPath,
chainSpec,
accumulateSequentially: globalOptions.accumulateSequentially,
accumulateWorkers: globalOptions.accumulateWorkers,
},
variant,
);
Expand Down
4 changes: 2 additions & 2 deletions bin/test-runner/javajam-071.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { StateTransition } from "@typeberry/state-vectors";
import { logger, main, parseArgs, runner, SelectedPvm } from "./common.js";
import { ALL_PVMS, logger, main, parseArgs, runner } from "./common.js";
import { runStateTransition } from "./state-transition/state-transition.js";

const runners = [
runner("state_transition", runStateTransition)
.fromJson(StateTransition.fromJson)
.fromBin(StateTransition.Codec)
.withVariants([SelectedPvm.Ananas, SelectedPvm.Builtin]),
.withVariants(ALL_PVMS),
].map((x) => x.build());

main(runners, "test-vectors/javajam_071", {
Expand Down
2 changes: 1 addition & 1 deletion bin/test-runner/state-transition/state-transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export async function runStateTransition(testContent: StateTransition, options:
spec,
preState,
hasher,
{ pvm, accumulateSequentially: options.accumulateSequentially },
{ pvm, accumulateSequentially: options.accumulateSequentially, accumulateWorkers: options.accumulateWorkers },
DbHeaderChain.new(blocksDb),
);

Expand Down
12 changes: 6 additions & 6 deletions bin/test-runner/w3f/accumulate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type { WorkPackageHash } from "@typeberry/block/refine-context.js";
import type { WorkReport } from "@typeberry/block/work-report.js";
import { fromJson, workReportFromJson } from "@typeberry/block-json";
import { asKnownSize, HashSet } from "@typeberry/collections";
import { type ChainSpec, PvmBackend, PvmBackendNames } from "@typeberry/config";
import { type ChainSpec, PvmBackendNames } from "@typeberry/config";
import { Blake2b } from "@typeberry/hash";
import { type FromJson, json } from "@typeberry/json-parser";
import {
Expand All @@ -26,7 +26,7 @@ import { JsonService, JsonServicePre072 } from "@typeberry/state-json";
import { AccumulateOutput } from "@typeberry/transition/accumulate/accumulate-output.js";
import { Accumulate, type AccumulateRoot } from "@typeberry/transition/accumulate/index.js";
import { Compatibility, deepEqual, GpVersion, Result } from "@typeberry/utils";
import type { RunOptions } from "../common.js";
import { type RunOptions, type SelectedPvm, selectedPvmToBackend } from "../common.js";

class Input {
static fromJson: FromJson<Input> = {
Expand Down Expand Up @@ -141,11 +141,11 @@ export class AccumulateTest {

export async function runAccumulateTest(
test: AccumulateTest,
{ chainSpec, accumulateSequentially }: RunOptions,
variant: "ananas" | "builtin",
{ chainSpec, accumulateSequentially, accumulateWorkers }: RunOptions,
variant: SelectedPvm,
) {
const pvm = variant === "ananas" ? PvmBackend.Ananas : PvmBackend.BuiltIn;
const options = { pvm, accumulateSequentially };
const pvm = selectedPvmToBackend(variant);
const options = { pvm, accumulateSequentially, accumulateWorkers };
/**
* entropy has to be moved to input because state is incompatibile -
* in test state we have: `entropy: EntropyHash;`
Expand Down
4 changes: 2 additions & 2 deletions bin/test-runner/w3f/runners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from "@typeberry/block-json";
import { fullChainSpec, tinyChainSpec } from "@typeberry/config";
import { StateTransition } from "@typeberry/state-vectors";
import { runner, SelectedPvm } from "../common.js";
import { ALL_PVMS, runner } from "../common.js";
import { runStateTransition } from "../state-transition/state-transition.js";
import { AccumulateTest, runAccumulateTest } from "./accumulate.js";
import { AssurancesTestFull, AssurancesTestTiny, runAssurancesTestFull, runAssurancesTestTiny } from "./assurances.js";
Expand Down Expand Up @@ -47,7 +47,7 @@ import { runShufflingTests, shufflingTestsFromJson } from "./shuffling.js";
import { runStatisticsTestFull, runStatisticsTestTiny, StatisticsTestFull, StatisticsTestTiny } from "./statistics.js";
import { runTrieTest, trieTestSuiteFromJson } from "./trie.js";

const pvms: SelectedPvm[] = [SelectedPvm.Ananas, SelectedPvm.Builtin];
const pvms = ALL_PVMS;
const tiny = [tinyChainSpec];
const full = [fullChainSpec];
const tinyFull = [...tiny, ...full];
Expand Down
22 changes: 22 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"packages/core/pvm-interface",
"packages/core/pvm-interpreter",
"packages/core/pvm-interpreter-ananas",
"packages/core/pvm-interpreter-lite",
"packages/core/shuffling",
"packages/core/telemetry",
"packages/core/trie",
Expand Down
3 changes: 2 additions & 1 deletion packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Contains fundamental packages that provide low-level functionality and utilities
- **pvm-host-calls** - PVM host call implementations
- **pvm-interface** - PVM interface definitions
- **pvm-interpreter** - PVM interpreter functionality
- **pvm-interpreter-ananas** - Ananas PVM interpreter implementation
- **pvm-interpreter-ananas** - Ananas PVM interpreter implementation (AssemblyScript/WASM)
- **pvm-interpreter-lite** - Lightweight PVM interpreter (`@fluffylabs/pvm-interpreter-lite`)
Comment thread
tomusdrw marked this conversation as resolved.
- **shuffling** - Shuffling algorithms
- **telemetry** - OpenTelemetry initialization utilities
- **trie** - Trie data structure implementation
Expand Down
1 change: 1 addition & 0 deletions packages/core/pvm-host-calls/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"@typeberry/pvm-interface": "*",
"@typeberry/pvm-interpreter": "*",
"@typeberry/pvm-interpreter-ananas": "*",
"@typeberry/pvm-interpreter-lite": "*",
"@typeberry/utils": "*"
},
"scripts": {
Expand Down
4 changes: 4 additions & 0 deletions packages/core/pvm-host-calls/pvm-instance-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PvmBackend } from "@typeberry/config";
import type { IPvmInterpreter } from "@typeberry/pvm-interface";
import { Interpreter } from "@typeberry/pvm-interpreter";
import { AnanasInterpreter } from "@typeberry/pvm-interpreter-ananas";
import { LiteInterpreter } from "@typeberry/pvm-interpreter-lite";
import { assertNever } from "@typeberry/utils";

type ResolveFn = (pvm: IPvmInterpreter) => void;
Expand All @@ -25,6 +26,9 @@ export class PvmInstanceManager {
case PvmBackend.Ananas:
instances.push(await AnanasInterpreter.new());
break;
case PvmBackend.Lite:
instances.push(new LiteInterpreter());
break;
default:
assertNever(interpreter);
}
Expand Down
Loading
Loading