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