Skip to main content

forest/blocks/
ticket.rs

1// Copyright 2019-2026 ChainSafe Systems
2// SPDX-License-Identifier: Apache-2.0, MIT
3
4use crate::blocks::VRFProof;
5use fvm_ipld_encoding::tuple::*;
6use get_size2::GetSize;
7
8/// A Ticket is a marker of a tick of the blockchain's clock.  It is the source
9/// of randomness for proofs of storage and leader election.  It is generated
10/// by the miner of a block using a `VRF` and a `VDF`.
11#[cfg_attr(test, derive(derive_more::Constructor))]
12#[derive(
13    Clone,
14    Debug,
15    PartialEq,
16    Eq,
17    Default,
18    Serialize_tuple,
19    Deserialize_tuple,
20    Hash,
21    PartialOrd,
22    Ord,
23    GetSize,
24)]
25pub struct Ticket {
26    /// A proof output by running a `VRF` on the `VDFResult` of the parent
27    /// ticket
28    pub vrfproof: VRFProof,
29}
30
31#[cfg(test)]
32impl quickcheck::Arbitrary for Ticket {
33    fn arbitrary(g: &mut quickcheck::Gen) -> Self {
34        let fmt_str = format!("===={}=====", u64::arbitrary(g));
35        let vrfproof = VRFProof::new(fmt_str.into_bytes());
36        Self { vrfproof }
37    }
38}