Skip to content

Commit c10f3dc

Browse files
authored
internal/ethapi: improve error msg when refusing bids (bnb-chain#3131)
1 parent 553c281 commit c10f3dc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

internal/ethapi/api_mev.go

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,29 @@ func (m *MevAPI) SendBid(ctx context.Context, args types.BidArgs) (common.Hash,
2929
return common.Hash{}, types.ErrMevNotRunning
3030
}
3131

32-
if !m.b.MinerInTurn() {
33-
return common.Hash{}, types.ErrMevNotInTurn
34-
}
35-
3632
var (
3733
rawBid = args.RawBid
38-
currentHeader = m.b.CurrentHeader()
34+
currentHeader = m.b.CurrentHeader() // `currentHeader` might change during use.
3935
)
4036

4137
if rawBid == nil {
4238
return common.Hash{}, types.NewInvalidBidError("rawBid should not be nil")
4339
}
4440

4541
// only support bidding for the next block not for the future block
46-
if rawBid.BlockNumber != currentHeader.Number.Uint64()+1 {
47-
return common.Hash{}, types.NewInvalidBidError("stale block number or block in future")
42+
if latestBlockNumber := currentHeader.Number.Uint64(); rawBid.BlockNumber < latestBlockNumber+1 {
43+
return common.Hash{}, types.NewInvalidBidError(
44+
fmt.Sprintf("stale block number: %d, latest block: %d", rawBid.BlockNumber, latestBlockNumber))
45+
} else if rawBid.BlockNumber > latestBlockNumber+1 {
46+
// For the first block of a validator's turn, the previous block must be imported first.
47+
// If a builder sends bids before the import is complete, the following error message will be returned.
48+
// However, this is not a significant issue because:
49+
// a. Each turn consists of 16 blocks, so this situation can only occur at most 1/16 of the time.
50+
// b. Each builder is allowed to submit multiple bids for each block.
51+
return common.Hash{}, types.NewInvalidBidError(
52+
fmt.Sprintf("block in future: %d, latest block: %d", rawBid.BlockNumber, latestBlockNumber))
53+
} else if !m.b.MinerInTurn() {
54+
return common.Hash{}, types.ErrMevNotInTurn
4855
}
4956

5057
if rawBid.ParentHash != currentHeader.Hash() {

0 commit comments

Comments
 (0)