Skip to content

Commit f9dc640

Browse files
authored
mev: make max bids per builder per block configurable (bnb-chain#3001)
1 parent 6de5d7b commit f9dc640

File tree

2 files changed

+30
-24
lines changed

2 files changed

+30
-24
lines changed

miner/bid_simulator.go

Lines changed: 28 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@ import (
3131
"github.com/ethereum/go-ethereum/rpc"
3232
)
3333

34-
const (
35-
// maxBidPerBuilderPerBlock is the max bid number per builder
36-
maxBidPerBuilderPerBlock = 3
37-
)
38-
3934
var (
4035
bidSimTimer = metrics.NewRegisteredTimer("bid/sim/duration", nil)
4136
)
@@ -118,6 +113,8 @@ type bidSimulator struct {
118113

119114
simBidMu sync.RWMutex
120115
simulatingBid map[common.Hash]*BidRuntime // prevBlockHash -> bidRuntime, in the process of simulation
116+
117+
maxBidsPerBuilder uint32 // Maximum number of bids allowed per builder per block
121118
}
122119

123120
func newBidSimulator(
@@ -129,24 +126,31 @@ func newBidSimulator(
129126
engine consensus.Engine,
130127
bidWorker bidWorker,
131128
) *bidSimulator {
129+
// Set default value
130+
maxBids := uint32(3)
131+
if config.MaxBidsPerBuilder > 0 {
132+
maxBids = config.MaxBidsPerBuilder
133+
}
134+
132135
b := &bidSimulator{
133-
config: config,
134-
delayLeftOver: delayLeftOver,
135-
minGasPrice: minGasPrice,
136-
chain: eth.BlockChain(),
137-
txpool: eth.TxPool(),
138-
chainConfig: chainConfig,
139-
engine: engine,
140-
bidWorker: bidWorker,
141-
exitCh: make(chan struct{}),
142-
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
143-
builders: make(map[common.Address]*builderclient.Client),
144-
simBidCh: make(chan *simBidReq),
145-
newBidCh: make(chan newBidPackage, 100),
146-
pending: make(map[uint64]map[common.Address]map[common.Hash]struct{}),
147-
bestBid: make(map[common.Hash]*BidRuntime),
148-
bestBidToRun: make(map[common.Hash]*types.Bid),
149-
simulatingBid: make(map[common.Hash]*BidRuntime),
136+
config: config,
137+
delayLeftOver: delayLeftOver,
138+
minGasPrice: minGasPrice,
139+
chain: eth.BlockChain(),
140+
txpool: eth.TxPool(),
141+
chainConfig: chainConfig,
142+
engine: engine,
143+
bidWorker: bidWorker,
144+
maxBidsPerBuilder: maxBids,
145+
exitCh: make(chan struct{}),
146+
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
147+
builders: make(map[common.Address]*builderclient.Client),
148+
simBidCh: make(chan *simBidReq),
149+
newBidCh: make(chan newBidPackage, 100),
150+
pending: make(map[uint64]map[common.Address]map[common.Hash]struct{}),
151+
bestBid: make(map[common.Hash]*BidRuntime),
152+
bestBidToRun: make(map[common.Hash]*types.Bid),
153+
simulatingBid: make(map[common.Hash]*BidRuntime),
150154
}
151155

152156
b.chainHeadSub = b.chain.SubscribeChainHeadEvent(b.chainHeadCh)
@@ -577,8 +581,8 @@ func (b *bidSimulator) CheckPending(blockNumber uint64, builder common.Address,
577581
return errors.New("bid already exists")
578582
}
579583

580-
if len(b.pending[blockNumber][builder]) >= maxBidPerBuilderPerBlock {
581-
return errors.New("too many bids")
584+
if len(b.pending[blockNumber][builder]) >= int(b.maxBidsPerBuilder) {
585+
return fmt.Errorf("too many bids: exceeded limit of %d bids per builder per block", b.maxBidsPerBuilder)
582586
}
583587

584588
return nil

miner/minerconfig/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ type MevConfig struct {
7676
ValidatorCommission uint64 // 100 means the validator claims 1% from block reward
7777
BidSimulationLeftOver time.Duration
7878
NoInterruptLeftOver time.Duration
79+
MaxBidsPerBuilder uint32 // Maximum number of bids allowed per builder per block
7980
}
8081

8182
var DefaultMevConfig = MevConfig{
@@ -86,4 +87,5 @@ var DefaultMevConfig = MevConfig{
8687
ValidatorCommission: 100,
8788
BidSimulationLeftOver: 50 * time.Millisecond,
8889
NoInterruptLeftOver: 400 * time.Millisecond,
90+
MaxBidsPerBuilder: 3,
8991
}

0 commit comments

Comments
 (0)