Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ jobs:
strategy:
matrix:
node-version:
- 16.x
- 18.x
# - 20.x

steps:
- name: Import secrets
Expand Down
2 changes: 1 addition & 1 deletion packages/client/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"devDependencies": {
"@fluencelabs/avm": "0.43.1",
"@fluencelabs/marine-js": "0.3.45",
"@fluencelabs/marine-js": "0.7.2",
"microbundle": "0.15.1",
"dts-bundle-generator": "7.2.0"
}
Expand Down
2 changes: 1 addition & 1 deletion packages/client/js-client.node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"@fluencelabs/js-peer": "0.9.1",
"@fluencelabs/interfaces": "0.8.1",
"@fluencelabs/avm": "0.43.1",
"@fluencelabs/marine-js": "0.3.45",
"@fluencelabs/marine-js": "0.7.2",
"platform": "1.3.6"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/js-client.web.standalone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
},
"devDependencies": {
"@fluencelabs/avm": "0.43.1",
"@fluencelabs/marine-js": "0.3.45",
"@fluencelabs/marine-js": "0.7.2",
"@types/node": "16.11.59",
"@types/jest": "28.1.0",
"jest": "28.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/core/interfaces/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,6 @@
"devDependencies": {
"@multiformats/multiaddr": "11.3.0",
"@fluencelabs/avm": "0.43.1",
"@fluencelabs/marine-js": "0.3.45"
"@fluencelabs/marine-js": "0.7.2"
}
}
2 changes: 1 addition & 1 deletion packages/core/js-peer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@fluencelabs/interfaces": "0.8.1",
"@fluencelabs/avm": "0.43.1",
"@fluencelabs/marine-js": "0.3.45",
"@fluencelabs/marine-js": "0.7.2",
"multiformats": "11.0.1",
"debug": "4.3.4",
"async": "3.2.4",
Expand Down
6 changes: 4 additions & 2 deletions packages/core/js-peer/src/jsPeer/FluencePeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
ParticleExecutionStage,
ParticleQueueItem,
} from '../particle/Particle.js';
import { defaultCallParameters } from "@fluencelabs/marine-js/dist/types"
import { jsonify, isString } from '../util/utils.js';
import { concatMap, filter, pipe, Subject, tap, Unsubscribable } from 'rxjs';
import { defaultSigGuard, Sig } from '../services/Sig.js';
Expand Down Expand Up @@ -184,7 +185,7 @@ export abstract class FluencePeer {
new Error("Can't use avm: peer is not initialized");
}

