Skip to content

Commit

Permalink
chore: update ipld crates (#2069)
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 21, 2024
1 parent 54a4da7 commit 9748513
Show file tree
Hide file tree
Showing 19 changed files with 153 additions and 153 deletions.
210 changes: 102 additions & 108 deletions Cargo.lock

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@ 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 }
fvm_ipld_hamt = { version = "0.9.0"}
fvm_ipld_amt = { version = "0.6.0"}
fvm_ipld_car = { version = "0.7.0" }
fvm_ipld_blockstore = { version = "0.2.0" }
fvm_ipld_encoding = { version = "0.4.0" }
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 }
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" }
wasmtime = { version = "25.0.2", default-features = false, features = ["cranelift", "pooling-allocator", "parallel-compilation", "runtime"] }
wasmtime-environ = "25.0.2"

fvm = { path = "fvm", version = "~2.9.1", default-features = false }
fvm_shared = { path = "shared", version = "~2.9.1", default-features = false }
Expand Down
3 changes: 2 additions & 1 deletion fvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ num-traits = "0.2"
derive_builder = "0.20.1"
num-derive = "0.4.0"
cid = { workspace = true, features = ["serde-codec"] }
multihash = { workspace = true }
multihash-codetable = { workspace = true, features = ["sha2", "sha3", "ripemd"] }
multihash-derive = { workspace = true }
fvm_shared = { workspace = true, features = ["crypto"] }
fvm_ipld_hamt = { workspace = true }
fvm_ipld_amt = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion fvm/src/blockstore/buffered.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,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
15 changes: 5 additions & 10 deletions fvm/src/kernel/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use fvm_shared::sector::SectorInfo;
use fvm_shared::version::NetworkVersion;
use fvm_shared::{commcid, ActorID};
use lazy_static::lazy_static;
use multihash::MultihashDigest;
use multihash_codetable::{Code, Multihash, MultihashDigest};
use rayon::iter::{IndexedParallelIterator, IntoParallelRefIterator, ParallelIterator};
use std::io::Write;

Expand Down Expand Up @@ -293,7 +293,7 @@ where
}

let block = self.blocks.get(id)?;
let code = multihash::Code::try_from(hash_fun)
let code = Code::try_from(hash_fun)
.map_err(|_| syscall_error!(IllegalCid; "invalid CID codec"))?;

self.call_manager.charge_gas(
Expand Down Expand Up @@ -479,17 +479,12 @@ where
})
}

fn hash(&mut self, code: u64, data: &[u8]) -> Result<MultihashGeneric<64>> {
fn hash(&mut self, code: u64, data: &[u8]) -> Result<Multihash> {
self.call_manager
.charge_gas(self.call_manager.price_list().on_hashing(data.len()))?;

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)
}
})?;
let hasher = SupportedHashes::try_from(code)
.map_err(|err| syscall_error!(IllegalArgument; "unsupported hash code {}", err.0))?;
Ok(hasher.digest(data))
}

Expand Down
7 changes: 4 additions & 3 deletions fvm/src/kernel/hash.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
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)]
#[derive(Clone, Copy, Debug, Eq, MultihashDigest, PartialEq)]
#[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 @@ -16,6 +16,7 @@ use fvm_shared::sector::{
};
use fvm_shared::version::NetworkVersion;
use fvm_shared::{ActorID, MethodNum};
use multihash_codetable::Multihash;

mod hash;

Expand All @@ -25,7 +26,6 @@ pub mod default;
mod error;

pub use error::{ClassifyResult, Context, ExecutionError, Result, SyscallError};
use multihash::MultihashGeneric;

use crate::call_manager::CallManager;
use crate::gas::{Gas, PriceList};
Expand Down Expand Up @@ -253,7 +253,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(&mut self, code: u64, data: &[u8]) -> Result<MultihashGeneric<64>>;
fn hash(&mut self, code: u64, data: &[u8]) -> Result<Multihash>;

