Skip to content

internal/ethapi: improve error msg when refusing bids#3131

Merged
zzzckck merged 1 commit intobnb-chain:developfrom
buddh0:improve-error-msg-when-refusing-bids
May 29, 2025
Merged

internal/ethapi: improve error msg when refusing bids#3131
zzzckck merged 1 commit intobnb-chain:developfrom
buddh0:improve-error-msg-when-refusing-bids

Conversation

@buddh0
Copy link
Copy Markdown
Contributor

@buddh0 buddh0 commented May 29, 2025

Description

internal/ethapi: improve error msg when refusing bids

Rationale

  1. send too early or too late is very different scenario, return different error msg here,
    It will be helpful for builders.
  2. when rawBid.BlockNumber > latestBlockNumber+1,
    without this PR, error msg will be ErrMevNotInTurn, this PR fix it.

Example

add an example CLI or API response...

Changes

Notable changes:

  • add each change in a bullet point here
  • ...

@buddh0 buddh0 marked this pull request as ready for review May 29, 2025 02:38
@zzzckck zzzckck requested a review from Copilot May 29, 2025 08:41
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refines error handling in SendBid by distinguishing between bids for stale blocks, future blocks, and out-of-turn bids.

  • Introduce explicit error messages for stale and future block numbers
  • Shift MinerInTurn check to after block-number validation
  • Retain existing nil-bid guard and parent-hash validation
Comments suppressed due to low confidence (4)

internal/ethapi/api_mev.go:42

  • Add unit tests covering the new 'stale block number' branch to ensure the error message and type are returned correctly when BlockNumber < latestBlockNumber+1.
if latestBlockNumber := currentHeader.Number.Uint64(); rawBid.BlockNumber < latestBlockNumber+1 {

internal/ethapi/api_mev.go:45

  • Add unit tests for the 'block in future' branch so builders get the intended error when BlockNumber > latestBlockNumber+1.
} else if rawBid.BlockNumber > latestBlockNumber+1 {

internal/ethapi/api_mev.go:52

  • [nitpick] Consider rephrasing to 'future block number: %d (latest: %d)' or capitalizing the message and ending with a period for consistency with other errors.
fmt.Sprintf("block in future: %d, latest block: %d", rawBid.BlockNumber, latestBlockNumber)

internal/ethapi/api_mev.go:53

  • Relocating the MinerInTurn check changes error prioritization—ensure that returning block-number errors before out-of-turn errors matches intended UX and downstream logic.
} else if !m.b.MinerInTurn() {

return common.Hash{}, types.NewInvalidBidError(
fmt.Sprintf("stale block number: %d, latest block: %d", rawBid.BlockNumber, latestBlockNumber))
} else if rawBid.BlockNumber > latestBlockNumber+1 {
// For the first block of a validator's turn, the previous block must be imported first.
Copy link

Copilot AI May 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The multi-line comment explaining turn import timing is quite detailed; consider condensing it or moving to higher-level documentation to keep the code path focused.

Copilot uses AI. Check for mistakes.
@zzzckck zzzckck merged commit c10f3dc into bnb-chain:develop May 29, 2025
7 checks passed
sysvm pushed a commit to sysvm/bsc that referenced this pull request Jun 16, 2025
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.

4 participants