@@ -11,12 +11,10 @@ use indexmap::map::Entry;
1111use indexmap:: IndexMap ;
1212#[ cfg( test) ]
1313use mockall:: automock;
14- use reqwest:: StatusCode ;
1514use starknet_api:: block:: BlockNumber ;
1615use starknet_api:: consensus_transaction:: InternalConsensusTransaction ;
1716use starknet_api:: transaction:: TransactionHash ;
18- use thiserror:: Error ;
19- use tracing:: { debug, error, info} ;
17+ use tracing:: { debug, info} ;
2018
2119use crate :: cende_client_types:: {
2220 CendeBlockMetadata ,
@@ -26,18 +24,10 @@ use crate::cende_client_types::{
2624} ;
2725use crate :: pre_confirmed_cende_client:: {
2826 CendeWritePreconfirmedBlock ,
29- PreconfirmedCendeClientError ,
27+ PreconfirmedCendeClientResult ,
3028 PreconfirmedCendeClientTrait ,
3129} ;
3230
33- #[ derive( Debug , Error ) ]
34- pub enum BlockWriterError {
35- #[ error( transparent) ]
36- PreconfirmedCendeClientError ( #[ from] PreconfirmedCendeClientError ) ,
37- }
38-
39- pub type BlockWriterResult < T > = Result < T , BlockWriterError > ;
40-
4131pub type CandidateTxReceiver = tokio:: sync:: mpsc:: Receiver < Vec < InternalConsensusTransaction > > ;
4232pub type CandidateTxSender = tokio:: sync:: mpsc:: Sender < Vec < InternalConsensusTransaction > > ;
4333
@@ -59,7 +49,7 @@ pub type PreconfirmedTxSender = tokio::sync::mpsc::Sender<(
5949#[ cfg_attr( test, automock) ]
6050#[ async_trait]
6151pub trait PreconfirmedBlockWriterTrait : Send {
62- async fn run ( & mut self ) -> BlockWriterResult < ( ) > ;
52+ async fn run ( & mut self ) ;
6353}
6454
6555pub struct PreconfirmedBlockWriter {
@@ -123,11 +113,20 @@ impl PreconfirmedBlockWriter {
123113 pre_confirmed_block,
124114 }
125115 }
116+
117+ // TODO(Arni): handle this error. Make sure it is logged, and that there is a metric for the
118+ // failure.
119+ fn handle_pre_confirmed_cende_client_result ( result : PreconfirmedCendeClientResult < ( ) > ) {
120+ if result. is_err ( ) {
121+ // Intentionally ignore write-task errors (including recorder BAD_REQUEST)
122+ // to preserve current best-effort pre-confirmed block writer behavior.
123+ }
124+ }
126125}
127126
128127#[ async_trait]
129128impl PreconfirmedBlockWriterTrait for PreconfirmedBlockWriter {
130- async fn run ( & mut self ) -> BlockWriterResult < ( ) > {
129+ async fn run ( & mut self ) {
131130 let mut transactions_map: IndexMap <
132131 TransactionHash ,
133132 (
@@ -137,6 +136,8 @@ impl PreconfirmedBlockWriterTrait for PreconfirmedBlockWriter {
137136 ) ,
138137 > = IndexMap :: new ( ) ;
139138
139+ // TODO(Arni): Replace `pending_tasks` with a single-task type since we only allow one
140+ // in-flight write task at a time.
140141 let mut pending_tasks = FuturesUnordered :: new ( ) ;
141142 let mut write_pre_confirmed_txs_timer =
142143 tokio:: time:: interval ( Duration :: from_millis ( self . write_block_interval_millis ) ) ;
@@ -168,13 +169,7 @@ impl PreconfirmedBlockWriterTrait for PreconfirmedBlockWriter {
168169 }
169170
170171 Some ( result) = pending_tasks. next( ) => {
171- if let Err ( error) = result {
172- if is_round_mismatch_error( & error, next_write_iteration) {
173- // TODO(noamsp): Remove this since we only have one ongoing write task.
174- pending_tasks. clear( ) ;
175- return Err ( error. into( ) ) ;
176- }
177- }
172+ Self :: handle_pre_confirmed_cende_client_result( result) ;
178173 }
179174 msg = self . pre_confirmed_tx_receiver. recv( ) => {
180175 match msg {
@@ -217,52 +212,17 @@ impl PreconfirmedBlockWriterTrait for PreconfirmedBlockWriter {
217212 // Wait for all pending tasks to complete gracefully.
218213 // TODO(noamsp): Add timeout.
219214 while let Some ( result) = pending_tasks. next ( ) . await {
220- if let Err ( error) = result {
221- if is_round_mismatch_error ( & error, next_write_iteration) {
222- // TODO(noamsp): Remove this since we only have one ongoing write task.
223- pending_tasks. clear ( ) ;
224- return Err ( error. into ( ) ) ;
225- }
226- }
215+ Self :: handle_pre_confirmed_cende_client_result ( result) ;
227216 }
228217
229218 if pending_changes {
230219 let pre_confirmed_block =
231220 self . create_pre_confirmed_block ( & transactions_map, next_write_iteration) ;
232- self . cende_client . write_pre_confirmed_block ( pre_confirmed_block) . await ?
221+ let result = self . cende_client . write_pre_confirmed_block ( pre_confirmed_block) . await ;
222+ Self :: handle_pre_confirmed_cende_client_result ( result) ;
233223 }
234224 info ! ( "Pre confirmed block writer finished" ) ;
235-
236- Ok ( ( ) )
237- }
238- }
239-
240- // TODO(noamsp): Remove this since we only have one ongoing write task.
241- fn is_round_mismatch_error (
242- error : & PreconfirmedCendeClientError ,
243- next_write_iteration : u64 ,
244- ) -> bool {
245- let PreconfirmedCendeClientError :: CendeRecorderError {
246- block_number,
247- round,
248- write_iteration,
249- status_code,
250- } = error
251- else {
252- return false ;
253- } ;
254-
255- // A bad request status indicates a round or write iteration mismatch. The latest request can
256- // receive a bad request status only if it is due to a round mismatch.
257- if * status_code == StatusCode :: BAD_REQUEST && * write_iteration == next_write_iteration - 1 {
258- error ! (
259- "A higher round was detected for block_number: {}. rejected round: {}. Stopping \
260- pre-confirmed block writer.",
261- block_number, round,
262- ) ;
263- return true ;
264225 }
265- false
266226}
267227
268228#[ cfg_attr( test, automock) ]
0 commit comments