1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
//! Commonly used types and traits in Reth.
//!
//! ## Overview
//!
//! This crate defines various traits and types that form the foundation of the reth stack.
//! The top-level trait is [`Block`] which represents a block in the blockchain. A [`Block`] is
//! composed of a [`Header`] and a [`BlockBody`]. A [`BlockBody`] contains the transactions in the
//! block and additional data that is part of the block. In ethereum, this includes uncle headers
//! and withdrawals. For optimism, uncle headers and withdrawals are always empty lists.
//!
//! The most common types you'll use are:
//! - [`Block`] - A basic block with header and body
//! - [`SealedBlock`] - A block with its hash cached
//! - [`SealedHeader`] - A header with its hash cached
//! - [`RecoveredBlock`] - A sealed block with sender addresses recovered
//!
//! ## Feature Flags
//!
//! - `arbitrary`: Adds `proptest` and `arbitrary` support for primitive types.
//! - `op`: Implements the traits for various [op-alloy](https://github.com/alloy-rs/op-alloy)
//! types.
//! - `reth-codec`: Enables db codec support for reth types including zstd compression for certain
//! types.
//! - `rpc-compat`: Adds RPC compatibility functions for the types in this crate, e.g. rpc type
//! conversions.
//! - `serde`: Adds serde support for all types.
//! - `secp256k1`: Adds secp256k1 support for transaction signing/recovery. (By default the no-std
//! friendly `k256` is used)
//! - `rayon`: Uses `rayon` for parallel transaction sender recovery in [`BlockBody`] by default.
//! - `serde-bincode-compat` provides helpers for dealing with the `bincode` crate.
//!
//! ### Sealing (Hashing)
//!
//! The block hash is derived from the [`Header`] and is used to uniquely identify the block. This
//! operation is referred to as sealing in the context of this crate. Sealing is an expensive
//! operation. This crate provides various wrapper types that cache the hash of the block to avoid
//! recomputing it: [`SealedHeader`] and [`SealedBlock`]. All sealed types can be downgraded to
//! their unsealed counterparts.
//!
//! ### Recovery
//!
//! The raw consensus transactions that make up a block don't include the sender's address. This
//! information is recovered from the transaction signature. This operation is referred to as
//! recovery in the context of this crate and is an expensive operation. The [`RecoveredBlock`]
//! represents a [`SealedBlock`] with the sender addresses recovered. A [`SealedBlock`] can be
//! upgraded to a [`RecoveredBlock`] by recovering the sender addresses:
//! [`SealedBlock::try_recover`]. A [`RecoveredBlock`] can be downgraded to a [`SealedBlock`] by
//! removing the sender addresses: [`RecoveredBlock::into_sealed_block`].
//!
//! #### Naming
//!
//! The types in this crate support multiple recovery functions, e.g.
//! [`SealedBlock::try_recover`] and [`SealedBlock::try_recover_unchecked`]. The `_unchecked` suffix indicates that this function recovers the signer _without ensuring that the signature has a low `s` value_, in other words this rule introduced in [EIP-2](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2.md) is ignored.
//! Hence this function is necessary when dealing with pre EIP-2 transactions on the ethereum
//! mainnet. Newer transactions must always be recovered with the regular `recover` functions, see
//! also [`recover_signer`](crypto::secp256k1::recover_signer).
//!
//! ## Error Handling
//!
//! Most operations that can fail return `Result` types:
//! - [`RecoveryError`](transaction::signed::RecoveryError) - Transaction signature recovery failed
//! - [`BlockRecoveryError`](block::error::BlockRecoveryError) - Block-level recovery failed
//! - [`GotExpected`] / [`GotExpectedBoxed`] - Generic error for mismatched values
//!
//! Recovery errors typically indicate invalid signatures or corrupted data. The block recovery
//! error preserves the original block for further inspection.
//!
//! ### Example
//!
//! ```rust
//! # use reth_primitives_traits::{SealedBlock, RecoveredBlock};
//! # use reth_primitives_traits::block::error::BlockRecoveryError;
//! # fn example<B: reth_primitives_traits::Block>(sealed_block: SealedBlock<B>) -> Result<(), BlockRecoveryError<SealedBlock<B>>>
//! # where B::Body: reth_primitives_traits::BlockBody<Transaction: reth_primitives_traits::SignedTransaction> {
//! // Attempt to recover senders from a sealed block
//! match sealed_block.try_recover() {
//! Ok(recovered) => {
//! // Successfully recovered all senders
//! println!("Recovered {} senders", recovered.senders().len());
//! Ok(())
//! }
//! Err(err) => {
//! // Recovery failed - the block is returned in the error
//! println!("Failed to recover senders for block");
//! // You can still access the original block
//! let block = err.into_inner();
//! let hash = block.hash();
//! Err(BlockRecoveryError::new(block))
//! }
//! }
//! # }
//! ```
//!
//! ## Performance Considerations
//!
//! - **Hashing**: Block hashing is expensive. Use [`SealedBlock`] to cache hashes.
//! - **Recovery**: Sender recovery is CPU-intensive. Use [`RecoveredBlock`] to cache results.
//! - **Parallel Recovery**: Enable the `rayon` feature for parallel transaction recovery.
extern crate alloc;
/// Re-export of [`quanta::Instant`] for high-resolution timing with minimal overhead.
pub use Instant as FastInstant;
/// Common constants.
pub use ;
/// Minimal account
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use WithEncoded;
pub use ;
pub use ;
pub use ;
/// Common header types
pub use ;
/// Heuristic size trait
pub use InMemorySize;
/// Rayon utilities
pub use ParallelBridgeBuffered;
/// Node traits
pub use ;
/// Helper trait that requires de-/serialize implementation since `serde` feature is enabled.
/// Noop. Helper trait that would require de-/serialize implementation if `serde` feature were
/// enabled.
/// Helper trait that requires database encoding implementation since `reth-codec` feature is
/// enabled.
/// Noop. Helper trait that would require database encoding implementation if `reth-codec` feature
/// were enabled.
/// Utilities for testing.
/// Re-exports of `dashmap` types with [`alloy_primitives::map::DefaultHashBuilder`] as the hasher.