From ebfd26b85cbd94113f8e608bcc4ec2de219b2a90 Mon Sep 17 00:00:00 2001 From: Fridrik Asmundsson Date: Mon, 15 Jan 2024 19:19:51 +0000 Subject: [PATCH] Add chain metadata actor --- Cargo.lock | 536 +++++++++++++++---- Cargo.toml | 33 +- fendermint/actors/Cargo.toml | 12 + fendermint/actors/build.rs | 110 ++++ fendermint/actors/chainmetadata/Cargo.toml | 26 + fendermint/actors/chainmetadata/src/actor.rs | 89 +++ fendermint/actors/chainmetadata/src/lib.rs | 4 + fendermint/actors/src/lib.rs | 2 + ipc/wallet/Cargo.toml | 2 +- 9 files changed, 712 insertions(+), 102 deletions(-) create mode 100644 fendermint/actors/Cargo.toml create mode 100644 fendermint/actors/build.rs create mode 100644 fendermint/actors/chainmetadata/Cargo.toml create mode 100644 fendermint/actors/chainmetadata/src/actor.rs create mode 100644 fendermint/actors/chainmetadata/src/lib.rs create mode 100644 fendermint/actors/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index eae26f2fa..a77404922 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -304,25 +304,96 @@ dependencies = [ "futures-core", ] +[[package]] +name = "async-channel" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ca33f4bc4ed1babef42cad36cc1f51fa88be00420404e5b1e80ab1b18f7678c" +dependencies = [ + "concurrent-queue", + "event-listener 4.0.3", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17ae5ebefcc48e7452b4987947920dac9450be1110cadf34d1b8c116bdbaf97c" +dependencies = [ + "async-lock 3.3.0", + "async-task", + "concurrent-queue", + "fastrand 2.0.1", + "futures-lite 2.2.0", + "slab", +] + +[[package]] +name = "async-global-executor" +version = "2.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" +dependencies = [ + "async-channel 2.1.1", + "async-executor", + "async-io 2.2.2", + "async-lock 3.3.0", + "blocking", + "futures-lite 2.2.0", + "once_cell", +] + +[[package]] +name = "async-io" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fc5b45d93ef0529756f812ca52e44c221b35341892d3dcc34132ac02f3dd2af" +dependencies = [ + "async-lock 2.8.0", + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-lite 1.13.0", + "log", + "parking", + "polling 2.8.0", + "rustix 0.37.27", + "slab", + "socket2 0.4.10", + "waker-fn", +] + [[package]] name = "async-io" version = "2.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6afaa937395a620e33dc6a742c593c01aced20aa376ffb0f628121198578ccc7" dependencies = [ - "async-lock", + "async-lock 3.3.0", "cfg-if", "concurrent-queue", "futures-io", - "futures-lite", + "futures-lite 2.2.0", "parking", - "polling", - "rustix", + "polling 3.3.1", + "rustix 0.38.28", "slab", "tracing", "windows-sys 0.52.0", ] +[[package]] +name = "async-lock" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "287272293e9d8c41773cec55e365490fe034813a2f172f502d6ddcf75b2f582b" +dependencies = [ + "event-listener 2.5.3", +] + [[package]] name = "async-lock" version = "3.3.0" @@ -334,6 +405,32 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "async-std" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "62565bb4402e926b29953c785397c6dc0391b7b446e45008b0049eb43cec6f5d" +dependencies = [ + "async-channel 1.9.0", + "async-global-executor", + "async-io 1.13.0", + "async-lock 2.8.0", + "crossbeam-utils", + "futures-channel", + "futures-core", + "futures-io", + "futures-lite 1.13.0", + "gloo-timers", + "kv-log-macro", + "log", + "memchr", + "once_cell", + "pin-project-lite", + "pin-utils", + "slab", + "wasm-bindgen-futures", +] + [[package]] name = "async-stm" version = "0.4.0" @@ -344,6 +441,12 @@ dependencies = [ "tokio", ] +[[package]] +name = "async-task" +version = "4.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" + [[package]] name = "async-trait" version = "0.1.77" @@ -408,6 +511,12 @@ dependencies = [ "pin-project-lite", ] +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + [[package]] name = "attohttpc" version = "0.24.1" @@ -766,6 +875,22 @@ dependencies = [ "generic-array 0.14.7", ] +[[package]] +name = "blocking" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" +dependencies = [ + "async-channel 2.1.1", + "async-lock 3.3.0", + "async-task", + "fastrand 2.0.1", + "futures-io", + "futures-lite 2.2.0", + "piper", + "tracing", +] + [[package]] name = "bloom" version = "0.3.2" @@ -1031,20 +1156,6 @@ dependencies = [ "windows-targets 0.48.5", ] -[[package]] -name = "cid" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6ed9c8b2d17acb8110c46f1da5bf4a696d745e1474a16db0cd2b49cd0249bf2" -dependencies = [ - "core2", - "multibase", - "multihash 0.16.3", - "serde", - "serde_bytes", - "unsigned-varint 0.7.2", -] - [[package]] name = "cid" version = "0.10.1" @@ -2065,6 +2176,19 @@ dependencies = [ "syn 2.0.48", ] +[[package]] +name = "env_logger" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44533bbbb3bb3c1fa17d9f2e4e38bbbaf8396ba82193c4cb1b6445d711445d36" +dependencies = [ + "atty", + "humantime 1.3.0", + "log", + "regex", + "termcolor", +] + [[package]] name = "env_logger" version = "0.8.4" @@ -2081,7 +2205,7 @@ version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "95b3f3e67048839cb0d0781f445682a35113da7121f7c949db0e2be96a4fbece" dependencies = [ - "humantime", + "humantime 2.1.0", "is-terminal", "log", "regex", @@ -2527,6 +2651,15 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" +[[package]] +name = "fastrand" +version = "1.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" +dependencies = [ + "instant", +] + [[package]] name = "fastrand" version = "2.0.1" @@ -2559,6 +2692,34 @@ dependencies = [ "tracing-subscriber", ] +[[package]] +name = "fendermint_actor_chainmetadata" +version = "0.1.0" +dependencies = [ + "cid", + "fil_actors_runtime", + "frc42_dispatch", + "fvm_ipld_amt", + "fvm_ipld_blockstore", + "fvm_ipld_encoding", + "fvm_sdk", + "fvm_shared", + "getrandom", + "num-derive 0.3.3", + "num-traits", + "serde", + "serde_tuple", +] + +[[package]] +name = "fendermint_actors" +version = "0.1.0" +dependencies = [ + "fil_actor_bundler", + "fil_actors_runtime", + "num-traits", +] + [[package]] name = "fendermint_app" version = "0.1.0" @@ -2568,7 +2729,7 @@ dependencies = [ "async-trait", "base64 0.21.6", "bytes", - "cid 0.10.1", + "cid", "fendermint_abci", "fendermint_app_options", "fendermint_app_settings", @@ -2627,7 +2788,7 @@ name = "fendermint_app_options" version = "0.1.0" dependencies = [ "bytes", - "cid 0.10.1", + "cid", "clap 4.4.14", "fendermint_vm_actor_interface", "fvm_ipld_encoding", @@ -2702,7 +2863,7 @@ dependencies = [ "anyhow", "async-trait", "axum", - "cid 0.10.1", + "cid", "clap 4.4.14", "erased-serde", "ethers", @@ -2749,7 +2910,7 @@ name = "fendermint_rocksdb" version = "0.1.0" dependencies = [ "anyhow", - "cid 0.10.1", + "cid", "fendermint_storage", "fvm_ipld_blockstore", "fvm_ipld_encoding", @@ -2769,7 +2930,7 @@ dependencies = [ "async-trait", "base64 0.21.6", "bytes", - "cid 0.10.1", + "cid", "clap 4.4.14", "ethers", "fendermint_crypto", @@ -2817,7 +2978,7 @@ version = "0.1.0" dependencies = [ "arbitrary", "arbtest", - "cid 0.10.1", + "cid", "ethers", "fendermint_testing", "fvm_ipld_encoding", @@ -2837,7 +2998,7 @@ name = "fendermint_vm_actor_interface" version = "0.1.0" dependencies = [ "anyhow", - "cid 0.10.1", + "cid", "ethers", "ethers-core", "fendermint_crypto", @@ -2867,7 +3028,7 @@ name = "fendermint_vm_core" version = "0.1.0" dependencies = [ "arbitrary", - "cid 0.10.1", + "cid", "fnv", "fvm_shared", "lazy_static", @@ -2882,7 +3043,7 @@ dependencies = [ name = "fendermint_vm_encoding" version = "0.1.0" dependencies = [ - "cid 0.10.1", + "cid", "fvm_shared", "ipc-api", "num-traits", @@ -2896,7 +3057,7 @@ version = "0.1.0" dependencies = [ "anyhow", "arbitrary", - "cid 0.10.1", + "cid", "fendermint_crypto", "fendermint_testing", "fendermint_vm_core", @@ -2923,7 +3084,7 @@ dependencies = [ "anyhow", "async-stm", "async-trait", - "cid 0.10.1", + "cid", "ethers", "fendermint_crypto", "fendermint_eth_hardhat", @@ -2970,7 +3131,7 @@ dependencies = [ "anyhow", "arbitrary", "blake2b_simd", - "cid 0.10.1", + "cid", "ethers", "ethers-core", "fendermint_crypto", @@ -2998,7 +3159,7 @@ name = "fendermint_vm_resolver" version = "0.1.0" dependencies = [ "async-stm", - "cid 0.10.1", + "cid", "im", "ipc-api", "ipc_ipld_resolver", @@ -3013,7 +3174,7 @@ dependencies = [ "anyhow", "arbitrary", "async-stm", - "cid 0.10.1", + "cid", "dircpy", "fendermint_testing", "fendermint_vm_core", @@ -3048,7 +3209,7 @@ dependencies = [ "anyhow", "async-stm", "async-trait", - "cid 0.10.1", + "cid", "clap 4.4.14", "ethers", "fvm_ipld_encoding", @@ -3094,6 +3255,25 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27573eac26f4dd11e2b1916c3fe1baa56407c83c71a773a8ba17ec0bca03b6b7" +[[package]] +name = "fil_actor_bundler" +version = "6.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e0b1448c65c9a054c640fc086e03b730919ca4feca697c34ed3bda9f16aa982f" +dependencies = [ + "anyhow", + "async-std", + "cid", + "clap 4.4.14", + "futures", + "fvm_ipld_blockstore", + "fvm_ipld_car", + "fvm_ipld_encoding", + "serde", + "serde_ipld_dagcbor", + "serde_json", +] + [[package]] name = "fil_actors_evm_shared" version = "12.0.0" @@ -3114,23 +3294,29 @@ source = "git+https://github.com/filecoin-project/builtin-actors?tag=v12.0.0#b86 dependencies = [ "anyhow", "base64 0.21.6", + "blake2b_simd", "byteorder", "castaway", - "cid 0.10.1", + "cid", "fvm_ipld_amt", "fvm_ipld_bitfield", "fvm_ipld_blockstore", "fvm_ipld_encoding", "fvm_ipld_hamt 0.8.0", "fvm_shared", + "hex", "integer-encoding", "itertools 0.10.5", + "lazy_static", + "libsecp256k1", "log", "multihash 0.18.1", "num", "num-derive 0.3.3", "num-traits", "paste", + "pretty_env_logger", + "rand", "regex", "serde", "serde_repr", @@ -3313,6 +3499,44 @@ dependencies = [ "thiserror", ] +[[package]] +name = "frc42_dispatch" +version = "5.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfe63cf3ff3e332ef15fd19d95cffcb3fd2af14ccb3cb04abc730271c1362c4f" +dependencies = [ + "frc42_hasher", + "frc42_macros", + "fvm_ipld_encoding", + "fvm_sdk", + "fvm_shared", + "thiserror", +] + +[[package]] +name = "frc42_hasher" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08a35e7214108f81cefc17b0466be01279f384faf913918a12dbc8528bb758a4" +dependencies = [ + "fvm_sdk", + "fvm_shared", + "thiserror", +] + +[[package]] +name = "frc42_macros" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f50cd62b077775194bde67eef8076b31f915b9c099f3a7fd1a760363d65f145" +dependencies = [ + "blake2b_simd", + "frc42_hasher", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "fs2" version = "0.4.3" @@ -3388,13 +3612,31 @@ version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" +[[package]] +name = "futures-lite" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49a9d51ce47660b1e808d3c990b4709f2f415d928835a17dfd16991515c46bce" +dependencies = [ + "fastrand 1.9.0", + "futures-core", + "futures-io", + "memchr", + "parking", + "pin-project-lite", + "waker-fn", +] + [[package]] name = "futures-lite" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "445ba825b27408685aaecefd65178908c36c6e96aaf6d8599419d46e624192ba" dependencies = [ + "fastrand 2.0.1", "futures-core", + "futures-io", + "parking", "pin-project-lite", ] @@ -3490,7 +3732,7 @@ dependencies = [ "arbitrary", "blake2b_simd", "byteorder", - "cid 0.10.1", + "cid", "derive_more", "filecoin-proofs-api", "fvm-wasm-instrument", @@ -3539,7 +3781,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fea333475130094f27ce67809aae3f69eb5247541d835950b7c5da733dbbb34" dependencies = [ "anyhow", - "cid 0.10.1", + "cid", "fvm_ipld_blockstore", "fvm_ipld_encoding", "itertools 0.11.0", @@ -3567,7 +3809,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "417f52f6915b9f9a68de8462e1cf46f14a2c16420f484b8d2066873de2ffe420" dependencies = [ "anyhow", - "cid 0.10.1", + "cid", "multihash 0.18.1", ] @@ -3577,7 +3819,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6190f03442b67b21a3d4e115c4d4dd3468aed24e27ebb074218822c1b3df41ba" dependencies = [ - "cid 0.10.1", + "cid", "futures", "fvm_ipld_blockstore", "fvm_ipld_encoding", @@ -3593,11 +3835,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90608092e31d9a06236268c58f7c36668ab4b2a48afafe3a97e08f094ad7ae50" dependencies = [ "anyhow", - "cid 0.10.1", + "cid", "fvm_ipld_blockstore", "multihash 0.18.1", "serde", - "serde_ipld_dagcbor 0.4.2", + "serde_ipld_dagcbor", "serde_repr", "serde_tuple", "thiserror", @@ -3611,7 +3853,7 @@ checksum = "03a53e14c789449cec999ca0e93d909490c921b967adb7a9ec8f12286fb809bd" dependencies = [ "anyhow", "byteorder", - "cid 0.10.1", + "cid", "forest_hash_utils", "fvm_ipld_blockstore", "fvm_ipld_encoding", @@ -3631,7 +3873,7 @@ checksum = "48c900736087ff87cc51f669eee2f8e000c80717472242eb3f712aaa059ac3b3" dependencies = [ "anyhow", "byteorder", - "cid 0.10.1", + "cid", "forest_hash_utils", "fvm_ipld_blockstore", "fvm_ipld_encoding", @@ -3643,6 +3885,22 @@ dependencies = [ "thiserror", ] +[[package]] +name = "fvm_sdk" +version = "4.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "258cfc9a2e5dcb28ffcadd4abed504893996d31238488a07ef7d2a6a6e80e1ec" +dependencies = [ + "byteorder", + "cid", + "fvm_ipld_encoding", + "fvm_shared", + "lazy_static", + "log", + "num-traits", + "thiserror", +] + [[package]] name = "fvm_shared" version = "4.0.0" @@ -3654,7 +3912,7 @@ dependencies = [ "bitflags 2.4.1", "blake2b_simd", "bls-signatures 0.15.0", - "cid 0.10.1", + "cid", "data-encoding", "data-encoding-macro", "filecoin-proofs-api", @@ -3961,7 +4219,7 @@ dependencies = [ "ipnet", "once_cell", "rand", - "socket2", + "socket2 0.5.5", "thiserror", "tinyvec", "tokio", @@ -4083,6 +4341,15 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9" +[[package]] +name = "humantime" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df004cfca50ef23c36850aaaa59ad52cc70d0e90243c3c7737a4dd32dc7a3c4f" +dependencies = [ + "quick-error", +] + [[package]] name = "humantime" version = "2.1.0" @@ -4106,7 +4373,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2", + "socket2 0.5.5", "tokio", "tower-service", "tracing", @@ -4242,7 +4509,7 @@ version = "3.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6b0422c86d7ce0e97169cc42e04ae643caf278874a7a3c87b8150a220dc7e1e" dependencies = [ - "async-io", + "async-io 2.2.2", "core-foundation", "fnv", "futures", @@ -4385,6 +4652,17 @@ version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8bb03732005da905c88227371639bf1ad885cc712789c011c31c5fb3ab3ccf02" +[[package]] +name = "io-lifetimes" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eae7b9aee968036d54dce06cebaefd919e4472e753296daccd6d344e3e2df0c2" +dependencies = [ + "hermit-abi 0.3.3", + "libc", + "windows-sys 0.48.0", +] + [[package]] name = "iowrap" version = "0.2.1" @@ -4399,7 +4677,7 @@ name = "ipc-api" version = "0.1.0" dependencies = [ "anyhow", - "cid 0.10.1", + "cid", "ethers", "fil_actors_runtime", "fnv", @@ -4424,11 +4702,11 @@ name = "ipc-cli" version = "0.1.0" dependencies = [ "anyhow", - "async-channel", + "async-channel 1.9.0", "async-trait", "base64 0.21.6", "bytes", - "cid 0.10.1", + "cid", "clap 4.4.14", "clap_complete", "env_logger 0.10.1", @@ -4466,11 +4744,11 @@ name = "ipc-provider" version = "0.1.0" dependencies = [ "anyhow", - "async-channel", + "async-channel 1.9.0", "async-trait", "base64 0.21.6", "bytes", - "cid 0.10.1", + "cid", "dirs", "ethers", "ethers-contract", @@ -4507,7 +4785,7 @@ name = "ipc-types" version = "0.1.0" dependencies = [ "anyhow", - "cid 0.10.1", + "cid", "fvm_ipld_amt", "fvm_ipld_blockstore", "fvm_ipld_encoding", @@ -4546,7 +4824,7 @@ dependencies = [ "quickcheck_macros", "rand", "serde", - "serde_ipld_dagcbor 0.2.2", + "serde_ipld_dagcbor", "serde_json", "tempfile", "thiserror", @@ -4603,7 +4881,7 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b58db92f96b720de98181bbbe63c831e87005ab460c1bf306eb2622b4707997f" dependencies = [ - "socket2", + "socket2 0.5.5", "widestring", "windows-sys 0.48.0", "winreg", @@ -4622,7 +4900,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bad00257d07be169d870ab665980b06cdb366d792ad690bf2e76876dc503455" dependencies = [ "hermit-abi 0.3.3", - "rustix", + "rustix 0.38.28", "windows-sys 0.52.0", ] @@ -4771,6 +5049,15 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "kv-log-macro" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0de8b303297635ad57c9f5059fd9cee7a47f8e8daa09df0fcd07dd39fb22977f" +dependencies = [ + "log", +] + [[package]] name = "lalrpop" version = "0.20.0" @@ -4859,7 +5146,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5acd707e8d8b092e967b2af978ed84709eaded82b75effe6cb6f6cc797ef8158" dependencies = [ "anyhow", - "cid 0.10.1", + "cid", "core2", "multibase", "multihash 0.18.1", @@ -5136,7 +5423,7 @@ dependencies = [ "libp2p-swarm", "rand", "smallvec", - "socket2", + "socket2 0.5.5", "tokio", "tracing", "void", @@ -5258,7 +5545,7 @@ dependencies = [ "rand", "ring 0.16.20", "rustls 0.21.10", - "socket2", + "socket2 0.5.5", "thiserror", "tokio", "tracing", @@ -5331,7 +5618,7 @@ dependencies = [ "libc", "libp2p-core", "libp2p-identity", - "socket2", + "socket2 0.5.5", "tokio", "tracing", ] @@ -5478,6 +5765,12 @@ version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +[[package]] +name = "linux-raw-sys" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef53942eb7bf7ff43a617b3e2c1c4a5ecf5944a7c1bc12d7ee39bbb15e5c1519" + [[package]] name = "linux-raw-sys" version = "0.4.12" @@ -5505,6 +5798,9 @@ name = "log" version = "0.4.20" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b5e6163cb8c49088c2c36f57875e58ccd8c87c7427f7fbd50ea6710b2f3f2e8f" +dependencies = [ + "value-bag", +] [[package]] name = "lru" @@ -5583,7 +5879,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2cffa4ad52c6f791f4f8b15f0c05f9824b2ced1160e88cc393d64fff9a8ac64" dependencies = [ - "rustix", + "rustix 0.38.28", ] [[package]] @@ -5707,19 +6003,6 @@ dependencies = [ "data-encoding-macro", ] -[[package]] -name = "multihash" -version = "0.16.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1c346cf9999c631f002d8f977c4eaeaa0e6386f16007202308d0b3757522c2cc" -dependencies = [ - "core2", - "multihash-derive", - "serde", - "serde-big-array", - "unsigned-varint 0.7.2", -] - [[package]] name = "multihash" version = "0.18.1" @@ -6590,6 +6873,17 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" +dependencies = [ + "atomic-waker", + "fastrand 2.0.1", + "futures-io", +] + [[package]] name = "pkcs8" version = "0.9.0" @@ -6622,6 +6916,22 @@ version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "626dec3cac7cc0e1577a2ec3fc496277ec2baa084bebad95bb6fdbfae235f84c" +[[package]] +name = "polling" +version = "2.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4b2d323e8ca7996b3e23126511a523f7e62924d93ecd5ae73b333815b0eb3dce" +dependencies = [ + "autocfg", + "bitflags 1.3.2", + "cfg-if", + "concurrent-queue", + "libc", + "log", + "pin-project-lite", + "windows-sys 0.48.0", +] + [[package]] name = "polling" version = "3.3.1" @@ -6631,7 +6941,7 @@ dependencies = [ "cfg-if", "concurrent-queue", "pin-project-lite", - "rustix", + "rustix 0.38.28", "tracing", "windows-sys 0.52.0", ] @@ -6692,6 +7002,16 @@ dependencies = [ "yansi", ] +[[package]] +name = "pretty_env_logger" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "926d36b9553851b8b0005f1275891b392ee4d2d833852c417ed025477350fb9d" +dependencies = [ + "env_logger 0.7.1", + "log", +] + [[package]] name = "prettyplease" version = "0.2.16" @@ -6984,7 +7304,7 @@ checksum = "055b4e778e8feb9f93c4e439f71dc2156ef13360b432b799e179a8c4cdf0b1d7" dependencies = [ "bytes", "libc", - "socket2", + "socket2 0.5.5", "tracing", "windows-sys 0.48.0", ] @@ -7385,6 +7705,20 @@ dependencies = [ "nom", ] +[[package]] +name = "rustix" +version = "0.37.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fea8ca367a3a01fe35e6943c400addf443c0f57670e6ec51196f71a4b8762dd2" +dependencies = [ + "bitflags 1.3.2", + "errno", + "io-lifetimes", + "libc", + "linux-raw-sys 0.3.8", + "windows-sys 0.48.0", +] + [[package]] name = "rustix" version = "0.38.28" @@ -7394,7 +7728,7 @@ dependencies = [ "bitflags 2.4.1", "errno", "libc", - "linux-raw-sys", + "linux-raw-sys 0.4.12", "windows-sys 0.52.0", ] @@ -7700,18 +8034,6 @@ dependencies = [ "syn 2.0.48", ] -[[package]] -name = "serde_ipld_dagcbor" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1e23de7a4a18dff77ab9531f279a882500b8cf3549fde044d4e10481b411f1e" -dependencies = [ - "cbor4ii", - "cid 0.8.6", - "scopeguard", - "serde", -] - [[package]] name = "serde_ipld_dagcbor" version = "0.4.2" @@ -7719,7 +8041,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e880e0b1f9c7a8db874642c1217f7e19b29e325f24ab9f0fcb11818adec7f01" dependencies = [ "cbor4ii", - "cid 0.10.1", + "cid", "scopeguard", "serde", ] @@ -8017,6 +8339,16 @@ dependencies = [ "subtle", ] +[[package]] +name = "socket2" +version = "0.4.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7916fc008ca5542385b89a3d3ce689953c143e9304a9bf8beec1de48994c0d" +dependencies = [ + "libc", + "winapi", +] + [[package]] name = "socket2" version = "0.5.5" @@ -8432,9 +8764,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "01ce4141aa927a6d1bd34a041795abd0db1cccba5d5f24b009f694bdf3a1f3fa" dependencies = [ "cfg-if", - "fastrand", + "fastrand 2.0.1", "redox_syscall", - "rustix", + "rustix 0.38.28", "windows-sys 0.52.0", ] @@ -8732,7 +9064,7 @@ dependencies = [ "parking_lot", "pin-project-lite", "signal-hook-registry", - "socket2", + "socket2 0.5.5", "tokio-macros", "windows-sys 0.48.0", ] @@ -9342,6 +9674,12 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" +[[package]] +name = "value-bag" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cdbaf5e132e593e9fc1de6a15bbec912395b11fb9719e061cf64f804524c503" + [[package]] name = "vcpkg" version = "0.2.15" @@ -9366,7 +9704,7 @@ version = "1.0.0" source = "git+https://github.com/filecoin-project/builtin-actors?tag=v12.0.0#b86938e410daebf27f9397fd622370a16b24f58b" dependencies = [ "anyhow", - "cid 0.10.1", + "cid", "fvm_ipld_blockstore", "fvm_ipld_encoding", "fvm_ipld_hamt 0.8.0", @@ -9384,6 +9722,12 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +[[package]] +name = "waker-fn" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" + [[package]] name = "walkdir" version = "2.4.0" @@ -9654,7 +9998,7 @@ dependencies = [ "log", "object 0.31.1", "rustc-demangle", - "rustix", + "rustix 0.38.28", "serde", "target-lexicon", "wasmtime-environ", @@ -9701,7 +10045,7 @@ dependencies = [ "memoffset", "paste", "rand", - "rustix", + "rustix 0.38.28", "sptr", "wasm-encoder 0.31.1", "wasmtime-asm-macros", diff --git a/Cargo.toml b/Cargo.toml index f33a1a7bb..15a0c408d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,6 +26,8 @@ members = [ "fendermint/testing", "fendermint/testing/*-test", "fendermint/vm/*", + "fendermint/actors", + "fendermint/actors/chainmetadata", ] [workspace.package] @@ -65,10 +67,14 @@ gcra = "0.4" hex = "0.4" im = "15.1.0" integer-encoding = { version = "3.0.3", default-features = false } -jsonrpc-v2 = { version = "0.11", default-features = false, features = ["bytes-v10"] } +jsonrpc-v2 = { version = "0.11", default-features = false, features = [ + "bytes-v10", +] } k256 = "0.11" # Same as tendermint-rs lazy_static = "1.4" -libipld = { version = "0.16", default-features = false, features = ["dag-cbor"] } +libipld = { version = "0.16", default-features = false, features = [ + "dag-cbor", +] } libp2p = { version = "0.53", default-features = false, features = [ "gossipsub", "kad", @@ -151,7 +157,7 @@ openssl = { version = "0.10", features = ["vendored"] } # to version which are different than the ones in the builtin-actors project, and since # they are 0.x cargo cannot upgrade them automatically, which leads to version conflicts. fvm = { version = "4.0.0", default-features = false } # no opencl feature or it fails on CI -fvm_shared = { version = "4.0.0", features = ["crypto"] } +fvm_shared = { version = "4.0.0" } fvm_sdk = { version = "4.0.0" } fvm_ipld_blockstore = "0.2.0" @@ -178,7 +184,10 @@ fil_actors_runtime = { git = "https://github.com/filecoin-project/builtin-actors # Using 0.8 because of ref-fvm. # 0.9 would be better because of its updated quickcheck dependency. # 0.10 breaks some API. -cid = { version = "0.10.1", default-features = false, features = ["serde-codec", "std"] } +cid = { version = "0.10.1", default-features = false, features = [ + "serde-codec", + "std", +] } # Depending on the release cycle, this dependency might want an earlier version of the FVM. # We can work around it by hardcoding the method hashes; currently there is only one. @@ -188,7 +197,11 @@ cid = { version = "0.10.1", default-features = false, features = ["serde-codec", tower-abci = { version = "0.7" } tendermint = { version = "0.31", features = ["secp256k1"] } tendermint-config = "0.33.0" -tendermint-rpc = { version = "0.31", features = ["secp256k1", "http-client", "websocket-client"] } +tendermint-rpc = { version = "0.31", features = [ + "secp256k1", + "http-client", + "websocket-client", +] } tendermint-proto = { version = "0.31" } [patch.crates-io] @@ -196,3 +209,13 @@ tendermint-proto = { version = "0.31" } gcra = { git = "https://github.com/consensus-shipyard/gcra-rs.git", branch = "main" } # Contains some API changes that the upstream has not merged. merkle-tree-rs = { git = "https://github.com/consensus-shipyard/merkle-tree-rs.git", branch = "dev" } + +[profile.wasm] +inherits = "release" +panic = "abort" +overflow-checks = false +lto = true +opt-level = "z" +strip = true +codegen-units = 1 +incremental = false diff --git a/fendermint/actors/Cargo.toml b/fendermint/actors/Cargo.toml new file mode 100644 index 000000000..b8f235be6 --- /dev/null +++ b/fendermint/actors/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "fendermint_actors" +version = "0.1.0" + +[build-dependencies] +fil_actors_runtime = { workspace = true, features = ["test_utils"] } +fil_actor_bundler = "6.1.0" +num-traits = { workspace = true} + +[features] +default=[] +testing=[] \ No newline at end of file diff --git a/fendermint/actors/build.rs b/fendermint/actors/build.rs new file mode 100644 index 000000000..be5e279f8 --- /dev/null +++ b/fendermint/actors/build.rs @@ -0,0 +1,110 @@ +// Copyright 2022-2024 Protocol Labs +// SPDX-License-Identifier: Apache-2.0, MIT +extern crate fil_actor_bundler; +extern crate fil_actors_runtime; +extern crate num_traits; + +use fil_actor_bundler::Bundler; +use std::error::Error; +use std::io::{BufRead, BufReader}; +use std::path::Path; +use std::process::{Command, Stdio}; +use std::thread; + +const ACTORS: &[&str] = &["chainmetadata"]; + +const FILES_TO_WATCH: &[&str] = &["Cargo.toml", "src", "actors"]; + +fn main() -> Result<(), Box> { + // Cargo executable location. + let cargo = std::env::var_os("CARGO").expect("no CARGO env var"); + + let out_dir = std::env::var_os("OUT_DIR") + .as_ref() + .map(Path::new) + .map(|p| p.join("bundle")) + .expect("no OUT_DIR env var"); + println!("cargo:warning=out_dir: {:?}", &out_dir); + + let manifest_path = + Path::new(&std::env::var_os("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR unset")) + .join("Cargo.toml"); + + for file in FILES_TO_WATCH.to_vec() { + println!("cargo:rerun-if-changed={}", file); + } + + // Cargo build command for all test_actors at once. + let mut cmd = Command::new(cargo); + cmd.arg("build") + .args( + ACTORS + .iter() + .map(|pkg| "-p=fendermint_actor_".to_owned() + pkg), + ) + .arg("--target=wasm32-unknown-unknown") + .arg("--profile=wasm") + .arg("--manifest-path=".to_owned() + manifest_path.to_str().unwrap()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + // We are supposed to only generate artifacts under OUT_DIR, + // so set OUT_DIR as the target directory for this build. + .env("CARGO_TARGET_DIR", &out_dir) + // As we are being called inside a build-script, this env variable is set. However, we set + // our own `RUSTFLAGS` and thus, we need to remove this. Otherwise cargo favors this + // env variable. + .env_remove("CARGO_ENCODED_RUSTFLAGS"); + + // Print out the command line we're about to run. + println!("cargo:warning=cmd={:?}", &cmd); + + // Launch the command. + let mut child = cmd.spawn().expect("failed to launch cargo build"); + + // Pipe the output as cargo warnings. Unfortunately this is the only way to + // get cargo build to print the output. + let stdout = child.stdout.take().expect("no stdout"); + let stderr = child.stderr.take().expect("no stderr"); + let j1 = thread::spawn(move || { + for line in BufReader::new(stderr).lines() { + println!("cargo:warning={:?}", line.unwrap()); + } + }); + let j2 = thread::spawn(move || { + for line in BufReader::new(stdout).lines() { + println!("cargo:warning={:?}", line.unwrap()); + } + }); + + j1.join().unwrap(); + j2.join().unwrap(); + + let result = child.wait().expect("failed to wait for build to finish"); + if !result.success() { + return Err("actor build failed".into()); + } + + let dst = Path::new(&out_dir).join("bundle.car"); + let mut bundler = Bundler::new(&dst); + for (&pkg, id) in ACTORS.iter().zip(1u32..) { + let bytecode_path = Path::new(&out_dir) + .join("wasm32-unknown-unknown/wasm") + .join(format!("fendermint_actor_{}.wasm", pkg)); + + // This actor version doesn't force synthetic CIDs; it uses genuine + // content-addressed CIDs. + let forced_cid = None; + + let cid = bundler + .add_from_file(id, pkg.to_owned(), forced_cid, &bytecode_path) + .unwrap_or_else(|err| { + panic!("failed to add file {:?} to bundle for actor {}: {}", bytecode_path, id, err) + }); + println!("cargo:warning=added {} ({}) to bundle with CID {}", pkg, id, cid); + } + bundler.finish().expect("failed to finish bundle"); + + println!("cargo:warning=bundle={}", dst.display()); + + Ok(()) +} diff --git a/fendermint/actors/chainmetadata/Cargo.toml b/fendermint/actors/chainmetadata/Cargo.toml new file mode 100644 index 000000000..6bc24c845 --- /dev/null +++ b/fendermint/actors/chainmetadata/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "fendermint_actor_chainmetadata" +description = "Actor for storing chain metadata" +license.workspace = true +edition.workspace = true +authors.workspace = true +version = "0.1.0" + +[target.'cfg(target_arch = "wasm32")'.dependencies] +cid = { workspace = true, default-features = false } +frc42_dispatch = "5.0.0" +fvm_sdk = { workspace = true } +fvm_ipld_blockstore = { workspace = true } +fil_actors_runtime = { workspace = true } +fvm_shared = { workspace = true } +fvm_ipld_encoding = { workspace = true } +fvm_ipld_amt = { workspace = true } +getrandom = { version = "0.2.12", features = ["js"] } +serde = { workspace = true, features = ["derive"] } +serde_tuple = { workspace = true } +num-traits = { workspace = true } +num-derive = { workspace = true } + + +[lib] +crate-type = ["cdylib", "lib"] diff --git a/fendermint/actors/chainmetadata/src/actor.rs b/fendermint/actors/chainmetadata/src/actor.rs new file mode 100644 index 000000000..5bcc15257 --- /dev/null +++ b/fendermint/actors/chainmetadata/src/actor.rs @@ -0,0 +1,89 @@ +// Copyright 2021-2023 Protocol Labs +// SPDX-License-Identifier: Apache-2.0, MIT + +use cid::Cid; +use fil_actors_runtime::actor_dispatch; +use fil_actors_runtime::actor_error; +use fil_actors_runtime::runtime::{ActorCode, Runtime}; +use fil_actors_runtime::ActorError; +use fvm_ipld_encoding::tuple::{Deserialize_tuple, Serialize_tuple}; +use fvm_shared::METHOD_CONSTRUCTOR; +use num_derive::FromPrimitive; +use std::collections::VecDeque; + +#[derive(Serialize_tuple, Deserialize_tuple)] +struct State { + blockhashes: VecDeque, + params: ConstructorParams, +} + +#[derive(Default, Debug, Serialize_tuple, Deserialize_tuple)] +struct ConstructorParams { + lookback_len: u64, +} + +#[derive(FromPrimitive)] +#[repr(u64)] +pub enum Method { + Constructor = METHOD_CONSTRUCTOR, + PushBlock = 2, + LookbackLen = 3, + BlockCID = 4, +} + +pub struct Actor; + +impl Actor { + fn constructor(rt: &impl Runtime, params: ConstructorParams) -> Result<(), ActorError> { + let state = State { + blockhashes: VecDeque::new(), + params, + }; + rt.create(&state)?; + Ok(()) + } + + fn push_block(rt: &impl Runtime, block: Cid) -> Result<(), ActorError> { + rt.transaction(|st: &mut State, _rt| { + st.blockhashes.push_back(block); + if st.blockhashes.len() > st.params.lookback_len as usize { + st.blockhashes.pop_front(); + } + + Ok(()) + })?; + + Ok(()) + } + + fn lookback_len(rt: &impl Runtime) -> Result { + let state: State = rt.state()?; + Ok(state.params.lookback_len) + } + + fn block_cid(rt: &impl Runtime, rewind: u64) -> Result { + let state: State = rt.state()?; + let block = state + .blockhashes + .get(state.blockhashes.len() - rewind as usize - 1) + .ok_or_else(|| actor_error!(illegal_argument; "lookback too large"))?; + + + Ok(*block) + } +} + +impl ActorCode for Actor { + type Methods = Method; + + fn name() -> &'static str { + "ChainMetadata" + } + + actor_dispatch! { + Constructor => constructor, + PushBlock => push_block, + LookbackLen => lookback_len, + BlockCID => block_cid, + } +} diff --git a/fendermint/actors/chainmetadata/src/lib.rs b/fendermint/actors/chainmetadata/src/lib.rs new file mode 100644 index 000000000..1d4daedef --- /dev/null +++ b/fendermint/actors/chainmetadata/src/lib.rs @@ -0,0 +1,4 @@ +// Copyright 2021-2023 Protocol Labs +// SPDX-License-Identifier: Apache-2.0, MIT +#[cfg(target_arch = "wasm32")] +mod actor; diff --git a/fendermint/actors/src/lib.rs b/fendermint/actors/src/lib.rs new file mode 100644 index 000000000..f4a17876d --- /dev/null +++ b/fendermint/actors/src/lib.rs @@ -0,0 +1,2 @@ +// Copyright 2022-2024 Protocol Labs +// SPDX-License-Identifier: Apache-2.0, MIT diff --git a/ipc/wallet/Cargo.toml b/ipc/wallet/Cargo.toml index 6dc7365ad..11cd5d946 100644 --- a/ipc/wallet/Cargo.toml +++ b/ipc/wallet/Cargo.toml @@ -22,7 +22,7 @@ libsecp256k1 = { workspace = true } log = { workspace = true } rand = { workspace = true } serde = { workspace = true } -serde_ipld_dagcbor = "0.2" +serde_ipld_dagcbor = "0.4.2" serde_json = { workspace = true } thiserror = { workspace = true } xsalsa20poly1305 = "0.9"