Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
fe3319d
Refactor cid, implement cbor deserialize, implement trait on Cid wrapper
austinabell Jan 13, 2020
f3e1811
implement cbor encoding for address
austinabell Jan 13, 2020
929b02c
Refactor and derive serialization traits on all necessary types
austinabell Jan 14, 2020
b786e80
refactor all crates using serde to point to encoding package
austinabell Jan 14, 2020
89cfeac
update author to CS
austinabell Jan 14, 2020
94c5212
lint
austinabell Jan 14, 2020
d43a3dc
Merge branch 'master' of github.com:ChainSafe/ferret into austin/cbor…
austinabell Jan 14, 2020
3a26a50
refactor from using Cid dependency and update multihash
austinabell Jan 14, 2020
50815ea
update merge and resolve
austinabell Jan 14, 2020
0b94436
add basic ipld test
austinabell Jan 14, 2020
c057da8
port existing cid tests
austinabell Jan 14, 2020
5600098
Add default tests
austinabell Jan 14, 2020
d200bfd
Merge branch 'master' into austin/cbor/impl
austinabell Jan 15, 2020
c50d545
consistent toml spacing for affected files
austinabell Jan 15, 2020
d9ba7fa
Merge branch 'austin/cbor/impl' of github.com:ChainSafe/ferret into a…
austinabell Jan 15, 2020
e2f6cf2
switch gas values back to serializable bigints
austinabell Jan 15, 2020
f38074e
lint
austinabell Jan 15, 2020
6daa3dd
change imports to more specific (readability)
austinabell Jan 15, 2020
6e23b66
cbor vector serialization round trip test and implement default cbor …
austinabell Jan 15, 2020
5f60402
update merge and resolve
austinabell Jan 15, 2020
11f003d
addr comments
austinabell Jan 15, 2020
860c081
Add documentation
austinabell Jan 15, 2020
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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ members = [
"node/clock",
"crypto",
"encoding",
"ipld/cid"
"ipld/cid",
"ipld",
]
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ clean:
@cargo clean -p interpreter
@cargo clean -p crypto
@cargo clean -p encoding
@cargo clean -p ferret_cid
@cargo clean -p ferret_ipld
@echo "Done cleaning."

lint: clean license
Expand Down
12 changes: 6 additions & 6 deletions blockchain/blocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2018"

[dependencies]
address = {path = "../../vm/address"}
crypto = {path = "../../crypto"}
message = {path = "../../vm/message"}
clock = {path = "../../node/clock"}
cid = {path = "../../ipld/cid"}
multihash = "0.8.0"
address = { path = "../../vm/address" }
crypto = { path = "../../crypto" }
message = { path = "../../vm/message" }
clock = { path = "../../node/clock" }
cid = { package = "ferret_cid", path = "../../ipld/cid" }
multihash = "0.9.3"
derive_builder = "0.9"
serde_cbor = "0.11.0"
10 changes: 2 additions & 8 deletions blockchain/blocks/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use super::ticket::Ticket;
use super::TipSetKeys;
use address::Address;
use cid::{Cid, Codec, Prefix, Version};
use cid::Cid;
use clock::ChainEpoch;
use crypto::Signature;
use derive_builder::Builder;
Expand Down Expand Up @@ -112,13 +112,7 @@ impl BlockHeader {
// Change DEFAULT_HASH_FUNCTION to utilize blake2b
//
// Currently content id for headers will be incomplete until encoding and supporting libraries are completed
let c = Prefix {
version: Version::V1,
codec: Codec::DagCBOR,
mh_type: DEFAULT_HASH_FUNCTION,
mh_len: 8,
};
let new_cid = Cid::new_from_prefix(&c, &self.cached_bytes);
let new_cid = Cid::from_bytes_default(&self.cached_bytes).unwrap();
self.cached_cid = new_cid;
self.cached_cid.clone()
}
Expand Down
8 changes: 3 additions & 5 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.clone())
(h.ticket.vrfproof.clone(), h.cid().to_bytes())
});

