Fix uint64 underflow in getHeader msIntoSlot for requests arriving before slot start#906
Fix uint64 underflow in getHeader msIntoSlot for requests arriving before slot start#906vsaraikin wants to merge 2 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a uint64 underflow in getHeader’s msIntoSlot computation that could incorrectly trigger the late-in-slot guard when a request arrives slightly before slot start, causing mev-boost to skip all relays and return 204 (and corrupting the mev_boost_millisec_into_slot metric). The PR switches to signed arithmetic and clamps negative values to zero, plus adds a regression test to ensure relays are still queried.
Changes:
- Compute
msIntoSlotusing signed subtraction and clamp negative values to0before applying late-in-slot logic. - Add a regression test verifying that an early (pre-slot-start)
getHeaderrequest still queries relays and returns a bid.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
server/get_header.go |
Prevents msIntoSlot underflow by using signed arithmetic and clamping early arrivals to 0ms into slot. |
server/service_test.go |
Adds a regression test for pre-slot-start getHeader requests to ensure relays are still queried. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // setting genesisTime so slot 1 starts one second in the future, | ||
| // making msIntoSlot negative. Without clamping, the unsigned | ||
| // subtraction wraps and the late-in-slot guard skips all relays. | ||
| backend.boost.genesisTime = uint64(time.Now().Unix()) - 11 |
There was a problem hiding this comment.
Good catch — moved the slot start to ~5s in the future so msIntoSlot is reliably negative regardless of the second truncation. Verified the test still fails against the pre-fix code.
Closes #902.
getHeadercomputesmsIntoSlotwith unsigned arithmetic. When the CL's request arrives even 1ms before slot start (sub-ms scheduling jitter between VC and BN is enough), the subtraction wraps to ~2^64, the late-in-slot guard concludes the request is hopelessly late, and mev-boost returns 204 without querying any relay — the proposer silently falls back to a locally built block and loses the MEV reward. The wrapped value also corrupts themev_boost_millisec_into_slotmetric.This computes the value with signed arithmetic and clamps negatives to zero, i.e. treats an early request as arriving exactly at slot start with the full time budget — mirroring how mev-boost-relay handled its analogous underflow.
Complements #900, which fixes the sibling underflow in the timing-games delay path but is not reached in this scenario: with a wrapped
msIntoSlotthe late-in-slot guard returns before timing games run.Adds a regression test: a getHeader request arriving before slot start must still query relays and return the bid.