Skip to main content

forest/blocks/
block.rs

1// Copyright 2019-2026 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use crate::message::SignedMessage;
5use crate::shim::message::Message;
6use cid::Cid;
7use fvm_ipld_encoding::tuple::*;
8
9use super::CachingBlockHeader;
10
11/// Limit of BLS and SECP messages combined in a block.
12pub const BLOCK_MESSAGE_LIMIT: usize = 10000;
13
14/// A complete Filecoin block. This contains the block header as well as all BLS
15/// and SECP messages.
16#[derive(Clone, Debug, PartialEq, Eq)]
17pub struct Block {
18    pub header: CachingBlockHeader,
19    pub bls_messages: Vec<Message>,
20    pub secp_messages: Vec<SignedMessage>,
21}
22
23impl std::hash::Hash for Block {
24    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
25        std::hash::Hash::hash(self.cid(), state)
26    }
27}
28
29impl Block {
30    pub fn header(&self) -> &CachingBlockHeader {
31        &self.header
32    }
33    pub fn bls_msgs(&self) -> &[Message] {
34        &self.bls_messages
35    }
36    pub fn secp_msgs(&self) -> &[SignedMessage] {
37        &self.secp_messages
38    }
39    /// Returns block header's CID.
40    pub fn cid(&self) -> &Cid {
41        self.header.cid()
42    }
43}
44
45/// Tracks the Merkle roots of both SECP and BLS messages separately.
46#[derive(Serialize_tuple, Deserialize_tuple)]
47pub struct TxMeta {
48    pub bls_message_root: Cid,
49    pub secp_message_root: Cid,
50}