@@ -16,9 +16,9 @@ use std::collections::HashSet;
1616use std:: time:: Duration ;
1717use tips_audit:: { BundleEvent , BundleEventPublisher , DropReason } ;
1818use tips_datastore:: BundleDatastore ;
19- use tips_datastore:: postgres:: { BundleFilter , BundleState , BundleWithMetadata } ;
19+ use tips_datastore:: postgres:: { BlockInfoUpdate , BundleFilter , BundleState , BundleWithMetadata } ;
2020use tokio:: sync:: mpsc;
21- use tracing:: { error, info, warn} ;
21+ use tracing:: { debug , error, info, warn} ;
2222use uuid:: Uuid ;
2323
2424pub struct MaintenanceJob < S : BundleDatastore , P : Provider < Optimism > , K : BundleEventPublisher > {
@@ -54,6 +54,11 @@ impl<S: BundleDatastore, P: Provider<Optimism>, K: BundleEventPublisher> Mainten
5454 . await ?
5555 . ok_or_else ( || anyhow:: anyhow!( "Failed to get latest block" ) ) ?;
5656
57+ debug ! (
58+ message = "Executing up to latest block" ,
59+ block_number = latest_block. number( )
60+ ) ;
61+
5762 let block_info = self . store . get_current_block_info ( ) . await ?;
5863
5964 if let Some ( current_block_info) = block_info {
@@ -62,6 +67,8 @@ impl<S: BundleDatastore, P: Provider<Optimism>, K: BundleEventPublisher> Mainten
6267 for block_num in
6368 ( current_block_info. latest_block_number + 1 ) ..=latest_block. header . number
6469 {
70+ debug ! ( message = "Fetching block number" , ?latest_block) ;
71+
6572 let block = self
6673 . node
6774 . get_block ( BlockId :: Number ( alloy_rpc_types:: BlockNumberOrTag :: Number (
@@ -71,12 +78,19 @@ impl<S: BundleDatastore, P: Provider<Optimism>, K: BundleEventPublisher> Mainten
7178 . await ?
7279 . ok_or_else ( || anyhow:: anyhow!( "Failed to get block {}" , block_num) ) ?;
7380
81+ let hash = block. hash ( ) ;
7482 self . on_new_block ( block) . await ?;
83+ self . store
84+ . commit_block_info ( vec ! [ BlockInfoUpdate {
85+ block_number: block_num,
86+ block_hash: hash,
87+ } ] )
88+ . await ?;
7589 }
7690 }
7791 } else {
7892 warn ! ( "No block info found in database, initializing with latest block as finalized" ) ;
79- let block_update = tips_datastore :: postgres :: BlockInfoUpdate {
93+ let block_update = BlockInfoUpdate {
8094 block_number : latest_block. header . number ,
8195 block_hash : latest_block. header . hash ,
8296 } ;
@@ -142,33 +156,36 @@ impl<S: BundleDatastore, P: Provider<Optimism>, K: BundleEventPublisher> Mainten
142156 loop {
143157 tokio:: select! {
144158 _ = maintenance_interval. tick( ) => {
159+ info!( message = "starting maintenance" ) ;
145160 match self . periodic_maintenance( ) . await {
146161 Ok ( _) => {
147- info!( "Periodic maintenance completed" ) ;
162+ info!( message = "Periodic maintenance completed" ) ;
148163 } ,
149164 Err ( err) => {
150- error!( "Error in periodic maintenance: {:?} " , err) ;
165+ error!( message = "Error in periodic maintenance" , error = % err) ;
151166 }
152167
153168 }
154169 }
155170 _ = execution_interval. tick( ) => {
171+ info!( message = "starting execution run" ) ;
156172 match self . execute( ) . await {
157173 Ok ( _) => {
158- info!( "Successfully executed maintenance run" ) ;
174+ info!( message = "Successfully executed maintenance run" ) ;
159175 }
160176 Err ( e) => {
161- error!( "Error executing maintenance run: {:?} " , e) ;
177+ error!( message = "Error executing maintenance run" , error = % e) ;
162178 }
163179 }
164180 }
165181 Some ( flashblock) = fb_rx. recv( ) => {
182+ info!( message = "starting flashblock processing" ) ;
166183 match self . process_flashblock( flashblock) . await {
167184 Ok ( _) => {
168- info!( "Successfully processed flashblock" ) ;
185+ info!( message = "Successfully processed flashblock" ) ;
169186 }
170187 Err ( e) => {
171- error!( "Error processing flashblock: {:?} " , e) ;
188+ error!( message = "Error processing flashblock" , error = % e) ;
172189 }
173190 }
174191 }
0 commit comments