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;
17mod sparse_mt;
18pub mod traits;
19mod txproof;
20mod utils;
21pub use header::Header;
22#[allow(unused_imports)]
23pub(crate) use impls::active_validator_set_from_l1_events;
24#[cfg(any(test, feature = "testing"))]
25pub use impls::mock;
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, StaticVersionType};
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);
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(crate) use v0_3::{L1ClientMetrics, L1Event, L1State, L1UpdateTask};
131
132#[derive(
133    Clone, Copy, Debug, Default, Hash, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize,
134)]
135pub struct SeqTypes;
136
137impl NodeType for SeqTypes {
138    type View = ViewNumber;
139    type Epoch = EpochNumber;
140    type BlockHeader = Header;
141    type BlockPayload = Payload;
142    type SignatureKey = PubKey;
143    type Transaction = Transaction;
144    type InstanceState = NodeState;
145    type ValidatedState = ValidatedState;
146    type Membership = EpochCommittees;
147    type BuilderSignatureKey = FeeAccount;
148    type StateSignatureKey = SchnorrPubKey;
149}
150
151#[derive(Clone, Default, Debug, Copy)]
152pub struct SequencerVersions<Base: StaticVersionType, Upgrade: StaticVersionType> {
153    _pd: PhantomData<(Base, Upgrade)>,
154}
155
156impl<Base: StaticVersionType, Upgrade: StaticVersionType> SequencerVersions<Base, Upgrade> {
157    pub fn new() -> Self {
158        Self {
159            _pd: Default::default(),
160        }
161    }
162}
163
164impl<Base: StaticVersionType + 'static, Upgrade: StaticVersionType + 'static> Versions
165    for SequencerVersions<Base, Upgrade>
166{
167    type Base = Base;
168    type Upgrade = Upgrade;
169    const UPGRADE_HASH: [u8; 32] = [
170        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,
171        0, 0,
172    ];
173
174    type Epochs = EpochVersion;
175    type DrbAndHeaderUpgrade = DrbAndHeaderUpgradeVersion;
176}
177
178pub type MockSequencerVersions = SequencerVersions<StaticVersion<0, 1>, StaticVersion<0, 2>>;
179
180pub type V0_0 = StaticVersion<0, 0>;
181pub type V0_1 = StaticVersion<0, 1>;
182pub type FeeVersion = StaticVersion<0, 2>;
183pub type EpochVersion = StaticVersion<0, 3>;
184pub type DrbAndHeaderUpgradeVersion = StaticVersion<0, 4>;
185
186pub type Leaf = hotshot_types::data::Leaf<SeqTypes>;
187pub type Leaf2 = hotshot_types::data::Leaf2<SeqTypes>;
188
189pub type Event = hotshot::types::Event<SeqTypes>;
190
191pub type PubKey = BLSPubKey;
192pub type PrivKey = <PubKey as SignatureKey>::PrivateKey;
193
194pub type NetworkConfig = hotshot_types::network::NetworkConfig<SeqTypes>;
195
196pub use self::impls::{NodeState, RewardDistributor, UpgradeMap, ValidatedState, ValidatorMap};
197pub use crate::{
198    v0::impls::StakeTableHash,
199    v0_1::{
200        BLOCK_MERKLE_TREE_HEIGHT, FEE_MERKLE_TREE_HEIGHT, NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN,
201        NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN,
202    },
203    v0_3::ChainConfig,
204};