Skip to main content

espresso_types/v0/
mod.rs

1pub use hotshot_types::{new_protocol::Proposal as NewProposal, simple_certificate::Certificate2};
2use hotshot_types::{
3    signature_key::{BLSPubKey, SchnorrPubKey},
4    traits::{node_implementation::NodeType, signature_key::SignatureKey},
5};
6use serde::{Deserialize, Serialize};
7
8pub mod config;
9mod header;
10mod impls;
11mod nsproof;
12pub mod reward_mt;
13pub mod sparse_mt;
14pub mod traits;
15mod txproof;
16mod utils;
17
18pub use header::Header;
19#[cfg(any(test, feature = "testing"))]
20pub use impls::mock;
21// export reward types for staking-ui-service
22pub use impls::reward::{
23    ComputedRewards, EpochRewardsCalculator, EpochRewardsResult, RewardDistributor,
24    ValidatorLeaderCounts,
25};
26#[cfg(any(test, feature = "testing"))]
27pub use impls::testing;
28pub use impls::{
29    BuilderValidationError, EpochCommittees, EpochCommitteesError, EpochSnapshot, FeeError,
30    ProposalValidationError, RECENT_STAKE_TABLES_LIMIT, StateValidationError, ValidatorSet,
31    get_l1_deposits, retain_accounts, validators_from_l1_events,
32};
33pub use nsproof::*;
34pub use txproof::*;
35pub use utils::*;
36use vbs::version::StaticVersion;
37
38// This is the single source of truth for minor versions supported by this major version.
39//
40// It is written as a higher-level macro which takes a macro invocation as an argument and appends
41// the comma-separated list of minor version identifiers to the arguments of the given invocation.
42// This is to get around Rust's lazy macro expansion: this macro forces expansion of the given
43// invocation. We would rather write something like `some_macro!(args, minor_versions!())`, but the
44// `minor_versions!()` argument would not be expanded for pattern-matching in `some_macro!`, so
45// instead we write `with_minor_versions!(some_macro!(args))`.
46macro_rules! with_minor_versions {
47    ($m:ident!($($arg:tt),*)) => {
48        $m!($($arg,)* v0_1, v0_2, v0_3, v0_4, v0_5, v0_6, v0_7);
49    };
50}
51
52// Define sub-modules for each supported minor version.
53macro_rules! define_modules {
54    ($($m:ident),+) => {
55        $(pub mod $m;)+
56    };
57}
58with_minor_versions!(define_modules!());
59
60macro_rules! assert_eq_all_versions_of_type {
61    ($t:ident, $($m:ident),+) => {
62        static_assertions::assert_type_eq_all!($($m::$t),+);
63    };
64}
65
66macro_rules! reexport_latest_version_of_type {
67    ($t:ident, $m:ident) => { pub use $m::$t; };
68    ($t:ident, $m1:ident, $($m:ident),+) => {
69        reexport_latest_version_of_type!($t, $($m),+);
70    }
71}
72
73/// Re-export types which have not changed across any minor version.
74macro_rules! reexport_unchanged_types {
75    ($($t:ident),+ $(,)?) => {
76        $(
77            with_minor_versions!(assert_eq_all_versions_of_type!($t));
78            with_minor_versions!(reexport_latest_version_of_type!($t));
79        )+
80    }
81}
82reexport_unchanged_types!(
83    AccountQueryData,
84    BlockMerkleCommitment,
85    BlockMerkleTree,
86    BuilderSignature,
87    ChainId,
88    FeeAccount,
89    FeeAccountProof,
90    FeeAmount,
91    FeeInfo,
92    FeeMerkleCommitment,
93    FeeMerkleProof,
94    FeeMerkleTree,
95    Index,
96    Iter,
97    L1BlockInfo,
98    L1ClientOptions,
99    L1SafetyMargin,
100    L1Snapshot,
101    NamespaceId,
102    NsIndex,
103    NsIter,
104    NsPayload,
105    NsPayloadBuilder,
106    NsPayloadByteLen,
107    NsPayloadOwned,
108    NsPayloadRange,
109    NsTable,
110    NsTableBuilder,
111    NsTableValidationError,
112    NumNss,
113    NumTxs,
114    NumTxsRange,
115    NumTxsUnchecked,
116    Payload,
117    PayloadByteLen,
118    Transaction,
119    TxIndex,
120    TxIter,
121    TxPayload,
122    TxPayloadRange,
123    TxTableEntries,
124    TxTableEntriesRange,
125    Upgrade,
126    UpgradeType,
127    UpgradeMode,
128    TimeBasedUpgrade,
129    ViewBasedUpgrade,
130    BlockSize,
131);
132
133#[cfg(feature = "node")]
134reexport_unchanged_types!(L1Client);
135
136pub use v0_3::StateCertQueryDataV1;
137#[cfg(feature = "node")]
138pub(crate) use v0_3::{L1ClientMetrics, L1Event, L1State, L1UpdateTask};
139pub use v0_4::StateCertQueryDataV2;
140
141#[derive(
142    Clone, Copy, Debug, Default, Hash, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize,
143)]
144pub struct SeqTypes;
145
146impl NodeType for SeqTypes {
147    type BlockHeader = Header;
148    type BlockPayload = Payload;
149    type SignatureKey = PubKey;
150    type Transaction = Transaction;
151    type InstanceState = NodeState;
152    type ValidatedState = ValidatedState;
153    type Membership = EpochCommittees;
154    type BuilderSignatureKey = FeeAccount;
155    type StateSignatureKey = SchnorrPubKey;
156}
157
158/// The version integration tests run a network at: the oldest one a live
159/// network can start from.
160pub const TEST_UPGRADE: versions::Upgrade =
161    versions::Upgrade::trivial(versions::NEW_PROTOCOL_VERSION);
162
163pub type FeeVersion = StaticVersion<0, 2>;
164pub type EpochVersion = StaticVersion<0, 3>;
165pub type DrbAndHeaderUpgradeVersion = StaticVersion<0, 4>;
166pub type EpochRewardVersion = StaticVersion<0, 5>;
167
168pub type Leaf = hotshot_types::data::Leaf<SeqTypes>;
169pub type Leaf2 = hotshot_types::data::Leaf2<SeqTypes>;
170
171pub type Event = hotshot_types::event::Event<SeqTypes>;
172
173pub type PubKey = BLSPubKey;
174pub type PrivKey = <PubKey as SignatureKey>::PrivateKey;
175
176pub type NetworkConfig = hotshot_types::network::NetworkConfig<SeqTypes>;
177
178pub use self::impls::{
179    AuthenticatedValidatorMap, NodeState, RegisteredValidatorMap, UpgradeMap, ValidatedState,
180};
181pub use crate::{
182    v0::impls::{
183        StakeTableHash, StakeTableState, calculate_proportion_staked_and_reward_rate,
184        to_registered_validator_map,
185    },
186    v0_1::{
187        BLOCK_MERKLE_TREE_HEIGHT, DECAF_CHAIN_ID, FEE_MERKLE_TREE_HEIGHT, MAINNET_CHAIN_ID,
188        NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN, NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN,
189    },
190    v0_3::ChainConfig,
191};