forest/blocks/
ticket.rs

1// Copyright 2019-2025 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#[derive(
12    Clone,
13    Debug,
14    PartialEq,
15    Eq,
16    Default,
17    Serialize_tuple,
18    Deserialize_tuple,
19    Hash,
20    PartialOrd,
21    Ord,
22    GetSize,
23)]
24pub struct Ticket {
25    /// A proof output by running a `VRF` on the `VDFResult` of the parent
26    /// ticket
27    pub vrfproof: VRFProof,
28}
29
30impl Ticket {
31    /// Ticket constructor
32    pub fn new(vrfproof: VRFProof) -> Self {
33        Self { vrfproof }
34    }
35}
36
37#[cfg(test)]
38impl quickcheck::Arbitrary for Ticket {
39    fn arbitrary(g: &mut quickcheck::Gen) -> Self {
40        let fmt_str = format!("===={}=====", u64::arbitrary(g));
41        let vrfproof = VRFProof::new(fmt_str.into_bytes());
42        Self { vrfproof }
43    }
44}