@@ -37,6 +37,21 @@ macro_rules! spawn_provider_send {
37
37
} ;
38
38
}
39
39
40
+ macro_rules! check_slot_still_valid {
41
+ ( $self: expr, $initial_slot: expr) => {
42
+ if !$self. slot_still_valid( $initial_slot) {
43
+ debug!(
44
+ current_slot =
45
+ $self. config. slot_calculator. current_slot( ) . expect( "host chain has started" ) ,
46
+ initial_slot = $initial_slot,
47
+ "slot changed before submission - skipping block"
48
+ ) ;
49
+ counter!( "builder.slot_missed" ) . increment( 1 ) ;
50
+ return Ok ( ControlFlow :: Skip ) ;
51
+ }
52
+ } ;
53
+ }
54
+
40
55
/// Control flow for transaction submission.
41
56
#[ derive( Debug , Copy , Clone , PartialEq , Eq ) ]
42
57
pub enum ControlFlow {
@@ -130,18 +145,9 @@ impl SubmitTask {
130
145
retry_limit : usize ,
131
146
) -> eyre:: Result < ControlFlow > {
132
147
let submitting_start_time = Instant :: now ( ) ;
133
- let now = utils:: now ( ) ;
134
148
135
149
let ( expected_slot, window) = self . get_expected_slot_and_window ( ) ;
136
150
137
- debug ! (
138
- expected_slot,
139
- start = window. start,
140
- end = window. end,
141
- now,
142
- "calculating target slot window"
143
- ) ;
144
-
145
151
let mut req = bumpable. req ( ) . clone ( ) ;
146
152
147
153
// Retry loop
@@ -151,27 +157,26 @@ impl SubmitTask {
151
157
"SubmitTask::retrying_send" ,
152
158
retries = bumpable. bump_count( ) ,
153
159
nonce = bumpable. req( ) . nonce,
160
+ expected_slot,
161
+ start = window. start,
162
+ end = window. end,
163
+ now = utils:: now( ) ,
154
164
) ;
155
165
156
- let inbound_result = match self . send_transaction ( req) . instrument ( span. clone ( ) ) . await {
157
- Ok ( control_flow) => control_flow,
158
- Err ( error) => {
159
- if let Some ( value) = self . slot_still_valid ( expected_slot) {
160
- return value;
161
- }
162
- // Log error and retry
163
- error ! ( %error, "error handling inbound block" ) ;
164
- ControlFlow :: Retry
165
- }
166
- } ;
166
+ // Check at the top of the loop if the slot is still valid. This
167
+ // will prevent unnecessary retries if the slot has changed.
168
+ check_slot_still_valid ! ( self , expected_slot) ;
167
169
168
- let guard = span. entered ( ) ;
170
+ let inbound_result = self
171
+ . send_transaction ( req)
172
+ . instrument ( span. clone ( ) )
173
+ . await
174
+ . inspect_err ( |e| error ! ( error = %e, "sending transaction" ) )
175
+ . unwrap_or ( ControlFlow :: Retry ) ;
169
176
177
+ let guard = span. entered ( ) ;
170
178
match inbound_result {
171
179
ControlFlow :: Retry => {
172
- if let Some ( value) = self . slot_still_valid ( expected_slot) {
173
- return value;
174
- }
175
180
// bump the req
176
181
req = bumpable. bumped ( ) ;
177
182
if bumpable. bump_count ( ) > retry_limit {
@@ -221,17 +226,8 @@ impl SubmitTask {
221
226
}
222
227
223
228
/// Checks if a slot is still valid during submission retries.
224
- fn slot_still_valid ( & self , initial_slot : usize ) -> Option < Result < ControlFlow , eyre:: Error > > {
225
- let current_slot =
226
- self . config . slot_calculator . current_slot ( ) . expect ( "host chain has started" ) ;
227
- if current_slot != initial_slot {
228
- // If the slot has changed, skip the block
229
- debug ! ( current_slot, initial_slot, "slot changed before submission - skipping block" ) ;
230
- counter ! ( "builder.slot_missed" ) . increment ( 1 ) ;
231
- return Some ( Ok ( ControlFlow :: Skip ) ) ;
232
- }
233
- debug ! ( current_slot, "slot still valid - continuing submission" ) ;
234
- None
229
+ fn slot_still_valid ( & self , initial_slot : usize ) -> bool {
230
+ initial_slot == self . config . slot_calculator . current_slot ( ) . expect ( "host chain has started" )
235
231
}
236
232
237
233
/// Task future for the submit task. This function runs the main loop of the task.
0 commit comments