/// 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 @@ -40,9 +40,9 @@ pub mod system_actor;

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 @@ -57,7 +57,7 @@ mod test {
use fvm_ipld_blockstore::MemoryBlockstore;
use fvm_ipld_encoding::CborStore;
use fvm_shared::state::StateTreeVersion;
use multihash::Code;
use multihash_codetable::Code;

use crate::call_manager::DefaultCallManager;
use crate::externs::{Consensus, Externs, Rand};
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 @@ -35,8 +35,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
14 changes: 8 additions & 6 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 std::collections::HashMap;

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 @@ -208,7 +208,10 @@ where
}
StateTreeVersion::V3 | StateTreeVersion::V4 => {
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 @@ -424,7 +427,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_ADDR, actor)?;
Expand Down Expand Up @@ -484,7 +487,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 @@ -629,8 +632,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;
use fvm_ipld_encoding::{CborStore, DAG_CBOR};
Expand All @@ -640,6 +641,7 @@ mod tests {
use fvm_shared::state::StateTreeVersion;
use fvm_shared::{IDENTITY_HASH, IPLD_RAW};
use lazy_static::lazy_static;
use multihash_codetable::{Code::Blake2b256, Multihash};

use crate::init_actor;
use crate::init_actor::INIT_ACTOR_ADDR;
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 @@ -5,7 +5,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 @@ -7,7 +7,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 @@ -15,7 +15,7 @@ use fvm_ipld_encoding::CborStore;
use fvm_shared::address::Address;
use fvm_shared::state::StateTreeVersion;
use fvm_shared::version::NetworkVersion;
use multihash::Code;
use multihash_codetable::Code;

pub const STUB_NETWORK_VER: NetworkVersion = NetworkVersion::V15;

Expand Down
5 changes: 3 additions & 2 deletions shared/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ data-encoding-macro = "0.1.12"
lazy_static = "1.4.0"
log = "0.4.8"
cid = { workspace = true, features = ["serde-codec", "std"] }
multihash = { workspace = true, features = ["multihash-impl", "sha2", "sha3", "ripemd"] }
multihash = { workspace = true }
unsigned-varint = "0.8.0"
anyhow = "1.0.51"
fvm_ipld_blockstore = { workspace = true }
Expand All @@ -42,7 +42,8 @@ byteorder = "1.4.3"
rand = "0.8"
rand_chacha = "0.3"
serde_json = "1.0.56"
multihash = { workspace = true, features = ["multihash-impl", "sha2", "sha3", "ripemd"] }
multihash = { workspace = true }
multihash-codetable = { workspace = true, features = ["sha2", "sha3", "ripemd"] }

[features]
default = []
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 @@ -7,3 +7,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
@@ -1,9 +1,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
3 changes: 1 addition & 2 deletions testing/conformance/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ derive_builder = "0.20.1"
ahash = "0.8"
num-derive = "0.4.0"
cid = { workspace = true }
multihash = { workspace = true }
serde = { version = "1.0", features = ["derive"] }
serde_tuple = "0.5"
serde_repr = "0.1"
Expand All @@ -47,7 +46,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 = { version = "0.4.1", features = ["serde"] }
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 @@ -13,8 +13,8 @@ use fvm_shared::address::Protocol;
use fvm_shared::crypto::signature::SECP_SIG_LEN;
use fvm_shared::message::Message;
use fvm_shared::receipt::Receipt;
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
@@ -1,5 +1,6 @@
use std::convert::TryFrom;

use cid::multihash::Multihash;
use cid::Cid;
use fvm::call_manager::{CallManager, DefaultCallManager, FinishRet, InvocationResult};
use fvm::gas::{Gas, GasTracker, PriceList};
Expand All @@ -26,7 +27,6 @@ use fvm_shared::sector::{
};
use fvm_shared::version::NetworkVersion;
use fvm_shared::{ActorID, MethodNum, TOTAL_FILECOIN};
use multihash::MultihashGeneric;

use crate::externs::TestExterns;
use crate::vector::{MessageVector, Variant};
Expand Down Expand Up @@ -389,7 +389,7 @@ where
K: Kernel<CallManager = TestCallManager<C>>,
{
// forwarded
fn hash(&mut self, code: u64, data: &[u8]) -> Result<MultihashGeneric<64>> {
fn hash(&mut self, code: u64, data: &[u8]) -> Result<Multihash<64>> {
self.0.hash(code, data)
}

Expand Down

0 comments on commit 9748513

Please sign in to comment.