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, StateValidationError, ValidatorSet, get_l1_deposits, retain_accounts,
31    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);
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    L1Snapshot,
100    NamespaceId,
101    NsIndex,
102    NsIter,
103    NsPayload,
104    NsPayloadBuilder,
105    NsPayloadByteLen,
106    NsPayloadOwned,
107    NsPayloadRange,
108    NsTable,
109    NsTableBuilder,
110    NsTableValidationError,
111    NumNss,
112    NumTxs,
113    NumTxsRange,
114    NumTxsUnchecked,
115    Payload,
116    PayloadByteLen,
117    Transaction,
118    TxIndex,
119    TxIter,
120    TxPayload,
121    TxPayloadRange,
122    TxTableEntries,
123    TxTableEntriesRange,
124    Upgrade,
125    UpgradeType,
126    UpgradeMode,
127    TimeBasedUpgrade,
128    ViewBasedUpgrade,
129    BlockSize,
130);
131
132#[cfg(feature = "node")]
133reexport_unchanged_types!(L1Client);
134
135pub use v0_3::StateCertQueryDataV1;
136#[cfg(feature = "node")]
137pub(crate) use v0_3::{L1ClientMetrics, L1Event, L1State, L1UpdateTask};
138pub use v0_4::StateCertQueryDataV2;
139use versions::version;
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
158pub const MOCK_SEQUENCER_VERSIONS: versions::Upgrade =
159    versions::Upgrade::new(version(0, 1), version(0, 2));
160
161pub type FeeVersion = StaticVersion<0, 2>;
162pub type EpochVersion = StaticVersion<0, 3>;
163pub type DrbAndHeaderUpgradeVersion = StaticVersion<0, 4>;
164pub type EpochRewardVersion = StaticVersion<0, 5>;
165
166pub type Leaf = hotshot_types::data::Leaf<SeqTypes>;
167pub type Leaf2 = hotshot_types::data::Leaf2<SeqTypes>;
168
169pub type Event = hotshot_types::event::Event<SeqTypes>;
170
171pub type PubKey = BLSPubKey;
172pub type PrivKey = <PubKey as SignatureKey>::PrivateKey;
173
174pub type NetworkConfig = hotshot_types::network::NetworkConfig<SeqTypes>;
175
176pub use self::impls::{
177    AuthenticatedValidatorMap, NodeState, RegisteredValidatorMap, UpgradeMap, ValidatedState,
178};
179pub use crate::{
180    v0::impls::{
181        StakeTableHash, StakeTableState, calculate_proportion_staked_and_reward_rate,
182        to_registered_validator_map,
183    },
184    v0_1::{
185        BLOCK_MERKLE_TREE_HEIGHT, DECAF_CHAIN_ID, FEE_MERKLE_TREE_HEIGHT, NS_ID_BYTE_LEN,
186        NS_OFFSET_BYTE_LEN, NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN,
187    },
188    v0_3::ChainConfig,
189};