const res = await this.marineHost.callService('avm', 'ast', [air], undefined);
const res = await this.marineHost.callService('avm', 'ast', [air], defaultCallParameters);
if (!isString(res)) {
throw new Error(`Call to avm:ast expected to return string. Actual return: ${res}`);
}
Expand Down Expand Up @@ -521,7 +522,8 @@ export abstract class FluencePeer {
log_particle.trace('id %s. executing call service handler %j', particleId, req);

if (this.marineHost && this.marineHost.hasService(req.serviceId)) {
const result = await this.marineHost.callService(req.serviceId, req.fnName, req.args, undefined);
// TODO build correct CallParameters instead of default ones
const result = await this.marineHost.callService(req.serviceId, req.fnName, req.args, defaultCallParameters);

return {
retCode: ResultCodes.success,
Expand Down
3 changes: 2 additions & 1 deletion packages/core/js-peer/src/jsPeer/avm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import type { CallResultsArray, InterpreterResult, RunParameters } from '@fluencelabs/avm';
import { deserializeAvmResult, serializeAvmArgs } from '@fluencelabs/avm';
import { IAvmRunner, IMarineHost, IWasmLoader } from '../marine/interfaces.js';
import { defaultCallParameters } from "@fluencelabs/marine-js/dist/types"

export class MarineBasedAvmRunner implements IAvmRunner {
constructor(private marine: IMarineHost, private avmWasmLoader: IWasmLoader) {}
Expand All @@ -31,7 +32,7 @@ export class MarineBasedAvmRunner implements IAvmRunner {

let avmCallResult: InterpreterResult | Error;
try {
const res = await this.marine.callService('avm', 'invoke', args, undefined);
const res = await this.marine.callService('avm', 'invoke', args, defaultCallParameters);
avmCallResult = deserializeAvmResult(res);
} catch (e) {
avmCallResult = e instanceof Error ? e : new Error((e as any).toString());
Expand Down
4 changes: 2 additions & 2 deletions packages/core/js-peer/src/marine/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { CallResultsArray, InterpreterResult, RunParameters } from '@fluencelabs/avm';
import { IStartable, JSONArray, JSONObject } from '../util/commonTypes.js';
import { IStartable, JSONArray, JSONObject, CallParameters } from '../util/commonTypes.js';
import { Buffer } from 'buffer';
// @ts-ignore
import type { WorkerImplementation } from 'threads/dist/types/master';
Expand Down Expand Up @@ -45,7 +45,7 @@ export interface IMarineHost extends IStartable {
serviceId: string,
functionName: string,
args: JSONArray | JSONObject,
callParams: any,
callParams: CallParameters,
): Promise<unknown>;
}

Expand Down
32 changes: 26 additions & 6 deletions packages/core/js-peer/src/marine/worker-script/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
*/

import { MarineService } from '@fluencelabs/marine-js/dist/MarineService';
import type { Env, MarineServiceConfig } from '@fluencelabs/marine-js/dist/config';
import type { JSONArray, JSONObject, LogMessage } from '@fluencelabs/marine-js/dist/types';
import type { Env, MarineModuleConfig, MarineServiceConfig, ModuleDescriptor } from '@fluencelabs/marine-js/dist/config'
import type { JSONArray, JSONObject, LogMessage, CallParameters } from '@fluencelabs/marine-js/dist/types';
import { Buffer } from 'buffer';
// @ts-ignore
import { Observable, Subject } from 'threads/observable';
Expand All @@ -26,6 +26,26 @@ import { expose } from 'threads/worker';
let marineServices = new Map<string, MarineService>();
let controlModule: WebAssembly.Module | undefined;

const createSimpleModuleDescriptor = (name: string, envs?: Env): ModuleDescriptor => {
return {
import_name: name,
config: {
logger_enabled: true,
logging_mask: 0,
wasi: {
envs: {...envs},
preopened_files: new Set(),
mapped_dirs: new Map,
}
}
}
}
const createSimpleMarineService = (name: string, env? : Env): MarineServiceConfig => {
return {
modules_config: [createSimpleModuleDescriptor(name, env)],
}
}

const onLogMessage = new Subject<LogMessage>();

const asArray = (buf: SharedArrayBuffer | Buffer) => {
Expand All @@ -40,20 +60,20 @@ const toExpose = {
createService: async (
wasm: SharedArrayBuffer | Buffer,
serviceId: string,
marineConfig?: MarineServiceConfig,
envs?: Env,
): Promise<void> => {
if (!controlModule) {
throw new Error('MarineJS is not initialized. To initialize call `init` function');
}

const service = await WebAssembly.compile(asArray(wasm));
const marineConfig = createSimpleMarineService(serviceId, envs);
const modules = {[serviceId]: new Uint8Array(wasm)}
const srv = new MarineService(
controlModule,
service,
serviceId,
onLogMessage.next.bind(onLogMessage),
marineConfig,
modules,
envs,
);
await srv.init();
Expand All @@ -67,7 +87,7 @@ const toExpose = {
onLogMessage.complete();
},

callService: (serviceId: string, functionName: string, args: JSONArray | JSONObject, callParams: any): unknown => {
callService: (serviceId: string, functionName: string, args: JSONArray | JSONObject, callParams: CallParameters): unknown => {
const srv = marineServices.get(serviceId);
if (!srv) {
throw new Error(`service with id=${serviceId} not found`);
Expand Down
6 changes: 3 additions & 3 deletions packages/core/js-peer/src/marine/worker/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import type { JSONArray, JSONObject } from '@fluencelabs/marine-js/dist/types';
import type { JSONArray, JSONObject, CallParameters } from '@fluencelabs/marine-js/dist/types';
import { LogFunction, logLevelToEnv } from '@fluencelabs/marine-js/dist/types';
import type { MarineBackgroundInterface } from '../worker-script/index.js';
// @ts-ignore
Expand Down Expand Up @@ -73,15 +73,15 @@ export class MarineBackgroundRunner implements IMarineHost {
// We enable all possible log levels passing the control for exact printouts to the logger
const env = logLevelToEnv('trace');
this.loggers.set(serviceId, marineLogger(serviceId));
await this.workerThread.createService(serviceModule, serviceId, undefined, env);
await this.workerThread.createService(serviceModule, serviceId, env);
this.marineServices.add(serviceId);
}

callService(
serviceId: string,
functionName: string,
args: JSONArray | JSONObject,
callParams: any,
callParams: CallParameters,
): Promise<unknown> {
if (!this.workerThread) {
throw 'Worker is not initialized';
Expand Down
2 changes: 2 additions & 0 deletions packages/core/js-peer/src/util/commonTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
* limitations under the License.
*/

export { CallParameters} from "@fluencelabs/marine-js/dist/types";

export interface IStartable {
start(): Promise<void>;
stop(): Promise<void>;
Expand Down
24 changes: 12 additions & 12 deletions pnpm-lock.yaml

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