@@ -15,6 +15,8 @@ mod env;
15
15
mod slots_processor;
16
16
mod utils;
17
17
18
+ const MAX_SLOTS_PER_SAVE : u32 = 1000 ;
19
+
18
20
#[ tokio:: main]
19
21
async fn main ( ) -> Result < ( ) > {
20
22
dotenv:: dotenv ( ) . ok ( ) ;
@@ -42,21 +44,62 @@ async fn main() -> Result<()> {
42
44
let latest_slot: u32 = latest_beacon_block. slot . parse ( ) ?;
43
45
44
46
if current_slot < latest_slot {
45
- let slot_manager_span = tracing:: debug_span!(
46
- "slot_processor_manager" ,
47
- initial_slot = current_slot,
48
- final_slot = latest_slot
47
+ let unprocessed_slots = latest_slot - current_slot;
48
+ let current_max_slots_size = std:: cmp:: min ( unprocessed_slots, MAX_SLOTS_PER_SAVE ) ;
49
+ let num_chunks = unprocessed_slots / current_max_slots_size;
50
+
51
+ let remaining_slots = unprocessed_slots % current_max_slots_size;
52
+ let num_chunks = if remaining_slots > 0 {
53
+ num_chunks + 1
54
+ } else {
55
+ num_chunks
56
+ } ;
57
+
58
+ info ! (
59
+ "Processing slots from {} to {}, partitioned into {} chunks…" ,
60
+ current_slot, latest_slot, num_chunks
49
61
) ;
50
62
51
- slots_processor
52
- . process_slots ( current_slot, latest_slot)
53
- . instrument ( slot_manager_span)
54
- . await ?;
63
+ thread:: sleep ( Duration :: from_secs ( 15 ) ) ;
64
+
65
+ for i in 0 ..num_chunks {
66
+ let slots_in_current_chunk = if i == num_chunks - 1 {
67
+ current_max_slots_size + remaining_slots
68
+ } else {
69
+ current_max_slots_size
70
+ } ;
71
+
72
+ let chunk_initial_slot = current_slot + i * current_max_slots_size;
73
+ let chunk_final_slot = chunk_initial_slot + slots_in_current_chunk;
55
74
56
- blobscan_client. update_slot ( latest_slot - 1 ) . await ?;
57
- info ! ( "Latest slot updated to {}" , latest_slot - 1 ) ;
75
+ let slot_manager_span = tracing:: info_span!(
76
+ "slots_processor" ,
77
+ initial_slot = chunk_initial_slot,
78
+ final_slot = chunk_final_slot
79
+ ) ;
80
+
81
+ slots_processor
82
+ . process_slots ( chunk_initial_slot, chunk_final_slot)
83
+ . instrument ( slot_manager_span)
84
+ . await ?;
85
+
86
+ blobscan_client. update_slot ( chunk_final_slot - 1 ) . await ?;
87
+
88
+ info ! (
89
+ "Chunk {} of {} ({} slots) processed successfully!. Updating latest slot to {}." ,
90
+ i+1 ,
91
+ num_chunks,
92
+ chunk_final_slot - chunk_initial_slot,
93
+ chunk_final_slot - 1
94
+ ) ;
95
+ }
58
96
59
97
current_slot = latest_slot;
98
+
99
+ info ! (
100
+ "All slots processed successfully! Total slots processed: {}" ,
101
+ unprocessed_slots
102
+ ) ;
60
103
}
61
104
}
62
105
0 commit comments