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;
24pub use impls::reward::{ComputedRewards, RewardDistributor};
26#[cfg(any(test, feature = "testing"))]
27pub use impls::testing;
28#[allow(unused_imports)]
29pub(crate) use impls::validator_set_from_l1_events;
30pub use impls::{
31 get_l1_deposits, retain_accounts, validators_from_l1_events, BuilderValidationError,
32 EpochCommittees, FeeError, ProposalValidationError, StateValidationError,
33};
34pub use nsproof::*;
35pub use txproof::*;
36pub use utils::*;
37use vbs::version::{StaticVersion, StaticVersionType};
38
39macro_rules! with_minor_versions {
48 ($m:ident!($($arg:tt),*)) => {
49 $m!($($arg,)* v0_1, v0_2, v0_3, v0_4, v0_5, v0_6);
50 };
51}
52
53macro_rules! define_modules {
55 ($($m:ident),+) => {
56 $(pub mod $m;)+
57 };
58}
59with_minor_versions!(define_modules!());
60
61macro_rules! assert_eq_all_versions_of_type {
62 ($t:ident, $($m:ident),+) => {
63 static_assertions::assert_type_eq_all!($($m::$t),+);
64 };
65}
66
67macro_rules! reexport_latest_version_of_type {
68 ($t:ident, $m:ident) => { pub use $m::$t; };
69 ($t:ident, $m1:ident, $($m:ident),+) => {
70 reexport_latest_version_of_type!($t, $($m),+);
71 }
72}
73
74macro_rules! reexport_unchanged_types {
76 ($($t:ident),+ $(,)?) => {
77 $(
78 with_minor_versions!(assert_eq_all_versions_of_type!($t));
79 with_minor_versions!(reexport_latest_version_of_type!($t));
80 )+
81 }
82}
83reexport_unchanged_types!(
84 AccountQueryData,
85 BlockMerkleCommitment,
86 BlockMerkleTree,
87 BuilderSignature,
88 ChainId,
89 FeeAccount,
90 FeeAccountProof,
91 FeeAmount,
92 FeeInfo,
93 FeeMerkleCommitment,
94 FeeMerkleProof,
95 FeeMerkleTree,
96 Index,
97 Iter,
98 L1BlockInfo,
99 L1Client,
100 L1ClientOptions,
101 L1Snapshot,
102 NamespaceId,
103 NsIndex,
104 NsIter,
105 NsPayload,
106 NsPayloadBuilder,
107 NsPayloadByteLen,
108 NsPayloadOwned,
109 NsPayloadRange,
110 NsTable,
111 NsTableBuilder,
112 NsTableValidationError,
113 NumNss,
114 NumTxs,
115 NumTxsRange,
116 NumTxsUnchecked,
117 Payload,
118 PayloadByteLen,
119 Transaction,
120 TxIndex,
121 TxIter,
122 TxPayload,
123 TxPayloadRange,
124 TxTableEntries,
125 TxTableEntriesRange,
126 Upgrade,
127 UpgradeType,
128 UpgradeMode,
129 TimeBasedUpgrade,
130 ViewBasedUpgrade,
131 BlockSize,
132);
133
134pub use v0_3::StateCertQueryDataV1;
135pub(crate) use v0_3::{L1ClientMetrics, L1Event, L1State, L1UpdateTask};
136pub use v0_4::StateCertQueryDataV2;
137
138#[derive(
139 Clone, Copy, Debug, Default, Hash, Eq, PartialEq, PartialOrd, Ord, Deserialize, Serialize,
140)]
141pub struct SeqTypes;
142
143impl NodeType for SeqTypes {
144 type View = ViewNumber;
145 type Epoch = EpochNumber;
146 type BlockHeader = Header;
147 type BlockPayload = Payload;
148 type SignatureKey = PubKey;
149 type Transaction = Transaction;
150 type InstanceState = NodeState;
151 type ValidatedState = ValidatedState;
152 type Membership = EpochCommittees;
153 type BuilderSignatureKey = FeeAccount;
154 type StateSignatureKey = SchnorrPubKey;
155}
156
157#[derive(Clone, Default, Debug, Copy)]
158pub struct SequencerVersions<Base: StaticVersionType, Upgrade: StaticVersionType> {
159 _pd: PhantomData<(Base, Upgrade)>,
160}
161
162impl<Base: StaticVersionType, Upgrade: StaticVersionType> SequencerVersions<Base, Upgrade> {
163 pub fn new() -> Self {
164 Self {
165 _pd: Default::default(),
166 }
167 }
168}
169
170impl<Base: StaticVersionType + 'static, Upgrade: StaticVersionType + 'static> Versions
171 for SequencerVersions<Base, Upgrade>
172{
173 type Base = Base;
174 type Upgrade = Upgrade;
175 const UPGRADE_HASH: [u8; 32] = [
176 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,
177 0, 0,
178 ];
179
180 type Epochs = EpochVersion;
181 type DrbAndHeaderUpgrade = DrbAndHeaderUpgradeVersion;
182 type Vid2Upgrade = Vid2UpgradeVersion;
183}
184
185pub type MockSequencerVersions = SequencerVersions<StaticVersion<0, 1>, StaticVersion<0, 2>>;
186
187pub type V0_0 = StaticVersion<0, 0>;
188pub type V0_1 = StaticVersion<0, 1>;
189pub type FeeVersion = StaticVersion<0, 2>;
190pub type EpochVersion = StaticVersion<0, 3>;
191pub type DrbAndHeaderUpgradeVersion = StaticVersion<0, 4>;
192pub type DaUpgradeVersion = StaticVersion<0, 5>;
193pub type Vid2UpgradeVersion = StaticVersion<0, 6>;
194
195pub type MaxSupportedVersion = DaUpgradeVersion;
197
198pub type Leaf = hotshot_types::data::Leaf<SeqTypes>;
199pub type Leaf2 = hotshot_types::data::Leaf2<SeqTypes>;
200
201pub type Event = hotshot::types::Event<SeqTypes>;
202
203pub type PubKey = BLSPubKey;
204pub type PrivKey = <PubKey as SignatureKey>::PrivateKey;
205
206pub type NetworkConfig = hotshot_types::network::NetworkConfig<SeqTypes>;
207
208pub use self::impls::{NodeState, UpgradeMap, ValidatedState, ValidatorMap};
209pub use crate::{
210 v0::impls::{
211 calculate_proportion_staked_and_reward_rate, select_active_validator_set, StakeTableHash,
212 StakeTableState,
213 },
214 v0_1::{
215 BLOCK_MERKLE_TREE_HEIGHT, FEE_MERKLE_TREE_HEIGHT, NS_ID_BYTE_LEN, NS_OFFSET_BYTE_LEN,
216 NUM_NSS_BYTE_LEN, NUM_TXS_BYTE_LEN, TX_OFFSET_BYTE_LEN,
217 },
218 v0_3::ChainConfig,
219};