Skip to content

Commit 89a3fe5

Browse files
committed
apollo_batcher: remove is_round_mismatch_error
1 parent 0a7ba12 commit 89a3fe5

4 files changed

Lines changed: 22 additions & 62 deletions

File tree

crates/apollo_batcher/src/batcher.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1028,8 +1028,7 @@ impl Batcher {
10281028
let writer_join_handle =
10291029
pre_confirmed_block_writer.map(|mut pre_confirmed_block_writer| {
10301030
tokio::spawn(async move {
1031-
// TODO(noamsp): add error handling
1032-
pre_confirmed_block_writer.run().await.ok();
1031+
pre_confirmed_block_writer.run().await;
10331032
})
10341033
});
10351034

crates/apollo_batcher/src/pre_confirmed_block_writer.rs

Lines changed: 19 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ use indexmap::map::Entry;
1111
use indexmap::IndexMap;
1212
#[cfg(test)]
1313
use mockall::automock;
14-
use reqwest::StatusCode;
1514
use starknet_api::block::BlockNumber;
1615
use starknet_api::consensus_transaction::InternalConsensusTransaction;
1716
use starknet_api::transaction::TransactionHash;
18-
use thiserror::Error;
19-
use tracing::{debug, error, info};
17+
use tracing::{debug, info};
2018

2119
use crate::cende_client_types::{
2220
CendeBlockMetadata,
@@ -26,18 +24,10 @@ use crate::cende_client_types::{
2624
};
2725
use 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-
4131
pub type CandidateTxReceiver = tokio::sync::mpsc::Receiver<Vec<InternalConsensusTransaction>>;
4232
pub 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]
6151
pub trait PreconfirmedBlockWriterTrait: Send {
62-
async fn run(&mut self) -> BlockWriterResult<()>;
52+
async fn run(&mut self);
6353
}
6454

6555
pub 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]
129128
impl 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)]

crates/apollo_batcher/src/pre_confirmed_cende_client.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ impl PreconfirmedCendeClientTrait for PreconfirmedCendeClient {
106106
PRECONFIRMED_BLOCK_WRITTEN.increment(1);
107107
Ok(())
108108
} else {
109+
// TODO(Arni): Add metric for failure.
109110
warn!(
110111
"write_pre_confirmed_block request failed. block_number={block_number}, \
111112
round={round}, write_iteration={write_iteration}, status={response_status}",

crates/apollo_batcher/src/test_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ impl Default for MockClients {
269269
let (non_working_candidate_tx_sender, _) = tokio::sync::mpsc::channel(1);
270270
let (non_working_pre_confirmed_tx_sender, _) = tokio::sync::mpsc::channel(1);
271271
let mut mock_writer = Box::new(MockPreconfirmedBlockWriterTrait::new());
272-
mock_writer.expect_run().return_once(|| Ok(()));
272+
mock_writer.expect_run().return_once(|| ());
273273
(mock_writer, non_working_candidate_tx_sender, non_working_pre_confirmed_tx_sender)
274274
});
275275

0 commit comments

Comments
 (0)