@@ -24,23 +24,30 @@ use trevm::{
24
24
} ,
25
25
} ;
26
26
27
- /// Pecorino Chain ID
27
+ /// Pecorino Chain ID used for the Pecorino network.
28
28
pub const PECORINO_CHAIN_ID : u64 = 14174 ;
29
29
30
- /// BlockBuilder is a task that periodically builds a block then sends it for
31
- /// signing and submission.
30
+ /// `BlockBuilder` is responsible for periodically building blocks and submitting them for signing and inclusion in the blockchain.
32
31
#[ derive( Debug ) ]
33
32
pub struct BlockBuilder {
34
- /// Configuration.
33
+ /// Configuration for the builder .
35
34
pub config : BuilderConfig ,
36
- /// A provider that cannot sign transactions.
35
+ /// A provider that cannot sign transactions, used for interacting with the rollup .
37
36
pub ru_provider : WalletlessProvider ,
38
- /// The slot calculator for waking up and sleeping the builder correctly
37
+ /// The slot calculator for determining when to wake up and build blocks.
39
38
pub slot_calculator : SlotCalculator ,
40
39
}
41
40
42
41
impl BlockBuilder {
43
- /// Creates a new block builder that builds blocks based on the given provider.
42
+ /// Creates a new `BlockBuilder` instance.
43
+ ///
44
+ /// # Arguments
45
+ /// - `config`: The configuration for the builder.
46
+ /// - `ru_provider`: A provider for interacting with the rollup.
47
+ /// - `slot_calculator`: A slot calculator for managing block timing.
48
+ ///
49
+ /// # Returns
50
+ /// A new `BlockBuilder` instance.
44
51
pub fn new (
45
52
config : & BuilderConfig ,
46
53
ru_provider : WalletlessProvider ,
@@ -50,6 +57,14 @@ impl BlockBuilder {
50
57
}
51
58
52
59
/// Handles building a single block.
60
+ ///
61
+ /// # Arguments
62
+ /// - `constants`: The system constants for the rollup.
63
+ /// - `sim_items`: The simulation cache containing transactions and bundles.
64
+ /// - `finish_by`: The deadline by which the block must be built.
65
+ ///
66
+ /// # Returns
67
+ /// A `Result` containing the built block or an error.
53
68
pub async fn handle_build (
54
69
& self ,
55
70
constants : SignetSystemConstants ,
@@ -74,14 +89,22 @@ impl BlockBuilder {
74
89
Ok ( block)
75
90
}
76
91
77
- /// Scans the tx and bundle receivers for new items and adds them to the cache.
92
+ /// Spawns a task to handle incoming transactions and bundles, adding them to the simulation cache.
93
+ ///
94
+ /// # Arguments
95
+ /// - `tx_receiver`: A channel receiver for incoming transactions.
96
+ /// - `bundle_receiver`: A channel receiver for incoming bundles.
97
+ /// - `cache`: The simulation cache to store the received items.
98
+ ///
99
+ /// # Returns
100
+ /// A `JoinHandle` for the spawned task.
78
101
pub fn spawn_cache_handler (
79
102
self : Arc < Self > ,
80
103
mut tx_receiver : mpsc:: UnboundedReceiver < TxEnvelope > ,
81
104
mut bundle_receiver : mpsc:: UnboundedReceiver < Bundle > ,
82
105
cache : SimCache ,
83
106
) -> JoinHandle < ( ) > {
84
- let jh = tokio:: spawn ( async move {
107
+ tokio:: spawn ( async move {
85
108
loop {
86
109
select ! {
87
110
maybe_tx = tx_receiver. recv( ) => {
@@ -96,18 +119,25 @@ impl BlockBuilder {
96
119
}
97
120
}
98
121
}
99
- } ) ;
100
- jh
122
+ } )
101
123
}
102
124
103
125
/// Spawns the block building task.
126
+ ///
127
+ /// # Arguments
128
+ /// - `constants`: The system constants for the rollup.
129
+ /// - `cache`: The simulation cache containing transactions and bundles.
130
+ /// - `submit_sender`: A channel sender for submitting built blocks.
131
+ ///
132
+ /// # Returns
133
+ /// A `JoinHandle` for the spawned task.
104
134
pub fn spawn_builder_task (
105
135
self : Arc < Self > ,
106
136
constants : SignetSystemConstants ,
107
137
cache : SimCache ,
108
138
submit_sender : mpsc:: UnboundedSender < BuiltBlock > ,
109
139
) -> JoinHandle < ( ) > {
110
- let jh = tokio:: spawn ( async move {
140
+ tokio:: spawn ( async move {
111
141
loop {
112
142
let sim_cache = cache. clone ( ) ;
113
143
@@ -126,19 +156,24 @@ impl BlockBuilder {
126
156
}
127
157
}
128
158
}
129
- } ) ;
130
- jh
159
+ } )
131
160
}
132
161
133
- /// Returns the instant at which simulation must stop.
162
+ /// Calculates the deadline for the current block simulation.
163
+ ///
164
+ /// # Returns
165
+ /// An `Instant` representing the deadline.
134
166
pub fn calculate_deadline ( & self ) -> Instant {
135
167
let now = SystemTime :: now ( ) ;
136
168
let unix_seconds = now. duration_since ( UNIX_EPOCH ) . expect ( "Time went backwards" ) . as_secs ( ) ;
137
169
138
170
Instant :: now ( ) . checked_add ( Duration :: from_secs ( unix_seconds) ) . unwrap ( )
139
171
}
140
172
141
- /// Creates an AlloyDB from a rollup provider
173
+ /// Creates an `AlloyDB` instance from the rollup provider.
174
+ ///
175
+ /// # Returns
176
+ /// An `Option` containing the wrapped database or `None` if an error occurs.
142
177
async fn create_db ( & self ) -> Option < WrapAlloyDatabaseAsync > {
143
178
let latest = match self . ru_provider . get_block_number ( ) . await {
144
179
Ok ( block_number) => block_number,
@@ -155,7 +190,7 @@ impl BlockBuilder {
155
190
}
156
191
}
157
192
158
- /// The wrapped alloy database type that is compatible with Db + DatabaseRef
193
+ /// The wrapped alloy database type that is compatible with `Db` and ` DatabaseRef`.
159
194
type WrapAlloyDatabaseAsync = WrapDatabaseAsync <
160
195
AlloyDB <
161
196
alloy:: network:: Ethereum ,
@@ -178,13 +213,17 @@ type WrapAlloyDatabaseAsync = WrapDatabaseAsync<
178
213
> ,
179
214
> ;
180
215
181
- /// Configuration struct for Pecorino network values
216
+ /// Configuration struct for Pecorino network values.
182
217
#[ derive( Debug , Clone ) ]
183
218
pub struct PecorinoCfg { }
184
219
185
220
impl Copy for PecorinoCfg { }
186
221
187
222
impl trevm:: Cfg for PecorinoCfg {
223
+ /// Fills the configuration environment with Pecorino-specific values.
224
+ ///
225
+ /// # Arguments
226
+ /// - `cfg_env`: The configuration environment to be filled.
188
227
fn fill_cfg_env ( & self , cfg_env : & mut CfgEnv ) {
189
228
let CfgEnv { chain_id, spec, .. } = cfg_env;
190
229
0 commit comments