From 22888c87254630fe39d6e26b25cfd035162edd83 Mon Sep 17 00:00:00 2001 From: Raina Date: Thu, 21 Mar 2024 15:03:35 +0800 Subject: [PATCH] feat: add mev metrics (#2317) --- miner/bid_simulator.go | 9 ++++++++- miner/worker.go | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/miner/bid_simulator.go b/miner/bid_simulator.go index 51dcf58355..b3cc20c4ab 100644 --- a/miner/bid_simulator.go +++ b/miner/bid_simulator.go @@ -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" @@ -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, @@ -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{ @@ -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 @@ -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{ diff --git a/miner/worker.go b/miner/worker.go index ba5afdf41f..f5f954880d 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -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) @@ -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