@@ -24,23 +24,30 @@ use trevm::{
2424 } ,
2525} ;
2626
27- /// Pecorino Chain ID
27+ /// Pecorino Chain ID used for the Pecorino network.
2828pub const PECORINO_CHAIN_ID : u64 = 14174 ;
2929
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.
3231#[ derive( Debug ) ]
3332pub struct BlockBuilder {
34- /// Configuration.
33+ /// Configuration for the builder .
3534 pub config : BuilderConfig ,
36- /// A provider that cannot sign transactions.
35+ /// A provider that cannot sign transactions, used for interacting with the rollup .
3736 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.
3938 pub slot_calculator : SlotCalculator ,
4039}
4140
4241impl 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.
4451 pub fn new (
4552 config : & BuilderConfig ,
4653 ru_provider : WalletlessProvider ,
@@ -50,6 +57,14 @@ impl BlockBuilder {
5057 }
5158
5259 /// 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.
5368 pub async fn handle_build (
5469 & self ,
5570 constants : SignetSystemConstants ,
@@ -74,14 +89,22 @@ impl BlockBuilder {
7489 Ok ( block)
7590 }
7691
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.
78101 pub fn spawn_cache_handler (
79102 self : Arc < Self > ,
80103 mut tx_receiver : mpsc:: UnboundedReceiver < TxEnvelope > ,
81104 mut bundle_receiver : mpsc:: UnboundedReceiver < Bundle > ,
82105 cache : SimCache ,
83106 ) -> JoinHandle < ( ) > {
84- let jh = tokio:: spawn ( async move {
107+ tokio:: spawn ( async move {
85108 loop {
86109 select ! {
87110 maybe_tx = tx_receiver. recv( ) => {
@@ -96,18 +119,25 @@ impl BlockBuilder {
96119 }
97120 }
98121 }
99- } ) ;
100- jh
122+ } )
101123 }
102124
103125 /// 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.
104134 pub fn spawn_builder_task (
105135 self : Arc < Self > ,
106136 constants : SignetSystemConstants ,
107137 cache : SimCache ,
108138 submit_sender : mpsc:: UnboundedSender < BuiltBlock > ,
109139 ) -> JoinHandle < ( ) > {
110- let jh = tokio:: spawn ( async move {
140+ tokio:: spawn ( async move {
111141 loop {
112142 let sim_cache = cache. clone ( ) ;
113143
@@ -126,19 +156,24 @@ impl BlockBuilder {
126156 }
127157 }
128158 }
129- } ) ;
130- jh
159+ } )
131160 }
132161
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.
134166 pub fn calculate_deadline ( & self ) -> Instant {
135167 let now = SystemTime :: now ( ) ;
136168 let unix_seconds = now. duration_since ( UNIX_EPOCH ) . expect ( "Time went backwards" ) . as_secs ( ) ;
137169
138170 Instant :: now ( ) . checked_add ( Duration :: from_secs ( unix_seconds) ) . unwrap ( )
139171 }
140172
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.
142177 async fn create_db ( & self ) -> Option < WrapAlloyDatabaseAsync > {
143178 let latest = match self . ru_provider . get_block_number ( ) . await {
144179 Ok ( block_number) => block_number,
@@ -155,7 +190,7 @@ impl BlockBuilder {
155190 }
156191}
157192
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`.
159194type WrapAlloyDatabaseAsync = WrapDatabaseAsync <
160195 AlloyDB <
161196 alloy:: network:: Ethereum ,
@@ -178,13 +213,17 @@ type WrapAlloyDatabaseAsync = WrapDatabaseAsync<
178213 > ,
179214> ;
180215
181- /// Configuration struct for Pecorino network values
216+ /// Configuration struct for Pecorino network values.
182217#[ derive( Debug , Clone ) ]
183218pub struct PecorinoCfg { }
184219
185220impl Copy for PecorinoCfg { }
186221
187222impl 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.
188227 fn fill_cfg_env ( & self , cfg_env : & mut CfgEnv ) {
189228 let CfgEnv { chain_id, spec, .. } = cfg_env;
190229
0 commit comments