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, v0_5);
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 use v0_3::StateCertQueryDataV1;
133pub(crate) use v0_3::{L1ClientMetrics, L1Event, L1State, L1UpdateTask};
134pub use v0_4::StateCertQueryDataV2;
135
136#[derive(
137    Clone, Copy, Debug, Default, Hash, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize,
138)]
139pub struct SeqTypes;
140
141impl NodeType for SeqTypes {
142    type View = ViewNumber;
143    type Epoch = EpochNumber;
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
155#[derive(Clone, Default, Debug, Copy)]
156pub struct SequencerVersions<Base: StaticVersionType, Upgrade: StaticVersionType> {
157    _pd: PhantomData<(Base, Upgrade)>,
158}
159
160impl<Base: StaticVersionType, Upgrade: StaticVersionType> SequencerVersions<Base, Upgrade> {
161    pub fn new() -> Self {
162        Self {
163            _pd: Default::default(),
164        }
165    }
166}
167
168impl<Base: StaticVersionType + 'static, Upgrade: StaticVersionType + 'static> Versions
169    for SequencerVersions<Base, Upgrade>
170{
171    type Base = Base;
172    type Upgrade = Upgrade;
173    const UPGRADE_HASH: [u8; 32] = [
174        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,
175        0, 0,
176    ];
177
178    type Epochs = EpochVersion;
179    type DrbAndHeaderUpgrade = DrbAndHeaderUpgradeVersion;
180}
181
182pub type MockSequencerVersions = SequencerVersions<StaticVersion<0, 1>, StaticVersion<0, 2>>;
183
184pub type V0_0 = StaticVersion<0, 0>;
185pub type V0_1 = StaticVersion<0, 1>;
186pub type FeeVersion = StaticVersion<0, 2>;
187pub type EpochVersion = StaticVersion<0, 3>;
188pub type DrbAndHeaderUpgradeVersion = StaticVersion<0, 4>;
189pub type DaUpgradeVersion = StaticVersion<0, 5>;
190
191/// The highest protocol version supported by this version of the software.
192pub type MaxSupportedVersion = DaUpgradeVersion;
193
194pub type Leaf = hotshot_types::data::Leaf<SeqTypes>;
195pub type Leaf2 = hotshot_types::data::Leaf2<SeqTypes>;
196
197pub type Event = hotshot::types::Event<SeqTypes>;
198
199pub type PubKey = BLSPubKey;
200pub type PrivKey = <PubKey as SignatureKey>::PrivateKey;
201
202pub type NetworkConfig = hotshot_types::network::NetworkConfig<SeqTypes>;
203
204pub use self::impls::{NodeState, RewardDistributor, UpgradeMap, ValidatedState, ValidatorMap};
205pub use crate::{
206    v0::impls::{StakeTableHash, StakeTableState},
207    v0_1::{
208        BLOCK_MERKLE_TREE_HEIGHT, FEE_MERKLE_TREE_HEIGHT, NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN,
209        NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN,
210    },
211    v0_3::ChainConfig,
212};