feat: use marine-js 0.7.2 (#321)

* use marine-js 0.5.0

* increace some timeouts

* increace some timeouts

* use latest marine + remove larger timeouts

* propagate CallParameters type

* use marine 0.7.2

* Temp use node 18 and 20

* Comment out node 20.x

---------

Co-authored-by: Anatoly Laskaris <github_me@nahsi.dev>
This commit is contained in:
Valery Antopol 2023-08-09 15:38:40 +03:00 committed by GitHub
parent f82a37ee96
commit c99a509c87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 57 additions and 32 deletions

View File

@ -37,8 +37,8 @@ jobs:
strategy:
matrix:
node-version:
- 16.x
- 18.x
# - 20.x
steps:
- name: Import secrets

View File

@ -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"
}

View File

@ -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": {

View File

@ -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",

View File

@ -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"
}
}

View File

@ -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",

View File

@ -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';
@ -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}`);
}
@ -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,

View File

@ -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) {}
@ -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());

View File

@ -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';
@ -45,7 +45,7 @@ export interface IMarineHost extends IStartable {
serviceId: string,
functionName: string,
args: JSONArray | JSONObject,
callParams: any,
callParams: CallParameters,
): Promise<unknown>;
}

View File

@ -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';
@ -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) => {
@ -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();
@ -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`);

View File

@ -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
@ -73,7 +73,7 @@ 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);
}
@ -81,7 +81,7 @@ export class MarineBackgroundRunner implements IMarineHost {
serviceId: string,
functionName: string,
args: JSONArray | JSONObject,
callParams: any,
callParams: CallParameters,
): Promise<unknown> {
if (!this.workerThread) {
throw 'Worker is not initialized';

View File

@ -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>;

24
pnpm-lock.yaml generated
View File

@ -148,8 +148,8 @@ importers:
specifier: 0.43.1
version: 0.43.1
'@fluencelabs/marine-js':
specifier: 0.3.45
version: 0.3.45
specifier: 0.7.2
version: 0.7.2
dts-bundle-generator:
specifier: 7.2.0
version: 7.2.0
@ -169,8 +169,8 @@ importers:
specifier: 0.9.1
version: link:../../core/js-peer
'@fluencelabs/marine-js':
specifier: 0.3.45
version: 0.3.45
specifier: 0.7.2
version: 0.7.2
platform:
specifier: 1.3.6
version: 1.3.6
@ -220,8 +220,8 @@ importers:
specifier: 0.43.1
version: 0.43.1
'@fluencelabs/marine-js':
specifier: 0.3.45
version: 0.3.45
specifier: 0.7.2
version: 0.7.2
'@rollup/plugin-inject':
specifier: 5.0.3
version: 5.0.3
@ -262,8 +262,8 @@ importers:
specifier: 0.43.1
version: 0.43.1
'@fluencelabs/marine-js':
specifier: 0.3.45
version: 0.3.45
specifier: 0.7.2
version: 0.7.2
'@multiformats/multiaddr':
specifier: 11.3.0
version: 11.3.0
@ -280,8 +280,8 @@ importers:
specifier: 0.8.1
version: link:../interfaces
'@fluencelabs/marine-js':
specifier: 0.3.45
version: 0.3.45
specifier: 0.7.2
version: 0.7.2
'@libp2p/crypto':
specifier: 1.0.8
version: 1.0.8(uint8arraylist@2.4.3)
@ -2999,8 +2999,8 @@ packages:
- typescript
dev: true
/@fluencelabs/marine-js@0.3.45:
resolution: {integrity: sha512-GmeTvaC9n6zM6FPPyoHXwe2I8F9mEeE9DKzJcqy4FkUmpI11Fu4HrTvKgJyTURJkZSu8cfrjA7ZVeYuDGHeimQ==}
/@fluencelabs/marine-js@0.7.2:
resolution: {integrity: sha512-etjbXDgzyZkK82UZvtuIU3bfy5f52siDUy1m+T5Y5r70k82xYdZZ8vgWVgB6ivi2f3aDyQjgNTfzWQjKFpAReQ==}
dependencies:
'@wasmer/wasi': 0.12.0
'@wasmer/wasmfs': 0.12.0