Skip to content

Commit

Permalink
Non-blocking wasm compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
soerenbf committed Sep 10, 2024
1 parent f762398 commit df090d5
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
1 change: 0 additions & 1 deletion packages/sdk/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
### Breaking changes

- `getEmbeddedModuleSchema` now uses the module version to determine in which custom wasm sections to look for the schema.
It also no longer is `async` because there isn't any need for it to be so.
- `ConcordiumGRPCClient.getEmbeddedSchema` now delegates to `getEmbeddedModuleSchema` instead of `wasmToSchema`
(which was removed as it was just a less capable version of `getEmbeddedModuleSchema`).
This means that it returns the complete `RawModuleSchema` instead of only the schema bytes.
Expand Down
7 changes: 5 additions & 2 deletions packages/sdk/src/types/VersionedModuleSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,11 @@ export async function parseModuleInterface(moduleSource: VersionedModuleSource):
* @returns {RawModuleSchema | null} The raw module schema if found.
* @throws If the module source cannot be parsed or contains duplicate schema sections.
*/
export function getEmbeddedModuleSchema({ source, version }: VersionedModuleSource): RawModuleSchema | undefined {
const sections = findCustomSections(new WebAssembly.Module(source), version);
export async function getEmbeddedModuleSchema({
source,
version,
}: VersionedModuleSource): Promise<RawModuleSchema | undefined> {
const sections = findCustomSections(await WebAssembly.compile(source), version);
if (sections === undefined) {
return undefined;
}
Expand Down
8 changes: 4 additions & 4 deletions packages/sdk/test/ci/module-schema.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => {
path.join(testFileDir, 'cis2-wccd-embedded-schema-v1-versioned.wasm.v1')
);
const moduleSource = versionedModuleSourceFromBuffer(contractModule);
const moduleSchema = getEmbeddedModuleSchema(moduleSource);
const moduleSchema = await getEmbeddedModuleSchema(moduleSource);
if (moduleSchema === undefined) {
fail('Failed to find module schame');
}
Expand All @@ -24,7 +24,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => {
path.join(testFileDir, 'cis1-wccd-embedded-schema-v0-versioned.wasm.v0')
);
const moduleSource = versionedModuleSourceFromBuffer(contractModule);
const moduleSchema = getEmbeddedModuleSchema(moduleSource);
const moduleSchema = await getEmbeddedModuleSchema(moduleSource);
if (moduleSchema === undefined) {
fail('Failed to find module schame');
}
Expand All @@ -39,7 +39,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => {
version: 0,
source: Buffer.from(unversionedContractModule),
} as const;
const moduleSchema = getEmbeddedModuleSchema(moduleSource);
const moduleSchema = await getEmbeddedModuleSchema(moduleSource);
if (moduleSchema === undefined) {
fail('Failed to find module schame');
}
Expand All @@ -51,7 +51,7 @@ describe('VersionedModuleSource: getEmbeddedModuleSchema', () => {
path.join(testFileDir, 'cis2-wccd-embedded-schema-v1-unversioned.wasm.v1')
);
const moduleSource = versionedModuleSourceFromBuffer(contractModule);
const moduleSchema = getEmbeddedModuleSchema(moduleSource);
const moduleSchema = await getEmbeddedModuleSchema(moduleSource);
if (moduleSchema === undefined) {
fail('Failed to find module schame');
}
Expand Down
4 changes: 2 additions & 2 deletions packages/sdk/test/ci/util.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ test('stringToInt will not change the string if no keys match', () => {
expect(transformed).toEqual(input);
});

test('Embedded schema is the same as a seperate schema file', () => {
test('Embedded schema is the same as a seperate schema file', async () => {
const versionedWasmModule = readFileSync('test/ci/resources/icecream-with-schema.wasm');
// Strip module version information
const wasmModule = versionedWasmModule.subarray(8);

const seperateSchema = readFileSync('test/ci/resources/icecream-schema.bin');
const embeddedSchema = getEmbeddedModuleSchema({
const embeddedSchema = await getEmbeddedModuleSchema({
source: wasmModule,
version: 1,
});
Expand Down

0 comments on commit df090d5

Please sign in to comment.