diff --git a/blockchain/blocks/Cargo.toml b/blockchain/blocks/Cargo.toml index c9c8b5374b96..8bba5f661d2e 100644 --- a/blockchain/blocks/Cargo.toml +++ b/blockchain/blocks/Cargo.toml @@ -9,6 +9,7 @@ address = {path = "../../vm/address"} crypto = {path = "../../crypto"} message = {path = "../../vm/message"} clock = {path = "../../node/clock"} -cid = "0.3.1" +cid = {path = "../../ipld/cid"} multihash = "0.8.0" derive_builder = "0.9" +serde_cbor = "0.11.0" diff --git a/blockchain/blocks/src/block.rs b/blockchain/blocks/src/block.rs index 056b5e5a4d2a..a7abd99b9c28 100644 --- a/blockchain/blocks/src/block.rs +++ b/blockchain/blocks/src/block.rs @@ -22,10 +22,6 @@ struct PoStCandidate {} struct PoStRandomness {} struct PoStProof {} -fn template_cid() -> Cid { - Cid::new(Codec::DagCBOR, Version::V1, &[]) -} - /// Header of a block /// /// Usage: @@ -42,8 +38,8 @@ fn template_cid() -> Cid { /// .weight(0) //optional /// .epoch(ChainEpoch::default()) //optional /// .messages(TxMeta::default()) //optional -/// .message_receipts(Cid::new(Codec::DagCBOR, Version::V1, &[])) //optional -/// .state_root(Cid::new(Codec::DagCBOR, Version::V1, &[])) //optional +/// .message_receipts(Cid::default()) //optional +/// .state_root(Cid::default()) //optional /// .timestamp(0) //optional /// .ticket(Ticket::default()) //optional /// .build() @@ -76,11 +72,11 @@ pub struct BlockHeader { pub messages: TxMeta, /// message_receipts is the Cid of the root of an array of MessageReceipts - #[builder(default = "template_cid()")] + #[builder(default)] pub message_receipts: Cid, /// state_root is a cid pointer to the state tree after application of the transactions state transitions - #[builder(default = "template_cid()")] + #[builder(default)] pub state_root: Cid, // CONSENSUS @@ -98,7 +94,7 @@ pub struct BlockHeader { // CACHE /// stores the cid for the block after the first call to `cid()` - #[builder(default = "template_cid()")] + #[builder(default)] pub cached_cid: Cid, /// stores the hashed bytes of the block after the fist call to `cid()` #[builder(default)] @@ -119,22 +115,12 @@ pub struct Block { secp_messages: SignedMessage, } -/// Tracks the merkleroots of both secp and bls messages separately -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Default)] pub struct TxMeta { pub bls_messages: Cid, pub secp_messages: Cid, } -impl Default for TxMeta { - fn default() -> Self { - Self { - bls_messages: template_cid(), - secp_messages: template_cid(), - } - } -} - /// ElectionPoStVerifyInfo seems to be connected to VRF /// see https://github.com/filecoin-project/lotus/blob/master/chain/sync.go#L1099 struct ElectionPoStVerifyInfo { diff --git a/blockchain/blocks/src/tipset.rs b/blockchain/blocks/src/tipset.rs index 377c3b848dc1..7897edfb8a67 100644 --- a/blockchain/blocks/src/tipset.rs +++ b/blockchain/blocks/src/tipset.rs @@ -106,7 +106,7 @@ impl Tipset { // break ticket ties with the header CIDs, which are distinct sorted_headers.sort_by_key(|header| { let mut h = header.clone(); - (h.ticket.vrfproof.clone(), h.cid().hash) + (h.ticket.vrfproof.clone(), h.cid().hash.clone()) }); // TODO @@ -175,7 +175,7 @@ mod tests { use super::*; use crate::block::TxMeta; use address::Address; - use cid::{Cid, Codec, Version}; + use cid::{Cid, Codec}; use clock::ChainEpoch; use crypto::VRFResult; @@ -184,7 +184,7 @@ mod tests { fn template_key(data: &[u8]) -> Cid { let h = multihash::encode(multihash::Hash::SHA2256, data).unwrap(); - let cid = Cid::new(Codec::DagProtobuf, Version::V1, &h); + let cid = Cid::from_bytes_v1(Codec::DagCBOR, h); return cid; } diff --git a/blockchain/chain/Cargo.toml b/blockchain/chain/Cargo.toml index 09fd6c7ecb86..81a5f2e806c6 100644 --- a/blockchain/chain/Cargo.toml +++ b/blockchain/chain/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] blocks = {path = "../blocks"} network = {path = "../../node/network"} -cid = "0.3.1" +cid = {path = "../../ipld/cid"} clock = {path = "../../node/clock"} num-bigint = "0.2.3" diff --git a/blockchain/chain/src/store/tip_index.rs b/blockchain/chain/src/store/tip_index.rs index 1fa04b242a79..9577dd9d4eb2 100644 --- a/blockchain/chain/src/store/tip_index.rs +++ b/blockchain/chain/src/store/tip_index.rs @@ -102,7 +102,7 @@ mod tests { use super::*; use address::Address; use blocks::{BlockHeader, Ticket, Tipset, TxMeta}; - use cid::{Cid, Codec, Version}; + use cid::{Cid, Codec}; use clock::ChainEpoch; use crypto::VRFResult; @@ -111,7 +111,7 @@ mod tests { fn template_key(data: &[u8]) -> Cid { let h = multihash::encode(multihash::Hash::SHA2256, data).unwrap(); - Cid::new(Codec::DagProtobuf, Version::V1, &h) + Cid::from_bytes_v1(Codec::DagCBOR, &h) } // key_setup returns a vec of distinct CIDs diff --git a/blockchain/sync_manager/Cargo.toml b/blockchain/sync_manager/Cargo.toml index e3e8d71344da..9cfefd2640f4 100644 --- a/blockchain/sync_manager/Cargo.toml +++ b/blockchain/sync_manager/Cargo.toml @@ -9,4 +9,4 @@ address = {path = "../../vm/address"} blocks = {path = "../blocks"} [dev-dependencies] -cid = "0.3.1" +cid = {path = "../../ipld/cid"} diff --git a/blockchain/sync_manager/src/bucket.rs b/blockchain/sync_manager/src/bucket.rs index 7746eeb67cf2..d6b296ef7f2f 100644 --- a/blockchain/sync_manager/src/bucket.rs +++ b/blockchain/sync_manager/src/bucket.rs @@ -74,11 +74,11 @@ mod tests { use super::*; use address::Address; use blocks::{BlockHeader, TipSetKeys}; - use cid::{Cid, Codec, Version}; + use cid::{Cid, Codec}; fn create_header(weight: u64, parent_bz: &[u8], cached_bytes: &[u8]) -> BlockHeader { let x = TipSetKeys { - cids: vec![Cid::new(Codec::DagCBOR, Version::V1, parent_bz)], + cids: vec![Cid::from_bytes_v1(Codec::DagCBOR, parent_bz)], }; BlockHeader::builder() .parents(x) diff --git a/blockchain/sync_manager/tests/manager_test.rs b/blockchain/sync_manager/tests/manager_test.rs index 16102efd6644..b06272d436aa 100644 --- a/blockchain/sync_manager/tests/manager_test.rs +++ b/blockchain/sync_manager/tests/manager_test.rs @@ -3,12 +3,12 @@ use address::Address; use blocks::{BlockHeader, TipSetKeys, Tipset}; -use cid::{Cid, Codec, Version}; +use cid::{Cid, Codec}; use sync_manager::SyncManager; fn create_header(weight: u64, parent_bz: &[u8], cached_bytes: &[u8]) -> BlockHeader { let x = TipSetKeys { - cids: vec![Cid::new(Codec::DagCBOR, Version::V1, parent_bz)], + cids: vec![Cid::from_bytes_v1(Codec::DagCBOR, parent_bz)], }; BlockHeader::builder() .parents(x) diff --git a/encoding/Cargo.toml b/encoding/Cargo.toml index 8fd50e72ee7e..5ef9e483e93f 100644 --- a/encoding/Cargo.toml +++ b/encoding/Cargo.toml @@ -8,4 +8,4 @@ edition = "2018" [dependencies] blake2b_simd = "0.5.9" -serde_cbor = "0.10.2" +serde_cbor = "0.11.0" diff --git a/ipld/cid/src/to_cid.rs b/ipld/cid/src/to_cid.rs index c1391c4eb96e..4bc7458ac708 100644 --- a/ipld/cid/src/to_cid.rs +++ b/ipld/cid/src/to_cid.rs @@ -84,7 +84,7 @@ impl ToCid for [u8] { // Verify that hash can be decoded, this is very cheap multihash::decode(self)?; - Ok(BaseCid::new(Codec::DagProtobuf, Version::V0, self).into()) + Ok(BaseCid::new(Codec::DagCBOR, Version::V0, self).into()) } else { let mut cur = Cursor::new(self); let raw_version = cur.read_varint()?; diff --git a/vm/address/Cargo.toml b/vm/address/Cargo.toml index 051bd0ebf64c..e178fdc93445 100644 --- a/vm/address/Cargo.toml +++ b/vm/address/Cargo.toml @@ -11,4 +11,4 @@ data-encoding = "2.1.2" data-encoding-macro = "0.1.7" leb128 = "0.2.1" encoding = {path = "../../encoding"} -serde_cbor = "0.10.2" +serde_cbor = "0.11.0"