Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: call mev_params before send bid #12

Merged
merged 2 commits into from
Mar 26, 2024
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
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
Loading