Skip to content

Commit

Permalink
feat: add mev metrics (#2317)
Browse files Browse the repository at this point in the history
  • Loading branch information
Raina authored Mar 21, 2024
1 parent e313d5b commit 22888c8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion miner/bid_simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/event"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/miner/builderclient"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rpc"
Expand All @@ -36,10 +37,12 @@ const (
)

var (
diffInTurn = big.NewInt(2) // the difficulty of a block that proposed by an in-turn validator
bidSimTimer = metrics.NewRegisteredTimer("bid/sim/duration", nil)
)

var (
diffInTurn = big.NewInt(2) // the difficulty of a block that proposed by an in-turn validator

dialer = &net.Dialer{
Timeout: time.Second,
KeepAlive: 60 * time.Second,
Expand Down Expand Up @@ -503,6 +506,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {

// ensure simulation exited then start next simulation
b.SetSimulatingBid(parentHash, bidRuntime)
start := time.Now()

defer func(simStart time.Time) {
logCtx := []any{
Expand Down Expand Up @@ -532,6 +536,7 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {
}

b.RemoveSimulatingBid(parentHash)
bidSimTimer.UpdateSince(start)
}(time.Now())

// prepareWork will configure header with a suitable time according to consensus
Expand Down Expand Up @@ -606,6 +611,8 @@ func (b *bidSimulator) simBid(interruptCh chan int32, bidRuntime *BidRuntime) {

// reportIssue reports the issue to the mev-sentry
func (b *bidSimulator) reportIssue(bidRuntime *BidRuntime, err error) {
metrics.GetOrRegisterCounter(fmt.Sprintf("bid/err/%v", bidRuntime.bid.Builder), nil).Inc(1)

cli := b.builders[bidRuntime.bid.Builder]
if cli != nil {
cli.ReportIssue(context.Background(), &types.BidIssue{
Expand Down
4 changes: 4 additions & 0 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1296,6 +1296,7 @@ LOOP:

// when out-turn, use bestWork to prevent bundle leakage.
// when in-turn, compare with remote work.
from := bestWork.coinbase
if w.bidFetcher != nil && bestWork.header.Difficulty.Cmp(diffInTurn) == 0 {
bestBid := w.bidFetcher.GetBestBid(bestWork.header.ParentHash)

Expand All @@ -1307,10 +1308,13 @@ LOOP:
// blockReward(benefits delegators) and validatorReward(benefits the validator) are both optimal
if localValidatorReward.CmpBig(bestBid.packedValidatorReward) < 0 {
bestWork = bestBid.env
from = bestBid.bid.Builder
}
}
}

metrics.GetOrRegisterCounter(fmt.Sprintf("block/from/%v", from), nil).Inc(1)

w.commit(bestWork, w.fullTaskHook, true, start)

// Swap out the old work with the new one, terminating any leftover
Expand Down

0 comments on commit 22888c8

Please sign in to comment.