Skip to content

Commit b0dc7bd

Browse files
feat(batcher): Notify the user that proof has been replaced
1 parent 8924dbe commit b0dc7bd

File tree

4 files changed

+27
-9
lines changed

4 files changed

+27
-9
lines changed

crates/batcher/src/lib.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,13 +1496,25 @@ impl Batcher {
14961496
// Close old sink in old entry and replace it with the new one
14971497
{
14981498
if let Some(messaging_sink) = replacement_entry.messaging_sink {
1499-
let mut old_sink = messaging_sink.write().await;
1500-
if let Err(e) = old_sink.close().await {
1501-
// we dont want to exit here, just log the error
1502-
warn!("Error closing sink: {e:?}");
1503-
} else {
1504-
info!("Old websocket sink closed");
1505-
}
1499+
tokio::spawn(async move {
1500+
// Before closing the old sink, send a message to the client notifying that their proof
1501+
// has been replaced
1502+
send_message(
1503+
messaging_sink.clone(),
1504+
SubmitProofResponseMessage::ProofReplaced,
1505+
).await;
1506+
1507+
// Note: This shuts down the sink, but does not wait for it to close, so the other side
1508+
// might not receive the message. However, we don't want to wait here since it would
1509+
// block the batcher.
1510+
let mut old_sink = messaging_sink.write().await;
1511+
if let Err(e) = old_sink.close().await {
1512+
// we dont want to exit here, just log the error
1513+
warn!("Error closing sink: {e:?}");
1514+
} else {
1515+
info!("Old websocket sink closed");
1516+
}
1517+
});
15061518
} else {
15071519
warn!(
15081520
"Old websocket sink was empty. This should only happen in testing environments"

crates/sdk/src/common/errors.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub enum SubmitError {
9999
BatchQueueLimitExceededError,
100100
GenericError(String),
101101
UserFundsUnlocked,
102+
ProofReplaced,
102103
}
103104

104105
impl From<tokio_tungstenite::tungstenite::Error> for SubmitError {
@@ -213,9 +214,9 @@ impl fmt::Display for SubmitError {
213214
write!(f, "Batcher responded with invalid batch inclusion data. Can't verify your proof was correctly included in the batch.")
214215
}
215216
SubmitError::BatchQueueLimitExceededError => {
216-
write!(f, "Error while adding entry to batch, queue limit exeeded.")
217+
write!(f, "Error while adding entry to batch, queue limit exceeded.")
217218
}
218-
219+
SubmitError::ProofReplaced => write!(f, "Proof has been replaced by a higher fee for the same proof"),
219220
SubmitError::GetNonceError(e) => write!(f, "Error while getting nonce {}", e),
220221
SubmitError::UserFundsUnlocked => write!(
221222
f,

crates/sdk/src/common/types.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -454,6 +454,7 @@ pub enum SubmitProofResponseMessage {
454454
UnderpricedProof,
455455
ServerBusy,
456456
UserFundsUnlocked,
457+
ProofReplaced,
457458
}
458459

459460
#[derive(Debug, Clone, Serialize, Deserialize)]

crates/sdk/src/communication/messaging.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,10 @@ async fn handle_batcher_response(msg: Message) -> Result<BatchInclusionData, Sub
279279
error!("User funds have been unlocked and proofs removed from queue. Funds have not been spent.");
280280
Err(SubmitError::UserFundsUnlocked)
281281
}
282+
Ok(SubmitProofResponseMessage::ProofReplaced) => {
283+
error!("Proof has been replaced by a higher fee for the same proof. Funds have not been spent.");
284+
Err(SubmitError::ProofReplaced)
285+
}
282286
Err(e) => {
283287
error!(
284288
"Error while deserializing batch inclusion data: {}. Funds have not been spent.",

0 commit comments

Comments
 (0)