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: mev metrics #2317

Merged
merged 3 commits into from
Mar 21, 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
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
Loading