Skip to content

update map_response to parse json string response with quotes#924

Merged
noot merged 1 commit into
developfrom
noot/fix-block-received-parsing
Jun 3, 2026
Merged

update map_response to parse json string response with quotes#924
noot merged 1 commit into
developfrom
noot/fix-block-received-parsing

Conversation

@noot

@noot noot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

📝 Summary

fix unnecessary warning log {message":{"fields":{"err":"Relay error: Unknown relay response, status: 200 OK, body: \"block received\"\n",...}}}, previously the block received response was being turned into a RelayError::UnknownRelayError since the trim() function just removed whitespace but didn't remove the quotes around block received. this now changes it to be Ok(()).

💡 Motivation and Context

log clean up


✅ I have completed the following steps:

  • Run make lint
  • Run make test
  • Added tests (if applicable)

@noot noot requested review from ZanCorDX and dvush as code owners June 2, 2026 20:41
@claude

claude Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Claude finished @noot's task in 58s —— View job


Claude PR Review

  • Load tools
  • Read PR diff
  • Analyze changes for bugs, edge cases, code quality
  • Post review

Review

The fix correctly addresses the bug — bloxroute returns the body as a JSON string literal "block received" (14 bytes including quotes), which fails RelayResponse<()> deserialization and previously fell through to UnknownRelayError because trim() only strips whitespace. Extracting map_response_body to make the logic unit-testable is a nice improvement, and the test coverage for plain/quoted/whitespace-padded/non-200/{} cases is solid.

A few minor observations:

trim_matches('"') is permissivecrates/rbuilder/src/mev_boost/mod.rs:1074

trim_matches('"') strips any number of quotes from either side, so it would also match """block received""", "block received (only opening quote), or block received" (only closing). In practice this is harmless (success-path), but a stricter alternative would be to parse the JSON string properly:

if status == StatusCode::OK {
    let unquoted = serde_json::from_slice::<String>(bytes).ok();
    let candidate = unquoted.as_deref().map(str::trim).unwrap_or(trimmed);
    if candidate == "block received" {
        return Ok(());
    }
}

That said, the current approach is simpler and matches the pragmatic "be liberal in what you accept" style already used here. Fine to leave as-is.

Inner whitespace not handled — if a relay ever returned " block received " (whitespace inside the JSON string), the outer trim() would not strip it (it's inside quotes) and trim_matches('"') would leave the inner spaces. Almost certainly a non-issue, but worth knowing.

Body content unused on errorbytes is borrowed as &[u8] and String::from_utf8_lossy(bytes).to_string() allocates a fresh String even on the happy path before checking trim equalities. Micro-optimization not worth chasing, but from_utf8_lossy(bytes) returns Cow<str> which you could use directly with .trim() without .to_string(). Existing behavior, not introduced by this PR.

No bugs, security, or performance concerns. LGTM.
branch

@noot noot merged commit 8365e13 into develop Jun 3, 2026
7 checks passed
@noot noot deleted the noot/fix-block-received-parsing branch June 3, 2026 17:27
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