Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Cid references, bump serde_cbor version #155

Merged
merged 7 commits into from
Jan 14, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion blockchain/blocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
26 changes: 6 additions & 20 deletions blockchain/blocks/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)]
Expand All @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions blockchain/blocks/src/tipset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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::DagProtobuf, h);
austinabell marked this conversation as resolved.
Show resolved Hide resolved
return cid;
}

Expand Down
2 changes: 1 addition & 1 deletion blockchain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
4 changes: 2 additions & 2 deletions blockchain/chain/src/store/tip_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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::DagProtobuf, &h)
}

// key_setup returns a vec of distinct CIDs
Expand Down
2 changes: 1 addition & 1 deletion blockchain/sync_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ address = {path = "../../vm/address"}
blocks = {path = "../blocks"}

[dev-dependencies]
cid = "0.3.1"
cid = {path = "../../ipld/cid"}
4 changes: 2 additions & 2 deletions blockchain/sync_manager/src/bucket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions blockchain/sync_manager/tests/manager_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion encoding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition = "2018"

[dependencies]
blake2b_simd = "0.5.9"
serde_cbor = "0.10.2"
serde_cbor = "0.11.0"
2 changes: 1 addition & 1 deletion vm/address/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"