hotshot_types/traits/consensus_api.rs
1// Copyright (c) 2021-2024 Espresso Systems (espressosys.com)
2// This file is part of the HotShot repository.
3
4// You should have received a copy of the MIT License
5// along with the HotShot repository. If not, see <https://mit-license.org/>.
6
7//! Contains the [`ConsensusApi`] trait.
8
9use std::{num::NonZeroUsize, time::Duration};
10
11use async_trait::async_trait;
12
13use crate::{
14 event::Event,
15 traits::{
16 node_implementation::{NodeImplementation, NodeType},
17 signature_key::{SignatureKey, StateSignatureKey},
18 },
19};
20
21/// The API that tasks use to talk to the system
22/// TODO we plan to drop this <https://github.com/EspressoSystems/HotShot/issues/2294>
23#[async_trait]
24pub trait ConsensusApi<TYPES: NodeType, I: NodeImplementation<TYPES>>: Send + Sync {
25 /// Total number of nodes in the network. Also known as `n`.
26 fn total_nodes(&self) -> NonZeroUsize;
27
28 /// The maximum amount of time a leader can wait to get a block from a builder.
29 fn builder_timeout(&self) -> Duration;
30
31 /// Get a reference to the public key.
32 fn public_key(&self) -> &TYPES::SignatureKey;
33
34 /// Get a reference to the private key.
35 fn private_key(&self) -> &<TYPES::SignatureKey as SignatureKey>::PrivateKey;
36
37 /// Get a reference to the light client signing key.
38 fn state_private_key(
39 &self,
40 ) -> &<TYPES::StateSignatureKey as StateSignatureKey>::StatePrivateKey;
41
42 /// Notify the system of an event within `hotshot-consensus`.
43 async fn send_event(&self, event: Event<TYPES>);
44}