feat!: move SecurityTetraplets from popyplets directly to marine-rs-sdk crate (#127)

* update to popyplets 4.0

* update Cargp.lock

* feat!: move SecurityTetraplets from popyplets directly to marine-rs-sdk crate

* update doc
This commit is contained in:
Valery Antopol 2023-08-16 19:59:28 +03:00 committed by GitHub
parent 46c53330ba
commit add9b919ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 69 additions and 66 deletions

53
Cargo.lock generated
View File

@ -232,35 +232,12 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "marine-macro"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f2928ba9662d0b60f757da8a9fb52f8a452b0c48143cdf20249bd33f607defa"
dependencies = [
"marine-macro-impl 0.8.0",
"marine-rs-sdk-main 0.8.0",
]
[[package]]
name = "marine-macro"
version = "0.8.1"
dependencies = [
"marine-macro-impl 0.8.1",
"marine-rs-sdk-main 0.8.1",
]
[[package]]
name = "marine-macro-impl"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "691de6935391c8d30de2848c201be166b46c1068caed64c78408ec5483e5b452"
dependencies = [
"proc-macro2",
"quote",
"serde",
"serde_json",
"syn 1.0.109",
"marine-macro-impl",
"marine-rs-sdk-main",
]
[[package]]
@ -289,24 +266,13 @@ dependencies = [
name = "marine-rs-sdk"
version = "0.8.1"
dependencies = [
"marine-macro 0.8.1",
"marine-rs-sdk-main 0.8.1",
"marine-macro",
"marine-rs-sdk-main",
"marine-timestamp-macro",
"polyplets",
"serde",
"trybuild",
]
[[package]]
name = "marine-rs-sdk-main"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6b58feff60121f01e6c8d9c1504b1e8147b5d12c6c9ea84032cddb2b2294799f"
dependencies = [
"log",
"serde",
]
[[package]]
name = "marine-rs-sdk-main"
version = "0.8.1"
@ -368,17 +334,6 @@ dependencies = [
"winapi",
]
[[package]]
name = "polyplets"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b579a79a461ca50abb202eac61c76d8782fdf091a91775c9e181352e7cd30a8b"
dependencies = [
"marine-macro 0.8.0",
"marine-rs-sdk-main 0.8.0",
"serde",
]
[[package]]
name = "pretty_assertions"
version = "1.3.0"

View File

@ -21,7 +21,6 @@ doctest = false
marine-macro = { path = "crates/marine-macro", version = "=0.8.1" }
marine-rs-sdk-main = { path = "crates/main", version = "=0.8.1" } # warning: silent compilation break on minor verison bump. See docs/update-guide.md for details
marine-timestamp-macro = { path = "crates/timestamp-macro", version = "=0.8.1" }
polyplets = "0.4.0"
serde = { version = "1.0.155", features = ["derive"]}

View File

@ -10,21 +10,9 @@ Here is the list of main components crucial from the update point of view:
## Marine Rust SDK update policy
### Versioning
All the crates in this repo have the same version, and all repository-local dependencies are strict (denoted by `=x.y.z` notation).
### Coupling with AquaVM
The `marine-rs-sdk-main` crate uses `#[no_mangle]` exports, and `marine-rs-sdk` crate too -- by transitivity. That's why it is impossible to use two different versions of this `marine-rs-sdk-main` when compiling a single binary, regardless of their versions. Also, there is a circular cross-repository dependency with [**AquaVM**](https://github.com/fluencelabs/aquavm):
[**polyplets**](https://github.com/fluencelabs/aquavm/tree/master/crates/air-lib/polyplets) depends on `marine-rs-sdk-main`, while `marine-rs-sdk` depends on `polyplets`. AquaVM repo also uses `marine-rs-sdk` in several crates.
As a result, it is not enough just to update a minor or patch version of this repo - it also requires updating `polyplets` to a version that uses `marine-rs-sdk-main` with the same major and minor versions as `marine-rs-sdk`.
The following update process should ensure that there is no semver-broken version is used:
1. release new *minor* version `marine-rs-sdk@0.x.0`and so on
2. update AquaVM to `marine-rs-sdk@0.x.0` and so on, bump *minor* version for `polyplets` to `0.y.0`
3. release `marine-rs-sdk@0.x.1` that uses `polyplets@0.y.0`
4. update AquaVM to use `marine-rs-sdk@0.x.1` and so on, bump *patch* version on `poluplets` to `0.y.1`
5. yank `marine-rs-sdk@0.x.0` and so on
This process **WILL** break build of the AquaVM between the steps 2-4, so the whole process should be completed without delays. `mairne-rs-sdk@0.x.0` will contain different minor versions of `marine-rs-sdk-main` so it should never be used -- therefore it is yanked.
## Important notes
The `marine-rs-sdk-main` crate uses `#[no_mangle]` exports, and `marine-rs-sdk` crate too - by transitivity. That's why it is impossible to use two different versions of this `marine-rs-sdk-main` when compiling a single binary, regardless of their versions.

View File

@ -15,11 +15,61 @@
*/
use marine_macro::marine;
pub use polyplets::SecurityTetraplet;
use serde::Serialize;
use serde::Deserialize;
/// Describes an origin that set corresponding value.
#[marine]
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash, Serialize, Deserialize)]
pub struct SecurityTetraplet {
/// Id of a peer where corresponding value was set.
pub peer_pk: String,
/// Id of a service that set corresponding value.
pub service_id: String,
/// Name of a function that returned corresponding value.
pub function_name: String,
/// Value was produced by applying this `json_path` to the output from `call_service`.
// TODO: since it's not a json path anymore, it's needed to rename it to lambda
pub json_path: String,
}
impl SecurityTetraplet {
pub fn new(
peer_pk: impl Into<String>,
service_id: impl Into<String>,
function_name: impl Into<String>,
json_path: impl Into<String>,
) -> Self {
Self {
peer_pk: peer_pk.into(),
service_id: service_id.into(),
function_name: function_name.into(),
json_path: json_path.into(),
}
}
/// Create a tetraplet for string literals defined in the script
/// such as variable here `(call ("" "") "" ["variable_1"])`.
pub fn literal_tetraplet(init_peer_id: impl Into<String>) -> Self {
Self {
// these variables represent the initiator peer
peer_pk: init_peer_id.into(),
service_id: String::new(),
function_name: String::new(),
// json path can't be applied to the string literals
json_path: String::new(),
}
}
pub fn add_lambda(&mut self, json_path: &str) {
self.json_path.push_str(json_path)
}
}
/// This struct contains parameters that would be accessible by Wasm modules.
#[marine]
#[derive(Clone, PartialEq, Default, Eq, Debug, Serialize, Deserialize)]
@ -43,6 +93,17 @@ pub struct CallParameters {
pub tetraplets: Vec<Vec<SecurityTetraplet>>,
}
use std::fmt;
impl fmt::Display for SecurityTetraplet {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"peer_pk: {}, service_id: {}, function_name: {}, json_path: {}",
self.peer_pk, self.service_id, self.function_name, self.json_path
)
}
}
/// This functions takes from host current call parameters.
/// Beware that this implies import function call which takes some time.
#[cfg(target_arch = "wasm32")]