Skip to content

Commit

Permalink
feat: call mev_params before send bid (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun authored Mar 26, 2024
1 parent 845fbc7 commit dbf64eb
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
28 changes: 24 additions & 4 deletions miner/bidder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@ type ValidatorConfig struct {
URL string
}

type validator struct {
*validatorclient.Client
BidSimulationLeftOver time.Duration
GasCeil uint64
}

type Bidder struct {
config *MevConfig
delayLeftOver time.Duration
engine consensus.Engine
chain *core.BlockChain

validators map[common.Address]*validatorclient.Client // validator address -> validatorclient.Client
validators map[common.Address]*validator // address -> validator

bestWorksMu sync.RWMutex
bestWorks map[int64]*environment
Expand All @@ -50,7 +56,7 @@ func NewBidder(config *MevConfig, delayLeftOver time.Duration, engine consensus.
delayLeftOver: delayLeftOver,
engine: engine,
chain: eth.BlockChain(),
validators: make(map[common.Address]*validatorclient.Client),
validators: make(map[common.Address]*validator),
bestWorks: make(map[int64]*environment),
newBidCh: make(chan *environment, 10),
exitCh: make(chan struct{}),
Expand All @@ -74,7 +80,17 @@ func NewBidder(config *MevConfig, delayLeftOver time.Duration, engine consensus.
continue
}

b.validators[v.Address] = cl
params, err := cl.MevParams(context.Background())
if err != nil {
log.Error("Bidder: failed to get mev params", "url", v.URL, "err", err)
continue
}

b.validators[v.Address] = &validator{
Client: cl,
BidSimulationLeftOver: params.BidSimulationLeftOver,
GasCeil: params.GasCeil,
}
}

if len(b.validators) == 0 {
Expand Down Expand Up @@ -107,8 +123,12 @@ func (b *Bidder) mainLoop() {

bidNum = 0
parentHeader := b.chain.GetHeaderByHash(work.header.ParentHash)
var bidSimulationLeftOver time.Duration
if b.validators[work.coinbase] != nil {
bidSimulationLeftOver = b.validators[work.coinbase].BidSimulationLeftOver
}
betterBidBefore = bidutil.BidBetterBefore(parentHeader, b.chain.Config().Parlia.Period, b.delayLeftOver,
b.config.BidSimulationLeftOver)
bidSimulationLeftOver)

if time.Now().After(betterBidBefore) {
timer.Reset(0)
Expand Down
4 changes: 4 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,10 @@ func (w *worker) commitWork(interruptCh chan int32, timestamp int64) {
log.Warn("Consensus engine does not support validator setting")
return
}

if w.bidder.validators[coinbase] != nil {
w.config.GasCeil = w.bidder.validators[coinbase].GasCeil
}
} else {
coinbase = w.etherbase()
if coinbase == (common.Address{}) {
Expand Down

0 comments on commit dbf64eb

Please sign in to comment.