Allow runtime to set maximum memory count (#127)

This commit is contained in:
Mike Voronov 2021-12-03 20:33:46 +03:00 committed by GitHub
parent e09a167bc7
commit c7c8d611d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
49 changed files with 715 additions and 318 deletions

378
Cargo.lock generated
View File

@ -36,15 +36,6 @@ dependencies = [
"memchr",
]
[[package]]
name = "ansi_term"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b"
dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "ansi_term"
version = "0.12.1"
@ -56,9 +47,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.45"
version = "1.0.51"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ee10e43ae4a853c0a3591d4e2ada1719e553be18199d9da9d4a83f5927c2f5c7"
checksum = "8b26702f315f53b6071259e15dd9d64528213b44d61de1ec926eca7715d62203"
[[package]]
name = "arguments-passing-test"
@ -197,6 +188,15 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
[[package]]
name = "bytesize"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c58ec36aac5066d5ca17df51b3e70279f5670a72102f5752cb7e7c856adfc70"
dependencies = [
"serde",
]
[[package]]
name = "call_parameters"
version = "0.1.0"
@ -218,9 +218,9 @@ dependencies = [
[[package]]
name = "cc"
version = "1.0.71"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "79c2681d6594606957bbb8631c4b90a7fcaaa72cdb714743a437b156d6a7eedd"
checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
[[package]]
name = "cfg-if"
@ -242,7 +242,7 @@ checksum = "686b97f42c02048850cf72da8a67a42c094d57f50e216b735d94aad32fd3c4c9"
dependencies = [
"anyhow",
"chrono",
"reqwest 0.11.6",
"reqwest 0.11.7",
"semver 1.0.4",
"serde",
]
@ -263,11 +263,11 @@ dependencies = [
[[package]]
name = "clap"
version = "2.33.3"
version = "2.34.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002"
checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c"
dependencies = [
"ansi_term 0.11.0",
"ansi_term",
"atty",
"bitflags",
"strsim 0.8.0",
@ -472,6 +472,16 @@ dependencies = [
"darling_macro 0.12.4",
]
[[package]]
name = "darling"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12"
dependencies = [
"darling_core 0.13.0",
"darling_macro 0.13.0",
]
[[package]]
name = "darling_core"
version = "0.10.2"
@ -500,6 +510,20 @@ dependencies = [
"syn",
]
[[package]]
name = "darling_core"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"strsim 0.10.0",
"syn",
]
[[package]]
name = "darling_macro"
version = "0.10.2"
@ -522,6 +546,17 @@ dependencies = [
"syn",
]
[[package]]
name = "darling_macro"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc"
dependencies = [
"darling_core 0.13.0",
"quote",
"syn",
]
[[package]]
name = "derive_builder"
version = "0.9.0"
@ -714,25 +749,11 @@ dependencies = [
"synstructure",
]
[[package]]
name = "fluence-app-service"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58d92fd37b7673513efafb0d1e0c366b8d6f297b74e9bfcda27c452f400af70a"
dependencies = [
"fluence-faas 0.9.2",
"log",
"maplit",
"serde",
"serde_derive",
"serde_json",
"toml",
"wasmer-wasi-fl",
]
[[package]]
name = "fluence-app-service"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01c66660de99826038c5ec4ad0f5dccf10b1c8a15924aeaa5315ab49d718bfc9"
dependencies = [
"fluence-faas 0.9.3",
"log",
@ -744,11 +765,25 @@ dependencies = [
"wasmer-wasi-fl",
]
[[package]]
name = "fluence-app-service"
version = "0.11.0"
dependencies = [
"fluence-faas 0.10.0",
"log",
"maplit",
"serde",
"serde_derive",
"serde_json",
"toml",
"wasmer-wasi-fl",
]
[[package]]
name = "fluence-faas"
version = "0.9.2"
version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fe120218635fd3055bdf3f7e4cf765e2e72866874818bd10f40e2abde882326"
checksum = "2abf1682505636b8c3436a2787df7bbae426d4f5277f5ae4ad193032b318b7f1"
dependencies = [
"cmd_lib",
"itertools 0.9.0",
@ -756,7 +791,7 @@ dependencies = [
"marine-module-interface 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
"marine-rs-sdk",
"marine-rs-sdk-main",
"marine-runtime 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)",
"marine-runtime 0.7.2",
"marine-utils 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"safe-transmute",
"serde",
@ -772,8 +807,9 @@ dependencies = [
[[package]]
name = "fluence-faas"
version = "0.9.3"
version = "0.10.0"
dependencies = [
"bytesize",
"cmd_lib",
"env_logger 0.7.1",
"itertools 0.9.0",
@ -781,7 +817,7 @@ dependencies = [
"marine-module-interface 0.1.6",
"marine-rs-sdk",
"marine-rs-sdk-main",
"marine-runtime 0.7.2",
"marine-runtime 0.8.0",
"marine-utils 0.2.0",
"once_cell",
"pretty_assertions",
@ -789,6 +825,7 @@ dependencies = [
"serde",
"serde_derive",
"serde_json",
"serde_with",
"thiserror",
"toml",
"wasmer-interface-types-fl",
@ -859,44 +896,43 @@ checksum = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7"
[[package]]
name = "futures-channel"
version = "0.3.17"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5da6ba8c3bb3c165d3c7319fc1cc8304facf1fb8db99c5de877183c08a273888"
checksum = "7fc8cd39e3dbf865f7340dce6a2d401d24fd37c6fe6c4f0ee0de8bfca2252d27"
dependencies = [
"futures-core",
]
[[package]]
name = "futures-core"
version = "0.3.17"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88d1c26957f23603395cd326b0ffe64124b818f4449552f960d815cfba83a53d"
checksum = "629316e42fe7c2a0b9a65b47d159ceaa5453ab14e8f0a3c5eedbb8cd55b4a445"
[[package]]
name = "futures-io"
version = "0.3.17"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "522de2a0fe3e380f1bc577ba0474108faf3f6b18321dbf60b3b9c39a75073377"
checksum = "e481354db6b5c353246ccf6a728b0c5511d752c08da7260546fc0933869daa11"
[[package]]
name = "futures-sink"
version = "0.3.17"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36ea153c13024fe480590b3e3d4cad89a0cfacecc24577b68f86c6ced9c2bc11"
checksum = "996c6442437b62d21a32cd9906f9c41e7dc1e19a9579843fad948696769305af"
[[package]]
name = "futures-task"
version = "0.3.17"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d3d00f4eddb73e498a54394f228cd55853bdf059259e8e7bc6e69d408892e99"
checksum = "dabf1872aaab32c886832f2276d2f5399887e2bd613698a02359e4ea83f8de12"
[[package]]
name = "futures-util"
version = "0.3.17"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "36568465210a3a6ee45e1f165136d68671471a501e632e9a98d96872222b5481"
checksum = "41d22213122356472061ac0f1ab2cee28d2bac8491410fd68c2af53d1cedb83e"
dependencies = [
"autocfg",
"futures-core",
"futures-io",
"futures-task",
@ -1027,7 +1063,7 @@ dependencies = [
"http",
"indexmap",
"slab",
"tokio 1.13.0",
"tokio 1.14.0",
"tokio-util 0.6.9",
"tracing",
]
@ -1108,9 +1144,9 @@ checksum = "494b4d60369511e7dea41cf646832512a94e542f68bb9c49e54518e0f468eb47"
[[package]]
name = "httpdate"
version = "1.0.1"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6456b8a6c8f33fee7d958fcd1b60d55b11940a79e63ae87013e6d22e26034440"
checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
[[package]]
name = "humantime"
@ -1147,9 +1183,9 @@ dependencies = [
[[package]]
name = "hyper"
version = "0.14.14"
version = "0.14.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b91bb1f221b6ea1f1e4371216b70f40748774c2fb5971b450c07773fb92d26b"
checksum = "436ec0091e4f20e655156a30a0df3770fe2900aa301e548e08446ec794b6953c"
dependencies = [
"bytes 1.1.0",
"futures-channel",
@ -1159,11 +1195,11 @@ dependencies = [
"http",
"http-body 0.4.4",
"httparse",
"httpdate 1.0.1",
"httpdate 1.0.2",
"itoa",
"pin-project-lite 0.2.7",
"socket2 0.4.2",
"tokio 1.13.0",
"tokio 1.14.0",
"tower-service",
"tracing",
"want",
@ -1189,9 +1225,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905"
dependencies = [
"bytes 1.1.0",
"hyper 0.14.14",
"hyper 0.14.15",
"native-tls",
"tokio 1.13.0",
"tokio 1.14.0",
"tokio-native-tls",
]
@ -1231,24 +1267,12 @@ dependencies = [
[[package]]
name = "inventory"
version = "0.1.10"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f0f7efb804ec95e33db9ad49e4252f049e37e8b0a4652e3cd61f7999f2eff7f"
checksum = "1367fed6750ff2a5bcb967a631528303bb85631f167a75eb1bf7762d57eb7678"
dependencies = [
"ctor",
"ghost",
"inventory-impl",
]
[[package]]
name = "inventory-impl"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "75c094e94816723ab936484666968f5b58060492e880f3c8d00489a1e244fa51"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
@ -1370,9 +1394,9 @@ dependencies = [
[[package]]
name = "libc"
version = "0.2.106"
version = "0.2.108"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a60553f9a9e039a333b4e9b20573b9e9b9c0bb3a11e201ccc48ef4283456d673"
checksum = "8521a1b57e76b1ec69af7599e75e38e7b7fad6610f037db8c79b127201b5d119"
[[package]]
name = "local_storage"
@ -1430,9 +1454,9 @@ dependencies = [
[[package]]
name = "marine-build-rs-generator"
version = "0.4.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c81d725ea49f554e23d3a0eb9464fcdad0bc190e42bb5a5a27699fb56557177c"
checksum = "0108407ef0528984cd5b226e6d69552b1658b205f60c83305ca33179d6e9eee1"
dependencies = [
"marine-test-macro-impl",
]
@ -1638,11 +1662,11 @@ dependencies = [
[[package]]
name = "marine-rs-sdk-test"
version = "0.4.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fe77591c893dcfda3acd02b89ad42102a6739ead8200717e4cf325c52ba7001e"
checksum = "03e286a347527936cf97456b928bd6271e0d39fc1c6b78e99461f00e6d74f018"
dependencies = [
"fluence-app-service 0.9.0",
"fluence-app-service 0.10.2",
"marine-build-rs-generator",
"marine-test-macro",
"serde",
@ -1650,37 +1674,6 @@ dependencies = [
"uuid",
]
[[package]]
name = "marine-runtime"
version = "0.7.2"
dependencies = [
"anyhow",
"boolinator",
"bytes 0.5.6",
"it-lilo",
"log",
"marine-it-generator 0.5.6",
"marine-it-interfaces 0.4.1",
"marine-it-parser 0.6.8",
"marine-module-info-parser 0.2.2",
"marine-module-interface 0.1.6",
"marine-utils 0.2.0",
"multimap",
"once_cell",
"parity-wasm",
"paste",
"pwasm-utils",
"reqwest 0.10.10",
"semver 0.11.0",
"serde",
"thiserror",
"tokio 0.2.25",
"wasmer-interface-types-fl",
"wasmer-runtime-core-fl",
"wasmer-runtime-fl",
"wasmer-wasi-fl",
]
[[package]]
name = "marine-runtime"
version = "0.7.2"
@ -1699,9 +1692,9 @@ dependencies = [
"marine-utils 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"multimap",
"once_cell",
"parity-wasm",
"parity-wasm 0.41.0",
"paste",
"pwasm-utils",
"pwasm-utils 0.12.0",
"semver 0.11.0",
"serde",
"thiserror",
@ -1711,6 +1704,37 @@ dependencies = [
"wasmer-wasi-fl",
]
[[package]]
name = "marine-runtime"
version = "0.8.0"
dependencies = [
"anyhow",
"boolinator",
"bytes 0.5.6",
"it-lilo",
"log",
"marine-it-generator 0.5.6",
"marine-it-interfaces 0.4.1",
"marine-it-parser 0.6.8",
"marine-module-info-parser 0.2.2",
"marine-module-interface 0.1.6",
"marine-utils 0.2.0",
"multimap",
"once_cell",
"parity-wasm 0.42.2",
"paste",
"pwasm-utils 0.18.2",
"reqwest 0.10.10",
"semver 0.11.0",
"serde",
"thiserror",
"tokio 0.2.25",
"wasmer-interface-types-fl",
"wasmer-runtime-core-fl",
"wasmer-runtime-fl",
"wasmer-wasi-fl",
]
[[package]]
name = "marine-sqlite-connector"
version = "0.5.2"
@ -1722,9 +1746,9 @@ dependencies = [
[[package]]
name = "marine-test-macro"
version = "0.4.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6c73a012946439eb619375cc825f008ac74489092f826fe596e465d355542cf"
checksum = "bf4d0463358f6c2459089ef8f130983dc911fd0c2aa4cb7c6b59de206f4a816e"
dependencies = [
"marine-test-macro-impl",
"proc-macro-error",
@ -1735,12 +1759,12 @@ dependencies = [
[[package]]
name = "marine-test-macro-impl"
version = "0.4.0"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fa833b78d05abb43ca46c2c85cce1e664bde4b8b1926ae2bd420aba426a9b22a"
checksum = "b8f4f1ae0ba20e9241e8882e6eb1b2302daa479d67eee5badb54b1520e17c0cb"
dependencies = [
"darling 0.12.4",
"fluence-app-service 0.9.0",
"fluence-app-service 0.10.2",
"itertools 0.10.1",
"marine-it-parser 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)",
"proc-macro-error",
@ -1795,9 +1819,9 @@ dependencies = [
[[package]]
name = "memoffset"
version = "0.6.4"
version = "0.6.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce"
dependencies = [
"autocfg",
]
@ -1883,13 +1907,13 @@ dependencies = [
[[package]]
name = "mrepl"
version = "0.9.2"
version = "0.10.0"
dependencies = [
"anyhow",
"check-latest",
"clap",
"env_logger 0.7.1",
"fluence-app-service 0.10.2",
"fluence-app-service 0.11.0",
"itertools 0.9.0",
"log",
"marine-rs-sdk-main",
@ -2078,9 +2102,9 @@ checksum = "28988d872ab76095a6e6ac88d99b54fd267702734fd7ffe610ca27f533ddb95a"
[[package]]
name = "openssl-sys"
version = "0.9.70"
version = "0.9.71"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c6517987b3f8226b5da3661dad65ff7f300cc59fb5ea8333ca191fc65fde3edf"
checksum = "7df13d165e607909b363a4757a6f133f8a818a74e9d3a98d09c6128e15fa4c73"
dependencies = [
"autocfg",
"cc",
@ -2114,6 +2138,12 @@ version = "0.41.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865"
[[package]]
name = "parity-wasm"
version = "0.42.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92"
[[package]]
name = "parking_lot"
version = "0.10.2"
@ -2140,9 +2170,9 @@ dependencies = [
[[package]]
name = "paste"
version = "1.0.5"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf547ad0c65e31259204bd90935776d1c693cec2f4ff7abb7a1bbbd40dfe58"
checksum = "0744126afe1a6dd7f394cb50a716dbe086cb06e255e53d8d0185d82828358fb5"
[[package]]
name = "percent-encoding"
@ -2226,7 +2256,7 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cab0e7c02cf376875e9335e0ba1da535775beb5450d21e1dffca068818ed98b"
dependencies = [
"ansi_term 0.12.1",
"ansi_term",
"ctor",
"diff",
"output_vt100",
@ -2279,7 +2309,18 @@ checksum = "4f7a12f176deee919f4ba55326ee17491c8b707d0987aed822682c821b660192"
dependencies = [
"byteorder",
"log",
"parity-wasm",
"parity-wasm 0.41.0",
]
[[package]]
name = "pwasm-utils"
version = "0.18.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "880b3384fb00b8f6ecccd5d358b93bd2201900ae3daad213791d1864f6441f5c"
dependencies = [
"byteorder",
"log",
"parity-wasm 0.42.2",
]
[[package]]
@ -2505,9 +2546,9 @@ dependencies = [
[[package]]
name = "reqwest"
version = "0.11.6"
version = "0.11.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "66d2927ca2f685faf0fc620ac4834690d29e7abb153add10f5812eef20b5e280"
checksum = "07bea77bc708afa10e59905c3d4af7c8fd43c9214251673095ff8b14345fcbc5"
dependencies = [
"base64",
"bytes 1.1.0",
@ -2516,7 +2557,7 @@ dependencies = [
"futures-util",
"http",
"http-body 0.4.4",
"hyper 0.14.14",
"hyper 0.14.15",
"hyper-tls 0.5.0",
"ipnet",
"js-sys",
@ -2529,7 +2570,7 @@ dependencies = [
"serde",
"serde_json",
"serde_urlencoded",
"tokio 1.13.0",
"tokio 1.14.0",
"tokio-native-tls",
"url",
"wasm-bindgen",
@ -2571,6 +2612,12 @@ version = "1.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cac77bea4e5c89acb455a2fe072bc19334cb130691af6e1bed4625d3f5396e89"
[[package]]
name = "rustversion"
version = "1.0.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088"
[[package]]
name = "rustyline"
version = "6.3.0"
@ -2603,9 +2650,9 @@ dependencies = [
[[package]]
name = "ryu"
version = "1.0.5"
version = "1.0.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71d301d4193d031abdd79ff7e3dd721168a9572ef3fe51a1517aba235bd8f86e"
checksum = "3c9613b5a66ab9ba26415184cfc41156594925a9cf3a2057e57f31ff145f6568"
[[package]]
name = "safe-transmute"
@ -2696,9 +2743,9 @@ dependencies = [
[[package]]
name = "serde"
version = "1.0.118"
version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06c64263859d87aa2eb554587e2d23183398d617427327cf2b3d0ed8c69e4800"
checksum = "f12d06de37cf59146fbdecab66aa99f9fe4f78722e3607577a5375d66bd0c913"
dependencies = [
"serde_derive",
]
@ -2724,9 +2771,9 @@ dependencies = [
[[package]]
name = "serde_derive"
version = "1.0.118"
version = "1.0.130"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c84d3526699cd55261af4b941e4e725444df67aa4f9e6a3564f18030d12672df"
checksum = "d7bc1a1ab1961464eae040d96713baa5a724a8152c1222492465b54322ec508b"
dependencies = [
"proc-macro2",
"quote",
@ -2735,9 +2782,9 @@ dependencies = [
[[package]]
name = "serde_json"
version = "1.0.68"
version = "1.0.72"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f690853975602e1bfe1ccbf50504d67174e3bcf340f23b5ea9992e0587a52d8"
checksum = "d0ffa0837f2dfa6fb90868c2b5468cad482e175f7dad97e7421951e663f2b527"
dependencies = [
"itoa",
"ryu",
@ -2756,6 +2803,29 @@ dependencies = [
"serde",
]
[[package]]
name = "serde_with"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad6056b4cb69b6e43e3a0f055def223380baecc99da683884f205bf347f7c4b3"
dependencies = [
"rustversion",
"serde",
"serde_with_macros",
]
[[package]]
name = "serde_with_macros"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12e47be9471c72889ebafb5e14d5ff930d89ae7a67bbdb5f8abb564f845a927e"
dependencies = [
"darling 0.13.0",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "shlex"
version = "0.1.1"
@ -2852,9 +2922,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "1.0.81"
version = "1.0.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2afee18b8beb5a596ecb4a2dce128c719b4ba399d34126b9e4396e3f9860966"
checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59"
dependencies = [
"proc-macro2",
"quote",
@ -2992,9 +3062,9 @@ dependencies = [
[[package]]
name = "tinyvec"
version = "1.5.0"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f83b2a3d4d9091d0abd7eba4dc2710b1718583bd4d8992e2190720ea38f391f7"
checksum = "2c1c1d5a42b6245520c249549ec267180beaffcc0615401ac8e31853d4b6d8d2"
dependencies = [
"tinyvec_macros",
]
@ -3025,9 +3095,9 @@ dependencies = [
[[package]]
name = "tokio"
version = "1.13.0"
version = "1.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "588b2d10a336da58d877567cd8fb8a14b463e2104910f8132cd054b4b96e29ee"
checksum = "70e992e41e0d2fb9f755b37446f20900f64446ef54874f40a60c78f021ac6144"
dependencies = [
"autocfg",
"bytes 1.1.0",
@ -3057,7 +3127,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f7d995660bd2b7f8c1568414c1126076c13fbb725c40112dc0120b78eb9b717b"
dependencies = [
"native-tls",
"tokio 1.13.0",
"tokio 1.14.0",
]
[[package]]
@ -3095,7 +3165,7 @@ dependencies = [
"futures-sink",
"log",
"pin-project-lite 0.2.7",
"tokio 1.13.0",
"tokio 1.14.0",
]
[[package]]
@ -3172,22 +3242,22 @@ checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec"
[[package]]
name = "typetag"
version = "0.1.7"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "422619e1a7299befb977a1f6d8932c499f6151dbcafae715193570860cae8f07"
checksum = "4080564c5b2241b5bff53ab610082234e0c57b0417f4bd10596f183001505b8a"
dependencies = [
"erased-serde",
"inventory",
"lazy_static",
"once_cell",
"serde",
"typetag-impl",
]
[[package]]
name = "typetag-impl"
version = "0.1.7"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "504f9626fe6cc1c376227864781996668e15c1ff251d222f63ef17f310bf1fec"
checksum = "e60147782cc30833c05fba3bab1d9b5771b2685a2557672ac96fa5d154099c0e"
dependencies = [
"proc-macro2",
"quote",

View File

@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#![warn(rust_2018_idioms)]
#![deny(
dead_code,
@ -24,6 +25,10 @@
unreachable_patterns
)]
mod wasm_mem_pages_conversion;
pub use wasm_mem_pages_conversion::*;
use std::rc::Rc;
#[derive(Debug, Clone, PartialEq, Eq, Default, Hash)]

View File

@ -0,0 +1,25 @@
/*
* Copyright 2021 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.
*/
pub const WASM_PAGE_SIZE: u32 = 65356;
pub fn to_wasm_page_count_ceil(offset: u32) -> u32 {
match offset {
0 => 0,
// ceiling
n => 1 + (n - 1) / WASM_PAGE_SIZE,
}
}

View File

@ -15,7 +15,7 @@ path = "src/main.rs"
marine-rs-sdk = "0.6.11"
[dev-dependencies]
marine-rs-sdk-test = "0.4.0"
marine-rs-sdk-test = "0.4.1"
[build-dependencies]
marine-rs-sdk-test = "0.4.0"
marine-rs-sdk-test = "0.4.1"

View File

@ -2,5 +2,5 @@ modules_dir = "artifacts/"
[[module]]
name = "build_rs_test"
mem_pages_count = 50
max_heap_size = "10 KiB"
logger_enabled = false

View File

@ -13,4 +13,4 @@ path = "src/main.rs"
marine-rs-sdk ="0.6.13"
[dev-dependencies]
marine-rs-sdk-test = "0.4.0"
marine-rs-sdk-test = "0.4.1"

View File

@ -2,5 +2,5 @@ modules_dir = "artifacts/"
[[module]]
name = "call_parameters"
mem_pages_count = 1
max_heap_size = "10 KiB"
logger_enabled = false

View File

@ -15,4 +15,4 @@ path = "src/main.rs"
marine-rs-sdk = "0.6.13"
[dev-dependencies]
marine-rs-sdk-test = "0.4.0"
marine-rs-sdk-test = "0.4.1"

View File

@ -2,5 +2,5 @@ modules_dir = "artifacts/"
[[module]]
name = "greeting"
mem_pages_count = 1
max_heap_size = "10 KiB"
logger_enabled = false

View File

@ -2,7 +2,7 @@ modules_dir = "artifacts/"
[[module]]
name = "ipfs_effector"
mem_pages_count = 100
max_heap_size = "10 KiB"
logger_enabled = true
[module.mounted_binaries]
@ -13,5 +13,5 @@ modules_dir = "artifacts/"
[[module]]
name = "ipfs_pure"
mem_pages_count = 100
max_heap_size = "10 KiB"
logger_enabled = true

View File

@ -8,4 +8,4 @@ publish = false
[dependencies]
[dev-dependencies]
marine-rs-sdk-test = "0.4.0"
marine-rs-sdk-test = "0.4.1"

View File

@ -1,6 +1,6 @@
modules_dir = "artifacts/"
[[module]]
name = "consumer"
mem_pages_count = 50
logger_enabled = false
name = "consumer"
max_heap_size = "10 KiB"
logger_enabled = false

View File

@ -1,6 +1,6 @@
modules_dir = "artifacts/"
[[module]]
name = "producer"
mem_pages_count = 50
logger_enabled = false
name = "producer"
max_heap_size = "10 KiB"
logger_enabled = false

View File

@ -2,10 +2,10 @@ modules_dir = "artifacts/"
[[module]]
name = "records_effector"
mem_pages_count = 1
max_heap_size = "10 KiB"
logger_enabled = true
[[module]]
name = "records_pure"
mem_pages_count = 1
max_heap_size = "10 KiB"
logger_enabled = true

View File

@ -2,7 +2,7 @@ modules_dir = "artifacts/"
[[module]]
name = "sqlite3"
mem_pages_count = 100
max_heap_size = "10 MiB"
logger_enabled = false
[module.wasi]
@ -11,7 +11,7 @@ modules_dir = "artifacts/"
[[module]]
name = "sqlite_test"
mem_pages_count = 1
max_heap_size = "1 MiB"
logger_enabled = false
[module.wasi]

View File

@ -1,13 +1,13 @@
[package]
name = "fluence-app-service"
description = "Fluence Application Service"
version = "0.10.2"
version = "0.11.0"
authors = ["Fluence Labs"]
license = "Apache-2.0"
edition = "2018"
[dependencies]
fluence-faas = { path = "../fluence-faas", version = "0.9.3" }
fluence-faas = { path = "../fluence-faas", version = "0.10.0" }
maplit = "1.0.2"
log = "0.4.8"

View File

@ -1,13 +1,13 @@
[package]
name = "fluence-faas"
description = "Fluence FaaS"
version = "0.9.3"
version = "0.10.0"
authors = ["Fluence Labs"]
license = "Apache-2.0"
edition = "2018"
[dependencies]
marine-runtime = { path = "../runtime", version = "0.7.2" }
marine-runtime = { path = "../runtime", version = "0.8.0" }
marine-module-interface = { path = "../crates/module-interface", version = "0.1.6" }
marine-utils = { path = "../crates/utils", version = "0.2.0" }
marine-rs-sdk-main = { version = "0.6.15", features = ["logger"] }
@ -23,6 +23,8 @@ toml = "0.5.6"
serde = { version = "1.0.118", features = ["derive"] }
serde_json = "1.0.53"
serde_derive = "1.0.118"
serde_with = "1.11.0"
bytesize = {version = "1.1.0", features = ["serde"]}
itertools = "0.9.0"
cmd_lib = "0.7.8"
log = "0.4.8"

View File

@ -18,7 +18,7 @@ use marine::HostImportDescriptor;
use std::collections::HashMap;
use std::collections::HashSet;
use std::path::{PathBuf};
use std::path::PathBuf;
/// Info to load a module from filesystem into runtime.
#[derive(Default)]
@ -47,6 +47,9 @@ pub struct FaaSModuleConfig {
/// Maximum memory size accessible by a module in Wasm pages (64 Kb).
pub mem_pages_count: Option<u32>,
/// Maximum memory size for heap of Wasm module in bytes, if it set, mem_pages_count ignored.
pub max_heap_size: Option<u64>,
/// Defines whether FaaS should provide a special host log_utf8_string function for this module.
pub logger_enabled: bool,
@ -167,6 +170,7 @@ impl TryFrom<TomlFaaSModuleConfig> for FaaSModuleConfig {
})
.collect::<Result<Vec<_>, Self::Error>>()?;
let max_heap_size = toml_config.max_heap_size.map(|v| v.as_u64());
let mut host_cli_imports = HashMap::new();
for (import_name, host_cmd) in mounted_binaries {
host_cli_imports.insert(
@ -179,6 +183,7 @@ impl TryFrom<TomlFaaSModuleConfig> for FaaSModuleConfig {
Ok(FaaSModuleConfig {
mem_pages_count: toml_config.mem_pages_count,
max_heap_size,
logger_enabled: toml_config.logger_enabled.unwrap_or(true),
host_imports: host_cli_imports,
wasi,

View File

@ -14,10 +14,13 @@
* limitations under the License.
*/
use crate::Result;
use crate::FaaSResult;
use serde_derive::Serialize;
use serde_derive::Deserialize;
use serde_with::serde_as;
use serde_with::skip_serializing_none;
use serde_with::DisplayFromStr;
use std::path::Path;
@ -64,7 +67,7 @@ pub struct TomlFaaSConfig {
impl TomlFaaSConfig {
/// Load config from filesystem.
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self> {
pub fn load<P: AsRef<Path>>(path: P) -> FaaSResult<Self> {
let file_content = std::fs::read(path)?;
Ok(toml::from_slice(&file_content)?)
}
@ -79,9 +82,14 @@ pub struct TomlFaaSNamedModuleConfig {
pub config: TomlFaaSModuleConfig,
}
#[serde_as]
#[skip_serializing_none]
#[derive(Deserialize, Serialize, Debug, Clone, Default)]
pub struct TomlFaaSModuleConfig {
pub mem_pages_count: Option<u32>,
#[serde_as(as = "Option<DisplayFromStr>")]
#[serde(default)]
pub max_heap_size: Option<bytesize::ByteSize>,
pub logger_enabled: Option<bool>,
pub wasi: Option<TomlWASIConfig>,
pub mounted_binaries: Option<toml::value::Table>,
@ -97,6 +105,7 @@ pub struct TomlWASIConfig {
#[cfg(test)]
mod tests {
use bytesize::ByteSize;
use super::{TomlFaaSNamedModuleConfig, TomlFaaSModuleConfig, TomlWASIConfig};
#[test]
@ -106,6 +115,7 @@ mod tests {
file_name: Some("file_name".to_string()),
config: TomlFaaSModuleConfig {
mem_pages_count: Some(100),
max_heap_size: Some(ByteSize::gib(4)),
logger_enabled: Some(false),
wasi: Some(TomlWASIConfig {
preopened_files: Some(vec!["a".to_string()]),

View File

@ -14,14 +14,19 @@
* limitations under the License.
*/
use crate::Result;
use crate::FaaSWASIConfig;
use crate::FaaSResult;
use crate::FaaSError;
use crate::config::FaaSModuleConfig;
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;
use marine::HostImportDescriptor;
use marine::MModuleConfig;
use marine_rs_sdk::CallParameters;
use marine_utils::to_wasm_page_count_ceil;
use wasmer_core::import::ImportObject;
use wasmer_core::import::Namespace;
use wasmer_runtime::func;
@ -30,31 +35,64 @@ use std::collections::HashMap;
use std::cell::RefCell;
use std::rc::Rc;
/// Make Marine config from provided FaaS config.
pub(crate) fn make_marine_config(
module_name: String,
faas_module_config: Option<FaaSModuleConfig>,
call_parameters: Rc<RefCell<marine_rs_sdk::CallParameters>>,
logger_filter: &LoggerFilter<'_>,
) -> Result<MModuleConfig> {
let mut marine_module_cfg = MModuleConfig::default();
const WASM_MAX_HEAP_SIZE: u64 = 4 * 1024 * 1024 * 1024 - 1; // 4 GiB - 1
let faas_module_config = match faas_module_config {
Some(faas_module_config) => faas_module_config,
None => return Ok(marine_module_cfg),
};
struct MModuleConfigBuilder {
config: MModuleConfig,
}
if let Some(mem_pages_count) = faas_module_config.mem_pages_count {
marine_module_cfg.mem_pages_count = mem_pages_count;
impl MModuleConfigBuilder {
pub(self) fn new() -> Self {
Self {
config: <_>::default(),
}
}
if let Some(wasi) = faas_module_config.wasi {
marine_module_cfg.wasi_envs = wasi.envs;
marine_module_cfg.wasi_preopened_files = wasi.preopened_files;
marine_module_cfg.wasi_mapped_dirs = wasi.mapped_dirs;
pub(self) fn build(
self,
module_name: String,
faas_module_config: Option<FaaSModuleConfig>,
call_parameters: Rc<RefCell<CallParameters>>,
logger_filter: &LoggerFilter<'_>,
) -> FaaSResult<MModuleConfig> {
let faas_module_config = match faas_module_config {
Some(config) => config,
None => return Ok(self.into_config()),
};
let FaaSModuleConfig {
mem_pages_count,
max_heap_size,
logger_enabled,
host_imports,
wasi,
logging_mask,
} = faas_module_config;
let config = self
.populate_max_heap_size(mem_pages_count, max_heap_size)?
.populate_logger(logger_enabled, logging_mask, logger_filter, module_name)
.populate_host_imports(host_imports, call_parameters)
.populate_wasi(wasi)
.add_version()
.into_config();
Ok(config)
}
fn populate_wasi(mut self, wasi: Option<FaaSWASIConfig>) -> Self {
let wasi = match wasi {
Some(wasi) => wasi,
None => return self,
};
self.config.wasi_envs = wasi.envs;
self.config.wasi_preopened_files = wasi.preopened_files;
self.config.wasi_mapped_dirs = wasi.mapped_dirs;
// create environment variables for all mapped directories
let mapped_dirs = marine_module_cfg
let mapped_dirs = self
.config
.wasi_mapped_dirs
.iter()
.map(|(from, to)| {
@ -65,17 +103,61 @@ pub(crate) fn make_marine_config(
})
.collect::<HashMap<_, _>>();
marine_module_cfg.wasi_envs.extend(mapped_dirs);
};
self.config.wasi_envs.extend(mapped_dirs);
marine_module_cfg.host_imports = faas_module_config.host_imports;
marine_module_cfg.host_imports.insert(
String::from("get_call_parameters"),
create_call_parameters_import(call_parameters),
);
self
}
fn populate_host_imports(
mut self,
host_imports: HashMap<String, HostImportDescriptor>,
call_parameters: Rc<RefCell<CallParameters>>,
) -> Self {
self.config.host_imports = host_imports;
self.config.host_imports.insert(
String::from("get_call_parameters"),
create_call_parameters_import(call_parameters),
);
self
}
fn populate_max_heap_size(
mut self,
mem_pages_count: Option<u32>,
max_heap_size: Option<u64>,
) -> FaaSResult<Self> {
let mem_pages_count = match (mem_pages_count, max_heap_size) {
(Some(v), None) => v,
(_, Some(max_heap_size_wanted)) => {
if max_heap_size_wanted > WASM_MAX_HEAP_SIZE {
return Err(FaaSError::MaxHeapSizeOverflow {
max_heap_size_wanted,
max_heap_size_allowed: WASM_MAX_HEAP_SIZE,
});
};
to_wasm_page_count_ceil(max_heap_size_wanted as u32)
}
// leave the default value
(None, None) => return Ok(self),
};
self.config.max_heap_size = mem_pages_count;
Ok(self)
}
fn populate_logger(
mut self,
logger_enabled: bool,
logging_mask: i32,
logger_filter: &LoggerFilter<'_>,
module_name: String,
) -> Self {
if !logger_enabled {
return self;
}
let mut namespace = Namespace::new();
if faas_module_config.logger_enabled {
if let Some(level_filter) = logger_filter.module_level(&module_name) {
let log_level = level_filter.to_level();
let log_level_str = match log_level {
@ -84,24 +166,47 @@ pub(crate) fn make_marine_config(
};
// overwrite possibly installed log variable in config
marine_module_cfg.wasi_envs.insert(
self.config.wasi_envs.insert(
WASM_LOG_ENV_NAME.as_bytes().to_owned(),
log_level_str.into_bytes(),
);
}
let logging_mask = faas_module_config.logging_mask;
let logging_mask = logging_mask;
let mut namespace = Namespace::new();
namespace.insert(
"log_utf8_string",
func!(log_utf8_string_closure(logging_mask, module_name)),
);
let mut raw_host_imports = ImportObject::new();
raw_host_imports.register("host", namespace);
self.config.raw_imports = raw_host_imports;
self
}
let mut raw_host_imports = ImportObject::new();
raw_host_imports.register("host", namespace);
marine_module_cfg.raw_imports = raw_host_imports;
fn add_version(mut self) -> Self {
self.config.wasi_version = wasmer_wasi::WasiVersion::Latest;
self
}
marine_module_cfg.wasi_version = wasmer_wasi::WasiVersion::Latest;
Ok(marine_module_cfg)
fn into_config(self) -> MModuleConfig {
self.config
}
}
/// Make Marine config from provided FaaS config.
pub(crate) fn make_marine_config(
module_name: String,
faas_module_config: Option<FaaSModuleConfig>,
call_parameters: Rc<RefCell<marine_rs_sdk::CallParameters>>,
logger_filter: &LoggerFilter<'_>,
) -> FaaSResult<MModuleConfig> {
MModuleConfigBuilder::new().build(
module_name,
faas_module_config,
call_parameters,
logger_filter,
)
}

View File

@ -65,6 +65,15 @@ pub enum FaaSError {
#[error("parsing config error: {0}")]
ParseConfigError(#[from] toml::de::Error),
/// Errors related to invalid config.
#[error(
"max_heap_size = '{max_heap_size_wanted}' can't be bigger than {max_heap_size_allowed}'"
)]
MaxHeapSizeOverflow {
max_heap_size_wanted: u64,
max_heap_size_allowed: u64,
},
/// Marine errors.
#[error("engine error: {0}")]
EngineError(#[from] MError),

View File

@ -17,7 +17,7 @@
use crate::config::FaaSConfig;
use crate::faas_interface::FaaSInterface;
use crate::FaaSError;
use crate::Result;
use crate::FaaSResult;
use crate::IValue;
use crate::IType;
use crate::module_loading::load_modules_from_fs;
@ -46,6 +46,7 @@ struct ModuleInterface {
}
// TODO: remove and use mutex instead
#[allow(clippy::non_send_fields_in_send_ty)]
unsafe impl Send for FluenceFaaS {}
pub struct FluenceFaaS {
@ -61,7 +62,7 @@ pub struct FluenceFaaS {
impl FluenceFaaS {
/// Creates FaaS from config deserialized from TOML.
pub fn with_raw_config<C>(config: C) -> Result<Self>
pub fn with_raw_config<C>(config: C) -> FaaSResult<Self>
where
C: TryInto<FaaSConfig>,
FaaSError: From<C::Error>,
@ -76,7 +77,7 @@ impl FluenceFaaS {
}
/// Creates FaaS with given modules.
pub fn with_modules<C>(mut modules: HashMap<String, Vec<u8>>, config: C) -> Result<Self>
pub fn with_modules<C>(mut modules: HashMap<String, Vec<u8>>, config: C) -> FaaSResult<Self>
where
C: TryInto<FaaSConfig>,
FaaSError: From<C::Error>,
@ -117,7 +118,7 @@ impl FluenceFaaS {
}
/// Searches for modules in `config.modules_dir`, loads only those in the `names` set
pub fn with_module_names<C>(names: &HashMap<String, String>, config: C) -> Result<Self>
pub fn with_module_names<C>(names: &HashMap<String, String>, config: C) -> FaaSResult<Self>
where
C: TryInto<FaaSConfig>,
FaaSError: From<C::Error>,
@ -140,7 +141,7 @@ impl FluenceFaaS {
func_name: FN,
args: &[IValue],
call_parameters: marine_rs_sdk::CallParameters,
) -> Result<Vec<IValue>> {
) -> FaaSResult<Vec<IValue>> {
self.call_parameters.replace(call_parameters);
self.marine
@ -155,7 +156,7 @@ impl FluenceFaaS {
func_name: FN,
json_args: JValue,
call_parameters: marine_rs_sdk::CallParameters,
) -> Result<JValue> {
) -> FaaSResult<JValue> {
use crate::json::json_to_ivalues;
use crate::json::ivalues_to_json;
@ -189,7 +190,7 @@ impl FluenceFaaS {
&'faas mut self,
module_name: &str,
func_name: &str,
) -> Result<MModuleInterface> {
) -> FaaSResult<MModuleInterface> {
use FaaSError::NoSuchModule;
use FaaSError::MissingFunctionError;
@ -240,7 +241,12 @@ impl FluenceFaaS {
// This API is intended for testing purposes (mostly in Marine REPL)
#[cfg(feature = "raw-module-api")]
impl FluenceFaaS {
pub fn load_module<S, C>(&mut self, name: S, wasm_bytes: &[u8], config: Option<C>) -> Result<()>
pub fn load_module<S, C>(
&mut self,
name: S,
wasm_bytes: &[u8],
config: Option<C>,
) -> FaaSResult<()>
where
S: Into<String>,
C: TryInto<crate::FaaSModuleConfig>,
@ -264,14 +270,14 @@ impl FluenceFaaS {
.map_err(Into::into)
}
pub fn unload_module<S: AsRef<str>>(&mut self, module_name: S) -> Result<()> {
pub fn unload_module<S: AsRef<str>>(&mut self, module_name: S) -> FaaSResult<()> {
self.marine.unload_module(module_name).map_err(Into::into)
}
pub fn module_wasi_state<S: AsRef<str>>(
&mut self,
module_name: S,
) -> Result<&wasmer_wasi::state::WasiState> {
) -> FaaSResult<&wasmer_wasi::state::WasiState> {
let module_name = module_name.as_ref();
self.marine

View File

@ -16,7 +16,7 @@
use crate::IValue;
use crate::IType;
use crate::Result;
use crate::FaaSResult;
use crate::errors::FaaSError::JsonOutputSerializationError as OutputDeError;
use marine::MRecordTypes;
@ -26,7 +26,7 @@ pub(crate) fn ivalues_to_json(
mut ivalues: Vec<IValue>,
outputs: &[IType],
record_types: &MRecordTypes,
) -> Result<JValue> {
) -> FaaSResult<JValue> {
if outputs.len() != ivalues.len() {
return Err(OutputDeError(format!(
"resulted values {:?} and function signature {:?} aren't compatible",
@ -42,7 +42,11 @@ pub(crate) fn ivalues_to_json(
}
}
fn ivalue_to_json(ivalue: IValue, output: &IType, record_types: &MRecordTypes) -> Result<JValue> {
fn ivalue_to_json(
ivalue: IValue,
output: &IType,
record_types: &MRecordTypes,
) -> FaaSResult<JValue> {
use serde_json::json;
// clone here needed because binding by-value and by-ref in the same pattern in unstable
@ -66,7 +70,7 @@ fn ivalue_to_json(ivalue: IValue, output: &IType, record_types: &MRecordTypes) -
Ok(JValue::Array(result))
}
(IValue::Array(value), IType::ByteArray) => {
let result: Result<Vec<_>> = value
let result: FaaSResult<Vec<_>> = value
.into_iter()
.map(|v| ivalue_to_json(v, &IType::U8, record_types))
.collect();
@ -74,7 +78,7 @@ fn ivalue_to_json(ivalue: IValue, output: &IType, record_types: &MRecordTypes) -
Ok(JValue::Array(result?))
}
(IValue::ByteArray(value), IType::Array(array_ty)) => {
let result: Result<Vec<_>> = value
let result: FaaSResult<Vec<_>> = value
.into_iter()
.map(|v| ivalue_to_json(IValue::U8(v), &array_ty, record_types))
.collect();
@ -82,7 +86,7 @@ fn ivalue_to_json(ivalue: IValue, output: &IType, record_types: &MRecordTypes) -
Ok(JValue::Array(result?))
}
(IValue::Array(value), IType::Array(array_ty)) => {
let result: Result<Vec<_>> = value
let result: FaaSResult<Vec<_>> = value
.into_iter()
.map(|v| ivalue_to_json(v, &array_ty, record_types))
.collect();

View File

@ -16,7 +16,7 @@
use crate::IValue;
use crate::IType;
use crate::Result;
use crate::FaaSResult;
use crate::FaaSError::JsonArgumentsDeserializationError as ArgDeError;
use marine::MRecordTypes;
@ -31,7 +31,7 @@ pub(crate) fn json_to_ivalues<'a, 'b>(
json_args: JValue,
arg_types: impl Iterator<Item = (&'a String, &'a IType)> + ExactSizeIterator,
record_types: &'b MRecordTypes,
) -> Result<Vec<IValue>> {
) -> FaaSResult<Vec<IValue>> {
let ivalues = match json_args {
JValue::Object(json_map) => json_map_to_ivalues(json_map, arg_types, record_types)?,
JValue::Array(json_array) => {
@ -49,7 +49,7 @@ fn json_map_to_ivalues<'a, 'b>(
mut json_map: serde_json::Map<String, JValue>,
arg_types: impl Iterator<Item = (&'a String, &'a IType)>,
record_types: &'b MRecordTypes,
) -> Result<Vec<IValue>> {
) -> FaaSResult<Vec<IValue>> {
let mut iargs = Vec::new();
for (arg_name, arg_type) in arg_types {
@ -76,7 +76,7 @@ fn json_array_to_ivalues<'a, 'b>(
json_array: Vec<JValue>,
arg_types: impl Iterator<Item = &'a IType> + ExactSizeIterator,
record_types: &'b MRecordTypes,
) -> Result<Vec<IValue>> {
) -> FaaSResult<Vec<IValue>> {
if json_array.len() != arg_types.len() {
return Err(ArgDeError(format!(
"function requires {} arguments, {} provided",
@ -89,7 +89,7 @@ fn json_array_to_ivalues<'a, 'b>(
.into_iter()
.zip(arg_types)
.map(|(json_value, arg_type)| jvalue_to_ivalue(json_value, arg_type, record_types))
.collect::<Result<Vec<_>>>()?;
.collect::<FaaSResult<Vec<_>>>()?;
Ok(iargs)
}
@ -98,7 +98,7 @@ fn json_array_to_ivalues<'a, 'b>(
fn json_value_to_ivalues<'a>(
json_value: JValue,
mut arg_types: impl Iterator<Item = (&'a String, &'a IType)> + ExactSizeIterator,
) -> Result<Vec<IValue>> {
) -> FaaSResult<Vec<IValue>> {
if arg_types.len() != 1 {
return Err(ArgDeError(format!(
"called function has the following signature: '{:?}', and it isn't suitable for an argument '{:?}' provided",
@ -117,7 +117,7 @@ fn json_value_to_ivalues<'a>(
/// Convert json Null to an empty array of ivalues.
fn json_null_to_ivalues<'a>(
arg_types: impl Iterator<Item = (&'a String, &'a IType)> + ExactSizeIterator,
) -> Result<Vec<IValue>> {
) -> FaaSResult<Vec<IValue>> {
if arg_types.len() != 0 {
return Err(ArgDeError(format!(
"the called function has the following signature: {:?}, but no arguments is provided",
@ -129,7 +129,7 @@ fn json_null_to_ivalues<'a>(
}
/// Convert one JValue to an array of ivalues according to the supplied argument type.
fn jvalue_to_ivalue(jvalue: JValue, ty: &IType, record_types: &MRecordTypes) -> Result<IValue> {
fn jvalue_to_ivalue(jvalue: JValue, ty: &IType, record_types: &MRecordTypes) -> FaaSResult<IValue> {
macro_rules! to_ivalue(
($json_value:expr, $ty:ident) => {
{
@ -169,7 +169,7 @@ fn jvalue_to_ivalue(jvalue: JValue, ty: &IType, record_types: &MRecordTypes) ->
let iargs = json_array
.into_iter()
.map(|json_value| jvalue_to_ivalue(json_value, &IType::U8, record_types))
.collect::<Result<Vec<_>>>()?;
.collect::<FaaSResult<Vec<_>>>()?;
Ok(iargs)
}
@ -184,7 +184,7 @@ fn jvalue_to_ivalue(jvalue: JValue, ty: &IType, record_types: &MRecordTypes) ->
let iargs = json_array
.into_iter()
.map(|json_value| jvalue_to_ivalue(json_value, value_type, record_types))
.collect::<Result<Vec<_>>>()?;
.collect::<FaaSResult<Vec<_>>>()?;
Ok(iargs)
}
@ -212,7 +212,7 @@ fn json_record_type_to_ivalue(
json_value: JValue,
record_type_id: &u64,
record_types: &MRecordTypes,
) -> Result<NEVec<IValue>> {
) -> FaaSResult<NEVec<IValue>> {
let record_type = record_types.get(record_type_id).ok_or_else(|| {
ArgDeError(format!(
"record with type id `{}` wasn't found",

View File

@ -32,7 +32,7 @@ mod faas;
mod faas_interface;
mod module_loading;
pub(crate) type Result<T> = std::result::Result<T, FaaSError>;
pub(crate) type FaaSResult<T> = std::result::Result<T, FaaSError>;
pub use faas::FluenceFaaS;
pub use faas_interface::FaaSInterface;

View File

@ -19,7 +19,7 @@ mod modules_load_strategy;
pub(crate) use modules_load_strategy::ModulesLoadStrategy;
use crate::FaaSError;
use crate::Result;
use crate::FaaSResult;
use std::collections::HashMap;
use std::path::Path;
@ -28,7 +28,7 @@ use std::path::Path;
pub(crate) fn load_modules_from_fs(
modules_dir: &Path,
modules: ModulesLoadStrategy<'_>,
) -> Result<HashMap<String, Vec<u8>>> {
) -> FaaSResult<HashMap<String, Vec<u8>>> {
use FaaSError::IOError;
let mut dir_entries =

View File

@ -2,10 +2,10 @@ modules_dir = "./artifacts/"
[[module]]
name = "arguments_passing_effector"
mem_pages_count = 1
max_heap_size = "10 KiB"
logger_enabled = true
[[module]]
name = "arguments_passing_pure"
mem_pages_count = 1
max_heap_size = "10 KiB"
logger_enabled = true

View File

@ -2,10 +2,10 @@ modules_dir = "./artifacts/"
[[module]]
name = "arrays_passing_effector"
mem_pages_count = 1
max_heap_size = "10 KiB"
logger_enabled = true
[[module]]
name = "arrays_passing_pure"
mem_pages_count = 1
max_heap_size = "10 KiB"
logger_enabled = true

View File

@ -2,10 +2,10 @@ modules_dir = "./artifacts/"
[[module]]
name = "records_passing_effector"
mem_pages_count = 1
max_heap_size = "10 KiB"
logger_enabled = true
[[module]]
name = "records_passing_pure"
mem_pages_count = 1
max_heap_size = "10 KiB"
logger_enabled = true

View File

@ -1,7 +1,7 @@
[package]
name = "marine-runtime"
description = "Marine is the Fluence Compute Runtime"
version = "0.7.2"
version = "0.8.0"
authors = ["Fluence Labs"]
license = "Apache-2.0"
edition = "2018"
@ -27,8 +27,8 @@ wasmer-wasi = { package = "wasmer-wasi-fl", version = "0.17.1" }
multimap = "0.8.1"
boolinator = "2.4.0"
parity-wasm = "0.41.0"
pwasm-utils = "0.12.0"
parity-wasm = "0.42.2"
pwasm-utils = "0.18.2"
once_cell = "1.7.2"
semver = "0.11.0"
serde = "1.0.118"

View File

@ -45,8 +45,8 @@ pub struct HostImportDescriptor {
pub struct MModuleConfig {
/// Maximum number of Wasm memory pages that loaded module can use.
/// Each Wasm pages is 65536 bytes long.
pub mem_pages_count: u32,
/// Each Wasm page is 65536 bytes long.
pub max_heap_size: u32,
/// Import object that will be used in module instantiation process.
pub raw_imports: ImportObject,
@ -72,7 +72,7 @@ impl Default for MModuleConfig {
// some reasonable defaults
Self {
// 65536*1600 ~ 100 Mb
mem_pages_count: 1600,
max_heap_size: 1600,
raw_imports: ImportObject::new(),
host_imports: HashMap::new(),
wasi_version: WasiVersion::Latest,
@ -88,7 +88,7 @@ impl Default for MModuleConfig {
impl MModuleConfig {
#[allow(dead_code)]
pub fn with_mem_pages_count(mut self, mem_pages_count: u32) -> Self {
self.mem_pages_count = mem_pages_count;
self.max_heap_size = mem_pages_count;
self
}

View File

@ -73,9 +73,8 @@ impl Marine {
wasm_bytes: &[u8],
config: MModuleConfig,
) -> MResult<()> {
let _prepared_wasm_bytes = crate::misc::prepare_module(wasm_bytes, config.mem_pages_count)?;
let module = MModule::new(&name, wasm_bytes, config, &self.modules)?;
let prepared_wasm_bytes = crate::misc::prepare_module(wasm_bytes, config.max_heap_size)?;
let module = MModule::new(&name, &prepared_wasm_bytes, config, &self.modules)?;
match self.modules.entry(name) {
Entry::Vacant(entry) => {
@ -115,7 +114,7 @@ impl Marine {
pub fn module_interface<S: AsRef<str>>(&self, module_name: S) -> Option<MModuleInterface<'_>> {
self.modules
.get(module_name.as_ref())
.map(|module| Self::get_module_interface(module))
.map(Self::get_module_interface)
}
/// Return record types exported by module with given name.

View File

@ -15,9 +15,10 @@
*/
use crate::HostImportError;
use crate::misc::PrepareError;
use marine_it_interfaces::MITInterfacesError;
use marine_it_parser::ITParserError;
use marine_module_info_parser::ModuleInfoError;
use marine_module_interface::it_interface::ITInterfaceError;
use wasmer_runtime::error as wasmer_error;
@ -25,6 +26,7 @@ use wasmer_runtime::error as wasmer_error;
use thiserror::Error as ThisError;
// TODO: refactor errors
// TODO: add module name to all errors variants
#[derive(Debug, ThisError)]
pub enum MError {
@ -73,8 +75,8 @@ pub enum MError {
ITInstructionError(#[from] wasmer_it::errors::InstructionError),
/// Error that raises on the preparation step.
#[error("PrepareError: {0}, probably module is malformed")]
PrepareError(#[from] parity_wasm::elements::Error),
#[error(transparent)]
PrepareError(#[from] PrepareError),
/// Indicates that there is already a module with such name.
#[error("module with name '{0}' already loaded into Marine, please specify another name")]
@ -99,30 +101,6 @@ pub enum MError {
/// Incorrect IT section.
#[error("{0}")]
IncorrectWIT(String),
/// Error is encountered while parsing module version.
#[error(transparent)]
ModuleVersionParseError(#[from] ModuleInfoError),
/// Provided module doesn't contain a sdk version that is necessary.
#[error("module with name '{0}' doesn't contain a version of sdk, probably it's compiled with an old one")]
ModuleWithoutVersion(String),
/// Module sdk versions are incompatible.
#[error("module with name '{module_name}' compiled with {provided} sdk version, but at least {required} required")]
IncompatibleSDKVersions {
module_name: String,
required: semver::Version,
provided: semver::Version,
},
/// Module IT versions are incompatible.
#[error("module with name '{module_name}' compiled with {provided} IT version, but at least {required} required")]
IncompatibleITVersions {
module_name: String,
required: semver::Version,
provided: semver::Version,
},
}
impl From<MITInterfacesError> for MError {

View File

@ -0,0 +1,71 @@
/*
* Copyright 2020 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_module_info_parser::ModuleInfoError;
use thiserror::Error as ThisError;
#[derive(Debug, ThisError)]
pub enum PrepareError {
/// Error that raises on a Wasm module validation.
#[error("validation error: {0}, probably module is malformed")]
ParseError(#[from] parity_wasm::elements::Error),
#[error(transparent)]
HeapBaseInvalidOrMissing(#[from] HeapBaseError),
#[error("overflow was happened while summation globals size '{globals_size}' and heap size '{max_heap_size}'")]
MemSizesOverflow {
globals_size: u32,
max_heap_size: u32,
},
/// Error is encountered while parsing module version.
#[error(transparent)]
ModuleVersionParseError(#[from] ModuleInfoError),
/// Provided module doesn't contain a sdk version that is necessary.
#[error("module with name '{0}' doesn't contain a version of sdk, probably it's compiled with an old one")]
ModuleWithoutVersion(String),
/// Module sdk versions are incompatible.
#[error("module with name '{module_name}' compiled with {provided} sdk version, but at least {required} required")]
IncompatibleSDKVersions {
module_name: String,
required: semver::Version,
provided: semver::Version,
},
/// Module IT versions are incompatible.
#[error("module with name '{module_name}' compiled with {provided} IT version, but at least {required} required")]
IncompatibleITVersions {
module_name: String,
required: semver::Version,
provided: semver::Version,
},
}
#[derive(Debug, ThisError)]
pub enum HeapBaseError {
#[error("a Wasm module doesn't expose __heap_base entry")]
ExportNotFound,
#[error("__heap_base is initialized not by i32.const, but by a different set of instructions, that's unsupported")]
InitializationNotI32Const,
#[error("__heap_base has not a i32 type")]
WrongType,
}

View File

@ -14,9 +14,14 @@
* limitations under the License.
*/
mod errors;
mod prepare;
mod version_checker;
pub(crate) use errors::HeapBaseError;
pub(crate) use errors::PrepareError;
pub(crate) use prepare::prepare_module;
pub(crate) use version_checker::check_sdk_version;
pub(crate) use version_checker::check_it_version;
pub(self) type PrepareResult<T> = std::result::Result<T, PrepareError>;

View File

@ -18,39 +18,59 @@
// https://github.com/paritytech/substrate/blob/master/srml/contracts/src/wasm/prepare.rs
// https://github.com/nearprotocol/nearcore/blob/master/runtime/near-vm-runner/src/prepare.rs
use crate::MResult;
mod heap_base;
use parity_wasm::{
builder, elements,
elements::{MemorySection, MemoryType},
};
use super::PrepareResult;
use crate::misc::PrepareError;
use heap_base::get_heap_base;
use marine_utils::to_wasm_page_count_ceil;
use parity_wasm::builder;
use parity_wasm::elements;
// not all clangs versions emits __heap_base, and this consts is a temporary solution
// until node has a dedicated config for that
const DEFAULT_GLOBALS_SIZE: u32 = 50;
struct ModuleBootstrapper {
module: elements::Module,
}
impl<'a> ModuleBootstrapper {
fn init(module_code: &[u8]) -> MResult<Self> {
fn init(module_code: &[u8]) -> PrepareResult<Self> {
let module = elements::deserialize_buffer(module_code)?;
Ok(Self { module })
}
fn set_mem_pages_count(self, mem_pages_count: u32) -> Self {
fn set_max_heap_size(self, max_heap_size: u32) -> PrepareResult<Self> {
use elements::{MemoryType, MemorySection};
let Self { mut module } = self;
let globals_size = get_heap_base(&module)
.map(to_wasm_page_count_ceil)
.unwrap_or(DEFAULT_GLOBALS_SIZE);
let max_mem_size =
globals_size
.checked_add(max_heap_size)
.ok_or(PrepareError::MemSizesOverflow {
globals_size,
max_heap_size,
})?;
// At now, there is could be only one memory section, so
// it needs just to extract previous initial page count,
// delete an old entry and add create a new one with updated limits
let mem_initial = match module.memory_section_mut() {
let mem_initial_size = match module.memory_section_mut() {
Some(section) => match section.entries_mut().pop() {
Some(entry) => entry.limits().initial(),
None => 0,
},
None => 0,
};
let mem_initial_size = std::cmp::min(mem_initial_size, max_mem_size);
let memory_entry = MemoryType::new(mem_initial, Some(mem_pages_count));
let memory_entry = MemoryType::new(mem_initial_size, Some(max_mem_size));
let mut default_mem_section = MemorySection::default();
module
@ -61,20 +81,21 @@ impl<'a> ModuleBootstrapper {
let builder = builder::from_module(module);
Self {
module: builder.build(),
}
let module = builder.build();
Ok(Self { module })
}
fn into_wasm(self) -> MResult<Vec<u8>> {
fn into_wasm(self) -> PrepareResult<Vec<u8>> {
elements::serialize(self.module).map_err(Into::into)
}
}
/// Prepares a Wasm module:
/// - set memory page count
pub(crate) fn prepare_module(module: &[u8], mem_pages_count: u32) -> MResult<Vec<u8>> {
/// - extracts __heap_base global
/// - computes module max memory size by summation of heap and globals sizes
/// - sets computed value as max memory page count of a module
pub(crate) fn prepare_module(module: &[u8], max_heap_size: u32) -> PrepareResult<Vec<u8>> {
ModuleBootstrapper::init(module)?
.set_mem_pages_count(mem_pages_count)
.set_max_heap_size(max_heap_size)?
.into_wasm()
}

View File

@ -0,0 +1,79 @@
/*
* Copyright 2021 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 crate::misc::HeapBaseError::*;
use parity_wasm::elements;
const HEAP_BASE_NAME: &str = "__heap_base";
type HResult<T> = std::result::Result<T, crate::misc::HeapBaseError>;
/// Return value of __heap_base.
pub(super) fn get_heap_base(wasm_module: &elements::Module) -> HResult<u32> {
let heap_base_index = find_global_name_index(wasm_module, HEAP_BASE_NAME)?;
let global_entry = find_global_by_index(wasm_module, heap_base_index as usize)?;
u32_from_global_entry(global_entry)
}
fn find_global_name_index(wasm_module: &elements::Module, name: &str) -> HResult<u32> {
use elements::Internal;
wasm_module
.export_section()
.and_then(|export_section| {
export_section
.entries()
.iter()
.find_map(|entry| match entry.internal() {
Internal::Global(index) if entry.field() == name => Some(*index),
_ => None,
})
})
.ok_or(ExportNotFound)
}
fn find_global_by_index(
wasm_module: &elements::Module,
index: usize,
) -> HResult<&elements::GlobalEntry> {
wasm_module
.global_section()
.and_then(|section| section.entries().get(index))
.ok_or(ExportNotFound)
}
fn u32_from_global_entry(global_entry: &elements::GlobalEntry) -> HResult<u32> {
use elements::{Instruction, ValueType};
let entry_type = global_entry.global_type().content_type();
if !matches!(entry_type, ValueType::I32) {
return Err(WrongType);
}
let init_expr = global_entry.init_expr().code();
// check that initialization expression consists of two instructions:
// i32.const <heap_base>
// end
if init_expr.len() != 2 {
return Err(InitializationNotI32Const);
}
match (&init_expr[0], &init_expr[1]) {
(Instruction::I32Const(value), Instruction::End) => Ok(*value as u32),
_ => Err(InitializationNotI32Const),
}
}

View File

@ -14,23 +14,26 @@
* limitations under the License.
*/
use crate::MResult;
use crate::MError;
use super::PrepareResult;
use super::PrepareError;
use marine_module_info_parser::sdk_version;
use wasmer_core::Module;
pub(crate) fn check_sdk_version(name: impl Into<String>, wasmer_module: &Module) -> MResult<()> {
pub(crate) fn check_sdk_version(
name: impl Into<String>,
wasmer_module: &Module,
) -> PrepareResult<()> {
let module_version = sdk_version::extract_from_wasmer_module(wasmer_module)?;
let module_version = match module_version {
Some(module_version) => module_version,
None => return Err(MError::ModuleWithoutVersion(name.into())),
None => return Err(PrepareError::ModuleWithoutVersion(name.into())),
};
let required_version = crate::min_sdk_version();
if module_version < *required_version {
return Err(MError::IncompatibleSDKVersions {
return Err(PrepareError::IncompatibleSDKVersions {
module_name: name.into(),
required: required_version.clone(),
provided: module_version,
@ -43,10 +46,10 @@ pub(crate) fn check_sdk_version(name: impl Into<String>, wasmer_module: &Module)
pub(crate) fn check_it_version(
name: impl Into<String>,
it_version: &semver::Version,
) -> MResult<()> {
) -> PrepareResult<()> {
let required_version = crate::min_it_version();
if it_version < required_version {
return Err(MError::IncompatibleITVersions {
return Err(PrepareError::IncompatibleITVersions {
module_name: name.into(),
required: required_version.clone(),
provided: it_version.clone(),

View File

@ -1,7 +1,7 @@
[package]
name = "mrepl"
description = "Fluence Marine REPL intended for testing purposes"
version = "0.9.2"
version = "0.10.0"
authors = ["Fluence Labs"]
repository = "https://github.com/fluencelabs/marine/tools/repl"
license = "Apache-2.0"
@ -12,8 +12,8 @@ name = "mrepl"
path = "src/main.rs"
[dependencies]
fluence-app-service = { path = "../../fluence-app-service", version = "0.10.0", features = ["raw-module-api"] }
marine-rs-sdk-main = { version = "0.6.13", features = ["logger"] }
fluence-app-service = { path = "../../fluence-app-service", version = "0.11.0", features = ["raw-module-api"] }
marine-rs-sdk-main = { version = "0.6.15", features = ["logger"] }
anyhow = "1.0.31"
clap = "2.33.1"