diff --git a/Cargo.lock b/Cargo.lock index db968c4940..553caae189 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2186,14 +2186,14 @@ dependencies = [ [[package]] name = "fluence-app-service" -version = "0.32.0" +version = "0.33.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a778e8164aa18de47e53c65f04f56b8dee7d3a7decef0d76313f41d855d990d2" +checksum = "ec5358cd011d91885b81539bc36f8f67075cd6bb1bf260c7ab35a7ff31b5870d" dependencies = [ "log", "maplit", "marine-min-it-version", - "marine-runtime 0.33.0", + "marine-runtime 0.34.0", "marine-wasm-backend-traits", "marine-wasmtime-backend", "serde", @@ -4297,6 +4297,17 @@ dependencies = [ "serde", ] +[[package]] +name = "marine-call-parameters" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d16852b36a3cfc8fa044955380901e78109db0035dc93eea4f666d8f3979072" +dependencies = [ + "marine-macro 0.13.0", + "marine-rs-sdk-main 0.13.0", + "serde", +] + [[package]] name = "marine-core" version = "0.26.1" @@ -4328,20 +4339,20 @@ dependencies = [ [[package]] name = "marine-core" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff7a647c1c71708d7888f4ffb345c941707834bbd6d045902f87b9d9cb6221f" +checksum = "9b9a08bd99ea96356abdac57700a58496dc4034d1f48000fb54e532fc5021c8d" dependencies = [ "anyhow", "bytesize", "it-lilo", "it-memory-traits", "log", - "marine-it-generator 0.14.0", + "marine-it-generator 0.15.0", "marine-it-interfaces", "marine-it-parser", "marine-min-it-version", - "marine-module-info-parser 0.12.0", + "marine-module-info-parser 0.13.0", "marine-module-interface", "marine-utils", "marine-wasm-backend-traits", @@ -4374,13 +4385,13 @@ dependencies = [ [[package]] name = "marine-it-generator" -version = "0.14.0" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93d2788f00beff11b53596c9bd4b4f0e0e9722e4a3562f87245c0cda9acfb6f2" +checksum = "64902f7fee0488f2b1e27e8f595772f1a7a386d07f74e55a07def1ad967a64fd" dependencies = [ "it-lilo", "marine-it-parser", - "marine-macro-impl 0.12.0", + "marine-macro-impl 0.13.0", "once_cell", "serde", "serde_json", @@ -4438,6 +4449,16 @@ dependencies = [ "marine-rs-sdk-main 0.12.0", ] +[[package]] +name = "marine-macro" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cec2cd19fedf559833d0f1e6a33cbcc5cf0efa338bb0975346ff12538a3cdde4" +dependencies = [ + "marine-macro-impl 0.13.0", + "marine-rs-sdk-main 0.13.0", +] + [[package]] name = "marine-macro-impl" version = "0.7.1" @@ -4477,6 +4498,19 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "marine-macro-impl" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e09acb3ada67e69a301b6d7b52a915a36176c5eedb312647de7d5b6cf17f51e4" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "serde_json", + "syn 1.0.109", +] + [[package]] name = "marine-min-it-version" version = "0.3.2" @@ -4506,14 +4540,14 @@ dependencies = [ [[package]] name = "marine-module-info-parser" -version = "0.12.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "756f037bef1271185452eb8297435751af31d8c62f7b04841bacf1b24d562c83" +checksum = "e39ef4b727e6e895b0b53682dc35463e00004aa0089d49797b4f289227ea3b5d" dependencies = [ "anyhow", "chrono", "derivative", - "marine-rs-sdk-main 0.12.0", + "marine-rs-sdk-main 0.13.0", "marine-wasm-backend-traits", "semver 1.0.20", "serde", @@ -4564,6 +4598,19 @@ dependencies = [ "serde", ] +[[package]] +name = "marine-rs-sdk" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f33834365d1e6dd041e821a758000f32bed5b960edb09f9d8c61e340dd82e29" +dependencies = [ + "marine-call-parameters 0.13.0", + "marine-macro 0.13.0", + "marine-rs-sdk-main 0.13.0", + "marine-timestamp-macro 0.13.0", + "serde", +] + [[package]] name = "marine-rs-sdk-main" version = "0.10.3" @@ -4584,6 +4631,16 @@ dependencies = [ "serde", ] +[[package]] +name = "marine-rs-sdk-main" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "58b487a1a1b288ba06c832942eadb43384cd99c9754c1454e1e061dd9866be92" +dependencies = [ + "log", + "serde", +] + [[package]] name = "marine-runtime" version = "0.32.1" @@ -4615,9 +4672,9 @@ dependencies = [ [[package]] name = "marine-runtime" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee2daa12b5143d9a152d6ae2f6accdc884887a653a2b259af901df86a6f49833" +checksum = "e26c68703d0dc853790adf27813734a696dc75182a93c2a7b3d24a86eed56254" dependencies = [ "bytesize", "it-json-serde", @@ -4625,10 +4682,11 @@ dependencies = [ "itertools 0.10.5", "log", "marine-call-parameters 0.10.3", - "marine-core 0.27.0", + "marine-call-parameters 0.12.0", + "marine-core 0.28.0", "marine-module-interface", - "marine-rs-sdk 0.12.0", - "marine-rs-sdk-main 0.12.0", + "marine-rs-sdk 0.13.0", + "marine-rs-sdk-main 0.13.0", "marine-utils", "marine-wasm-backend-traits", "marine-wasmtime-backend", @@ -4673,6 +4731,16 @@ dependencies = [ "quote", ] +[[package]] +name = "marine-timestamp-macro" +version = "0.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a5086357724dc2a65e7abe39c85d58b9971198f8678ebc642a69aae1bbc7ae0" +dependencies = [ + "chrono", + "quote", +] + [[package]] name = "marine-utils" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 686698cff7..f8f08538ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -105,7 +105,7 @@ fluence-spell-dtos = "=0.7.0" fluence-spell-distro = "=0.7.0" # marine -fluence-app-service = { version = "0.32.0" } +fluence-app-service = { version = "0.33.0" } marine-utils = "0.5.1" marine-it-parser = "0.15.1" diff --git a/aquamarine/src/plumber.rs b/aquamarine/src/plumber.rs index fde54a57c6..208a9eae06 100644 --- a/aquamarine/src/plumber.rs +++ b/aquamarine/src/plumber.rs @@ -15,6 +15,7 @@ */ use eyre::eyre; +use fluence_keypair::KeyPair; use futures::future::BoxFuture; use futures::FutureExt; use std::collections::hash_map::Entry; @@ -180,7 +181,13 @@ impl Plumber { match entry { Entry::Occupied(actor) => Ok(actor.into_mut()), Entry::Vacant(entry) => { - let params = ParticleParams::clone_from(particle.as_ref(), peer_scope); + // TODO: move to a better place + let particle_token = get_particle_token( + &self.key_storage.root_key_pair, + &particle.particle.signature, + )?; + let params = + ParticleParams::clone_from(particle.as_ref(), peer_scope, particle_token); let functions = Functions::new(params, builtins.clone()); let key_pair = self .key_storage @@ -416,6 +423,16 @@ impl Plumber { } } +fn get_particle_token(key_pair: &KeyPair, signature: &Vec) -> eyre::Result { + let particle_token = key_pair.sign(signature.as_slice()).map_err(|err| { + eyre!( + "Could not produce particle token by signing the particle signature: {}", + err + ) + })?; + Ok(bs58::encode(particle_token.to_vec()).into_string()) +} + /// Implements `now` by taking number of non-leap seconds from `Utc::now()` mod real_time { #[allow(dead_code)] diff --git a/crates/nox-tests/tests/tetraplets.rs b/crates/nox-tests/tests/tetraplets.rs index 0760efa7b0..172fa4207c 100644 --- a/crates/nox-tests/tests/tetraplets.rs +++ b/crates/nox-tests/tests/tetraplets.rs @@ -95,7 +95,7 @@ async fn test_tetraplets() { let tetraplet = &ap_literal_tetraplets[0][0]; assert_eq!(tetraplet.function_name, ""); assert_eq!(tetraplet.peer_pk, client.peer_id.to_base58()); - assert_eq!(tetraplet.json_path, ""); + assert_eq!(tetraplet.lambda, ""); assert_eq!(tetraplet.service_id, ""); let first_tetraplets = args.next().unwrap(); @@ -108,7 +108,7 @@ async fn test_tetraplets() { let tetraplet = &first_tetraplets[0][0]; assert_eq!(tetraplet.function_name, "identity"); assert_eq!(tetraplet.peer_pk, client.node.to_base58()); - assert_eq!(tetraplet.json_path, ""); + assert_eq!(tetraplet.lambda, ""); assert_eq!(tetraplet.service_id, "op"); let ap_first_tetraplets = args.next().unwrap(); @@ -127,6 +127,6 @@ async fn test_tetraplets() { let tetraplet = &second_tetraplets[0][0]; assert_eq!(tetraplet.function_name, "get_tetraplets"); assert_eq!(tetraplet.peer_pk, client.node.to_base58()); - assert_eq!(tetraplet.json_path, ".$.[0].[0].peer_pk"); + assert_eq!(tetraplet.lambda, ".$.[0].[0].peer_pk"); assert_eq!(tetraplet.service_id, tetraplets_service.id.as_str()); } diff --git a/crates/nox-tests/tests/tetraplets/Cargo.toml b/crates/nox-tests/tests/tetraplets/Cargo.toml index 630739d8ca..82bf46fa24 100644 --- a/crates/nox-tests/tests/tetraplets/Cargo.toml +++ b/crates/nox-tests/tests/tetraplets/Cargo.toml @@ -5,11 +5,9 @@ authors = ["Fluence Labs"] edition = "2021" [dependencies] -marine-rs-sdk = "0.7.0" -once_cell = { workspace = true } +marine-rs-sdk = "0.13.0" +once_cell = "1.19.0" [[bin]] name = "tetraplets" -path = "src/main.rs" - -[workspace] +path = "src/main.rs" \ No newline at end of file diff --git a/crates/nox-tests/tests/tetraplets/artifacts/tetraplets.wasm b/crates/nox-tests/tests/tetraplets/artifacts/tetraplets.wasm index 62ee7a7d1b..cb9a26d558 100755 Binary files a/crates/nox-tests/tests/tetraplets/artifacts/tetraplets.wasm and b/crates/nox-tests/tests/tetraplets/artifacts/tetraplets.wasm differ diff --git a/crates/nox-tests/tests/tetraplets/src/main.rs b/crates/nox-tests/tests/tetraplets/src/main.rs index 012c0b85be..84c4797ce5 100644 --- a/crates/nox-tests/tests/tetraplets/src/main.rs +++ b/crates/nox-tests/tests/tetraplets/src/main.rs @@ -1,4 +1,3 @@ -#![feature(once_cell)] /* * Copyright 2021 Fluence Labs Limited * diff --git a/particle-execution/src/particle_params.rs b/particle-execution/src/particle_params.rs index 4fe725d474..23fdfd00a5 100644 --- a/particle-execution/src/particle_params.rs +++ b/particle-execution/src/particle_params.rs @@ -14,6 +14,7 @@ * limitations under the License. */ +use fluence_app_service::ParticleParameters; use fluence_libp2p::PeerId; use particle_protocol::Particle; use types::peer_scope::PeerScope; @@ -31,10 +32,12 @@ pub struct ParticleParams { pub ttl: u32, pub script: String, pub signature: Vec, + // Particle token, `signature` signed with the peer's private key + pub token: String, } impl ParticleParams { - pub fn clone_from(particle: &Particle, peer_scope: PeerScope) -> Self { + pub fn clone_from(particle: &Particle, peer_scope: PeerScope, token: String) -> Self { let Particle { id, init_peer_id, @@ -53,6 +56,7 @@ impl ParticleParams { ttl: *ttl, script: script.clone(), signature: signature.clone(), + token, } } @@ -67,4 +71,16 @@ impl ParticleParams { None } } + + pub fn to_particle_parameters(self) -> ParticleParameters { + ParticleParameters { + id: self.id, + init_peer_id: self.init_peer_id.to_string(), + timestamp: self.timestamp, + ttl: self.ttl, + script: self.script, + signature: self.signature, + token: self.token, + } + } } diff --git a/particle-services/src/app_services.rs b/particle-services/src/app_services.rs index f5f7187b5c..83f9fc402d 100644 --- a/particle-services/src/app_services.rs +++ b/particle-services/src/app_services.rs @@ -437,10 +437,11 @@ impl ParticleAppServices { let call_parameters_worker_id = self.scopes.to_peer_id(peer_scope); let params = CallParameters { + particle: particle.to_particle_parameters(), + service_id: service_id.clone(), + service_creator_peer_id: service.owner_id.to_string(), host_id: self.scopes.get_host_peer_id().to_string(), worker_id: call_parameters_worker_id.to_string(), - particle_id: particle.id, - init_peer_id: particle.init_peer_id.to_string(), tetraplets: function_args .tetraplets .into_iter() @@ -450,13 +451,11 @@ impl ParticleAppServices { peer_pk: st.peer_pk, service_id: st.service_id, function_name: st.function_name, - json_path: st.json_path, + lambda: st.json_path, }) .collect() }) .collect(), - service_id: service_id.clone(), - service_creator_peer_id: service.owner_id.to_string(), }; let function_name = function_args.function_name; @@ -518,6 +517,7 @@ impl ParticleAppServices { FunctionOutcome::Ok(result) } + // TODO: is it safe? #[allow(clippy::too_many_arguments)] pub fn call_function( &self, @@ -544,6 +544,8 @@ impl ParticleAppServices { ttl: particle_ttl.as_millis() as u32, script: "".to_string(), signature: vec![], + // TODO: Is it safe? + token: "host_call".to_string(), }; self.call_service(args, particle, false)