Skip to content
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

Return both error and success responses from a broadcast #27

Merged
merged 1 commit into from
Dec 7, 2023

Conversation

hazim-j
Copy link
Contributor

@hazim-j hazim-j commented Dec 6, 2023

Thanks for the amazing work on this package @metachris and also @TitanBuilder for adding the broadcaster middleware in #19.

We are currently trying to integrate flashbotsrpc into stackup-bundler to enable broadcasting of ERC-4337 UserOperations to a list of known builders. I ran into some issues with error handling which I think this PR would fix.

In a success scenario, if I broadcast a batch to 3 builders with no errors, I would expect a response like this:

{BundleResponse:{BundleHash:0x48529d4d335ffe9a0cc322edb7f8e78585ee0587eb346d6e54a884ed4bea6970} Err:<nil>}
{BundleResponse:{BundleHash:0x0923989048a5efaa098d75ce4d281335d086beea70b5085e71ead16a4a6958c2} Err:<nil>}
{BundleResponse:{BundleHash:0xbd7dd6a2c84900ab933686e418c85cd520b991f36277553e34365444e0e31941} Err:<nil>}

But in the case where one builder returns an error, we end up with a response like this:

{BundleResponse:{BundleHash:} Err:...}
{BundleResponse:{BundleHash:} Err:unexpected end of JSON input}

In this case the error from a bad builder is causing all the successful responses to be thrown away and we are adding an additional response with the error unexpected end of JSON input. Ideally the response should look like this:

{BundleResponse:{BundleHash:0x48529d4d335ffe9a0cc322edb7f8e78585ee0587eb346d6e54a884ed4bea6970} Err:<nil>}
{BundleResponse:{BundleHash:} Err:...}
{BundleResponse:{BundleHash:0xbd7dd6a2c84900ab933686e418c85cd520b991f36277553e34365444e0e31941} Err:<nil>}

The reason for this, which I address in the PR, is because:

  1. In the first loop we exit on error rather than continuing to process all other remaining HTTP responses.
  2. In the second loop we try to json.Unmarshal an error response with a nil msg which is causing the additional unexpected end of JSON input error.

@metachris
Copy link
Owner

lgtm. any comment @TitanBuilder ?

@metachris metachris merged commit aec8186 into metachris:master Dec 7, 2023
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants