espresso_types/v0/
mod.rs

1use hotshot_types::{
2    signature_key::{BLSPubKey, SchnorrPubKey},
3    traits::{node_implementation::NodeType, signature_key::SignatureKey},
4};
5use serde::{Deserialize, Serialize};
6
7pub mod config;
8mod header;
9mod impls;
10mod nsproof;
11pub mod reward_mt;
12pub mod sparse_mt;
13pub mod traits;
14mod txproof;
15mod utils;
16
17pub use header::Header;
18#[cfg(any(test, feature = "testing"))]
19pub use impls::mock;
20// export reward types for staking-ui-service
21pub use impls::reward::{
22    ComputedRewards, EpochRewardsCalculator, EpochRewardsResult, RewardDistributor,
23    ValidatorLeaderCounts,
24};
25#[cfg(any(test, feature = "testing"))]
26pub use impls::testing;
27#[allow(unused_imports)]
28pub(crate) use impls::validator_set_from_l1_events;
29pub use impls::{
30    BuilderValidationError, EpochCommittees, FeeError, ProposalValidationError,
31    StateValidationError, 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);
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    L1Client,
99    L1ClientOptions,
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
133pub use v0_3::StateCertQueryDataV1;
134pub(crate) use v0_3::{L1ClientMetrics, L1Event, L1State, L1UpdateTask};
135pub use v0_4::StateCertQueryDataV2;
136use versions::version;
137
138#[derive(
139    Clone, Copy, Debug, Default, Hash, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize,
140)]
141pub struct SeqTypes;
142
143impl NodeType for SeqTypes {
144    type BlockHeader = Header;
145    type BlockPayload = Payload;
146    type SignatureKey = PubKey;
147    type Transaction = Transaction;
148    type InstanceState = NodeState;
149    type ValidatedState = ValidatedState;
150    type Membership = EpochCommittees;
151    type BuilderSignatureKey = FeeAccount;
152    type StateSignatureKey = SchnorrPubKey;
153}
154
155pub const MOCK_SEQUENCER_VERSIONS: versions::Upgrade =
156    versions::Upgrade::new(version(0, 1), version(0, 2));
157
158pub type FeeVersion = StaticVersion<0, 2>;
159pub type EpochVersion = StaticVersion<0, 3>;
160pub type DrbAndHeaderUpgradeVersion = StaticVersion<0, 4>;
161pub type EpochRewardVersion = StaticVersion<0, 5>;
162pub type DaUpgradeVersion = StaticVersion<0, 6>;
163pub type Vid2UpgradeVersion = StaticVersion<0, 7>;
164
165pub type Leaf = hotshot_types::data::Leaf<SeqTypes>;
166pub type Leaf2 = hotshot_types::data::Leaf2<SeqTypes>;
167
168pub type Event = hotshot::types::Event<SeqTypes>;
169
170pub type PubKey = BLSPubKey;
171pub type PrivKey = <PubKey as SignatureKey>::PrivateKey;
172
173pub type NetworkConfig = hotshot_types::network::NetworkConfig<SeqTypes>;
174
175pub use self::impls::{
176    AuthenticatedValidatorMap, NodeState, RegisteredValidatorMap, UpgradeMap, ValidatedState,
177};
178pub use crate::{
179    v0::impls::{
180        StakeTableHash, StakeTableState, calculate_proportion_staked_and_reward_rate,
181        select_active_validator_set, to_registered_validator_map,
182    },
183    v0_1::{
184        BLOCK_MERKLE_TREE_HEIGHT, FEE_MERKLE_TREE_HEIGHT, NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN,
185        NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN,
186    },
187    v0_3::ChainConfig,
188};