Skip to content
Closed
Show file tree
Hide file tree
Changes from all 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
143 changes: 137 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ fvm_shared2 = { package = "fvm_shared", version = "~2.11" }
fvm_shared3 = { package = "fvm_shared", version = "~3.13", features = ["proofs"] }
fvm_shared4 = { package = "fvm_shared", version = "~4.7", features = ["proofs"] }
gethostname = "1"
get-size2 = { version = "0.5.2", features = ["derive"] }
get-size-derive2 = "*"
git-version = "0.3"
group = "0.13"
hex = { version = "0.4", features = ["serde"] }
Expand Down Expand Up @@ -183,7 +185,7 @@ semver = "1"
serde = { version = "1", default-features = false, features = ["derive"] }
serde_ipld_dagcbor = "0.6"
serde_json = { version = "1", features = ["raw_value"] }
serde_tuple = "1"
serde_tuple = "1.1.2"
serde_with = { version = "3", features = ["chrono_0_4"] }
serde_yaml = "0.9"
sha2 = { version = "0.10", default-features = false }
Expand Down
13 changes: 12 additions & 1 deletion src/beacon/beacon_entries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use crate::utils::encoding::serde_byte_array;
use byteorder::{BigEndian, ByteOrder as _};
use digest::Digest as _;
use get_size2::GetSize;
use serde_tuple::{self, Deserialize_tuple, Serialize_tuple};

/// The result from getting an entry from `Drand`.
Expand All @@ -12,7 +13,17 @@ use serde_tuple::{self, Deserialize_tuple, Serialize_tuple};
/// This beacon entry is stored on chain in the block header.
#[cfg_attr(test, derive(derive_quickcheck_arbitrary::Arbitrary))]
#[derive(
Clone, Debug, Default, Eq, PartialEq, Hash, Ord, PartialOrd, Serialize_tuple, Deserialize_tuple,
Clone,
Debug,
Default,
Eq,
PartialEq,
Hash,
Ord,
PartialOrd,
Serialize_tuple,
Deserialize_tuple,
GetSize,
)]
pub struct BeaconEntry {
round: u64,
Expand Down
15 changes: 14 additions & 1 deletion src/blocks/election_proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,26 @@ impl Poiss {
}
}

use get_size2::GetSize;

/// Proofs generated by a miner which determines the reward they earn.
/// This is generated from hashing a partial ticket and using the hash to
/// generate a value.
#[derive(
Clone, Debug, PartialEq, PartialOrd, Eq, Default, Ord, Serialize_tuple, Deserialize_tuple, Hash,
Clone,
Debug,
PartialEq,
PartialOrd,
Eq,
Default,
Ord,
Serialize_tuple,
Deserialize_tuple,
Hash,
GetSize,
)]
pub struct ElectionProof {
#[get_size(size = 200)]
pub win_count: i64,
pub vrfproof: VRFProof,
}
Expand Down
47 changes: 46 additions & 1 deletion src/blocks/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::utils::{cid::CidCborExt as _, encoding::blake2b_256};
use cid::Cid;
use fvm_ipld_blockstore::Blockstore;
use fvm_ipld_encoding::CborStore as _;
use get_size2::GetSize;
use num::BigInt;
use serde::{Deserialize, Serialize};
use serde_tuple::{Deserialize_tuple, Serialize_tuple};
Expand All @@ -35,41 +36,85 @@ static FILECOIN_GENESIS_CID: std::sync::LazyLock<Cid> = std::sync::LazyLock::new
pub static GENESIS_BLOCK_PARENTS: std::sync::LazyLock<TipsetKey> =
std::sync::LazyLock::new(|| nunny::vec![*FILECOIN_GENESIS_CID].into());

#[derive(Deserialize_tuple, Serialize_tuple, Clone, Hash, Eq, PartialEq, Debug)]
#[derive(Deserialize_tuple, Serialize_tuple, Clone, Hash, Eq, PartialEq, Debug, GetSize)]
pub struct RawBlockHeader {
/// The address of the miner actor that mined this block
#[get_size(size = 20)]
pub miner_address: Address,
pub ticket: Option<Ticket>,
pub election_proof: Option<ElectionProof>,
/// The verifiable oracle randomness used to elect this block's author leader
pub beacon_entries: Vec<BeaconEntry>,
#[get_size(size_fn = post_proof_size_helper)]
pub winning_post_proof: Vec<PoStProof>,
/// The set of parents this block was based on.
/// Typically one, but can be several in the case where there were multiple
/// winning ticket-holders for an epoch
#[get_size(size_fn = tipset_key_size_helper)]
pub parents: TipsetKey,
/// The aggregate chain weight of the parent set
#[serde(with = "crate::shim::fvm_shared_latest::bigint::bigint_ser")]
#[get_size(size_fn = bigint_size_helper)]
pub weight: BigInt,
/// The period in which a new block is generated.
/// There may be multiple rounds in an epoch.
pub epoch: ChainEpoch,
/// The CID of the parent state root after calculating parent tipset.
#[get_size(size_fn = cid_size_helper)]
pub state_root: Cid,
/// The CID of the root of an array of `MessageReceipts`
#[get_size(size_fn = cid_size_helper)]
pub message_receipts: Cid,
/// The CID of the Merkle links for `bls_messages` and `secp_messages`
#[get_size(size_fn = cid_size_helper)]
pub messages: Cid,
/// Aggregate signature of miner in block
#[get_size(size_fn = signature_size_helper)]
pub bls_aggregate: Option<Signature>,
/// Block creation time, in seconds since the Unix epoch
pub timestamp: u64,
#[get_size(size_fn = signature_size_helper)]
pub signature: Option<Signature>,
pub fork_signal: u64,
/// The base fee of the parent block
#[get_size(size_fn = tokenamount_size_helper)]
pub parent_base_fee: TokenAmount,
}

fn cid_size_helper(cid: &Cid) -> usize {
// Cid is a wrapper around a Vec<u8>, so we can use its size directly
cid.hash().digest().len()
}

fn post_proof_size_helper(post_proof: &Vec<PoStProof>) -> usize {
post_proof
.iter()
.map(|p| std::mem::size_of_val(p) + p.proof_bytes.len())
.sum::<usize>()
}

fn tipset_key_size_helper(tipset_key: &TipsetKey) -> usize {
// according to the smallcid docs, the median size of it is 40 bytes
tipset_key.len() * 40
}

fn bigint_size_helper(bigint: &BigInt) -> usize {
// BigInt is a wrapper around a Vec<u8>, so we can use its size directly
bigint.to_bytes_le().1.len()
}

fn tokenamount_size_helper(token_amount: &TokenAmount) -> usize {
// TokenAmount is a wrapper around BigInt, so we can use its size directly
bigint_size_helper(token_amount.atto())
}

fn signature_size_helper(signature: &Option<Signature>) -> usize {
// Signature is a wrapper around a Vec<u8>, so we can use its size directly
signature
.as_ref()
.map_or(0, |s| s.bytes().len() + std::mem::size_of::<Signature>())
}

#[cfg(test)]
impl Default for RawBlockHeader {
fn default() -> Self {
Expand Down
Loading