From b20a27f8b64733f3300afc8e4b5409337dc860aa Mon Sep 17 00:00:00 2001 From: Valery Antopol Date: Wed, 21 Feb 2024 16:59:49 +0400 Subject: [PATCH] feat: support marine-rs-sdk 0.14 (#419) * uodate sdk * add cp v3 test --- Cargo.lock | 128 ++++++++++--- Cargo.toml | 1 + core/src/config.rs | 2 + .../wasm_tests/lilo_after_2gb/Cargo.toml | 2 +- crates/it-generator/Cargo.toml | 2 +- crates/module-info-parser/Cargo.toml | 2 +- examples/call_parameters/Cargo.toml | 2 +- .../artifacts/call_parameters.wasm | Bin 49881 -> 49877 bytes examples/failing/Cargo.toml | 2 +- examples/greeting/Cargo.toml | 2 +- examples/greeting_record/Cargo.toml | 2 +- examples/ipfs-node/effector/Cargo.toml | 2 +- examples/ipfs-node/pure/Cargo.toml | 2 +- .../motivational-example/donkey/Cargo.toml | 2 +- .../motivational-example/shrek/Cargo.toml | 2 +- examples/records/effector/Cargo.toml | 2 +- examples/records/pure/Cargo.toml | 2 +- examples/records/test-record/Cargo.toml | 2 +- examples/sqlite/Cargo.toml | 2 +- .../url-downloader/curl_adapter/Cargo.toml | 2 +- examples/url-downloader/facade/Cargo.toml | 2 +- .../url-downloader/local_storage/Cargo.toml | 2 +- .../npm-package/src/__test__/test.spec.ts | 2 +- marine-js/npm-package/src/marine_js.js | 172 +++++++++--------- marine-js/npm-package/src/types.ts | 4 +- marine/Cargo.toml | 5 +- marine/src/config/to_marine_config.rs | 73 +++----- marine/src/host_imports/call_parameters.rs | 118 ++++++------ marine/src/host_imports/mod.rs | 9 +- marine/src/marine.rs | 33 +++- marine/tests/call_parameters.rs | 80 +++++++- .../wasm_tests/arguments_passing/Cargo.toml | 2 +- .../wasm_tests/arrays_passing/Cargo.toml | 2 +- .../wasm_tests/call_parameters_v0/Cargo.toml | 2 +- .../wasm_tests/call_parameters_v1/Cargo.toml | 2 +- .../wasm_tests/call_parameters_v3/Cargo.toml | 14 ++ .../wasm_tests/call_parameters_v3/Config.toml | 6 + .../wasm_tests/call_parameters_v3/src/main.rs | 25 +++ .../wasm_tests/memory_limiting/Cargo.toml | 2 +- .../wasm_tests/records_passing/Cargo.toml | 2 +- marine/tests/wasm_tests/wasi/Cargo.toml | 2 +- tools/repl/Cargo.toml | 2 +- 42 files changed, 466 insertions(+), 258 deletions(-) create mode 100644 marine/tests/wasm_tests/call_parameters_v3/Cargo.toml create mode 100644 marine/tests/wasm_tests/call_parameters_v3/Config.toml create mode 100644 marine/tests/wasm_tests/call_parameters_v3/src/main.rs diff --git a/Cargo.lock b/Cargo.lock index 4a3484af..a4c1a9fa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,7 +102,7 @@ checksum = "a2e1373abdaa212b704512ec2bd8b26bd0b7d5c3f70117411a5d9a451383c859" name = "arguments-passing-test" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "safe-transmute", ] @@ -110,7 +110,7 @@ dependencies = [ name = "arrays-passing-test" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "safe-transmute", ] @@ -250,11 +250,19 @@ dependencies = [ "serde_json", ] +[[package]] +name = "call-parameters-v3-test" +version = "0.1.0" +dependencies = [ + "marine-rs-sdk 0.14.0", + "serde_json", +] + [[package]] name = "call_parameters" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "serde_json", ] @@ -698,7 +706,7 @@ name = "curl_adapter" version = "0.1.0" dependencies = [ "log", - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", ] [[package]] @@ -849,7 +857,7 @@ dependencies = [ name = "donkey" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", ] [[package]] @@ -938,7 +946,7 @@ version = "0.1.0" dependencies = [ "anyhow", "log", - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", ] [[package]] @@ -1489,7 +1497,7 @@ name = "ipfs-effector" version = "0.1.0" dependencies = [ "log", - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", ] [[package]] @@ -1497,7 +1505,7 @@ name = "ipfs-pure" version = "0.1.0" dependencies = [ "log", - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", ] [[package]] @@ -1632,7 +1640,7 @@ checksum = "89d92a4743f9a61002fae18374ed11e7973f530cb3a3255fb354818118b2203c" name = "lilo-after-2gb-test" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "safe-transmute", ] @@ -1653,7 +1661,7 @@ name = "local_storage" version = "0.1.0" dependencies = [ "log", - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "wasm-tracing-allocator", ] @@ -1748,6 +1756,17 @@ dependencies = [ "serde", ] +[[package]] +name = "marine-call-parameters" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05495180730abae04abe209386ce367309a82110edb65fcdb1f3080f819bc1a0" +dependencies = [ + "marine-macro 0.14.0", + "marine-rs-sdk-main 0.14.0", + "serde", +] + [[package]] name = "marine-core" version = "0.28.0" @@ -1784,7 +1803,7 @@ version = "0.15.0" dependencies = [ "it-lilo", "marine-it-parser", - "marine-macro-impl 0.13.0", + "marine-macro-impl 0.14.0", "once_cell", "serde", "serde_json", @@ -1894,6 +1913,16 @@ dependencies = [ "marine-rs-sdk-main 0.13.0", ] +[[package]] +name = "marine-macro" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f502185316f584a9373cceb6ff24a11d260dfd39505c817056bc127cd1a96a08" +dependencies = [ + "marine-macro-impl 0.14.0", + "marine-rs-sdk-main 0.14.0", +] + [[package]] name = "marine-macro-impl" version = "0.9.0" @@ -1946,6 +1975,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "marine-macro-impl" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e50fbc0e70ee4cde7802f0748acfb197d7770c7feffb980ce8c29bddd007519e" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 1.0.109", +] + [[package]] name = "marine-min-it-version" version = "0.3.2" @@ -1961,7 +2003,7 @@ dependencies = [ "anyhow", "chrono", "derivative", - "marine-rs-sdk-main 0.13.0", + "marine-rs-sdk-main 0.14.0", "marine-wasm-backend-traits", "semver", "serde", @@ -2035,6 +2077,19 @@ dependencies = [ "serde", ] +[[package]] +name = "marine-rs-sdk" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93d2bd852fea1fea8097c195044430347eda98fd6a3752119b549192d5ac4ba" +dependencies = [ + "marine-call-parameters 0.14.0", + "marine-macro 0.14.0", + "marine-rs-sdk-main 0.14.0", + "marine-timestamp-macro 0.14.0", + "serde", +] + [[package]] name = "marine-rs-sdk-main" version = "0.9.0" @@ -2075,6 +2130,16 @@ dependencies = [ "serde", ] +[[package]] +name = "marine-rs-sdk-main" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b79c165fc21438b069babeec5ae36ba0eade5e08fb1d92dabbe6b41014ce841" +dependencies = [ + "log", + "serde", +] + [[package]] name = "marine-runtime" version = "0.34.0" @@ -2087,10 +2152,11 @@ dependencies = [ "log", "marine-call-parameters 0.10.3", "marine-call-parameters 0.12.0", + "marine-call-parameters 0.13.0", "marine-core", "marine-module-interface", - "marine-rs-sdk 0.13.0", - "marine-rs-sdk-main 0.13.0", + "marine-rs-sdk 0.14.0", + "marine-rs-sdk-main 0.14.0", "marine-utils", "marine-wasm-backend-traits", "marine-wasmtime-backend", @@ -2157,6 +2223,16 @@ dependencies = [ "quote", ] +[[package]] +name = "marine-timestamp-macro" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d03f267ac0a29f543ef12a1a519ff8d98e74ac66e1c580f2930d41ce2c50507d" +dependencies = [ + "chrono", + "quote", +] + [[package]] name = "marine-utils" version = "0.5.1" @@ -2223,7 +2299,7 @@ dependencies = [ name = "memory-limiting-test" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "safe-transmute", ] @@ -2272,7 +2348,7 @@ dependencies = [ "fluence-app-service", "itertools", "log", - "marine-rs-sdk-main 0.13.0", + "marine-rs-sdk-main 0.14.0", "marine-wasm-backend-traits", "rustop", "rustyline", @@ -2603,7 +2679,7 @@ dependencies = [ name = "record-effector" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "test-record", ] @@ -2611,7 +2687,7 @@ dependencies = [ name = "record-pure" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "test-record", ] @@ -2619,7 +2695,7 @@ dependencies = [ name = "records-passing-test" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "safe-transmute", ] @@ -3056,7 +3132,7 @@ dependencies = [ name = "shrek" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", ] [[package]] @@ -3248,7 +3324,7 @@ dependencies = [ name = "test-record" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", ] [[package]] @@ -3684,7 +3760,7 @@ dependencies = [ name = "wasi-test" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "safe-transmute", ] @@ -3795,14 +3871,14 @@ dependencies = [ name = "wasm-failing" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", ] [[package]] name = "wasm-greeting" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", ] [[package]] @@ -3810,14 +3886,14 @@ name = "wasm-greeting-record" version = "0.1.0" dependencies = [ "log", - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", ] [[package]] name = "wasm-sqlite-test" version = "0.1.0" dependencies = [ - "marine-rs-sdk 0.13.0", + "marine-rs-sdk 0.14.0", "marine-sqlite-connector", ] diff --git a/Cargo.toml b/Cargo.toml index 851d71b4..6d927bf9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ members = [ "marine/tests/wasm_tests/call_parameters_v0", "marine/tests/wasm_tests/call_parameters_v1", "marine/tests/wasm_tests/call_parameters_v2", + "marine/tests/wasm_tests/call_parameters_v3", "marine/tests/wasm_tests/memory_limiting", "marine/tests/wasm_tests/records_passing", "marine/tests/wasm_tests/wasi", diff --git a/core/src/config.rs b/core/src/config.rs index 5d624a8b..82b50925 100644 --- a/core/src/config.rs +++ b/core/src/config.rs @@ -58,6 +58,7 @@ pub enum HostAPIVersion { V0, V1, V2, + V3, } impl HostAPIVersion { @@ -67,6 +68,7 @@ impl HostAPIVersion { Self::V0 => "host", Self::V1 => "__marine_host_api_v1", Self::V2 => "__marine_host_api_v2", + Self::V3 => "__marine_host_api_v3", } } } diff --git a/core/tests/wasm_tests/lilo_after_2gb/Cargo.toml b/core/tests/wasm_tests/lilo_after_2gb/Cargo.toml index 81ea4155..7df82d87 100644 --- a/core/tests/wasm_tests/lilo_after_2gb/Cargo.toml +++ b/core/tests/wasm_tests/lilo_after_2gb/Cargo.toml @@ -10,5 +10,5 @@ name = "lilo_after_2gb" path = "src/pure.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" safe-transmute = "0.11.0" diff --git a/crates/it-generator/Cargo.toml b/crates/it-generator/Cargo.toml index e572874e..ccfad37b 100644 --- a/crates/it-generator/Cargo.toml +++ b/crates/it-generator/Cargo.toml @@ -13,7 +13,7 @@ path = "src/lib.rs" [dependencies] marine-it-parser = { path = "../it-parser", version = "0.15.1" } -marine-macro-impl = "0.13.0" +marine-macro-impl = "0.14.0" wasmer-it = { package = "wasmer-interface-types-fl", version = "0.27.0" } it-lilo = "0.6.0" diff --git a/crates/module-info-parser/Cargo.toml b/crates/module-info-parser/Cargo.toml index c66ec1ed..0ab38d00 100644 --- a/crates/module-info-parser/Cargo.toml +++ b/crates/module-info-parser/Cargo.toml @@ -12,7 +12,7 @@ name = "marine_module_info_parser" path = "src/lib.rs" [dependencies] -marine-rs-sdk-main = { version = "0.13.0", default-features = false } +marine-rs-sdk-main = { version = "0.14.0", default-features = false } marine-wasm-backend-traits = { path = "../wasm-backend-traits", version = "0.5.1" } diff --git a/examples/call_parameters/Cargo.toml b/examples/call_parameters/Cargo.toml index 8be6aaea..1e2143fb 100644 --- a/examples/call_parameters/Cargo.toml +++ b/examples/call_parameters/Cargo.toml @@ -10,5 +10,5 @@ name = "call_parameters" path = "src/main.rs" [dependencies] -marine-rs-sdk = { version = "0.13.0", features = ["logger"] } +marine-rs-sdk = { version = "0.14.0", features = ["logger"] } serde_json = "1.0.111" \ No newline at end of file diff --git a/examples/call_parameters/artifacts/call_parameters.wasm b/examples/call_parameters/artifacts/call_parameters.wasm index bd1c542f74b5e8016b8ad06d9a054a1eebb0a9be..5e83af38fb2456c055837295605e1ad9114ff2a4 100755 GIT binary patch delta 496 zcmYMtJxEny9LI6bIi`2>a4n@F2oVzkdEQ^BA%e41wB!_o{+~Axqy}Ar8ZQRL#d;hX z0t;_VLEat`qrwDfi-rseBBG@N2R9*?jx@CW_J{_O8N8)08ByG3v^kytVT+Ud^mQFSX zh(?Yhhl~~&Yn@I#7%EDn9nzc`M+jrw;RMV3S*a1_!69#@b(DIaW*_ZmgBnYT!7@dR zMF@*(>_Xh=jKzm5M+P}HUI+q&bBrw`)rtSc6w_E+O_;@8b5V`|vonu}1_INX8UO@b z+2A5{&X>wD!h`3AA+7|b>2)V$$EXdAi2Bz`E)9eVPfT6DNayAqnYk9fKRui-J=tuO zf)E2#1dv{Vqauzz``z@eo=yZLh0uU)btQIJd7NCm*QAJQX{F}%KNkY3=>uwN@XTAV zfeHW*w1R`2=DXjDQq&Nv0xXe0M(Jo??3Ds}5|q`zh4S9uG_!UtFV^$%xch22zF+@S i_^WgA?wirH`|?&_wh^ztT{zS`TgTMD`5`OV1o{iD|F3!g delta 501 zcmYk2J!n)x6oq~7>AIbdjX#J8AxI1eVSetLAG8u)qhez!L6SRfW*`u;Fkqu32#bYr z367-_#YGST?m8G;5p_F3#Ks^t!9wt-5i7wozF3Ie<$UKHxM#hceQamTmlM{%(n!u={6Q?Uyfh)jPR7er$?rkO` zU}R;r0*(dcmauaCRCw7P4|nhH8Q~lWNLyJ#>Wg7{_&??ft~e^948aO~Iq{F>R6C)a zMq>&DY03sk)J<61U_y-`~h`FrK-hUXc=mRJvfE{K~lpOObI-3ufvE;_TXqG<%j#gr9?b m;qBAkJMg@*80cU$ejh9~l3}>?>e|l6++R6n!*@x>C&?eKzp!Qi diff --git a/examples/failing/Cargo.toml b/examples/failing/Cargo.toml index af77095c..8a4108cc 100644 --- a/examples/failing/Cargo.toml +++ b/examples/failing/Cargo.toml @@ -11,4 +11,4 @@ name = "failing" path = "src/main.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" diff --git a/examples/greeting/Cargo.toml b/examples/greeting/Cargo.toml index 04b32101..4efdbedb 100644 --- a/examples/greeting/Cargo.toml +++ b/examples/greeting/Cargo.toml @@ -11,4 +11,4 @@ name = "greeting" path = "src/main.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" diff --git a/examples/greeting_record/Cargo.toml b/examples/greeting_record/Cargo.toml index 5753cd09..e735cde4 100644 --- a/examples/greeting_record/Cargo.toml +++ b/examples/greeting_record/Cargo.toml @@ -11,6 +11,6 @@ name = "greeting-record" path = "src/main.rs" [dependencies] -marine-rs-sdk = { version = "0.13.0", features = ["logger"] } +marine-rs-sdk = { version = "0.14.0", features = ["logger"] } log = "0.4.8" diff --git a/examples/ipfs-node/effector/Cargo.toml b/examples/ipfs-node/effector/Cargo.toml index 214c420a..e1a85622 100644 --- a/examples/ipfs-node/effector/Cargo.toml +++ b/examples/ipfs-node/effector/Cargo.toml @@ -10,5 +10,5 @@ name = "ipfs_effector" path = "src/main.rs" [dependencies] -marine-rs-sdk = { version = "0.13.0", features = ["logger"] } +marine-rs-sdk = { version = "0.14.0", features = ["logger"] } log = "0.4.14" diff --git a/examples/ipfs-node/pure/Cargo.toml b/examples/ipfs-node/pure/Cargo.toml index b1f3386c..704eb936 100644 --- a/examples/ipfs-node/pure/Cargo.toml +++ b/examples/ipfs-node/pure/Cargo.toml @@ -10,5 +10,5 @@ name = "ipfs_pure" path = "src/main.rs" [dependencies] -marine-rs-sdk = { version = "0.13.0", features = ["logger"] } +marine-rs-sdk = { version = "0.14.0", features = ["logger"] } log = "0.4.14" diff --git a/examples/motivational-example/donkey/Cargo.toml b/examples/motivational-example/donkey/Cargo.toml index d4bd2303..d829033c 100644 --- a/examples/motivational-example/donkey/Cargo.toml +++ b/examples/motivational-example/donkey/Cargo.toml @@ -10,4 +10,4 @@ name = "donkey" path = "src/main.rs" [dependencies] -marine-rs-sdk = { version = "0.13.0", features = ["logger"] } +marine-rs-sdk = { version = "0.14.0", features = ["logger"] } diff --git a/examples/motivational-example/shrek/Cargo.toml b/examples/motivational-example/shrek/Cargo.toml index 7c13e85f..a6d4c01c 100644 --- a/examples/motivational-example/shrek/Cargo.toml +++ b/examples/motivational-example/shrek/Cargo.toml @@ -10,4 +10,4 @@ path = "src/main.rs" name = "shrek" [dependencies] -marine-rs-sdk = { version = "0.13.0", features = ["logger"] } +marine-rs-sdk = { version = "0.14.0", features = ["logger"] } diff --git a/examples/records/effector/Cargo.toml b/examples/records/effector/Cargo.toml index a3f1f8b6..a4e842dd 100644 --- a/examples/records/effector/Cargo.toml +++ b/examples/records/effector/Cargo.toml @@ -10,5 +10,5 @@ name = "records_effector" path = "src/main.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" test-record = { path = "../test-record" } diff --git a/examples/records/pure/Cargo.toml b/examples/records/pure/Cargo.toml index efa4a743..e77b8244 100644 --- a/examples/records/pure/Cargo.toml +++ b/examples/records/pure/Cargo.toml @@ -10,5 +10,5 @@ name = "records_pure" path = "src/main.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" test-record = { path = "../test-record" } diff --git a/examples/records/test-record/Cargo.toml b/examples/records/test-record/Cargo.toml index dc400899..8505b667 100644 --- a/examples/records/test-record/Cargo.toml +++ b/examples/records/test-record/Cargo.toml @@ -10,4 +10,4 @@ name = "test_record" path = "src/test_record.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" diff --git a/examples/sqlite/Cargo.toml b/examples/sqlite/Cargo.toml index 152a56a9..2fd48100 100644 --- a/examples/sqlite/Cargo.toml +++ b/examples/sqlite/Cargo.toml @@ -10,5 +10,5 @@ name = "sqlite_test" path = "src/main.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" marine-sqlite-connector = "0.9.0" diff --git a/examples/url-downloader/curl_adapter/Cargo.toml b/examples/url-downloader/curl_adapter/Cargo.toml index a9d57596..570b72f1 100644 --- a/examples/url-downloader/curl_adapter/Cargo.toml +++ b/examples/url-downloader/curl_adapter/Cargo.toml @@ -10,5 +10,5 @@ path = "src/main.rs" name = "curl_adapter" [dependencies] -marine-rs-sdk = { version = "0.13.0", features = ["logger"] } +marine-rs-sdk = { version = "0.14.0", features = ["logger"] } log = "0.4.8" diff --git a/examples/url-downloader/facade/Cargo.toml b/examples/url-downloader/facade/Cargo.toml index d5e446b8..75bf3779 100644 --- a/examples/url-downloader/facade/Cargo.toml +++ b/examples/url-downloader/facade/Cargo.toml @@ -10,6 +10,6 @@ name = "facade" path = "src/main.rs" [dependencies] -marine-rs-sdk = { version = "0.13.0", features = ["logger"] } +marine-rs-sdk = { version = "0.14.0", features = ["logger"] } anyhow = "1.0.31" log = "0.4.8" diff --git a/examples/url-downloader/local_storage/Cargo.toml b/examples/url-downloader/local_storage/Cargo.toml index 290d8395..66e7879c 100644 --- a/examples/url-downloader/local_storage/Cargo.toml +++ b/examples/url-downloader/local_storage/Cargo.toml @@ -10,7 +10,7 @@ name = "local_storage" path = "src/main.rs" [dependencies] -marine-rs-sdk = { version = "0.13.0", features = ["logger"] } +marine-rs-sdk = { version = "0.14.0", features = ["logger"] } wasm-tracing-allocator = "0.1.0" log = "0.4.8" diff --git a/marine-js/npm-package/src/__test__/test.spec.ts b/marine-js/npm-package/src/__test__/test.spec.ts index 08defe30..98d22a9c 100644 --- a/marine-js/npm-package/src/__test__/test.spec.ts +++ b/marine-js/npm-package/src/__test__/test.spec.ts @@ -424,7 +424,7 @@ describe('Fluence app service tests', () => { const tetraplet: SecurityTetraplet = { function_name: "some_func_name", - lambda: "some_lambda", + lens: "some_lens", peer_pk: "peer_pk", service_id: "service_id" } diff --git a/marine-js/npm-package/src/marine_js.js b/marine-js/npm-package/src/marine_js.js index 743fea7b..cdccaf21 100644 --- a/marine-js/npm-package/src/marine_js.js +++ b/marine-js/npm-package/src/marine_js.js @@ -405,6 +405,30 @@ export async function init(module) { const imports = {}; imports.wbg = {}; + imports.wbg.__wbindgen_object_clone_ref = function(arg0) { + const ret = getObject(arg0); + return addHeapObject(ret); + }; + + imports.wbg.__wbg_buffer_085ec1f694018c4f = function(arg0) { + const ret = getObject(arg0).buffer; + return addHeapObject(ret); + }; + + imports.wbg.__wbg_byteLength_0488a7a303dccf40 = function(arg0) { + const ret = getObject(arg0).byteLength; + return ret; + }; + + imports.wbg.__wbindgen_object_drop_ref = function(arg0) { + takeObject(arg0); + }; + + imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) { + const ret = getObject(arg0) == getObject(arg1); + return ret; + }; + imports.wbg.__wbindgen_is_object = function(arg0) { const val = getObject(arg0); const ret = typeof val === "object" && val !== null; @@ -426,8 +450,10 @@ export async function init(module) { return ret; }; - imports.wbg.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); + imports.wbg.__wbindgen_boolean_get = function(arg0) { + const v = getObject(arg0); + const ret = typeof v === "boolean" ? (v ? 1 : 0) : 2; + return ret; }; imports.wbg.__wbg_isArray_4c24b343cb13cfb1 = function(arg0) { @@ -462,6 +488,18 @@ export async function init(module) { return addHeapObject(ret); }; + imports.wbg.__wbindgen_number_get = function(arg0, arg1) { + const obj = getObject(arg1); + const ret = typeof obj === "number" ? obj : undefined; + getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; + getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); + }; + + imports.wbg.__wbg_isSafeInteger_bb8e18dd21c97288 = function(arg0) { + const ret = Number.isSafeInteger(getObject(arg0)); + return ret; + }; + imports.wbg.__wbg_keys_386d224d0262f361 = function(arg0) { const ret = Object.keys(getObject(arg0)); return addHeapObject(ret); @@ -520,18 +558,6 @@ export async function init(module) { return ret; }; - imports.wbg.__wbindgen_number_get = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof obj === "number" ? obj : undefined; - getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; - getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); - }; - - imports.wbg.__wbg_isSafeInteger_bb8e18dd21c97288 = function(arg0) { - const ret = Number.isSafeInteger(getObject(arg0)); - return ret; - }; - imports.wbg.__wbg_iterator_97f0c81209c6c35a = function() { const ret = Symbol.iterator; return addHeapObject(ret); @@ -559,11 +585,6 @@ export async function init(module) { return addHeapObject(ret); }; - imports.wbg.__wbg_buffer_085ec1f694018c4f = function(arg0) { - const ret = getObject(arg0).buffer; - return addHeapObject(ret); - }; - imports.wbg.__wbg_new_8125e318e6245eed = function(arg0) { const ret = new Uint8Array(getObject(arg0)); return addHeapObject(ret); @@ -578,64 +599,6 @@ export async function init(module) { return addHeapObject(ret); }; - imports.wbg.__wbg_byteLength_0488a7a303dccf40 = function(arg0) { - const ret = getObject(arg0).byteLength; - return ret; - }; - - imports.wbg.__wbg_getindex_961202524f8271d6 = function(arg0, arg1) { - const ret = getObject(arg0)[arg1 >>> 0]; - return ret; - }; - - imports.wbg.__wbindgen_object_clone_ref = function(arg0) { - const ret = getObject(arg0); - return addHeapObject(ret); - }; - - imports.wbg.__wbg_apply_f9ecfcbfefaf7349 = function() { - return handleError(function(arg0, arg1, arg2) { - const ret = Reflect.apply(getObject(arg0), getObject(arg1), getObject(arg2)); - return addHeapObject(ret); - }, arguments); - }; - - imports.wbg.__wbindgen_string_new = function(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); - }; - - imports.wbg.__wbg_log_576ca876af0d4a77 = function(arg0, arg1) { - console.log(getObject(arg0), getObject(arg1)); - }; - - imports.wbg.__wbg_newwithlength_e5d69174d6984cd7 = function(arg0) { - const ret = new Uint8Array(arg0 >>> 0); - return addHeapObject(ret); - }; - - imports.wbg.__wbg_new_553093d7f6eb5551 = function() { - return handleError(function(arg0) { - const ret = new WebAssembly.Module(getObject(arg0)); - return addHeapObject(ret); - }, arguments); - }; - - imports.wbg.__wbg_new_56693dbed0c32988 = function() { - const ret = new Map(); - return addHeapObject(ret); - }; - - imports.wbg.__wbg_set_bedc3d02d0f05eb0 = function(arg0, arg1, arg2) { - const ret = getObject(arg0).set(getObject(arg1), getObject(arg2)); - return addHeapObject(ret); - }; - - imports.wbg.__wbg_createwasi_b2f38d9d47d4b768 = function(arg0) { - const ret = create_wasi(takeObject(arg0)); - return addHeapObject(ret); - }; - imports.wbg.__wbg_setindex_24de8908d99d47eb = function(arg0, arg1, arg2) { getObject(arg0)[arg1 >>> 0] = arg2; }; @@ -648,6 +611,11 @@ export async function init(module) { getInt32Memory0()[arg0 / 4 + 0] = ptr1; }; + imports.wbg.__wbg_getindex_961202524f8271d6 = function(arg0, arg1) { + const ret = getObject(arg0)[arg1 >>> 0]; + return ret; + }; + imports.wbg.__wbg_log_53ed96ea72ace5e9 = function(arg0, arg1) { console.log(getStringFromWasm0(arg0, arg1)); }; @@ -665,6 +633,11 @@ export async function init(module) { return addHeapObject(ret); }; + imports.wbg.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbg_set_841ac57cff3d672b = function(arg0, arg1, arg2) { getObject(arg0)[takeObject(arg1)] = takeObject(arg2); }; @@ -679,19 +652,46 @@ export async function init(module) { return ret; }; + imports.wbg.__wbg_apply_f9ecfcbfefaf7349 = function() { + return handleError(function(arg0, arg1, arg2) { + const ret = Reflect.apply(getObject(arg0), getObject(arg1), getObject(arg2)); + return addHeapObject(ret); + }, arguments); + }; + imports.wbg.__wbg_error_c9309504864e78b5 = function(arg0, arg1) { console.error(getObject(arg0), getObject(arg1)); }; - imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) { - const ret = getObject(arg0) == getObject(arg1); - return ret; + imports.wbg.__wbg_newwithlength_e5d69174d6984cd7 = function(arg0) { + const ret = new Uint8Array(arg0 >>> 0); + return addHeapObject(ret); }; - imports.wbg.__wbindgen_boolean_get = function(arg0) { - const v = getObject(arg0); - const ret = typeof v === "boolean" ? (v ? 1 : 0) : 2; - return ret; + imports.wbg.__wbg_new_553093d7f6eb5551 = function() { + return handleError(function(arg0) { + const ret = new WebAssembly.Module(getObject(arg0)); + return addHeapObject(ret); + }, arguments); + }; + + imports.wbg.__wbg_new_56693dbed0c32988 = function() { + const ret = new Map(); + return addHeapObject(ret); + }; + + imports.wbg.__wbg_set_bedc3d02d0f05eb0 = function(arg0, arg1, arg2) { + const ret = getObject(arg0).set(getObject(arg1), getObject(arg2)); + return addHeapObject(ret); + }; + + imports.wbg.__wbg_createwasi_b2f38d9d47d4b768 = function(arg0) { + const ret = create_wasi(takeObject(arg0)); + return addHeapObject(ret); + }; + + imports.wbg.__wbg_log_576ca876af0d4a77 = function(arg0, arg1) { + console.log(getObject(arg0), getObject(arg1)); }; imports.wbg.__wbg_entries_e51f29c7bba0c054 = function(arg0) { @@ -794,8 +794,8 @@ export async function init(module) { throw new Error(getStringFromWasm0(arg0, arg1)); }; - imports.wbg.__wbindgen_closure_wrapper1464 = function(arg0, arg1, arg2) { - const ret = makeMutClosure(arg0, arg1, 132, __wbg_adapter_46); + imports.wbg.__wbindgen_closure_wrapper1471 = function(arg0, arg1, arg2) { + const ret = makeMutClosure(arg0, arg1, 131, __wbg_adapter_46); return addHeapObject(ret); }; diff --git a/marine-js/npm-package/src/types.ts b/marine-js/npm-package/src/types.ts index 52a2c4bc..e59285d2 100644 --- a/marine-js/npm-package/src/types.ts +++ b/marine-js/npm-package/src/types.ts @@ -70,8 +70,8 @@ export type SecurityTetraplet = { /// Name of a function that returned corresponding value. function_name: string, - /// Value was produced by applying this `lambda` to the output from `call_service`. - lambda: string, + /// Value was produced by applying this `lens` to the output from `call_service`. + lens: string, } export type LogFunction = (message: LogMessage) => void; diff --git a/marine/Cargo.toml b/marine/Cargo.toml index de1234f2..57b4df94 100644 --- a/marine/Cargo.toml +++ b/marine/Cargo.toml @@ -15,10 +15,11 @@ path = "src/lib.rs" marine-core = { path = "../core", version = "0.28.0", default-features = false} marine-module-interface = { path = "../crates/module-interface", version = "0.8.1" } marine-utils = { path = "../crates/utils", version = "0.5.1" } -marine-rs-sdk-main = { version = "0.13.0", default-features = false, features = ["logger"] } -marine-rs-sdk = { version = "0.13.0", default-features = false, features = ["logger"] } +marine-rs-sdk-main = { version = "0.14.0", default-features = false, features = ["logger"] } +marine-rs-sdk = { version = "0.14.0", default-features = false, features = ["logger"] } marine_call_parameters_v0 = { package = "marine-call-parameters", version = "=0.10.3", default-features = false } marine_call_parameters_v1 = { package = "marine-call-parameters", version = "=0.12.0", default-features = false } +marine_call_parameters_v2 = { package = "marine-call-parameters", version = "=0.13.0", default-features = false } it-json-serde = { path = "../crates/it-json-serde", version = "0.5.1" } marine-wasm-backend-traits = { path = "../crates/wasm-backend-traits", version = "0.5.1" } diff --git a/marine/src/config/to_marine_config.rs b/marine/src/config/to_marine_config.rs index 846cae02..f77b9d6a 100644 --- a/marine/src/config/to_marine_config.rs +++ b/marine/src/config/to_marine_config.rs @@ -21,9 +21,7 @@ use crate::config::MarineModuleConfig; use crate::host_imports::logger::log_utf8_string_closure; use crate::host_imports::logger::LoggerFilter; use crate::host_imports::logger::WASM_LOG_ENV_NAME; -use crate::host_imports::create_call_parameters_import_v0; -use crate::host_imports::create_call_parameters_import_v1; -use crate::host_imports::create_call_parameters_import_v2; +use crate::host_imports::create_call_parameters_import; use marine_core::generic::HostImportDescriptor; use marine_core::generic::MModuleConfig; @@ -34,6 +32,7 @@ use marine_wasm_backend_traits::WasmBackend; use marine_rs_sdk::CallParameters; use parking_lot::Mutex; +use serde::Serialize; use std::collections::HashMap; use std::collections::hash_map::Entry; @@ -56,7 +55,8 @@ impl MModuleConfigBuilder { marine_module_config: Option>, call_parameters_v0: Arc>, call_parameters_v1: Arc>, - call_parameters_v2: Arc>, + call_parameters_v2: Arc>, + call_parameters_v3: Arc>, logger_filter: &LoggerFilter<'_>, ) -> MarineResult> { let marine_module_config = match marine_module_config { @@ -78,6 +78,7 @@ impl MModuleConfigBuilder { call_parameters_v0, call_parameters_v1, call_parameters_v2, + call_parameters_v3, ) .populate_wasi(wasi)? .into_config(); @@ -133,36 +134,29 @@ impl MModuleConfigBuilder { host_imports: HashMap>>, call_parameters_v0: Arc>, call_parameters_v1: Arc>, - call_parameters_v2: Arc>, + call_parameters_v2: Arc>, + call_parameters_v3: Arc>, ) -> Self { self.config.host_imports = host_imports; - self.config - .host_imports - .entry(HostAPIVersion::V0) - .or_default() - .insert( - String::from("get_call_parameters"), - create_call_parameters_import_v0(call_parameters_v0), - ); - - self.config - .host_imports - .entry(HostAPIVersion::V1) - .or_default() - .insert( - String::from("get_call_parameters"), - create_call_parameters_import_v1(call_parameters_v1), - ); + self.add_call_parameters_import(HostAPIVersion::V0, call_parameters_v0) + .add_call_parameters_import(HostAPIVersion::V1, call_parameters_v1) + .add_call_parameters_import(HostAPIVersion::V2, call_parameters_v2) + .add_call_parameters_import(HostAPIVersion::V3, call_parameters_v3) + } + fn add_call_parameters_import( + mut self, + api_version: HostAPIVersion, + call_parameters: Arc>, + ) -> Self { self.config .host_imports - .entry(HostAPIVersion::V2) + .entry(api_version) .or_default() .insert( String::from("get_call_parameters"), - create_call_parameters_import_v2(call_parameters_v2), + create_call_parameters_import(call_parameters), ); - self } @@ -198,23 +192,14 @@ impl MModuleConfigBuilder { ) }); - self.config - .raw_imports - .entry(HostAPIVersion::V0) - .or_default() - .insert("log_utf8_string".to_string(), creator.clone()); - - self.config - .raw_imports - .entry(HostAPIVersion::V1) - .or_default() - .insert("log_utf8_string".to_string(), creator.clone()); - - self.config - .raw_imports - .entry(HostAPIVersion::V2) - .or_default() - .insert("log_utf8_string".to_string(), creator); + use HostAPIVersion::*; + for api_version in [V0, V1, V2, V3] { + self.config + .raw_imports + .entry(api_version) + .or_default() + .insert("log_utf8_string".to_string(), creator.clone()); + } self } @@ -230,7 +215,8 @@ pub(crate) fn make_marine_config( marine_module_config: Option>, call_parameters_v0: Arc>, call_parameters_v1: Arc>, - call_parameters_v2: Arc>, + call_parameters_v2: Arc>, + call_parameters_v3: Arc>, logger_filter: &LoggerFilter<'_>, ) -> MarineResult> { MModuleConfigBuilder::new().build( @@ -239,6 +225,7 @@ pub(crate) fn make_marine_config( call_parameters_v0, call_parameters_v1, call_parameters_v2, + call_parameters_v3, logger_filter, ) } diff --git a/marine/src/host_imports/call_parameters.rs b/marine/src/host_imports/call_parameters.rs index 1f3e6b1b..0ca3a8cc 100644 --- a/marine/src/host_imports/call_parameters.rs +++ b/marine/src/host_imports/call_parameters.rs @@ -23,14 +23,15 @@ use wasmer_it::IValue; use wasmer_it::IType; use parking_lot::Mutex; +use serde::Serialize; use std::ops::Deref; use std::sync::Arc; /// Create the import intended for handling get_call_parameters SDK api. -pub(crate) fn create_call_parameters_import_v2( - call_parameters: Arc>, // TODO try to avoid using mutex +pub(crate) fn create_call_parameters_import( + call_parameters: Arc>, // TODO try to avoid using mutex ) -> HostImportDescriptor { let call_parameters_closure = move |_ctx: &mut ::ImportCallContext<'_>, _args: Vec| { @@ -51,51 +52,7 @@ pub(crate) fn create_call_parameters_import_v2( } } -pub(crate) fn create_call_parameters_import_v1( - call_parameters: Arc>, // TODO try to avoid using mutex -) -> HostImportDescriptor { - let call_parameters_closure = move |_ctx: &mut ::ImportCallContext<'_>, - _args: Vec| { - let result = { - // a separate code block to unlock the mutex ASAP and to avoid double locking - crate::to_interface_value(call_parameters.lock().deref()) - .unwrap_or_else(|_| panic!("CallParameters should be convertible to IValue")) - }; - - Some(result) - }; - - HostImportDescriptor { - host_exported_func: Box::new(call_parameters_closure), - argument_types: vec![], - output_type: Some(IType::Record(0)), - error_handler: None, - } -} - -pub(crate) fn create_call_parameters_import_v0( - call_parameters: Arc>, // TODO try to avoid using mutex -) -> HostImportDescriptor { - let call_parameters_closure = move |_ctx: &mut ::ImportCallContext<'_>, - _args: Vec| { - let result = { - // a separate code block to unlock the mutex ASAP and to avoid double locking - crate::to_interface_value(call_parameters.lock().deref()) - .unwrap_or_else(|_| panic!("CallParameters should be convertible to IValue")) - }; - - Some(result) - }; - - HostImportDescriptor { - host_exported_func: Box::new(call_parameters_closure), - argument_types: vec![], - output_type: Some(IType::Record(0)), - error_handler: None, - } -} - -pub(crate) fn call_parameters_v2_to_v0( +pub(crate) fn call_parameters_v3_to_v0( call_parameters: marine_rs_sdk::CallParameters, ) -> marine_call_parameters_v0::CallParameters { let marine_rs_sdk::CallParameters { @@ -117,7 +74,7 @@ pub(crate) fn call_parameters_v2_to_v0( } } -pub(crate) fn call_parameters_v2_to_v1( +pub(crate) fn call_parameters_v3_to_v1( call_parameters: marine_rs_sdk::CallParameters, ) -> marine_call_parameters_v1::CallParameters { let marine_rs_sdk::CallParameters { @@ -140,6 +97,36 @@ pub(crate) fn call_parameters_v2_to_v1( } } +pub(crate) fn call_parameters_v3_to_v2( + call_parameters: marine_rs_sdk::CallParameters, +) -> marine_call_parameters_v2::CallParameters { + let marine_rs_sdk::CallParameters { + particle, + service_id, + service_creator_peer_id, + host_id, + tetraplets, + worker_id, + } = call_parameters; + + marine_call_parameters_v2::CallParameters { + particle: marine_call_parameters_v2::ParticleParameters { + id: particle.id, + init_peer_id: particle.init_peer_id, + signature: particle.signature, + timestamp: particle.timestamp, + ttl: particle.ttl, + script: particle.script, + token: particle.token, + }, + service_id, + service_creator_peer_id, + host_id, + worker_id, + tetraplets: to_v2_sdk_tetraplets(tetraplets), + } +} + fn to_v0_sdk_tetraplets( tetraplets: Vec>, ) -> Vec> { @@ -156,14 +143,14 @@ fn to_v0_sdk_tetraplet( peer_pk, service_id, function_name, - lambda, + lens, } = tetraplet; marine_call_parameters_v0::SecurityTetraplet { peer_pk, service_id, function_name, - json_path: lambda, + json_path: lens, } } @@ -183,13 +170,40 @@ fn to_v1_sdk_tetraplet( peer_pk, service_id, function_name, - lambda, + lens, } = tetraplet; marine_call_parameters_v1::SecurityTetraplet { peer_pk, service_id, function_name, - json_path: lambda, + json_path: lens, + } +} + +fn to_v2_sdk_tetraplets( + tetraplets: Vec>, +) -> Vec> { + tetraplets + .into_iter() + .map(|tetraplets| tetraplets.into_iter().map(to_v2_sdk_tetraplet).collect()) + .collect() +} + +fn to_v2_sdk_tetraplet( + tetraplet: SecurityTetraplet, +) -> marine_call_parameters_v2::SecurityTetraplet { + let SecurityTetraplet { + peer_pk, + service_id, + function_name, + lens, + } = tetraplet; + + marine_call_parameters_v2::SecurityTetraplet { + peer_pk, + service_id, + function_name, + lambda: lens, } } diff --git a/marine/src/host_imports/mod.rs b/marine/src/host_imports/mod.rs index 8ab01e53..e3cd9693 100644 --- a/marine/src/host_imports/mod.rs +++ b/marine/src/host_imports/mod.rs @@ -18,9 +18,8 @@ pub(crate) mod logger; mod call_parameters; mod mounted_binaries; -pub(crate) use call_parameters::create_call_parameters_import_v0; -pub(crate) use call_parameters::create_call_parameters_import_v1; -pub(crate) use call_parameters::create_call_parameters_import_v2; -pub(crate) use call_parameters::call_parameters_v2_to_v0; -pub(crate) use call_parameters::call_parameters_v2_to_v1; +pub(crate) use call_parameters::create_call_parameters_import; +pub(crate) use call_parameters::call_parameters_v3_to_v0; +pub(crate) use call_parameters::call_parameters_v3_to_v1; +pub(crate) use call_parameters::call_parameters_v3_to_v2; pub(crate) use mounted_binaries::create_mounted_binary_import; diff --git a/marine/src/marine.rs b/marine/src/marine.rs index 27bc599c..535f7c9f 100644 --- a/marine/src/marine.rs +++ b/marine/src/marine.rs @@ -24,8 +24,9 @@ use crate::MemoryStats; use crate::module_loading::load_modules_from_fs; use crate::host_imports::logger::LoggerFilter; use crate::host_imports::logger::WASM_LOG_ENV_NAME; -use crate::host_imports::call_parameters_v2_to_v0; -use crate::host_imports::call_parameters_v2_to_v1; +use crate::host_imports::call_parameters_v3_to_v0; +use crate::host_imports::call_parameters_v3_to_v1; +use crate::host_imports::call_parameters_v3_to_v2; use crate::json_to_marine_err; use marine_wasm_backend_traits::WasmBackend; @@ -66,8 +67,10 @@ pub struct Marine { call_parameters_v1: Arc>, + call_parameters_v2: Arc>, + /// Parameters of call accessible by Wasm modules. - call_parameters_v2: Arc>, + call_parameters_v3: Arc>, /// Cached module interfaces by names. module_interfaces_cache: HashMap, @@ -105,7 +108,8 @@ impl Marine { let mut marine = MarineCore::new(core_config)?; let call_parameters_v0 = Arc::>::default(); let call_parameters_v1 = Arc::>::default(); - let call_parameters_v2 = Arc::>::default(); + let call_parameters_v2 = Arc::>::default(); + let call_parameters_v3 = Arc::>::default(); let modules_dir = config.modules_dir; @@ -128,6 +132,7 @@ impl Marine { call_parameters_v0.clone(), call_parameters_v1.clone(), call_parameters_v2.clone(), + call_parameters_v3.clone(), &logger_filter, )?; @@ -141,6 +146,7 @@ impl Marine { call_parameters_v0, call_parameters_v1, call_parameters_v2, + call_parameters_v3, module_interfaces_cache: HashMap::new(), }) } @@ -287,20 +293,26 @@ impl Marine { fn update_call_parameters(&mut self, call_parameters: CallParameters) { { // a separate code block to unlock the mutex ASAP and to avoid double locking - let mut cp = self.call_parameters_v2.lock(); - *cp = call_parameters.clone(); + let mut cp = self.call_parameters_v0.lock(); + *cp = call_parameters_v3_to_v0(call_parameters.clone()); } { // a separate code block to unlock the mutex ASAP and to avoid double locking - let mut cp = self.call_parameters_v0.lock(); - *cp = call_parameters_v2_to_v0(call_parameters.clone()); + let mut cp = self.call_parameters_v1.lock(); + *cp = call_parameters_v3_to_v1(call_parameters.clone()); } { // a separate code block to unlock the mutex ASAP and to avoid double locking - let mut cp = self.call_parameters_v1.lock(); - *cp = call_parameters_v2_to_v1(call_parameters); + let mut cp = self.call_parameters_v2.lock(); + *cp = call_parameters_v3_to_v2(call_parameters.clone()); + } + + { + // a separate code block to unlock the mutex ASAP and to avoid double locking + let mut cp = self.call_parameters_v3.lock(); + *cp = call_parameters; } } } @@ -332,6 +344,7 @@ impl Marine { self.call_parameters_v0.clone(), self.call_parameters_v1.clone(), self.call_parameters_v2.clone(), + self.call_parameters_v3.clone(), &logger_filter, )?; self.core diff --git a/marine/tests/call_parameters.rs b/marine/tests/call_parameters.rs index 0c2efe58..90c6f8ed 100644 --- a/marine/tests/call_parameters.rs +++ b/marine/tests/call_parameters.rs @@ -36,6 +36,11 @@ static CONFIG_V2: Lazy = Lazy::new(|| { .expect("toml faas config should be created") }); +static CONFIG_V3: Lazy = Lazy::new(|| { + marine::TomlMarineConfig::load("./tests/wasm_tests/call_parameters_v3/Config.toml") + .expect("toml faas config should be created") +}); + #[test] pub fn call_parameters_v0() { let mut faas = Marine::with_raw_config(CONFIG_V0.clone()) @@ -50,7 +55,7 @@ pub fn call_parameters_v0() { let tetraplet = marine_rs_sdk::SecurityTetraplet { function_name: "some_func_name".to_string(), - lambda: "some_lambda".to_string(), + lens: "some_lens".to_string(), ..Default::default() }; @@ -93,7 +98,7 @@ pub fn call_parameters_v0() { "peer_pk": "", "service_id": "", "function_name": "some_func_name", - "json_path": "some_lambda", + "json_path": "some_lens", }]], }); @@ -115,7 +120,7 @@ pub fn call_parameters_v1() { let tetraplet = marine_rs_sdk::SecurityTetraplet { function_name: "some_func_name".to_string(), - lambda: "some_lambda".to_string(), + lens: "some_lens".to_string(), ..Default::default() }; @@ -159,7 +164,7 @@ pub fn call_parameters_v1() { "peer_pk": "", "service_id": "", "function_name": "some_func_name", - "json_path": "some_lambda", + "json_path": "some_lens", }]], }); @@ -181,7 +186,7 @@ pub fn call_parameters_v2() { let tetraplet = marine_rs_sdk::SecurityTetraplet { function_name: "some_func_name".to_string(), - lambda: "some_lambda".to_string(), + lens: "some_lens".to_string(), ..Default::default() }; @@ -210,6 +215,71 @@ pub fn call_parameters_v2() { "call_parameters_v2", "call_parameters", json!([]), + call_parameters, + ) + .unwrap_or_else(|e| panic!("can't invoke call_parameters: {:?}", e)); + + let expected = json!({ + "particle": particle, + "service_id": service_id, + "service_creator_peer_id": service_creator_peer_id, + "host_id": host_id, + "worker_id": worker_id, + "tetraplets": [[{ + "peer_pk": "", + "service_id": "", + "function_name": "some_func_name", + "lambda": "some_lens", + }]], + }); + + let result_json: serde_json::Value = serde_json::from_str(result.as_str().unwrap()).unwrap(); + assert_eq!(expected, result_json,); +} + +#[test] +pub fn call_parameters_v3() { + let mut faas = Marine::with_raw_config(CONFIG_V3.clone()) + .unwrap_or_else(|e| panic!("can't create Fluence FaaS instance: {}", e)); + + let init_peer_id = "init_peer_id"; + let service_id = "service_id"; + let service_creator_peer_id = "service_creator_peer_id"; + let worker_id = "worker_id"; + let host_id = "host_id"; + let particle_id = "particle_id"; + + let tetraplet = marine_rs_sdk::SecurityTetraplet { + function_name: "some_func_name".to_string(), + lens: "some_lens".to_string(), + ..Default::default() + }; + + let tetraplets = vec![vec![tetraplet]]; + + let particle = marine_rs_sdk::ParticleParameters { + id: particle_id.to_string(), + init_peer_id: init_peer_id.to_string(), + timestamp: 0, + ttl: 0, + script: "(null)".to_string(), + signature: vec![], + token: "token".to_string(), + }; + let call_parameters = marine_rs_sdk::CallParameters { + particle: particle.clone(), + service_id: service_id.to_string(), + service_creator_peer_id: service_creator_peer_id.to_string(), + host_id: host_id.to_string(), + worker_id: worker_id.to_string(), + tetraplets: tetraplets.clone(), + }; + + let result = faas + .call_with_json( + "call_parameters_v3", + "call_parameters", + json!([]), call_parameters.clone(), ) .unwrap_or_else(|e| panic!("can't invoke call_parameters: {:?}", e)); diff --git a/marine/tests/wasm_tests/arguments_passing/Cargo.toml b/marine/tests/wasm_tests/arguments_passing/Cargo.toml index 3e304a44..3c5526a8 100644 --- a/marine/tests/wasm_tests/arguments_passing/Cargo.toml +++ b/marine/tests/wasm_tests/arguments_passing/Cargo.toml @@ -14,5 +14,5 @@ name = "arguments_passing_effector" path = "src/effector.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" safe-transmute = "0.11.0" diff --git a/marine/tests/wasm_tests/arrays_passing/Cargo.toml b/marine/tests/wasm_tests/arrays_passing/Cargo.toml index 31d11ce4..6396ea39 100644 --- a/marine/tests/wasm_tests/arrays_passing/Cargo.toml +++ b/marine/tests/wasm_tests/arrays_passing/Cargo.toml @@ -14,5 +14,5 @@ name = "arrays_passing_effector" path = "src/effector.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" safe-transmute = "0.11.0" diff --git a/marine/tests/wasm_tests/call_parameters_v0/Cargo.toml b/marine/tests/wasm_tests/call_parameters_v0/Cargo.toml index bbe59aef..16a1a127 100644 --- a/marine/tests/wasm_tests/call_parameters_v0/Cargo.toml +++ b/marine/tests/wasm_tests/call_parameters_v0/Cargo.toml @@ -10,5 +10,5 @@ name = "call_parameters_v0" path = "src/main.rs" [dependencies] -marine-rs-sdk = "0.10.3" # do not update, host API v0 test +marine-rs-sdk = "=0.10.3" # do not update, host API v0 test serde_json = "1.0.111" diff --git a/marine/tests/wasm_tests/call_parameters_v1/Cargo.toml b/marine/tests/wasm_tests/call_parameters_v1/Cargo.toml index c25559eb..7194970a 100644 --- a/marine/tests/wasm_tests/call_parameters_v1/Cargo.toml +++ b/marine/tests/wasm_tests/call_parameters_v1/Cargo.toml @@ -10,5 +10,5 @@ name = "call_parameters_v1" path = "src/main.rs" [dependencies] -marine-rs-sdk = "0.12.0" # do not update, host API v1 test +marine-rs-sdk = "=0.12.0" # do not update, host API v1 test serde_json = "1.0.111" diff --git a/marine/tests/wasm_tests/call_parameters_v3/Cargo.toml b/marine/tests/wasm_tests/call_parameters_v3/Cargo.toml new file mode 100644 index 00000000..9321b526 --- /dev/null +++ b/marine/tests/wasm_tests/call_parameters_v3/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "call-parameters-v3-test" +version = "0.1.0" +authors = ["Fluence Labs"] +edition = "2021" +publish = false + +[[bin]] +name = "call_parameters_v3" +path = "src/main.rs" + +[dependencies] +marine-rs-sdk = "=0.14.0" # do not update, host API v3 test +serde_json = "1.0.111" diff --git a/marine/tests/wasm_tests/call_parameters_v3/Config.toml b/marine/tests/wasm_tests/call_parameters_v3/Config.toml new file mode 100644 index 00000000..a5723e51 --- /dev/null +++ b/marine/tests/wasm_tests/call_parameters_v3/Config.toml @@ -0,0 +1,6 @@ +modules_dir = "./artifacts/" +total_memory_limit = "10 MiB" + +[[module]] + name = "call_parameters_v3" + diff --git a/marine/tests/wasm_tests/call_parameters_v3/src/main.rs b/marine/tests/wasm_tests/call_parameters_v3/src/main.rs new file mode 100644 index 00000000..0b810969 --- /dev/null +++ b/marine/tests/wasm_tests/call_parameters_v3/src/main.rs @@ -0,0 +1,25 @@ +/* + * Copyright 2024 Fluence Labs Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +use marine_rs_sdk::marine; + +pub fn main() {} + +#[marine] +pub fn call_parameters() -> String { + let cp = marine_rs_sdk::get_call_parameters(); + serde_json::to_string(&cp).unwrap() +} diff --git a/marine/tests/wasm_tests/memory_limiting/Cargo.toml b/marine/tests/wasm_tests/memory_limiting/Cargo.toml index afaa5c98..78af5c30 100644 --- a/marine/tests/wasm_tests/memory_limiting/Cargo.toml +++ b/marine/tests/wasm_tests/memory_limiting/Cargo.toml @@ -14,5 +14,5 @@ name = "memory_limiting_effector" path = "src/effector.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" safe-transmute = "0.11.0" diff --git a/marine/tests/wasm_tests/records_passing/Cargo.toml b/marine/tests/wasm_tests/records_passing/Cargo.toml index 4019be84..51903390 100644 --- a/marine/tests/wasm_tests/records_passing/Cargo.toml +++ b/marine/tests/wasm_tests/records_passing/Cargo.toml @@ -14,5 +14,5 @@ name = "records_passing_pure" path = "src/pure.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" safe-transmute = "0.11.0" diff --git a/marine/tests/wasm_tests/wasi/Cargo.toml b/marine/tests/wasm_tests/wasi/Cargo.toml index 73e3dd32..bc4ca5c8 100644 --- a/marine/tests/wasm_tests/wasi/Cargo.toml +++ b/marine/tests/wasm_tests/wasi/Cargo.toml @@ -10,5 +10,5 @@ name = "wasi_effector" path = "src/effector.rs" [dependencies] -marine-rs-sdk = "0.13.0" +marine-rs-sdk = "0.14.0" safe-transmute = "0.11.0" diff --git a/tools/repl/Cargo.toml b/tools/repl/Cargo.toml index db46e2a4..87ea7ce1 100644 --- a/tools/repl/Cargo.toml +++ b/tools/repl/Cargo.toml @@ -13,7 +13,7 @@ path = "src/main.rs" [dependencies] fluence-app-service = { path = "../../crates/fluence-app-service", version = "0.33.0", features = ["raw-module-api"] } -marine-rs-sdk-main = { version = "0.13.0", default-features = false, features = ["logger"] } +marine-rs-sdk-main = { version = "0.14.0", default-features = false, features = ["logger"] } marine-wasm-backend-traits = {path = "../../crates/wasm-backend-traits", version = "0.5.1" } anyhow = "1.0.75"