-
Notifications
You must be signed in to change notification settings - Fork 35
fix(toolkit): emit successful txs from batch-single-tx on partial failure #1731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -249,8 +249,21 @@ impl<C: BuilderContext<DefaultDB>> BuildTxs for BatchSingleTxBuilder<C> { | |
|
|
||
| progress.finish(format!("batch-single-tx: {} succeeded, {} failed", succeeded, failed)); | ||
|
|
||
| // Emit every tx we managed to build, even on partial failure. Discarding the | ||
| // successful txs because a few transfers failed wastes the whole batch and starves | ||
| // downstream load appliers. Only treat a batch with zero successes as an error. | ||
| if failed > 0 { | ||
| return Err(BatchSingleTxError::PartialFailure { succeeded, failed }); | ||
| if succeeded == 0 { | ||
| return Err(BatchSingleTxError::AllFailed { failed }); | ||
| } | ||
|
Comment on lines
+256
to
+258
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When Useful? React with 👍 / 👎. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tiny nit on the warn-message: structured fields above are |
||
| tracing::warn!( | ||
| succeeded = succeeded, | ||
| failed = failed, | ||
| "Partial batch: {} of {} transfers failed; emitting {} successful txs", | ||
| failed, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the new code path worth a test: |
||
| succeeded + failed, | ||
| succeeded | ||
| ); | ||
| } | ||
|
|
||
| Ok(SerializedTxBatches { batches: vec![txs] }) | ||
|
|
@@ -259,6 +272,6 @@ impl<C: BuilderContext<DefaultDB>> BuildTxs for BatchSingleTxBuilder<C> { | |
|
|
||
| #[derive(Debug, thiserror::Error)] | ||
| pub enum BatchSingleTxError { | ||
| #[error("{failed} of {} transfers failed", succeeded + failed)] | ||
| PartialFailure { succeeded: usize, failed: usize }, | ||
| #[error("all {failed} transfers failed")] | ||
| AllFailed { failed: usize }, | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make sure that process returns a valid JSON for downstream instead of playing with error codes here.
As pointed by another comment: 0 of 0 is success, 0 of 1 if failure, but in both cases downstream doesn't have much to work on. It seems that return code alone isn't sufficient here.
Also, is 1 okay out of 250 a success? It hardly seems so to me.
It seems simpler to me if downstream makes decision what is enough for it.