Skip to main content

hotshot_types/traits/
node_implementation.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
7use std::{fmt::Debug, hash::Hash};
8
9use serde::Deserialize;
10
11use super::{
12    ValidatedState,
13    block_contents::{BlockHeader, Transaction},
14    signature_key::{
15        BuilderSignatureKey, LCV1StateSignatureKey, LCV2StateSignatureKey, LCV3StateSignatureKey,
16        StateSignatureKey,
17    },
18};
19use crate::{
20    constants::DEFAULT_UPGRADE_CONSTANTS,
21    traits::{
22        BlockPayload, election::Membership, signature_key::SignatureKey, states::InstanceState,
23    },
24    upgrade_config::UpgradeConstants,
25};
26
27/// Trait with all the type definitions that are used in the current hotshot setup.
28pub trait NodeType:
29    Clone
30    + Copy
31    + Debug
32    + Hash
33    + PartialEq
34    + Eq
35    + Default
36    + serde::Serialize
37    + for<'de> Deserialize<'de>
38    + Send
39    + Sync
40    + 'static
41{
42    /// Constants used to construct upgrade proposals
43    const UPGRADE_CONSTANTS: UpgradeConstants = DEFAULT_UPGRADE_CONSTANTS;
44    /// The block header type that this hotshot setup is using.
45    type BlockHeader: BlockHeader<Self>;
46    /// The block type that this hotshot setup is using.
47    ///
48    /// This should be the same block that `ValidatedState::BlockPayload` is using.
49    type BlockPayload: BlockPayload<
50            Self,
51            Instance = Self::InstanceState,
52            Transaction = Self::Transaction,
53            ValidatedState = Self::ValidatedState,
54        >;
55    /// The signature key that this hotshot setup is using.
56    type SignatureKey: SignatureKey;
57    /// The transaction type that this hotshot setup is using.
58    ///
59    /// This should be equal to `BlockPayload::Transaction`
60    type Transaction: Transaction;
61
62    /// The instance-level state type that this hotshot setup is using.
63    type InstanceState: InstanceState;
64
65    /// The validated state type that this hotshot setup is using.
66    type ValidatedState: ValidatedState<Self, Instance = Self::InstanceState>;
67
68    /// Membership used for this implementation
69    type Membership: Membership<Self>;
70
71    /// The type builder uses to sign its messages
72    type BuilderSignatureKey: BuilderSignatureKey;
73
74    /// The type replica uses to sign the light client state
75    type StateSignatureKey: StateSignatureKey
76        + LCV1StateSignatureKey
77        + LCV2StateSignatureKey
78        + LCV3StateSignatureKey;
79}