Skip to content

Commit

Permalink
chore: update ipld crates
Browse files Browse the repository at this point in the history
- cid
- multihash
- ipld-core

This is a major breaking change and requires a bit of a refactor.
  • Loading branch information
Stebalien committed Nov 22, 2024
1 parent fb13774 commit ac564c1
Show file tree
Hide file tree
Showing 22 changed files with 169 additions and 161 deletions.
214 changes: 104 additions & 110 deletions Cargo.lock

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ repository = "https://github.com/filecoin-project/ref-fvm"
authors = ["Protocol Labs", "Filecoin Core Devs"]

[workspace.dependencies]
cid = { version = "0.10.1", default-features = false }
multihash = { version = "0.18.1", default-features = false }
cid = { version = "0.11.1", default-features = false }
multihash = { version = "0.19.2", default-features = false }
multihash-codetable = { version = "0.1.4", default-features = false }
multihash-derive = { version = "0.9.1", default-features = false }
ipld-core = { version = "0.4.1", features = ["serde"] }
wasmtime = { version = "25.0.2", default-features = false, features = ["cranelift", "pooling-allocator", "parallel-compilation", "runtime"] }
wasmtime-environ = "25.0.2"

Expand All @@ -25,6 +28,12 @@ fvm_shared = { path = "shared", version = "~3.11.1", default-features = false }
fvm_sdk = { path = "sdk", version = "~3.11.1" }
fvm_integration_tests = { path = "testing/integration", version = "~3.11.1" }

fvm_ipld_hamt = { version = "0.10.2"}
fvm_ipld_amt = { version = "0.7.3"}
fvm_ipld_car = { version = "0.8.1" }
fvm_ipld_blockstore = { version = "0.3.1" }
fvm_ipld_encoding = { version = "0.5.1" }

[profile.actor]
inherits = "release"
panic = "abort"
Expand Down
13 changes: 7 additions & 6 deletions fvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ crate-type = ["lib"]
anyhow = { version = "1.0.71", features = ["backtrace"] }
thiserror = "1.0.40"
num-traits = "0.2"
cid = { workspace = true, features = ["serde-codec"] }
multihash = { workspace = true, features = ["sha2", "sha3", "ripemd"] }
cid = { workspace = true, features = ["serde"] }
multihash-codetable = { workspace = true, features = ["sha2", "sha3", "ripemd"] }
multihash-derive = { workspace = true }
fvm_shared = { workspace = true, features = ["crypto"] }
fvm_ipld_hamt = { version = "0.9.0" }
fvm_ipld_amt = { version = "0.6.1" }
fvm_ipld_blockstore = { version = "0.2.0" }
fvm_ipld_encoding = { version = "0.4.0" }
fvm_ipld_hamt = { workspace = true }
fvm_ipld_amt = { workspace = true }
fvm_ipld_blockstore = { workspace = true }
fvm_ipld_encoding = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
serde_tuple = "0.5"
lazy_static = "1.4.0"
Expand Down
4 changes: 2 additions & 2 deletions fvm/src/blockstore/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ where

