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