espresso_types/v0/
mod.rs

1use std::marker::PhantomData;
2
3use hotshot_types::{
4    data::{EpochNumber, ViewNumber},
5    signature_key::{BLSPubKey, SchnorrPubKey},
6    traits::{
7        node_implementation::{NodeType, Versions},
8        signature_key::SignatureKey,
9    },
10};
11use serde::{Deserialize, Serialize};
12
13pub mod config;
14mod header;
15mod impls;
16mod nsproof;
17pub mod sparse_mt;
18pub mod traits;
19mod txproof;
20mod utils;
21pub use header::Header;
22#[cfg(any(test, feature = "testing"))]
23pub use impls::mock;
24#[cfg(any(test, feature = "testing"))]
25pub use impls::testing;
26#[allow(unused_imports)]
27pub(crate) use impls::validator_set_from_l1_events;
28pub use impls::{
29    get_l1_deposits, retain_accounts, validators_from_l1_events, BuilderValidationError,
30    EpochCommittees, FeeError, ProposalValidationError, StateValidationError,
31};
32pub use nsproof::*;
33pub use txproof::*;
34pub use utils::*;
35use vbs::version::{StaticVersion, StaticVersionType};
36
37// This is the single source of truth for minor versions supported by this major version.
38//
39// It is written as a higher-level macro which takes a macro invocation as an argument and appends
40// the comma-separated list of minor version identifiers to the arguments of the given invocation.
41// This is to get around Rust's lazy macro expansion: this macro forces expansion of the given
42// invocation. We would rather write something like `some_macro!(args, minor_versions!())`, but the
43// `minor_versions!()` argument would not be expanded for pattern-matching in `some_macro!`, so
44// instead we write `with_minor_versions!(some_macro!(args))`.
45macro_rules! with_minor_versions {
46    ($m:ident!($($arg:tt),*)) => {
47        $m!($($arg,)* v0_1, v0_2, v0_3, v0_4);
48    };
49}
50
51// Define sub-modules for each supported minor version.
52macro_rules! define_modules {
53    ($($m:ident),+) => {
54        $(pub mod $m;)+
55    };
56}
57with_minor_versions!(define_modules!());
58
59macro_rules! assert_eq_all_versions_of_type {
60    ($t:ident, $($m:ident),+) => {
61        static_assertions::assert_type_eq_all!($($m::$t),+);
62    };
63}
64
65macro_rules! reexport_latest_version_of_type {
66    ($t:ident, $m:ident) => { pub use $m::$t; };
67    ($t:ident, $m1:ident, $($m:ident),+) => {
68        reexport_latest_version_of_type!($t, $($m),+);
69    }
70}
71
72/// Re-export types which have not changed across any minor version.
73macro_rules! reexport_unchanged_types {
74    ($($t:ident),+ $(,)?) => {
75        $(
76            with_minor_versions!(assert_eq_all_versions_of_type!($t));
77            with_minor_versions!(reexport_latest_version_of_type!($t));
78        )+
79    }
80}
81reexport_unchanged_types!(
82    AccountQueryData,
83    BlockMerkleCommitment,
84    BlockMerkleTree,
85    BuilderSignature,
86    ChainId,
87    FeeAccount,
88    FeeAccountProof,
89    FeeAmount,
90    FeeInfo,
91    FeeMerkleCommitment,
92    FeeMerkleProof,
93    FeeMerkleTree,
94    Index,
95    Iter,
96    L1BlockInfo,
97    L1Client,
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
132pub(crate) use v0_3::{L1ClientMetrics, L1Event, L1State, L1UpdateTask};
133
134#[derive(
135    Clone, Copy, Debug, Default, Hash, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize,
136)]
137pub struct SeqTypes;
138
139impl NodeType for SeqTypes {
140    type View = ViewNumber;
141    type Epoch = EpochNumber;
142    type BlockHeader = Header;
143    type BlockPayload = Payload;
144    type SignatureKey = PubKey;
145    type Transaction = Transaction;
146    type InstanceState = NodeState;
147    type ValidatedState = ValidatedState;
148    type Membership = EpochCommittees;
149    type BuilderSignatureKey = FeeAccount;
150    type StateSignatureKey = SchnorrPubKey;
151}
152
153#[derive(Clone, Default, Debug, Copy)]
154pub struct SequencerVersions<Base: StaticVersionType, Upgrade: StaticVersionType> {
155    _pd: PhantomData<(Base, Upgrade)>,
156}
157
158impl<Base: StaticVersionType, Upgrade: StaticVersionType> SequencerVersions<Base, Upgrade> {
159    pub fn new() -> Self {
160        Self {
161            _pd: Default::default(),
162        }
163    }
164}
165
166impl<Base: StaticVersionType + 'static, Upgrade: StaticVersionType + 'static> Versions
167    for SequencerVersions<Base, Upgrade>
168{
169    type Base = Base;
170    type Upgrade = Upgrade;
171    const UPGRADE_HASH: [u8; 32] = [
172        1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,
173        0, 0,
174    ];
175
176    type Epochs = EpochVersion;
177    type DrbAndHeaderUpgrade = DrbAndHeaderUpgradeVersion;
178}
179
180pub type MockSequencerVersions = SequencerVersions<StaticVersion<0, 1>, StaticVersion<0, 2>>;
181
182pub type V0_0 = StaticVersion<0, 0>;
183pub type V0_1 = StaticVersion<0, 1>;
184pub type FeeVersion = StaticVersion<0, 2>;
185pub type EpochVersion = StaticVersion<0, 3>;
186pub type DrbAndHeaderUpgradeVersion = StaticVersion<0, 4>;
187
188pub type Leaf = hotshot_types::data::Leaf<SeqTypes>;
189pub type Leaf2 = hotshot_types::data::Leaf2<SeqTypes>;
190
191pub type Event = hotshot::types::Event<SeqTypes>;
192
193pub type PubKey = BLSPubKey;
194pub type PrivKey = <PubKey as SignatureKey>::PrivateKey;
195
196pub type NetworkConfig = hotshot_types::network::NetworkConfig<SeqTypes>;
197
198pub use self::impls::{NodeState, RewardDistributor, UpgradeMap, ValidatedState, ValidatorMap};
199pub use crate::{
200    v0::impls::StakeTableHash,
201    v0_1::{
202        BLOCK_MERKLE_TREE_HEIGHT, FEE_MERKLE_TREE_HEIGHT, NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN,
203        NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN,
204    },
205    v0_3::ChainConfig,
206};