From 0fc577ef375b8a58ccdb274c9dfdc81436ba3e4d Mon Sep 17 00:00:00 2001 From: hanabi1224 Date: Thu, 28 Nov 2024 18:50:56 +0800 Subject: [PATCH] chore: replace `libipld` with `ipld-core` (#5013) --- Cargo.lock | 147 ++++++++++++++------------ Cargo.toml | 7 +- interop-tests/build.rs | 1 + src/documentation.rs | 4 +- src/ipld/mod.rs | 2 +- src/ipld/tests/cbor_test.rs | 10 +- src/ipld/util.rs | 4 +- src/lotus_json/ipld.rs | 6 +- src/rpc/methods/chain.rs | 4 +- src/rpc/methods/eth.rs | 2 +- src/rpc/methods/eth/types.rs | 2 +- src/rpc/methods/state.rs | 17 ++- src/rpc/types/mod.rs | 2 +- src/statediff/mod.rs | 6 +- src/statediff/resolve.rs | 4 +- src/tool/subcommands/api_cmd.rs | 3 +- src/tool/subcommands/benchmark_cmd.rs | 2 +- src/utils/cid/mod.rs | 12 +++ src/utils/encoding/cid_de_cbor.rs | 12 +-- src/utils/encoding/mod.rs | 9 +- 20 files changed, 147 insertions(+), 109 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 19c1ba454d71..818b7fc262a3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -663,9 +663,9 @@ dependencies = [ [[package]] name = "backon" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4fa97bb310c33c811334143cf64c5bb2b7b3c06e453db6b095d7061eff8f113" +checksum = "ba5289ec98f68f28dd809fd601059e6aa908bb8f6108620930828283d4ee23d7" dependencies = [ "fastrand 2.2.0", "gloo-timers", @@ -1286,6 +1286,23 @@ dependencies = [ "unsigned-varint 0.7.2", ] +[[package]] +name = "cid" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3147d8272e8fa0ccd29ce51194dd98f79ddfb8191ba9e3409884e751798acf3a" +dependencies = [ + "arbitrary", + "core2", + "multibase", + "multihash 0.19.2", + "quickcheck", + "rand", + "serde", + "serde_bytes", + "unsigned-varint 0.8.0", +] + [[package]] name = "cipher" version = "0.4.4" @@ -2681,7 +2698,7 @@ version = "17.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "221d40848fed6bbf3a891c4ef847d35989866443edb7d9d3a00606ee78fa274d" dependencies = [ - "cid", + "cid 0.10.1", "fil_actors_shared", "frc42_macros", "fvm_ipld_encoding", @@ -2702,7 +2719,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf62fb4dd864a3e4a93823989e27285d39e9a0805dece809903ba41444b7936e" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "fil_actors_shared", "frc42_macros", "fvm_ipld_blockstore", @@ -2723,7 +2740,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bf47419f82f9d70ab6d5c246f9c529e43c8207f52845a159381c5b05c830978" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "fil_actor_account_state", "fil_actor_cron_state", "fil_actor_datacap_state", @@ -2756,7 +2773,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "550c482acda09001e00e71bc64da59f9c354d18ef11b642fa7a98d0eaf4eeb44" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "fil_actor_verifreg_state", "fil_actors_shared", "frc42_dispatch", @@ -2784,7 +2801,7 @@ checksum = "6137f5b221f5a2c36d3b0c4ca117ac00f6a02f26cb1174d89d61e1fb8c9abeec" dependencies = [ "anyhow", "bitflags 2.6.0", - "cid", + "cid 0.10.1", "fil_actor_verifreg_state", "fil_actors_shared", "frc42_dispatch", @@ -2814,7 +2831,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0be25b9201f83892f82512b263e3d6739386bd648edf8d67c50cdf12e34ab058" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "fil_actors_shared", "frc42_dispatch", "frc42_macros", @@ -2838,7 +2855,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "28b2ece48faebb6d514c7968da24a556b9324a929cfcce059a941058e27fe2b4" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "fil_actors_shared", "frc42_dispatch", "frc42_macros", @@ -2879,7 +2896,7 @@ version = "17.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c6870b81aef1a11b5a7fec4c605084740f0c9cd56db9a52727f1503a2a5d090" dependencies = [ - "cid", + "cid 0.10.1", "fil_actors_shared", "fvm_ipld_blockstore", "fvm_ipld_encoding", @@ -2897,7 +2914,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a0b60c9f1a5afc1b4a90fd525f0eea6924cbff87135f8fe913462b97d768cb9a" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "fil_actors_shared", "frc42_dispatch", "frc42_macros", @@ -2919,7 +2936,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d82a54fed6cc20618d7183e161396d647dd6ec918d202f15a480ae7bbb5ed89d" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "filecoin-proofs-api", "frc46_token", "fvm_ipld_amt", @@ -3127,7 +3144,8 @@ dependencies = [ "cfg-if", "cfg-vis", "chrono", - "cid", + "cid 0.10.1", + "cid 0.11.1", "clap", "colored", "console-subscriber", @@ -3184,6 +3202,7 @@ dependencies = [ "indicatif", "insta", "integer-encoding", + "ipld-core", "is-terminal", "itertools 0.13.0", "jsonrpsee", @@ -3191,9 +3210,6 @@ dependencies = [ "keccak-hash", "kubert-prometheus-process", "lazy-regex", - "libipld", - "libipld-core", - "libipld-macro", "libp2p", "libp2p-swarm-test", "libsecp256k1", @@ -3247,7 +3263,7 @@ dependencies = [ "scopeguard", "semver", "serde", - "serde_ipld_dagcbor", + "serde_ipld_dagcbor 0.6.1", "serde_json", "serde_tuple 1.1.0", "serde_with", @@ -3296,7 +3312,7 @@ name = "forest-interop-tests" version = "0.1.0" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "flume 0.11.1", "forest-filecoin", "futures", @@ -3383,7 +3399,7 @@ version = "11.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af558bacb4e00ac1aa47115464f2bfa3d8dbd2a3b032dc325d20eaaaa22522e7" dependencies = [ - "cid", + "cid 0.10.1", "frc42_dispatch", "fvm_actor_utils", "fvm_ipld_blockstore", @@ -3585,7 +3601,7 @@ dependencies = [ "anyhow", "blake2b_simd", "byteorder", - "cid", + "cid 0.10.1", "derive-getters", "derive_builder", "derive_more 1.0.0", @@ -3623,7 +3639,7 @@ dependencies = [ "arbitrary", "blake2b_simd", "byteorder", - "cid", + "cid 0.10.1", "derive_more 1.0.0", "filecoin-proofs-api", "fvm-wasm-instrument 0.4.0", @@ -3660,7 +3676,7 @@ dependencies = [ "ambassador", "anyhow", "arbitrary", - "cid", + "cid 0.10.1", "derive_more 0.99.18", "filecoin-proofs-api", "fvm-wasm-instrument 0.4.0", @@ -3716,7 +3732,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fe8cad6375c09395099f25313600a53b1012a29595f9666a48c00eba7a8adaf9" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "frc42_dispatch", "fvm_ipld_blockstore", "fvm_ipld_encoding", @@ -3735,7 +3751,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5fea333475130094f27ce67809aae3f69eb5247541d835950b7c5da733dbbb34" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "fvm_ipld_blockstore", "fvm_ipld_encoding", "itertools 0.11.0", @@ -3763,7 +3779,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d064b957420f5ecc137a153baaa6c32e2eb19b674135317200b6f2537eabdbfd" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "multihash 0.18.1", ] @@ -3774,11 +3790,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90608092e31d9a06236268c58f7c36668ab4b2a48afafe3a97e08f094ad7ae50" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "fvm_ipld_blockstore", "multihash 0.18.1", "serde", - "serde_ipld_dagcbor", + "serde_ipld_dagcbor 0.4.2", "serde_repr", "serde_tuple 0.5.0", "thiserror 1.0.69", @@ -3792,7 +3808,7 @@ checksum = "48c900736087ff87cc51f669eee2f8e000c80717472242eb3f712aaa059ac3b3" dependencies = [ "anyhow", "byteorder", - "cid", + "cid 0.10.1", "forest_hash_utils", "fvm_ipld_blockstore", "fvm_ipld_encoding", @@ -3810,7 +3826,7 @@ version = "4.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7e53061f4d51562b90fb3fe9be7a3ab9650a9bd8f08cc6b48d25e6bfe052a21b" dependencies = [ - "cid", + "cid 0.10.1", "fvm_ipld_encoding", "fvm_shared 4.3.3", "lazy_static", @@ -3829,7 +3845,7 @@ dependencies = [ "blake2b_simd", "bls-signatures", "byteorder", - "cid", + "cid 0.10.1", "cs_serde_bytes", "data-encoding", "data-encoding-macro", @@ -3862,7 +3878,7 @@ dependencies = [ "bitflags 2.6.0", "blake2b_simd", "bls-signatures", - "cid", + "cid 0.10.1", "data-encoding", "data-encoding-macro", "filecoin-proofs-api", @@ -3892,7 +3908,7 @@ dependencies = [ "bitflags 2.6.0", "blake2b_simd", "bls-signatures", - "cid", + "cid 0.10.1", "data-encoding", "data-encoding-macro", "filecoin-proofs-api", @@ -4868,6 +4884,18 @@ dependencies = [ "winreg", ] +[[package]] +name = "ipld-core" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4ede82a79e134f179f4b29b5fdb1eb92bd1b38c4dfea394c539051150a21b9b" +dependencies = [ + "cid 0.11.1", + "quickcheck", + "serde", + "serde_bytes", +] + [[package]] name = "ipnet" version = "2.10.1" @@ -5239,9 +5267,7 @@ checksum = "f1ccd6b8ffb3afee7081fcaec00e1b099fd1c7ccf35ba5729d88538fcc3b4599" dependencies = [ "fnv", "libipld-cbor", - "libipld-cbor-derive", "libipld-core", - "libipld-json", "libipld-macro", "log", "multihash 0.18.1", @@ -5259,19 +5285,6 @@ dependencies = [ "thiserror 1.0.69", ] -[[package]] -name = "libipld-cbor-derive" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d5ba3a729b72973e456a1812b0afe2e176a376c1836cc1528e9fc98ae8cb838" -dependencies = [ - "proc-macro-crate 1.3.1", - "proc-macro2", - "quote", - "syn 1.0.109", - "synstructure 0.12.6", -] - [[package]] name = "libipld-core" version = "0.16.0" @@ -5279,27 +5292,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5acd707e8d8b092e967b2af978ed84709eaded82b75effe6cb6f6cc797ef8158" dependencies = [ "anyhow", - "cid", + "cid 0.10.1", "core2", "multibase", "multihash 0.18.1", - "quickcheck", "serde", "thiserror 1.0.69", ] -[[package]] -name = "libipld-json" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25856def940047b07b25c33d4e66d248597049ab0202085215dc4dca0487731c" -dependencies = [ - "libipld-core", - "multihash 0.18.1", - "serde", - "serde_json", -] - [[package]] name = "libipld-macro" version = "0.16.0" @@ -6240,7 +6240,10 @@ version = "0.19.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cc41f430805af9d1cf4adae4ed2149c759b877b01d909a1f40256188d09345d2" dependencies = [ + "arbitrary", "core2", + "quickcheck", + "rand", "serde", "unsigned-varint 0.8.0", ] @@ -7037,9 +7040,9 @@ dependencies = [ [[package]] name = "postcard" -version = "1.0.10" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f7f0a8d620d71c457dd1d47df76bb18960378da56af4527aaa10f515eee732e" +checksum = "f63d01def49fc815900a83e7a4a5083d2abc81b7ddd569a3fa0477778ae9b3ec" dependencies = [ "cobs", "embedded-io 0.4.0", @@ -8324,7 +8327,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e880e0b1f9c7a8db874642c1217f7e19b29e325f24ab9f0fcb11818adec7f01" dependencies = [ "cbor4ii", - "cid", + "cid 0.10.1", + "scopeguard", + "serde", +] + +[[package]] +name = "serde_ipld_dagcbor" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ded35fbe4ab8fdec1f1d14b4daff2206b1eada4d6e708cb451d464d2d965f493" +dependencies = [ + "cbor4ii", + "ipld-core", "scopeguard", "serde", ] @@ -9577,9 +9592,9 @@ checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" [[package]] name = "tracing" -version = "0.1.40" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" +checksum = "784e0ac535deb450455cbfa28a6f0df145ea1bb7ae51b821cf5e7927fdcfbdd0" dependencies = [ "log", "pin-project-lite", diff --git a/Cargo.toml b/Cargo.toml index d1a1f72c8823..d7193bb4653f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,6 +44,7 @@ cfg-if = "1" cfg-vis = "0.3" chrono = { version = "0.4", default-features = false, features = ["clock"] } cid = { workspace = true } +cid_0_11 = { package = "cid", version = "0.11", default-features = false, features = ["std"] } clap = { version = "4", features = ["derive"] } colored = "2.0" crypto_secretbox = "0.1" @@ -93,6 +94,7 @@ humantime = "2" indexmap = { version = "2", features = ["serde"] } indicatif = { version = "0.17", features = ["tokio"] } integer-encoding = "4.0" +ipld-core = { version = "0.4", features = ["serde", "arb"] } is-terminal = "0.4" itertools = "0.13" jsonrpsee = { version = "0.24", features = ["server", "ws-client", "http-client"] } @@ -100,9 +102,6 @@ jsonwebtoken = "9" keccak-hash = "0.11" kubert-prometheus-process = "0.1" lazy-regex = "3" -libipld = { version = "0.16", default-features = false, features = ["dag-cbor", "dag-json", "derive", "serde-codec"] } -libipld-core = { version = "0.16", features = ['arb', 'serde-codec'] } -libipld-macro = "0.16" libp2p = { workspace = true, features = [ 'autonat', 'gossipsub', @@ -171,7 +170,7 @@ schemars = { version = "0.8", features = ["chrono", "uuid1"] } scopeguard = "1" semver = "1" serde = { version = "1", default-features = false, features = ["derive"] } -serde_ipld_dagcbor = "0.4" +serde_ipld_dagcbor = "0.6" serde_json = { version = "1.0", features = ["raw_value"] } serde_tuple = "1" serde_with = { version = "3", features = ["chrono_0_4"] } diff --git a/interop-tests/build.rs b/interop-tests/build.rs index 43d9f73c17af..fd2c5225553c 100644 --- a/interop-tests/build.rs +++ b/interop-tests/build.rs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0, MIT fn main() { + println!("cargo::rerun-if-changed=src/tests/go_app"); rust2go::Builder::default() .with_go_src("./src/tests/go_app") .with_regen_arg(rust2go::RegenArgs { diff --git a/src/documentation.rs b/src/documentation.rs index f963fcb08aee..3e376e016a5a 100644 --- a/src/documentation.rs +++ b/src/documentation.rs @@ -111,7 +111,7 @@ /// which is a representation of all Filecoin state at a point in time. /// For each actor, the `StateTree` holds the CID for its state: [`ActorState.state`](fvm4::state_tree::ActorState::state). /// -/// Actor state is serialized and stored as [`Ipld`](libipld::Ipld). +/// Actor state is serialized and stored as [`Ipld`](ipld_core::ipld::Ipld). /// Think of this as "JSON with links ([`Cid`](cid::Cid)s)". /// So the `cron` actor's state mentioned above will be ultimately serialized into `Ipld` /// and stored in the `StateStore`, per @@ -169,7 +169,7 @@ /// /// With respect to a particular IPLD [`Blockstore`](fvm_ipld_blockstore::Blockstore): /// - An item such a list is _fully inhabited_ if all its recursive -/// [`Ipld::Link`](libipld::Ipld::Link)s exist in the blockstore. +/// [`Ipld::Link`](ipld_core::ipld::Ipld::Link)s exist in the blockstore. /// - Otherwise, an item is only _partially inhabited_. /// The links are said to be "dead links". /// diff --git a/src/ipld/mod.rs b/src/ipld/mod.rs index f626912d17f9..4e3d069133bc 100644 --- a/src/ipld/mod.rs +++ b/src/ipld/mod.rs @@ -4,7 +4,7 @@ pub mod selector; pub mod util; -pub use libipld_core::ipld::Ipld; +pub use ipld_core::ipld::Ipld; pub use util::*; #[cfg(test)] diff --git a/src/ipld/tests/cbor_test.rs b/src/ipld/tests/cbor_test.rs index 43fa671a1226..c663307fcab6 100644 --- a/src/ipld/tests/cbor_test.rs +++ b/src/ipld/tests/cbor_test.rs @@ -1,7 +1,7 @@ // Copyright 2019-2024 ChainSafe Systems // SPDX-License-Identifier: Apache-2.0, MIT -use crate::{ipld::Ipld, utils::encoding::from_slice_with_fallback}; +use crate::utils::encoding::from_slice_with_fallback; use cid::{ multihash::{ Code::{Blake2b256, Identity}, @@ -10,19 +10,19 @@ use cid::{ Cid, }; use fvm_ipld_encoding::{to_vec, DAG_CBOR}; -use libipld_core::serde::to_ipld; -use libipld_macro::ipld; +use ipld_core::{ipld, ipld::Ipld, serde::to_ipld}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone)] struct TestStruct { name: String, - details: Cid, + details: cid_0_11::Cid, } #[test] fn encode_new_type() { let details = Cid::new_v1(DAG_CBOR, Blake2b256.digest(&[1, 2, 3])); + let details = crate::utils::cid::cid_10_to_11(&details); let name = "Test".to_string(); let t_struct = TestStruct { name: name.clone(), @@ -46,6 +46,7 @@ fn encode_new_type() { #[test] fn cid_conversions_ipld() { let cid = Cid::new_v1(DAG_CBOR, Blake2b256.digest(&[1, 2, 3])); + let cid = crate::utils::cid::cid_10_to_11(&cid); let m_s = TestStruct { name: "s".to_owned(), details: cid, @@ -63,6 +64,7 @@ fn cid_conversions_ipld() { // Test with identity hash (different length prefix for cbor) let cid = Cid::new_v1(DAG_CBOR, Identity.digest(&[1, 2])); + let cid = crate::utils::cid::cid_10_to_11(&cid); let ipld = ipld!(Ipld::Link(cid)); let ipld2 = to_ipld(cid).unwrap(); assert_eq!(ipld, ipld2); diff --git a/src/ipld/util.rs b/src/ipld/util.rs index 245fc22a95fb..45eedf585d29 100644 --- a/src/ipld/util.rs +++ b/src/ipld/util.rs @@ -81,7 +81,7 @@ impl DfsIter { impl From for DfsIter { fn from(cid: Cid) -> Self { - DfsIter::new(Ipld::Link(cid)) + DfsIter::new(Ipld::Link(crate::utils::cid::cid_10_to_11(&cid))) } } @@ -181,7 +181,7 @@ impl + Unpin> Stream for ChainStream< let ipld_to_cid = |ipld| { if let Ipld::Link(cid) = ipld { - return Some(cid); + return Some(crate::utils::cid::cid_11_to_10(&cid)); } None }; diff --git a/src/lotus_json/ipld.rs b/src/lotus_json/ipld.rs index cc7eb02a32df..a758d3b98be1 100644 --- a/src/lotus_json/ipld.rs +++ b/src/lotus_json/ipld.rs @@ -19,7 +19,7 @@ //! compatible, we cannot switch to `libipld-json`. //! //! # Tech debt -//! - The real way to do this is to implement [`libipld::codec`] bits appropriately, +//! - The real way to do this is to implement [`ipld_core::codec::Codec`] bits appropriately, //! or embrace using our own struct. use std::{collections::BTreeMap, fmt}; @@ -27,7 +27,7 @@ use std::{collections::BTreeMap, fmt}; use super::*; use ::cid::multibase; -use libipld::{ipld, Ipld}; +use ipld_core::{ipld, ipld::Ipld}; use serde::de; #[derive(Serialize, Deserialize, JsonSchema)] @@ -313,7 +313,7 @@ quickcheck::quickcheck! { /// Error: "called `Result::unwrap()` on an `Err` value: Error(\"Input too short\", line: 1, column: 52)"', /// ``` /// The actual error message is a little ambiguous with regards to the cause -/// because [`libipld` has a custom debug implementation][unhelpful] +/// because [`ipld_core`] has a custom debug implementation [unhelpful] /// /// Here's what the minimal test case (or simply another bug) is after trying to understand the above. /// diff --git a/src/rpc/methods/chain.rs b/src/rpc/methods/chain.rs index 2375d7807134..507189b834bc 100644 --- a/src/rpc/methods/chain.rs +++ b/src/rpc/methods/chain.rs @@ -28,9 +28,9 @@ use cid::Cid; use fvm_ipld_blockstore::Blockstore; use fvm_ipld_encoding::{CborStore, RawBytes}; use hex::ToHex; +use ipld_core::ipld::Ipld; use jsonrpsee::types::error::ErrorObjectOwned; use jsonrpsee::types::Params; -use libipld::Ipld; use num::BigInt; use once_cell::sync::Lazy; use schemars::JsonSchema; @@ -319,7 +319,7 @@ impl RpcMethod<2> for ChainStatObj { { for ipld in DfsIter::new(ipld) { if let Ipld::Link(cid) = ipld { - queue.push_back(cid); + queue.push_back(crate::utils::cid::cid_11_to_10(&cid)); } } } diff --git a/src/rpc/methods/eth.rs b/src/rpc/methods/eth.rs index 26ac7cc6be2e..b80e1cbb7416 100644 --- a/src/rpc/methods/eth.rs +++ b/src/rpc/methods/eth.rs @@ -47,8 +47,8 @@ use cbor4ii::core::Value; use cid::Cid; use fvm_ipld_blockstore::Blockstore; use fvm_ipld_encoding::{RawBytes, CBOR, DAG_CBOR, IPLD_RAW}; +use ipld_core::ipld::Ipld; use itertools::Itertools; -use libipld_core::ipld::Ipld; use num::{BigInt, Zero as _}; use schemars::JsonSchema; use serde::{Deserialize, Serialize}; diff --git a/src/rpc/methods/eth/types.rs b/src/rpc/methods/eth/types.rs index 67814effa8e5..247155e74740 100644 --- a/src/rpc/methods/eth/types.rs +++ b/src/rpc/methods/eth/types.rs @@ -3,7 +3,7 @@ use super::*; use anyhow::ensure; -use libipld::error::SerdeError; +use ipld_core::serde::SerdeError; use libsecp256k1::util::FULL_PUBLIC_KEY_SIZE; use serde::de::{value::StringDeserializer, IntoDeserializer}; use std::hash::Hash; diff --git a/src/rpc/methods/state.rs b/src/rpc/methods/state.rs index d16bb72589aa..38e5bb2e7bc7 100644 --- a/src/rpc/methods/state.rs +++ b/src/rpc/methods/state.rs @@ -62,8 +62,8 @@ use futures::StreamExt; use fvm_ipld_blockstore::Blockstore; use fvm_ipld_encoding::{CborStore, DAG_CBOR}; pub use fvm_shared3::sector::StoragePower; +use ipld_core::ipld::Ipld; use jsonrpsee::types::error::ErrorObject; -use libipld_core::ipld::Ipld; use num_bigint::BigInt; use num_traits::Euclid; use nunny::{vec as nonempty, Vec as NonEmpty}; @@ -1219,7 +1219,14 @@ impl RpcMethod<2> for StateFetchRoot { // When walking an Ipld graph, we're only interested in the DAG_CBOR encoded nodes. let mut get_ipld_link = |ipld: &Ipld| match ipld { - &Ipld::Link(cid) if cid.codec() == DAG_CBOR && seen.insert(cid) => Some(cid), + &Ipld::Link(cid) if cid.codec() == DAG_CBOR => { + let cid = crate::utils::cid::cid_11_to_10(&cid); + if seen.insert(cid) { + Some(cid) + } else { + None + } + } _ => None, }; @@ -1228,7 +1235,9 @@ impl RpcMethod<2> for StateFetchRoot { // depth-first-search pauses until one of the work tasks returns. The memory usage of this // algorithm is dominated by the set of seen CIDs and the 'dfs' stack is not expected to grow to // more than 1000 elements (even when walking tens of millions of nodes). - let dfs = Arc::new(Mutex::new(vec![Ipld::Link(root_cid)])); + let dfs = Arc::new(Mutex::new(vec![Ipld::Link( + crate::utils::cid::cid_10_to_11(&root_cid), + )])); let mut to_be_fetched = vec![]; // Loop until: No more items in `dfs` AND no running worker tasks. @@ -1496,7 +1505,7 @@ impl RpcMethod<2> for StateReadState { balance: actor.balance.clone().into(), code: actor.code, state: crate::rpc::types::ApiState { - builtin_actors: Ipld::Link(state), + builtin_actors: Ipld::Link(crate::utils::cid::cid_10_to_11(&state)), }, }) } diff --git a/src/rpc/types/mod.rs b/src/rpc/types/mod.rs index cee44b243335..09f030e3510d 100644 --- a/src/rpc/types/mod.rs +++ b/src/rpc/types/mod.rs @@ -35,7 +35,7 @@ use fil_actors_shared::fvm_ipld_bitfield::BitField; use fvm_ipld_encoding::RawBytes; use fvm_shared4::piece::PaddedPieceSize; use fvm_shared4::ActorID; -use libipld_core::ipld::Ipld; +use ipld_core::ipld::Ipld; use num_bigint::BigInt; use nunny::Vec as NonEmpty; use schemars::JsonSchema; diff --git a/src/statediff/mod.rs b/src/statediff/mod.rs index 80a95ffe3ca2..548c89ba7296 100644 --- a/src/statediff/mod.rs +++ b/src/statediff/mod.rs @@ -27,7 +27,7 @@ use fil_actor_interface::{ reward::State as RewardState, system::State as SystemState, }; use fvm_ipld_blockstore::Blockstore; -use libipld_core::ipld::Ipld; +use ipld_core::ipld::Ipld; use resolve::resolve_cids_recursive; use serde::{Deserialize, Serialize}; use similar::{ChangeTag, TextDiff}; @@ -47,8 +47,8 @@ fn actor_to_resolved( actor: &ActorState, depth: Option, ) -> ActorStateResolved { - let resolved = - resolve_cids_recursive(bs, &actor.state, depth).unwrap_or(Ipld::Link(actor.state)); + let resolved = resolve_cids_recursive(bs, &actor.state, depth) + .unwrap_or(Ipld::Link(crate::utils::cid::cid_10_to_11(&actor.state))); ActorStateResolved { state: resolved, code: actor.code, diff --git a/src/statediff/resolve.rs b/src/statediff/resolve.rs index 9acbe71bf230..3ed9ba3b9610 100644 --- a/src/statediff/resolve.rs +++ b/src/statediff/resolve.rs @@ -6,7 +6,7 @@ use cid::Cid; use fvm_ipld_blockstore::Blockstore; use fvm_ipld_encoding::CborStore; use fvm_ipld_encoding::DAG_CBOR; -use libipld_core::ipld::Ipld; +use ipld_core::ipld::Ipld; /// Resolves link to recursively resolved [`Ipld`] with no hash links. pub fn resolve_cids_recursive( @@ -47,7 +47,7 @@ where } Ipld::Link(cid) => { if cid.codec() == DAG_CBOR { - if let Some(mut x) = bs.get_cbor(cid)? { + if let Some(mut x) = bs.get_cbor(&crate::utils::cid::cid_11_to_10(cid))? { resolve_ipld(bs, &mut x, depth)?; *ipld = x; } diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 61eea8fe82e3..06c07080451e 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -39,6 +39,7 @@ use fil_actors_shared::fvm_ipld_bitfield::BitField; use fil_actors_shared::v10::runtime::DomainSeparationTag; use futures::{stream::FuturesUnordered, StreamExt}; use fvm_ipld_blockstore::Blockstore; +use ipld_core::ipld::Ipld; use itertools::Itertools as _; use jsonrpsee::types::ErrorCode; use libp2p::PeerId; @@ -1946,8 +1947,6 @@ fn format_as_markdown(results: &[((&'static str, TestSummary, TestSummary), u32) } fn validate_message_lookup(req: rpc::Request) -> RpcTest { - use libipld_core::ipld::Ipld; - RpcTest::validate(req, |mut forest, mut lotus| { // TODO(hanabi1224): https://github.com/ChainSafe/forest/issues/3784 forest.return_dec = Ipld::Null; diff --git a/src/tool/subcommands/benchmark_cmd.rs b/src/tool/subcommands/benchmark_cmd.rs index 3bdda27a56bd..ceac99ac2bf9 100644 --- a/src/tool/subcommands/benchmark_cmd.rs +++ b/src/tool/subcommands/benchmark_cmd.rs @@ -34,7 +34,7 @@ pub enum BenchmarkCommands { /// Snapshot input files (`.car.`, `.car.zst`, `.forest.car.zst`) #[arg(required = true)] snapshot_files: Vec, - /// Whether or not we want to expect [`libipld_core::ipld::Ipld`] data for each block. + /// Whether or not we want to expect [`ipld_core::ipld::Ipld`] data for each block. #[arg(long)] inspect: bool, }, diff --git a/src/utils/cid/mod.rs b/src/utils/cid/mod.rs index ad7405a91d01..138623068047 100644 --- a/src/utils/cid/mod.rs +++ b/src/utils/cid/mod.rs @@ -25,3 +25,15 @@ pub trait CidCborExt { } impl CidCborExt for Cid {} + +/// A temporary utility for converting [`cid::Cid`] to [`cid_0_11::Cid`] +pub fn cid_10_to_11(cid: &cid::Cid) -> cid_0_11::Cid { + let bytes = cid.to_bytes(); + cid_0_11::Cid::read_bytes(bytes.as_slice()).unwrap() +} + +/// A temporary utility for converting [`cid_0_11::Cid`] to [`cid::Cid`] +pub fn cid_11_to_10(cid: &cid_0_11::Cid) -> cid::Cid { + let bytes = cid.to_bytes(); + cid::Cid::read_bytes(bytes.as_slice()).unwrap() +} diff --git a/src/utils/encoding/cid_de_cbor.rs b/src/utils/encoding/cid_de_cbor.rs index 1abf58d6e470..c96f1549e292 100644 --- a/src/utils/encoding/cid_de_cbor.rs +++ b/src/utils/encoding/cid_de_cbor.rs @@ -19,8 +19,8 @@ pub fn extract_cids(cbor_blob: &[u8]) -> anyhow::Result> { /// vector of [`Cid`]. struct CidVec(Vec); -/// [`FilterCids`] traverses an [`libipld_core::ipld::Ipld`] tree, appending [`Cid`]s (and only CIDs) to a single vector. -/// This is much faster than constructing an [`libipld_core::ipld::Ipld`] tree and then performing the filtering. +/// [`FilterCids`] traverses an [`ipld_core::ipld::Ipld`] tree, appending [`Cid`]s (and only CIDs) to a single vector. +/// This is much faster than constructing an [`ipld_core::ipld::Ipld`] tree and then performing the filtering. struct FilterCids<'a>(&'a mut Vec); impl<'de, 'a> DeserializeSeed<'de> for FilterCids<'a> { @@ -187,7 +187,7 @@ mod test { use cid::Cid; use fvm_ipld_encoding::DAG_CBOR; - use libipld_core::ipld::Ipld; + use ipld_core::ipld::Ipld; use quickcheck::{Arbitrary, Gen}; use quickcheck_macros::quickcheck; @@ -204,14 +204,14 @@ mod test { match ipld { // [`Cid`]s have to be valid in order to be decodable. Ipld::Link(cid) => { - *cid = Cid::new_v1( + *cid = crate::utils::cid::cid_10_to_11(&Cid::new_v1( DAG_CBOR, Blake2b256.digest(&[ u8::arbitrary(g), u8::arbitrary(g), u8::arbitrary(g), ]), - ) + )) } Ipld::Map(map) => map.values_mut().for_each(|val| cleanup_ipld(val, g)), Ipld::List(vec) => vec.iter_mut().for_each(|val| cleanup_ipld(val, g)), @@ -238,7 +238,7 @@ mod test { fn deserialize_various_blobs(ipld: IpldWrapper) { let ipld_to_cid = |ipld| { if let Ipld::Link(cid) = ipld { - return Some(cid); + return Some(crate::utils::cid::cid_11_to_10(&cid)); } None }; diff --git a/src/utils/encoding/mod.rs b/src/utils/encoding/mod.rs index 45f1ffdc02b3..372240697fb6 100644 --- a/src/utils/encoding/mod.rs +++ b/src/utils/encoding/mod.rs @@ -107,8 +107,8 @@ pub fn prover_id_from_u64(id: u64) -> ProverId { #[cfg(test)] mod tests { - use itertools::Itertools; - use libipld::Ipld; + use ipld_core::ipld::Ipld; + use itertools::Itertools as _; use rand::Rng; use serde::{Deserialize, Serialize}; use serde_ipld_dagcbor::to_vec; @@ -147,9 +147,10 @@ mod tests { inner: vec![0; BYTE_ARRAY_MAX_LEN + 1], }; + let err = serde_ipld_dagcbor::to_vec(&bytes).unwrap_err(); assert!( - format!("{}", serde_ipld_dagcbor::to_vec(&bytes).err().unwrap()) - .contains("Array exceed max length") + format!("{}", err).contains("Struct value cannot be serialized."), + "{err}" ); }