// TODO
Expand Down Expand Up @@ -175,17 +175,15 @@ mod tests {
use super::*;
use crate::block::TxMeta;
use address::Address;
use cid::{Cid, Codec};
use cid::Cid;
use clock::ChainEpoch;
use crypto::VRFResult;

const WEIGHT: u64 = 1;
const CACHED_BYTES: [u8; 1] = [0];

fn template_key(data: &[u8]) -> Cid {
let h = multihash::encode(multihash::Hash::SHA2256, data).unwrap();
let cid = Cid::from_bytes_v1(Codec::DagCBOR, h);
return cid;
Cid::from_bytes_default(data).unwrap()
}

// key_setup returns a vec of 4 distinct CIDs
Expand Down
14 changes: 7 additions & 7 deletions blockchain/chain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2018"

[dependencies]
blocks = {path = "../blocks"}
network = {path = "../../node/network"}
cid = {path = "../../ipld/cid"}
clock = {path = "../../node/clock"}
blocks = { path = "../blocks" }
network = { path = "../../node/network" }
cid = { package = "ferret_cid", path = "../../ipld/cid" }
clock = { path = "../../node/clock" }
num-bigint = "0.2.3"

[dev-dependencies]
address = {path = "../../vm/address"}
crypto = {path = "../../crypto"}
multihash = "0.8.0"
address = { path = "../../vm/address" }
crypto = { path = "../../crypto" }
multihash = "0.9.3"
5 changes: 2 additions & 3 deletions blockchain/chain/src/store/tip_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,15 @@ mod tests {
use super::*;
use address::Address;
use blocks::{BlockHeader, Ticket, Tipset, TxMeta};
use cid::{Cid, Codec};
use cid::Cid;
use clock::ChainEpoch;
use crypto::VRFResult;

const WEIGHT: u64 = 1;
const CACHED_BYTES: [u8; 1] = [0];

fn template_key(data: &[u8]) -> Cid {
let h = multihash::encode(multihash::Hash::SHA2256, data).unwrap();
Cid::from_bytes_v1(Codec::DagCBOR, &h)
Cid::from_bytes_default(data).unwrap()
}

// key_setup returns a vec of distinct CIDs
Expand Down
6 changes: 3 additions & 3 deletions blockchain/sync_manager/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2018"

[dependencies]
address = {path = "../../vm/address"}
blocks = {path = "../blocks"}
address = { path = "../../vm/address" }
blocks = { path = "../blocks" }

[dev-dependencies]
cid = {path = "../../ipld/cid"}
cid = { package = "ferret_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};
use cid::Cid;

fn create_header(weight: u64, parent_bz: &[u8], cached_bytes: &[u8]) -> BlockHeader {
let x = TipSetKeys {
cids: vec![Cid::from_bytes_v1(Codec::DagCBOR, parent_bz)],
cids: vec![Cid::from_bytes_default(parent_bz).unwrap()],
};
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};
use cid::Cid;
use sync_manager::SyncManager;

fn create_header(weight: u64, parent_bz: &[u8], cached_bytes: &[u8]) -> BlockHeader {
let x = TipSetKeys {
cids: vec![Cid::from_bytes_v1(Codec::DagCBOR, parent_bz)],
cids: vec![Cid::from_bytes_default(parent_bz).unwrap()],
};
BlockHeader::builder()
.parents(x)
Expand Down
6 changes: 3 additions & 3 deletions encoding/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ version = "0.1.0"
authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2018"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
blake2b_simd = "0.5.9"
serde_cbor = "0.11.0"
serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.11.3"
serde_cbor = { version = "0.11.0", features = ["tags"] }
10 changes: 5 additions & 5 deletions encoding/src/cbor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
// SPDX-License-Identifier: Apache-2.0

use super::errors::Error;
use crate::{ser, to_vec};

/// Implemented for types that are CBOR encodable
pub trait Cbor {
fn unmarshal_cbor(bz: &[u8]) -> Result<Self, Error>
where
Self: Sized;
fn marshal_cbor(&self) -> Result<Vec<u8>, Error>;
pub trait Cbor: ser::Serialize {
fn marshal_cbor(&self) -> Result<Vec<u8>, Error> {
Ok(to_vec(&self)?)
}
}
4 changes: 4 additions & 0 deletions encoding/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ mod cbor;
mod errors;
mod hash;

pub use serde::{de, ser};
pub use serde_bytes;
pub use serde_cbor::{from_reader, from_slice, tags, to_vec, to_writer};

pub use self::cbor::*;
pub use self::errors::*;
pub use self::hash::*;
13 changes: 13 additions & 0 deletions ipld/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "ferret_ipld"
version = "0.1.0"
authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2018"

[dependencies]
encoding = { path = "../encoding" }
serde = { version = "1.0", features = ["derive"] }

[dev-dependencies]
cid = { package = "ferret_cid", path = "../ipld/cid" }
encoding = { path = "../encoding" }
7 changes: 4 additions & 3 deletions ipld/cid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[package]
name = "cid"
name = "ferret_cid"
version = "0.1.0"
authors = ["ChainSafe Systems <info@chainsafe.io>"]
edition = "2018"

[dependencies]
dep_cid = {package = "cid", version = "0.3.1"}
multihash = "0.8.0"
multihash = "0.9.3"
multibase = "0.6.0"
integer-encoding = "1.0.3"
encoding = { path = "../../encoding" }
serde = { version = "1.0", features = ["derive"] }
56 changes: 56 additions & 0 deletions ipld/cid/src/codec.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0

use crate::Error;

macro_rules! build_codec_enum {
{$( $val:expr => $var:ident, )*} => {
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum Codec {
$( $var, )*
}

use Codec::*;

impl Codec {
/// Convert a number to the matching codec
pub fn from(raw: u64) -> Result<Codec, Error> {
match raw {
$( $val => Ok($var), )*
_ => Err(Error::UnknownCodec),
}
}
}

impl From<Codec> for u64 {
/// Convert to the matching integer code
fn from(codec: Codec) -> u64 {
match codec {
$( $var => $val, )*

}
}
}
}
}

build_codec_enum! {
0x55 => Raw,
0x70 => DagProtobuf,
0x71 => DagCBOR,
0x78 => GitRaw,
0x90 => EthereumBlock,
0x91 => EthereumBlockList,
0x92 => EthereumTxTrie,
0x93 => EthereumTx,
0x94 => EthereumTxReceiptTrie,
0x95 => EthereumTxReceipt,
0x96 => EthereumStateTrie,
0x97 => EthereumAccountSnapshot,
0x98 => EthereumStorageTrie,
0xb0 => BitcoinBlock,
0xb1 => BitcoinTx,
0xc0 => ZcashBlock,
0xc1 => ZcashTx,
0x0129 => DagJSON,
}
70 changes: 70 additions & 0 deletions ipld/cid/src/error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// Copyright 2020 ChainSafe Systems
// SPDX-License-Identifier: Apache-2.0

use multibase;
use multihash;
use std::{error, fmt, io};

/// Error types
#[derive(PartialEq, Eq, Clone, Copy, Debug)]
pub enum Error {
UnknownCodec,
InputTooShort,
ParsingError,
InvalidCidVersion,
}

impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.write_str(error::Error::description(self))
}
}

impl error::Error for Error {
fn description(&self) -> &str {
use self::Error::*;

match *self {
UnknownCodec => "Unknown codec",
InputTooShort => "Input too short",
ParsingError => "Failed to parse multihash",
InvalidCidVersion => "Unrecognized CID version",
}
}
}

impl From<io::Error> for Error {
fn from(_: io::Error) -> Error {
Error::ParsingError
}
}

impl From<multibase::Error> for Error {
fn from(_: multibase::Error) -> Error {
Error::ParsingError
}
}

impl From<multihash::DecodeOwnedError> for Error {
fn from(_: multihash::DecodeOwnedError) -> Error {
Error::ParsingError
}
}

impl From<multihash::EncodeError> for Error {
fn from(_: multihash::EncodeError) -> Error {
Error::ParsingError
}
}

impl From<multihash::DecodeError> for Error {
fn from(_: multihash::DecodeError) -> Error {
Error::ParsingError
}
}

impl From<Error> for fmt::Error {
fn from(_: Error) -> fmt::Error {
fmt::Error {}
}
}
Loading