node/block_producer/vrf_evaluator/
mod.rs

1mod block_producer_vrf_evaluator_state;
2pub use block_producer_vrf_evaluator_state::*;
3
4mod block_producer_vrf_evaluator_event;
5pub use block_producer_vrf_evaluator_event::*;
6
7mod block_producer_vrf_evaluator_actions;
8pub use block_producer_vrf_evaluator_actions::*;
9
10mod block_producer_vrf_evaluator_reducer;
11
12use std::{collections::BTreeMap, sync::Arc};
13
14use ledger::AccountIndex;
15use mina_p2p_messages::v2::{EpochSeed, LedgerHash};
16use serde::{Deserialize, Serialize};
17use vrf::{VrfEvaluationOutput, VrfWonSlot};
18
19use crate::account::AccountPublicKey;
20
21pub type DelegatorTable = BTreeMap<AccountIndex, (AccountPublicKey, u64)>;
22
23#[derive(Debug, Deserialize, Clone, Serialize)]
24pub struct VrfEvaluatorInput {
25    pub epoch_seed: EpochSeed,
26    pub delegator_table: Arc<DelegatorTable>,
27    pub global_slot: u32,
28    pub total_currency: u64,
29    pub staking_ledger_hash: LedgerHash,
30}
31
32#[derive(Debug, Deserialize, Clone, Serialize)]
33pub struct VrfWonSlotWithHash {
34    pub won_slot: VrfWonSlot,
35    pub staking_ledger_hash: LedgerHash,
36}
37
38impl VrfWonSlotWithHash {
39    pub fn new(won_slot: VrfWonSlot, staking_ledger_hash: LedgerHash) -> Self {
40        Self {
41            won_slot,
42            staking_ledger_hash,
43        }
44    }
45}
46
47#[derive(Debug, Deserialize, Clone, Serialize)]
48pub struct VrfEvaluationOutputWithHash {
49    pub evaluation_result: VrfEvaluationOutput,
50    pub staking_ledger_hash: LedgerHash,
51}
52
53impl std::fmt::Display for VrfEvaluationOutputWithHash {
54    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55        write!(f, "{} ", self.staking_ledger_hash)?;
56        match &self.evaluation_result {
57            VrfEvaluationOutput::SlotWon(won_slot) => {
58                write!(f, "SlotWon {}", won_slot.global_slot)
59            }
60            VrfEvaluationOutput::SlotLost(global_slot) => {
61                write!(f, "SlotLost {}", global_slot)
62            }
63        }
64    }
65}
66
67impl VrfEvaluationOutputWithHash {
68    pub fn new(evaluation_result: VrfEvaluationOutput, staking_ledger_hash: LedgerHash) -> Self {
69        Self {
70            evaluation_result,
71            staking_ledger_hash,
72        }
73    }
74}
75
76impl VrfEvaluatorInput {
77    pub fn new(
78        epoch_seed: EpochSeed,
79        delegator_table: Arc<DelegatorTable>,
80        global_slot: u32,
81        total_currency: u64,
82        staking_ledger_hash: LedgerHash,
83    ) -> Self {
84        Self {
85            epoch_seed,
86            delegator_table,
87            global_slot,
88            total_currency,
89            staking_ledger_hash,
90        }
91    }
92}