From 414111f510a185e1e5b1b691ac2a035d3eb5f84c Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 10 Jun 2022 14:40:35 +0300 Subject: [PATCH 1/6] cargo patch ref-fvm to release/v1 --- rust/Cargo.toml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 6c71f6df..d0c1b6ae 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -72,3 +72,11 @@ c-headers = ["safer-ffi/headers"] [patch.crates-io] wasmtime = { git = "https://github.com/filecoin-project/wasmtime", branch = "fix/sse-feature" } +fvm = { git = "https://github.com/filecoin-project/ref-fvm", branch = "release/v1" } +fvm_shared = { git = "https://github.com/filecoin-project/ref-fvm", branch = "release/v1" } +fvm_sdk = { git = "https://github.com/filecoin-project/ref-fvm", branch = "release/v1" } +fvm_ipld_hamt = { git = "https://github.com/filecoin-project/ref-fvm", branch = "release/v1" } +fvm_ipld_amt = { git = "https://github.com/filecoin-project/ref-fvm", branch = "release/v1" } +fvm_ipld_bitfield = { git = "https://github.com/filecoin-project/ref-fvm", branch = "release/v1" } +fvm_ipld_encoding = { git = "https://github.com/filecoin-project/ref-fvm", branch = "release/v1" } +fvm_ipld_blockstore = { git = "https://github.com/filecoin-project/ref-fvm", branch = "release/v1" } From e7622f242e58960d023627b7bea994fd28ef4c2d Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 22 Jun 2022 12:19:03 +0300 Subject: [PATCH 2/6] cargo update --- rust/Cargo.lock | 172 ++++++++++++++++++++++++------------------------ 1 file changed, 85 insertions(+), 87 deletions(-) diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 4c2ab0a5..317d8f38 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -82,9 +82,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.57" +version = "1.0.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f9b8508dccb7687a1d6c4ce66b2b0ecef467c94667de27d8d7fe1f8d2a9cdc" +checksum = "bb07d2053ccdbe10e2af2995a2f116c1330396493dc1269f6a91d0ae82e19704" [[package]] name = "anymap" @@ -137,9 +137,9 @@ dependencies = [ [[package]] name = "async-global-executor" -version = "2.1.0" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd8b508d585e01084059b60f06ade4cb7415cd2e4084b71dd1cb44e7d3fb9880" +checksum = "5262ed948da60dd8956c6c5aca4d4163593dddb7b32d73267c93dab7b2e98940" dependencies = [ "async-channel", "async-executor", @@ -147,6 +147,7 @@ dependencies = [ "async-lock", "blocking", "futures-lite", + "num_cpus", "once_cell", ] @@ -180,9 +181,9 @@ dependencies = [ [[package]] name = "async-std" -version = "1.11.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52580991739c5cdb36cde8b2a516371c0a3b70dda36d916cc08b82372916808c" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" dependencies = [ "async-channel", "async-global-executor", @@ -197,7 +198,6 @@ dependencies = [ "kv-log-macro", "log", "memchr", - "num_cpus", "once_cell", "pin-project-lite", "pin-utils", @@ -624,16 +624,16 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.1" +version = "3.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a836566fa5f52f7ddf909a8a2f9029b9f78ca584cd95cf7e87f8073110f4c5c9" +checksum = "9f1fe12880bae935d142c8702d500c63a4e8634b6c3c57ad72bf978fc7b6249a" dependencies = [ "atty", "bitflags 1.3.2", "clap_derive", "clap_lex", "indexmap", - "lazy_static", + "once_cell", "strsim", "termcolor", "textwrap", @@ -641,9 +641,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "3.2.1" +version = "3.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "986fd75d1dfd2c34eb8c9275ae38ad87ea9478c9b79e87f1801f7d866dfb1e37" +checksum = "ed6db9e867166a43a53f7199b5e4d1f522a1e5bd626654be263c999ce59df39a" dependencies = [ "heck", "proc-macro-error", @@ -654,9 +654,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5538cd660450ebeb4234cfecf8f2284b844ffc4c50531e66d584ad5b91293613" +checksum = "87eba3c8c7f42ef17f6c659fc7416d0f4758cd3e58861ee63c5fa4a4dde649e4" dependencies = [ "os_str_bytes", ] @@ -833,9 +833,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5aaa7bd5fb665c6864b5f963dd9097905c54125909c7aa94c9e18507cdbe6c53" +checksum = "4c02a4d71819009c192cf4872265391563fd6a84c81ff2c0f2a7026ca4c1d85c" dependencies = [ "cfg-if 1.0.0", "crossbeam-utils", @@ -854,15 +854,15 @@ dependencies = [ [[package]] name = "crossbeam-epoch" -version = "0.9.8" +version = "0.9.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1145cf131a2c6ba0615079ab6a638f7e1973ac9c2634fcbeaaad6114246efe8c" +checksum = "07db9d94cbd326813772c968ccd25999e5f8ae22f4f8d1b11effa37ef6ce281d" dependencies = [ "autocfg", "cfg-if 1.0.0", "crossbeam-utils", - "lazy_static", "memoffset", + "once_cell", "scopeguard", ] @@ -878,12 +878,12 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.8" +version = "0.8.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf124c720b7686e3c2663cf54062ab0f68a88af2fb6a030e87e30bf721fcb38" +checksum = "8ff1f980957787286a554052d03c7aee98d99cc32e09f6d45f0a814133c87978" dependencies = [ "cfg-if 1.0.0", - "lazy_static", + "once_cell", ] [[package]] @@ -1300,9 +1300,9 @@ dependencies = [ [[package]] name = "fil_actor_bundler" -version = "3.0.3" +version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "646120abeada2d68a2970cc52a624642c100d5c83189110846b16e807b88e06a" +checksum = "715d3ad31a6e4715a49747e136d5daa1a6bbe7c078385bca7e11215c57884a35" dependencies = [ "anyhow", "async-std", @@ -1312,7 +1312,7 @@ dependencies = [ "fvm_ipld_blockstore", "fvm_ipld_car", "fvm_ipld_encoding", - "fvm_shared 0.7.1", + "fvm_shared 0.8.0", "serde", "serde_ipld_dagcbor", "serde_json", @@ -1631,9 +1631,9 @@ dependencies = [ [[package]] name = "filecoin-hashers" -version = "6.1.0" +version = "6.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5459189a6cd4eff6e425be7295e5e083dee3c9b1508291b955869f3b6b24f0cd" +checksum = "31b13b919031ffcf145e4a03f1d0e0ec52d9df52ea2ea77fa20141403b07d0cd" dependencies = [ "anyhow", "bellperson", @@ -1651,9 +1651,9 @@ dependencies = [ [[package]] name = "filecoin-proofs" -version = "11.1.0" +version = "11.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2993a1de1b2cff6c7212da3a4fd53ab91936c4ab6bfd00b09a19a79dfbf6d47a" +checksum = "e956a3235e86b88bfb3ffedf700ab1ff17145ac8d3936cd57d8bdef664d6a5d0" dependencies = [ "anyhow", "bellperson", @@ -1763,9 +1763,9 @@ dependencies = [ [[package]] name = "fr32" -version = "4.1.0" +version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "355338c73ad12186e0f99c563f2e5666f837d5c04edfd4302e7b89b356b8c86e" +checksum = "80932cb34221f04d5a79245d1d9d3aff991abc0ae7cc49100694b6e478bb8a19" dependencies = [ "anyhow", "bellperson", @@ -1905,8 +1905,7 @@ dependencies = [ [[package]] name = "fvm" version = "1.0.0-rc.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "82209c76fa405128e5f1406fe4c7bd58754f582835923c09b36782a3fe779301" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=release/v1#c05db5929e013ea56d51afeca1b40a42d03e496a" dependencies = [ "anyhow", "anymap", @@ -1951,8 +1950,7 @@ dependencies = [ [[package]] name = "fvm_ipld_amt" version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d09e5aa7de45452676d18fcb70b750acd65faae7a4fe18fe784b4c85f869fb" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=release/v1#c05db5929e013ea56d51afeca1b40a42d03e496a" dependencies = [ "ahash", "anyhow", @@ -1968,8 +1966,7 @@ dependencies = [ [[package]] name = "fvm_ipld_bitfield" version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af1587207c7455ea70a762d4360f502b6728ea6e2dfbec2b66b6d4d943ee29ae" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=release/v1#c05db5929e013ea56d51afeca1b40a42d03e496a" dependencies = [ "cs_serde_bytes", "fvm_ipld_encoding", @@ -1981,8 +1978,7 @@ dependencies = [ [[package]] name = "fvm_ipld_blockstore" version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "688239a96199577f6705a3f9689abfd795f867f91f5847bc7e236017cc672df7" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=release/v1#c05db5929e013ea56d51afeca1b40a42d03e496a" dependencies = [ "anyhow", "cid", @@ -2007,8 +2003,7 @@ dependencies = [ [[package]] name = "fvm_ipld_encoding" version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce9cfcb4ae444801009182fded790dd56aff9c9a567e54510e2ccf14fb9daf8e" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=release/v1#c05db5929e013ea56d51afeca1b40a42d03e496a" dependencies = [ "anyhow", "cid", @@ -2025,8 +2020,7 @@ dependencies = [ [[package]] name = "fvm_ipld_hamt" version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65b5c939897aa1bfd63e7cb9c458ba10689371af3278ff20d66c6f8ca152c6c0" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=release/v1#c05db5929e013ea56d51afeca1b40a42d03e496a" dependencies = [ "anyhow", "byteorder 1.4.3", @@ -2046,8 +2040,7 @@ dependencies = [ [[package]] name = "fvm_sdk" version = "1.0.0-rc.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3bd162cff8cab78c3798762bc6879429ecbd0f5515856bcb3bc31d197208db70" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=release/v1#c05db5929e013ea56d51afeca1b40a42d03e496a" dependencies = [ "cid", "fvm_ipld_encoding", @@ -2091,8 +2084,7 @@ dependencies = [ [[package]] name = "fvm_shared" version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94c2485c563703b730df0502e2e8fcea86bc183b7018a080c6a5b15b7a29c5d0" +source = "git+https://github.com/filecoin-project/ref-fvm?branch=release/v1#c05db5929e013ea56d51afeca1b40a42d03e496a" dependencies = [ "anyhow", "bimap", @@ -2236,6 +2228,12 @@ dependencies = [ "ahash", ] +[[package]] +name = "hashbrown" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db0d4cf898abf0081f964436dc980e96670a0f36863e4b83aaacdb65c9d7ccc3" + [[package]] name = "heck" version = "0.4.0" @@ -2299,12 +2297,12 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "1.8.2" +version = "1.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a" +checksum = "10a35a97730320ffe8e2d410b5d3b69279b98d2c14bdb8b70ea89ecf7888d41e" dependencies = [ "autocfg", - "hashbrown", + "hashbrown 0.12.1", "serde", ] @@ -2390,9 +2388,9 @@ checksum = "112c678d4050afce233f4f2852bb2eb519230b3cf12f33585275537d7e41578d" [[package]] name = "js-sys" -version = "0.3.57" +version = "0.3.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671a26f820db17c2a2750743f1dd03bafd15b98c9f30c7c2628c024c05d73397" +checksum = "c3fac17f7123a73ca62df411b1bf727ccc805daa070338fda671c86dac1bdc27" dependencies = [ "wasm-bindgen", ] @@ -2835,7 +2833,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e42c982f2d955fac81dd7e1d0e1426a7d702acd9c98d19ab01083a6a0328c424" dependencies = [ "crc32fast", - "hashbrown", + "hashbrown 0.11.2", "indexmap", "memchr", ] @@ -3022,9 +3020,9 @@ checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5" [[package]] name = "proc-macro2" -version = "1.0.39" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c54b25569025b7fc9651de43004ae593a75ad88543b17178aa5e1b9c4f15f56f" +checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7" dependencies = [ "unicode-ident", ] @@ -3040,9 +3038,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1feb54ed693b93a84e14094943b84b7c4eae204c512b7ccb95ab0c66d278ad1" +checksum = "3bcdf212e9776fbcb2d23ab029360416bb1706b1aea2d1a5ba002727cbcab804" dependencies = [ "proc-macro2", ] @@ -3357,9 +3355,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" +checksum = "a0a5f7c728f5d284929a1cccb5bc19884422bfe6ef4d6c409da2c41838983fcf" [[package]] name = "ryu" @@ -3564,9 +3562,9 @@ dependencies = [ [[package]] name = "sha2raw" -version = "6.1.0" +version = "6.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fc780bf01fa69500c5e0555d1a444bb05e5789bcad81c88e3eb96d9c51e3d395" +checksum = "a6e2b67a24ce79212efcb5c44cbd9e7c3776a731272f747149a792a2afe5c45e" dependencies = [ "block-buffer 0.9.0", "byteorder 1.4.3", @@ -3639,9 +3637,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "storage-proofs-core" -version = "11.1.0" +version = "11.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b46f91043e71be271bbe34d4d22916e2ba55a0d128d5a18bd4dcfff44f4bc3ec" +checksum = "b3bff040dcf0834917f69db391f4fb5e72d43c7d5cb90b5bbd4ae9d6b744a894" dependencies = [ "aes", "anyhow", @@ -3680,9 +3678,9 @@ dependencies = [ [[package]] name = "storage-proofs-porep" -version = "11.1.0" +version = "11.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "343b7faebb6376e20a44f91a34ee3e9c1533069434b6a1a05ed1c7b95c53c1d3" +checksum = "395dd7a7802d002def493315e0ec8e6bda274c7a31406c5104dfc1a19fbfc7b3" dependencies = [ "anyhow", "bellperson", @@ -3723,9 +3721,9 @@ dependencies = [ [[package]] name = "storage-proofs-post" -version = "11.1.0" +version = "11.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "741f7f1bcae57dcc449dd8189eb6984f3332b73d214ab7945a5c3f6c9a05a8ad" +checksum = "e868618ef3b6968928924a38410e816752799ce26242799497bd1461b6228a22" dependencies = [ "anyhow", "bellperson", @@ -3752,9 +3750,9 @@ dependencies = [ [[package]] name = "storage-proofs-update" -version = "11.1.0" +version = "11.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "734fae4ec0920273ba044ffad9d55c6214f15dffd914d35f15540ec15632a91b" +checksum = "0e69871eb1a083fa5a3db211981d5959f549708bb578b0e0e9961467384d31d1" dependencies = [ "anyhow", "bellperson", @@ -3807,9 +3805,9 @@ checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" [[package]] name = "syn" -version = "1.0.96" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0748dd251e24453cb8717f0354206b91557e4ec8703673a4b30208f2abaf1ebf" +checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" dependencies = [ "proc-macro2", "quote", @@ -3910,9 +3908,9 @@ dependencies = [ [[package]] name = "time" -version = "0.3.9" +version = "0.3.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2702e08a7a860f005826c6815dcac101b19b5eb330c27fe4a5928fec1d20ddd" +checksum = "72c91f41dcb2f096c05f0873d667dceec1087ce5bcf984ec8ffb19acddbb3217" dependencies = [ "itoa", "libc", @@ -4001,9 +3999,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27370197c907c55e3f1a9fbe26f44e937fe6451368324e009cba39e139dc08ad" +checksum = "7c53b543413a17a202f4be280a7e5c62a1c69345f5de525ee64f8cfdbc954994" dependencies = [ "cfg-if 1.0.0", "wasm-bindgen-macro", @@ -4011,9 +4009,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "53e04185bfa3a779273da532f5025e33398409573f348985af9a1cbf3774d3f4" +checksum = "5491a68ab4500fa6b4d726bd67408630c3dbe9c4fe7bda16d5c82a1fd8c7340a" dependencies = [ "bumpalo", "lazy_static", @@ -4026,9 +4024,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-futures" -version = "0.4.30" +version = "0.4.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f741de44b75e14c35df886aff5f1eb73aa114fa5d4d00dcd37b5e01259bf3b2" +checksum = "de9a9cec1733468a8c657e57fa2413d2ae2c0129b95e87c5b72b8ace4d13f31f" dependencies = [ "cfg-if 1.0.0", "js-sys", @@ -4038,9 +4036,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "17cae7ff784d7e83a2fe7611cfe766ecf034111b49deb850a3dc7699c08251f5" +checksum = "c441e177922bc58f1e12c022624b6216378e5febc2f0533e41ba443d505b80aa" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -4048,9 +4046,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99ec0dc7a4756fffc231aab1b9f2f578d23cd391390ab27f952ae0c9b3ece20b" +checksum = "7d94ac45fcf608c1f45ef53e748d35660f168490c10b23704c7779ab8f5c3048" dependencies = [ "proc-macro2", "quote", @@ -4061,9 +4059,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.80" +version = "0.2.81" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d554b7f530dee5964d9a9468d95c1f8b8acae4f282807e7d27d4b03099a46744" +checksum = "6a89911bd99e5f3659ec4acf9c4d93b0a90fe4a2a11f15328472058edc5261be" [[package]] name = "wasmparser" @@ -4210,9 +4208,9 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.57" +version = "0.3.58" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b17e741662c70c8bd24ac5c5b18de314a2c26c32bf8346ee1e6f53de919c283" +checksum = "2fed94beee57daf8dd7d51f2b15dc2bcde92d7a72304cdf662a4371008b71b90" dependencies = [ "js-sys", "wasm-bindgen", From 11cc6df4018218e60703023cd57098b84dabd287 Mon Sep 17 00:00:00 2001 From: vyzo Date: Fri, 10 Jun 2022 14:42:02 +0300 Subject: [PATCH 3/6] fvm machine for debug execution --- cgo/fvm.go | 27 ++++++++++++++ fvm.go | 44 ++++++++++++++++------ rust/src/fvm/machine.rs | 81 ++++++++++++++++++++++++++++++++++++++++- 3 files changed, 139 insertions(+), 13 deletions(-) diff --git a/cgo/fvm.go b/cgo/fvm.go index 8b6cb54f..22c3e192 100644 --- a/cgo/fvm.go +++ b/cgo/fvm.go @@ -35,6 +35,33 @@ func CreateFvmMachine(fvmVersion FvmRegisteredVersion, chainEpoch, baseFeeHi, ba return executor, nil } +func CreateFvmDebugMachine(fvmVersion FvmRegisteredVersion, chainEpoch, baseFeeHi, baseFeeLo, baseCircSupplyHi, baseCircSupplyLo, networkVersion uint64, stateRoot SliceRefUint8, actorRedirect SliceRefUint8, tracing bool, blockstoreId, externsId uint64) (*FvmMachine, error) { + resp := C.create_fvm_debug_machine( + fvmVersion, + C.uint64_t(chainEpoch), + C.uint64_t(baseFeeHi), + C.uint64_t(baseFeeLo), + C.uint64_t(baseCircSupplyHi), + C.uint64_t(baseCircSupplyLo), + C.uint64_t(networkVersion), + stateRoot, + actorRedirect, + C.bool(tracing), + C.uint64_t(blockstoreId), + C.uint64_t(externsId), + ) + // take out the pointer from the result to ensure it doesn't get freed + executor := resp.value + resp.value = nil + defer resp.destroy() + + if err := CheckErr(resp); err != nil { + return nil, err + } + + return executor, nil +} + func FvmMachineExecuteMessage(executor *FvmMachine, message SliceRefUint8, chainLen, applyKind uint64) (FvmMachineExecuteResponseGo, error) { resp := C.fvm_machine_execute_message( executor, diff --git a/fvm.go b/fvm.go index f1451b94..ed65cf7d 100644 --- a/fvm.go +++ b/fvm.go @@ -42,6 +42,9 @@ type FVMOpts struct { StateBase cid.Cid Manifest cid.Cid Tracing bool + + Debug bool + ActorRedirect cid.Cid } // CreateFVM creates a new FVM instance. @@ -56,18 +59,35 @@ func CreateFVM(opts *FVMOpts) (*FVM, error) { } exHandle := cgo.Register(context.TODO(), opts.Externs) - executor, err := cgo.CreateFvmMachine(cgo.FvmRegisteredVersion(opts.FVMVersion), - uint64(opts.Epoch), - baseFeeHi, - baseFeeLo, - baseCircSupplyHi, - baseCircSupplyLo, - uint64(opts.NetworkVersion), - cgo.AsSliceRefUint8(opts.StateBase.Bytes()), - cgo.AsSliceRefUint8(opts.Manifest.Bytes()), - opts.Tracing, - exHandle, exHandle, - ) + var executor *cgo.FvmMachine + if !opts.Debug { + executor, err = cgo.CreateFvmMachine(cgo.FvmRegisteredVersion(opts.FVMVersion), + uint64(opts.Epoch), + baseFeeHi, + baseFeeLo, + baseCircSupplyHi, + baseCircSupplyLo, + uint64(opts.NetworkVersion), + cgo.AsSliceRefUint8(opts.StateBase.Bytes()), + cgo.AsSliceRefUint8(opts.Manifest.Bytes()), + opts.Tracing, + exHandle, exHandle, + ) + } else { + executor, err = cgo.CreateFvmDebugMachine(cgo.FvmRegisteredVersion(opts.FVMVersion), + uint64(opts.Epoch), + baseFeeHi, + baseFeeLo, + baseCircSupplyHi, + baseCircSupplyLo, + uint64(opts.NetworkVersion), + cgo.AsSliceRefUint8(opts.StateBase.Bytes()), + cgo.AsSliceRefUint8(opts.ActorRedirect.Bytes()), + opts.Tracing, + exHandle, exHandle, + ) + } + if err != nil { return nil, err } diff --git a/rust/src/fvm/machine.rs b/rust/src/fvm/machine.rs index 962dc28d..e401d0e0 100644 --- a/rust/src/fvm/machine.rs +++ b/rust/src/fvm/machine.rs @@ -12,7 +12,7 @@ use fvm::DefaultKernel; use fvm_ipld_blockstore::Blockstore; use fvm_ipld_car::load_car; use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple}; -use fvm_ipld_encoding::{to_vec, RawBytes}; +use fvm_ipld_encoding::{to_vec, CborStore, RawBytes}; use fvm_shared::address::Address; use fvm_shared::error::{ErrorNumber, ExitCode}; use fvm_shared::receipt::Receipt; @@ -132,6 +132,85 @@ fn create_fvm_machine( } } +#[ffi_export] +fn create_fvm_debug_machine( + fvm_version: FvmRegisteredVersion, + chain_epoch: u64, + base_fee_hi: u64, + base_fee_lo: u64, + base_circ_supply_hi: u64, + base_circ_supply_lo: u64, + network_version: u64, + state_root: c_slice::Ref, + actor_redirect: c_slice::Ref, + tracing: bool, + blockstore_id: u64, + externs_id: u64, +) -> repr_c::Box> { + use fvm::machine::NetworkConfig; + unsafe { + catch_panic_response_no_default("create_fvm_machine", || { + match fvm_version { + FvmRegisteredVersion::V1 => info!("using FVM V1"), + //_ => panic!("unsupported FVM Registered Version") + } + + let chain_epoch = chain_epoch as ChainEpoch; + + let base_circ_supply = TokenAmount::from( + ((base_circ_supply_hi as u128) << u64::BITS) | base_circ_supply_lo as u128, + ); + let base_fee = + TokenAmount::from(((base_fee_hi as u128) << u64::BITS) | base_fee_lo as u128); + + let network_version = NetworkVersion::try_from(network_version as u32) + .map_err(|_| anyhow!("unsupported network version: {}", network_version))?; + let state_root = Cid::try_from(&state_root[..]) + .map_err(|err| anyhow!("invalid state root: {}", err))?; + + let blockstore = FakeBlockstore::new(CgoBlockstore::new(blockstore_id)).finish(); + let externs = CgoExterns::new(externs_id); + + let mut network_config = NetworkConfig::new(network_version); + + network_config.enable_actor_debugging(); + if !actor_redirect.is_empty() { + let actor_redirect_cid = Cid::try_from(&actor_redirect[..]) + .map_err(|err| anyhow!("invalid redirect CID: {}", err))?; + let redirect: Vec<(Cid, Cid)> = match blockstore + .get_cbor(&actor_redirect_cid) + .map_err(|err| anyhow!("invalid redirect cid: {}", err))? + { + Some(v) => v, + None => bail!("failed to create engine: missing redirect vector"), + }; + network_config.redirect_actors(redirect); + } + + let mut machine_context = network_config.for_epoch(chain_epoch, state_root); + + machine_context + .set_base_fee(base_fee) + .set_circulating_supply(base_circ_supply); + + if tracing { + machine_context.enable_tracing(); + } + + let engine = match ENGINES.get(&network_config) { + Ok(e) => e, + Err(err) => bail!("failed to create engine: {}", err), + }; + + let machine = CgoMachine::new(&engine, &machine_context, blockstore, externs)?; + + Ok(Some(repr_c::Box::new(InnerFvmMachine { + machine: Some(Mutex::new(new_executor(machine))), + }))) + }) + } +} + #[ffi_export] fn fvm_machine_execute_message( executor: &'_ InnerFvmMachine, From 4effec47eaa0550f95bd7803e0300cf87d0774e1 Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 22 Jun 2022 12:20:27 +0300 Subject: [PATCH 4/6] dedup dual machine construction code --- rust/src/fvm/machine.rs | 168 ++++++++++++++++++++++------------------ 1 file changed, 91 insertions(+), 77 deletions(-) diff --git a/rust/src/fvm/machine.rs b/rust/src/fvm/machine.rs index e401d0e0..b7892553 100644 --- a/rust/src/fvm/machine.rs +++ b/rust/src/fvm/machine.rs @@ -40,12 +40,7 @@ lazy_static! { static ref ENGINES: MultiEngine = MultiEngine::new(); } -/// Note: the incoming args as u64 and odd conversions to i32/i64 -/// for some types is due to the generated bindings not liking the -/// 32bit types as incoming args -/// -#[ffi_export] -fn create_fvm_machine( +fn create_fvm_machine_generic( fvm_version: FvmRegisteredVersion, chain_epoch: u64, base_fee_hi: u64, @@ -54,7 +49,9 @@ fn create_fvm_machine( base_circ_supply_lo: u64, network_version: u64, state_root: c_slice::Ref, - manifest_cid: c_slice::Ref, + manifest_cid: Option>, + actor_redirect: Option>, + actor_debug: bool, tracing: bool, blockstore_id: u64, externs_id: u64, @@ -80,11 +77,12 @@ fn create_fvm_machine( let state_root = Cid::try_from(&state_root[..]) .map_err(|err| anyhow!("invalid state root: {}", err))?; - let manifest_cid = if !manifest_cid.is_empty() { - let cid = Cid::try_from(&manifest_cid[..]) - .map_err(|err| anyhow!("invalid manifest: {}", err))?; - Some(cid) - } else { + let manifest_cid = match manifest_cid { + Some(manifest_cid) => { + let cid = Cid::try_from(&manifest_cid[..]) + .map_err(|err| anyhow!("invalid manifest: {}", err))?; + Some(cid) + } // handle cid.Undef for no manifest // this can mean two things: // - for pre nv16, use the builtin bundles @@ -92,7 +90,7 @@ fn create_fvm_machine( // actor and we can pass None to the machine constructor to fish it from state. // The presence of the manifest cid argument allows us to test with new bundles // with minimum friction. - None + None => None, }; let blockstore = FakeBlockstore::new(CgoBlockstore::new(blockstore_id)); @@ -102,9 +100,28 @@ fn create_fvm_machine( Ok(Some(manifest)) => { network_config.override_actors(manifest); } - Ok(None) => {} + Ok(None) => (), Err(err) => bail!("couldn't load builtin actors: {}", err), } + + if actor_debug { + network_config.enable_actor_debugging(); + } + + let blockstore = blockstore.finish(); + if let Some(ar) = actor_redirect { + let actor_redirect_cid = Cid::try_from(&ar[..]) + .map_err(|err| anyhow!("invalid redirect CID: {}", err))?; + let redirect: Vec<(Cid, Cid)> = match blockstore + .get_cbor(&actor_redirect_cid) + .map_err(|err| anyhow!("invalid redirect cid: {}", err))? + { + Some(v) => v, + None => bail!("failed to create engine: missing redirect vector"), + }; + network_config.redirect_actors(redirect); + } + let mut machine_context = network_config.for_epoch(chain_epoch, state_root); machine_context @@ -114,7 +131,6 @@ fn create_fvm_machine( if tracing { machine_context.enable_tracing(); } - let blockstore = blockstore.finish(); let externs = CgoExterns::new(externs_id); @@ -131,6 +147,46 @@ fn create_fvm_machine( }) } } +/// Note: the incoming args as u64 and odd conversions to i32/i64 +/// for some types is due to the generated bindings not liking the +/// 32bit types as incoming args +/// +#[ffi_export] +fn create_fvm_machine( + fvm_version: FvmRegisteredVersion, + chain_epoch: u64, + base_fee_hi: u64, + base_fee_lo: u64, + base_circ_supply_hi: u64, + base_circ_supply_lo: u64, + network_version: u64, + state_root: c_slice::Ref, + manifest_cid: c_slice::Ref, + tracing: bool, + blockstore_id: u64, + externs_id: u64, +) -> repr_c::Box> { + create_fvm_machine_generic( + fvm_version, + chain_epoch, + base_fee_hi, + base_fee_lo, + base_circ_supply_hi, + base_circ_supply_lo, + network_version, + state_root, + if manifest_cid.is_empty() { + None + } else { + Some(manifest_cid) + }, + None, + false, + tracing, + blockstore_id, + externs_id, + ) +} #[ffi_export] fn create_fvm_debug_machine( @@ -147,68 +203,26 @@ fn create_fvm_debug_machine( blockstore_id: u64, externs_id: u64, ) -> repr_c::Box> { - use fvm::machine::NetworkConfig; - unsafe { - catch_panic_response_no_default("create_fvm_machine", || { - match fvm_version { - FvmRegisteredVersion::V1 => info!("using FVM V1"), - //_ => panic!("unsupported FVM Registered Version") - } - - let chain_epoch = chain_epoch as ChainEpoch; - - let base_circ_supply = TokenAmount::from( - ((base_circ_supply_hi as u128) << u64::BITS) | base_circ_supply_lo as u128, - ); - let base_fee = - TokenAmount::from(((base_fee_hi as u128) << u64::BITS) | base_fee_lo as u128); - - let network_version = NetworkVersion::try_from(network_version as u32) - .map_err(|_| anyhow!("unsupported network version: {}", network_version))?; - let state_root = Cid::try_from(&state_root[..]) - .map_err(|err| anyhow!("invalid state root: {}", err))?; - - let blockstore = FakeBlockstore::new(CgoBlockstore::new(blockstore_id)).finish(); - let externs = CgoExterns::new(externs_id); - - let mut network_config = NetworkConfig::new(network_version); - - network_config.enable_actor_debugging(); - if !actor_redirect.is_empty() { - let actor_redirect_cid = Cid::try_from(&actor_redirect[..]) - .map_err(|err| anyhow!("invalid redirect CID: {}", err))?; - let redirect: Vec<(Cid, Cid)> = match blockstore - .get_cbor(&actor_redirect_cid) - .map_err(|err| anyhow!("invalid redirect cid: {}", err))? - { - Some(v) => v, - None => bail!("failed to create engine: missing redirect vector"), - }; - network_config.redirect_actors(redirect); - } - - let mut machine_context = network_config.for_epoch(chain_epoch, state_root); - - machine_context - .set_base_fee(base_fee) - .set_circulating_supply(base_circ_supply); - - if tracing { - machine_context.enable_tracing(); - } - - let engine = match ENGINES.get(&network_config) { - Ok(e) => e, - Err(err) => bail!("failed to create engine: {}", err), - }; - - let machine = CgoMachine::new(&engine, &machine_context, blockstore, externs)?; - - Ok(Some(repr_c::Box::new(InnerFvmMachine { - machine: Some(Mutex::new(new_executor(machine))), - }))) - }) - } + create_fvm_machine_generic( + fvm_version, + chain_epoch, + base_fee_hi, + base_fee_lo, + base_circ_supply_hi, + base_circ_supply_lo, + network_version, + state_root, + None, + if actor_redirect.is_empty() { + None + } else { + Some(actor_redirect) + }, + true, + tracing, + blockstore_id, + externs_id, + ) } #[ffi_export] From 61e495f48a7874824403a5a90771739ee5c44046 Mon Sep 17 00:00:00 2001 From: vyzo Date: Wed, 22 Jun 2022 12:34:32 +0300 Subject: [PATCH 5/6] shut up clippy --- rust/src/fvm/machine.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/rust/src/fvm/machine.rs b/rust/src/fvm/machine.rs index b7892553..bd7a7c5b 100644 --- a/rust/src/fvm/machine.rs +++ b/rust/src/fvm/machine.rs @@ -40,6 +40,7 @@ lazy_static! { static ref ENGINES: MultiEngine = MultiEngine::new(); } +#[allow(clippy::too_many_arguments)] fn create_fvm_machine_generic( fvm_version: FvmRegisteredVersion, chain_epoch: u64, From 0b00ec811356b926800c910e5e9ad455aff4b19a Mon Sep 17 00:00:00 2001 From: Steven Allen Date: Wed, 22 Jun 2022 14:21:07 -0700 Subject: [PATCH 6/6] nit: rewrite match as functional rust Feel free to revert if this is too rusty. --- rust/src/fvm/machine.rs | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/rust/src/fvm/machine.rs b/rust/src/fvm/machine.rs index bd7a7c5b..c285dd77 100644 --- a/rust/src/fvm/machine.rs +++ b/rust/src/fvm/machine.rs @@ -1,7 +1,7 @@ use std::convert::{TryFrom, TryInto}; use std::sync::Mutex; -use anyhow::{anyhow, bail}; +use anyhow::{anyhow, bail, Context}; use cid::Cid; use futures::executor::block_on; use fvm::call_manager::DefaultCallManager; @@ -78,21 +78,17 @@ fn create_fvm_machine_generic( let state_root = Cid::try_from(&state_root[..]) .map_err(|err| anyhow!("invalid state root: {}", err))?; - let manifest_cid = match manifest_cid { - Some(manifest_cid) => { - let cid = Cid::try_from(&manifest_cid[..]) - .map_err(|err| anyhow!("invalid manifest: {}", err))?; - Some(cid) - } - // handle cid.Undef for no manifest - // this can mean two things: - // - for pre nv16, use the builtin bundles - // - for nv16 or higher, it means we have already migrated state for system - // actor and we can pass None to the machine constructor to fish it from state. - // The presence of the manifest cid argument allows us to test with new bundles - // with minimum friction. - None => None, - }; + // There may be no manifest CID: + // - for pre nv16, use the builtin bundles + // - for nv16 or higher, it means we have already migrated state for system + // actor and we can pass None to the machine constructor to fish it from state. + // The presence of the manifest cid argument allows us to test with new bundles + // with minimum friction. + let manifest_cid = manifest_cid + .as_deref() // into a slice + .map(Cid::try_from) // into a cid + .transpose() // Option> -> Result> + .context("invalid manifest")?; let blockstore = FakeBlockstore::new(CgoBlockstore::new(blockstore_id));