#[cfg(test)]
mod tests {
use cid::multihash::{Code, Multihash};
use fvm_ipld_blockstore::{Blockstore, MemoryBlockstore};
use fvm_ipld_encoding::CborStore;
use fvm_shared::{commcid, IDENTITY_HASH};
use multihash_codetable::{Code, Multihash};
use serde::{Deserialize, Serialize};

use super::*;
Expand Down Expand Up @@ -324,7 +324,7 @@ mod tests {
mem.get_cbor::<(Cid, u8)>(&root_cid).unwrap(),
Some((obj_cid, 1)),
);
assert_eq!(buf_store.get_cbor::<u8>(&identity_cid).unwrap(), None);
assert_eq!(buf_store.get(&identity_cid).unwrap(), None);
assert_eq!(buf_store.get(&unsealed_comm_cid).unwrap(), None);
assert_eq!(buf_store.get(&sealed_comm_cid).unwrap(), None);
assert_eq!(mem.get_cbor::<u8>(&unconnected).unwrap(), None);
Expand Down
2 changes: 1 addition & 1 deletion fvm/src/init_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ impl State {
#[allow(unused)]
pub fn new_test<B: Blockstore>(store: &B) -> Self {
#[cfg(feature = "m2-native")]
use cid::multihash::Code::Blake2b256;
use multihash_codetable::Code::Blake2b256;

// Empty hamt Cid used for testing
let e_cid = Hamt::<_, String>::new_with_bit_width(&store, 5)
Expand Down
14 changes: 5 additions & 9 deletions fvm/src/kernel/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::path::PathBuf;
use anyhow::{anyhow, Context as _};
use blake2b_simd::Params;
use byteorder::WriteBytesExt;
use cid::multihash::Multihash;
use cid::Cid;
use filecoin_proofs_api::{self as proofs, ProverId, PublicReplicaInfo, SectorId};
use fvm_ipld_blockstore::Blockstore;
Expand All @@ -26,7 +27,7 @@ use fvm_shared::sector::{RegisteredPoStProof, SectorInfo};
use fvm_shared::sys::out::vm::ContextFlags;
use fvm_shared::{commcid, ActorID};
use lazy_static::lazy_static;
use multihash::MultihashDigest;
use multihash_codetable::MultihashDigest;
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
use rayon::prelude::ParallelDrainRange;
use std::io::Write;
Expand Down Expand Up @@ -486,14 +487,9 @@ where
)
}

fn hash(&self, code: u64, data: &[u8]) -> Result<MultihashGeneric<64>> {
let hasher = SupportedHashes::try_from(code).map_err(|e| {
if let multihash::Error::UnsupportedCode(code) = e {
syscall_error!(IllegalArgument; "unsupported hash code {}", code)
} else {
syscall_error!(AssertionFailed; "hash expected unsupported code, got {}", e)
}
})?;
fn hash(&self, code: u64, data: &[u8]) -> Result<Multihash<64>> {
let hasher = SupportedHashes::try_from(code)
.map_err(|err| syscall_error!(IllegalArgument; "unsupported hash code {}", err.0))?;

let t = self.call_manager.charge_gas(
self.call_manager
Expand Down
7 changes: 4 additions & 3 deletions fvm/src/kernel/hash.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Copyright 2021-2023 Protocol Labs
// SPDX-License-Identifier: Apache-2.0, MIT
use multihash::derive::Multihash;
use multihash::{Blake2b256, Blake2b512, Keccak256, Ripemd160, Sha2_256};
use multihash_codetable::{
Blake2b256, Blake2b512, Keccak256, MultihashDigest, Ripemd160, Sha2_256,
};

#[derive(Clone, Copy, Debug, Eq, Multihash, PartialEq, Hash)]
#[derive(Clone, Copy, Debug, Eq, MultihashDigest, PartialEq, Hash)]
#[mh(alloc_size = 64)]
/// Codes and hashers supported by FVM.
/// You _can_ use this hash directly inside of your actor,
Expand Down
4 changes: 2 additions & 2 deletions fvm/src/kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ pub mod default;

pub(crate) mod error;

use cid::multihash::Multihash;
pub use error::{ClassifyResult, Context, ExecutionError, Result, SyscallError};
use fvm_shared::event::StampedEvent;
pub use hash::SupportedHashes;
use multihash::MultihashGeneric;

use crate::call_manager::CallManager;
use crate::gas::{Gas, GasTimer, PriceList};
Expand Down Expand Up @@ -276,7 +276,7 @@ pub trait CryptoOps {
/// `digest_out`, returning the size of the digest written to `digest_out`. If `digest_out` is
/// to small to fit the entire digest, it will be truncated. If too large, the leftover space
/// will not be overwritten.
fn hash(&self, code: u64, data: &[u8]) -> Result<MultihashGeneric<64>>;
fn hash(&self, code: u64, data: &[u8]) -> Result<Multihash<64>>;

/// Computes an unsealed sector CID (CommD) from its constituent piece CIDs (CommPs) and sizes.
fn compute_unsealed_sector_cid(
Expand Down
4 changes: 2 additions & 2 deletions fvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ mod eam_actor;
mod history_map;
pub mod trace;

use cid::multihash::{Code, MultihashDigest};
use cid::Cid;
use fvm_ipld_encoding::{to_vec, DAG_CBOR};
use multihash_codetable::{Code, MultihashDigest};

lazy_static::lazy_static! {
/// Cid of the empty array Cbor bytes (`EMPTY_ARR_BYTES`).
Expand All @@ -61,7 +61,7 @@ mod test {
use fvm_ipld_encoding::{CborStore, DAG_CBOR};
use fvm_shared::state::StateTreeVersion;
use fvm_shared::IDENTITY_HASH;
use multihash::{Code, Multihash};
use multihash_codetable::{Code, Multihash};

use crate::call_manager::DefaultCallManager;
use crate::engine::EnginePool;
Expand Down
2 changes: 1 addition & 1 deletion fvm/src/machine/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use fvm_ipld_blockstore::{Block, Blockstore, Buffered};
use fvm_ipld_encoding::{to_vec, CborStore, DAG_CBOR};
use fvm_shared::version::NetworkVersion;
use log::debug;
use multihash::Code::Blake2b256;
use multihash_codetable::Code::Blake2b256;

use super::{Machine, MachineContext};
use crate::blockstore::BufferedBlockstore;
Expand Down
2 changes: 1 addition & 1 deletion fvm/src/machine/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ pub struct Manifest {
const fn id_cid(name: &[u8]) -> Cid {
use std::mem;

use cid::multihash::Multihash;
use fvm_shared::{IDENTITY_HASH, IPLD_RAW};
use multihash::Multihash;

// This code is ugly because const fns are a bit ugly right now:
//
Expand Down
13 changes: 8 additions & 5 deletions fvm/src/state_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use std::cell::RefCell;

use anyhow::{anyhow, Context as _};
use cid::{multihash, Cid};
use cid::Cid;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::tuple::*;
use fvm_ipld_encoding::CborStore;
Expand Down Expand Up @@ -75,7 +75,10 @@ where
}
StateTreeVersion::V5 => {
let cid = store
.put_cbor(&StateInfo0::default(), multihash::Code::Blake2b256)
.put_cbor(
&StateInfo0::default(),
multihash_codetable::Code::Blake2b256,
)
.context("failed to put state info")
.or_fatal()?;
Some(cid)
Expand Down Expand Up @@ -268,7 +271,7 @@ where
// Set state for init actor in store and update root Cid
actor.state = self
.store()
.put_cbor(&state, multihash::Code::Blake2b256)
.put_cbor(&state, multihash_codetable::Code::Blake2b256)
.or_fatal()?;

self.set_actor(crate::init_actor::INIT_ACTOR_ID, actor);
Expand Down Expand Up @@ -353,7 +356,7 @@ where
};
let root = self
.store()
.put_cbor(obj, multihash::Code::Blake2b256)
.put_cbor(obj, multihash_codetable::Code::Blake2b256)
.or_fatal()?;
Ok(root)
}
Expand Down Expand Up @@ -534,7 +537,6 @@ pub mod json {

#[cfg(test)]
mod tests {
use cid::multihash::Code::Blake2b256;
use cid::multihash::Multihash;
use cid::Cid;
use fvm_ipld_blockstore::MemoryBlockstore;
Expand All @@ -544,6 +546,7 @@ mod tests {
use fvm_shared::state::StateTreeVersion;
use fvm_shared::{ActorID, IDENTITY_HASH, IPLD_RAW};
use lazy_static::lazy_static;
use multihash_codetable::Code::Blake2b256;

use crate::init_actor;
use crate::init_actor::INIT_ACTOR_ID;
Expand Down
2 changes: 1 addition & 1 deletion fvm/tests/default_kernel/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::rc::Rc;
use fvm::kernel::default::DefaultKernel;
use fvm::kernel::{Block, BlockRegistry};
use fvm::Kernel;
use multihash::Code;
use multihash_codetable::Code;
use num_traits::Zero;

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion fvm/tests/default_kernel/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ mod ipld {
use fvm::machine::Machine;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::DAG_CBOR;
use multihash::MultihashDigest;
use multihash_codetable::MultihashDigest;
use pretty_assertions::{assert_eq, assert_ne};

use super::*;
Expand Down
2 changes: 1 addition & 1 deletion fvm/tests/dummy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use fvm_shared::event::StampedEvent;
use fvm_shared::state::StateTreeVersion;
use fvm_shared::version::NetworkVersion;
use fvm_shared::{ActorID, IDENTITY_HASH};
use multihash::{Code, Multihash};
use multihash_codetable::{Code, Multihash};

pub const STUB_NETWORK_VER: NetworkVersion = NetworkVersion::V18;

Expand Down
2 changes: 1 addition & 1 deletion sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ crate-type = ["lib"]
[dependencies]
cid = { workspace = true }
fvm_shared = { workspace = true }
fvm_ipld_encoding = { workspace = true }
## num-traits; disabling default features makes it play nice with no_std.
num-traits = { version = "0.2.15", default-features = false }
lazy_static = { version = "1.4.0" }
log = "0.4.19"
thiserror = "1.0.40"
fvm_ipld_encoding = { version = "0.4" }

[features]
default = []
Expand Down
7 changes: 3 additions & 4 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ num-integer = "0.1"
data-encoding = "2.4.0"
data-encoding-macro = "0.1.13"
lazy_static = "1.4.0"
cid = { workspace = true, features = ["serde-codec", "std"] }
cid = { workspace = true, features = ["serde", "std"] }
multihash = { workspace = true }
unsigned-varint = "0.8.0"
anyhow = "1.0.71"
fvm_ipld_encoding = { version = "0.4" }
fvm_ipld_encoding = { workspace = true }
serde = { version = "1", default-features = false }
serde_tuple = "0.5"
arbitrary = { version = "1.3", optional = true, features = ["derive"] }
Expand All @@ -39,9 +39,8 @@ bls-signatures = { version = "0.15", default-features = false, optional = true }
rand = "0.8"
rand_chacha = "0.3"
serde_json = "1.0.99"
multihash = { workspace = true, features = ["multihash-impl", "sha2", "sha3", "ripemd"] }
multihash-codetable = { workspace = true, features = ["sha2", "sha3", "ripemd"] }
quickcheck_macros = "1"

fvm_shared = { path = ".", features = ["arb"] }

[features]
Expand Down
6 changes: 6 additions & 0 deletions shared/src/crypto/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ pub enum SupportedHashes {
Keccak256 = 0x1b,
Ripemd160 = 0x1053,
}

impl From<SupportedHashes> for u64 {
fn from(value: SupportedHashes) -> Self {
value as Self
}
}
2 changes: 1 addition & 1 deletion shared/tests/commcid_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
// Copyright 2019-2022 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0, MIT

use cid::multihash::{Code, Multihash, MultihashDigest};
use cid::Cid;
use fvm_shared::commcid::*;
use multihash_codetable::{Code, Multihash, MultihashDigest};
use rand::{thread_rng, Rng};

fn rand_comm() -> Commitment {
Expand Down
9 changes: 4 additions & 5 deletions testing/conformance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ repository = "https://github.com/filecoin-project/ref-fvm"
[dependencies]
fvm = { workspace = true, features = ["testing"] }
fvm_shared = { workspace = true }
fvm_ipld_car = { version = "0.7.1" }
fvm_ipld_blockstore = { version = "0.2.0" }
fvm_ipld_encoding = { version = "0.4.0" }
fvm_ipld_car = { workspace = true }
fvm_ipld_blockstore = { workspace = true }
fvm_ipld_encoding = { workspace = true }

anyhow = "1.0.71"
num-traits = "0.2"
cid = { workspace = true }
multihash = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
lazy_static = "1.4.0"
log = "0.4.19"
Expand All @@ -35,7 +34,7 @@ serde_json = { version = "1.0", features = ["raw_value"] }
walkdir = "2.3"
regex = { version = "1.8" }
ittapi-rs = { version = "0.3.0", optional = true }
libipld-core = { version = "0.16.0", features = ["serde-codec"] }
ipld-core = { workspace = true }
tar = { version = "0.4.38", default-features = false }
zstd = { version = "0.13.2", default-features = false }

Expand Down
2 changes: 1 addition & 1 deletion testing/conformance/src/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ use fvm_shared::crypto::signature::SECP_SIG_LEN;
use fvm_shared::message::Message;
use fvm_shared::receipt::Receipt;
use fvm_shared::version::NetworkVersion;
use ipld_core::ipld::Ipld;
use lazy_static::lazy_static;
use libipld_core::ipld::Ipld;
use regex::Regex;
use walkdir::DirEntry;

Expand Down
4 changes: 2 additions & 2 deletions testing/conformance/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// SPDX-License-Identifier: Apache-2.0, MIT
use std::sync::{Arc, Mutex};

use cid::multihash::Multihash;
use cid::Cid;
use multihash::MultihashGeneric;

use fvm::call_manager::{CallManager, DefaultCallManager};
use fvm::gas::{price_list_by_network_version, Gas, GasTimer, PriceList};
Expand Down Expand Up @@ -342,7 +342,7 @@ where
K: Kernel<CallManager = C>,
{
// forwarded
fn hash(&self, code: u64, data: &[u8]) -> Result<MultihashGeneric<64>> {
fn hash(&self, code: u64, data: &[u8]) -> Result<Multihash<64>> {
self.0.hash(code, data)
}

Expand Down

0 comments on commit ac564c1

Please sign in to comment.