Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions miner/bid_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ import (
"github.com/ethereum/go-ethereum/rpc"
)

const (
// maxBidPerBuilderPerBlock is the max bid number per builder
maxBidPerBuilderPerBlock = 3
)

var (
bidSimTimer = metrics.NewRegisteredTimer("bid/sim/duration", nil)
)
Expand Down Expand Up @@ -118,6 +113,8 @@ type bidSimulator struct {

simBidMu sync.RWMutex
simulatingBid map[common.Hash]*BidRuntime // prevBlockHash -> bidRuntime, in the process of simulation

maxBidsPerBuilder uint32 // Maximum number of bids allowed per builder per block
}

func newBidSimulator(
Expand All @@ -129,24 +126,31 @@ func newBidSimulator(
engine consensus.Engine,
bidWorker bidWorker,
) *bidSimulator {
// Set default value
maxBids := uint32(3)
if config.MaxBidsPerBuilder > 0 {
maxBids = config.MaxBidsPerBuilder
}

b := &bidSimulator{
config: config,
delayLeftOver: delayLeftOver,
minGasPrice: minGasPrice,
chain: eth.BlockChain(),
txpool: eth.TxPool(),
chainConfig: chainConfig,
engine: engine,
bidWorker: bidWorker,
exitCh: make(chan struct{}),
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
builders: make(map[common.Address]*builderclient.Client),
simBidCh: make(chan *simBidReq),
newBidCh: make(chan newBidPackage, 100),
pending: make(map[uint64]map[common.Address]map[common.Hash]struct{}),
bestBid: make(map[common.Hash]*BidRuntime),
bestBidToRun: make(map[common.Hash]*types.Bid),
simulatingBid: make(map[common.Hash]*BidRuntime),
config: config,
delayLeftOver: delayLeftOver,
minGasPrice: minGasPrice,
chain: eth.BlockChain(),
txpool: eth.TxPool(),
chainConfig: chainConfig,
engine: engine,
bidWorker: bidWorker,
maxBidsPerBuilder: maxBids,
exitCh: make(chan struct{}),
chainHeadCh: make(chan core.ChainHeadEvent, chainHeadChanSize),
builders: make(map[common.Address]*builderclient.Client),
simBidCh: make(chan *simBidReq),
newBidCh: make(chan newBidPackage, 100),
pending: make(map[uint64]map[common.Address]map[common.Hash]struct{}),
bestBid: make(map[common.Hash]*BidRuntime),
bestBidToRun: make(map[common.Hash]*types.Bid),
simulatingBid: make(map[common.Hash]*BidRuntime),
}

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

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

return nil
Expand Down
2 changes: 2 additions & 0 deletions miner/minerconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ type MevConfig struct {
ValidatorCommission uint64 // 100 means the validator claims 1% from block reward
BidSimulationLeftOver time.Duration
NoInterruptLeftOver time.Duration
MaxBidsPerBuilder uint32 // Maximum number of bids allowed per builder per block
}

var DefaultMevConfig = MevConfig{
Expand All @@ -86,4 +87,5 @@ var DefaultMevConfig = MevConfig{
ValidatorCommission: 100,
BidSimulationLeftOver: 50 * time.Millisecond,
NoInterruptLeftOver: 400 * time.Millisecond,
MaxBidsPerBuilder: 3,
}