eth, miner: query the balances for wonky mev blocks

This commit is contained in:
Péter Szilágyi 2024-03-12 18:51:33 +02:00
parent 607d83e0d5
commit 80e46a6613
2 changed files with 35 additions and 12 deletions

View file

@ -614,7 +614,7 @@ func (api *ConsensusAPI) newPayload(params engine.ExecutableData, versionedHashe
// Share the block with the miner to pull out any relevant stats to previous // Share the block with the miner to pull out any relevant stats to previous
// local block production attempt // local block production attempt
if payload := api.localBlocks.find(block.NumberU64()); payload != nil { if payload := api.localBlocks.find(block.NumberU64()); payload != nil {
api.eth.Miner().ReportFeeMetrics(payload, block) api.eth.Miner().ReportFeeMetrics(payload, block, api.eth.BlockChain())
} }
hash := block.Hash() hash := block.Hash()
return engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &hash}, nil return engine.PayloadStatusV1{Status: engine.VALID, LatestValidHash: &hash}, nil

View file

@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/metrics" "github.com/ethereum/go-ethereum/metrics"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
"github.com/holiman/uint256"
) )
// Backend wraps all methods required for mining. Only full node is capable // Backend wraps all methods required for mining. Only full node is capable
@ -168,7 +169,7 @@ func (miner *Miner) getPending() *newPayloadResult {
// ReportFeeMetrics injects a few miner metrics based on live blocks matched with // ReportFeeMetrics injects a few miner metrics based on live blocks matched with
// previously locally proposed blocks. // previously locally proposed blocks.
func (miner *Miner) ReportFeeMetrics(payload *Payload, block *types.Block) { func (miner *Miner) ReportFeeMetrics(payload *Payload, block *types.Block, chain *core.BlockChain) {
// Skip everything if something's screwy being sent to us // Skip everything if something's screwy being sent to us
if payload.full == nil { if payload.full == nil {
return return
@ -203,12 +204,23 @@ func (miner *Miner) ReportFeeMetrics(payload *Payload, block *types.Block) {
log.Info("MEV block detected", "reward", mevInEther, "local", feeInEther) log.Info("MEV block detected", "reward", mevInEther, "local", feeInEther)
blockIncludedFeeGauge.Update(new(big.Int).Div(payout.Value(), bigGwei).Int64()) blockIncludedFeeGauge.Update(new(big.Int).Div(payout.Value(), bigGwei).Int64())
} else { } else {
// Possibly not an MEV block, report the boring mining fees // Possibly not an MEV block, pull in the balance change and report that
// TODO(karalabe): This is wrong, should do a block trace since our pool is not the same a the block parent := chain.GetBlock(block.ParentHash(), block.NumberU64()-1)
feeInEther := new(big.Float).Quo(new(big.Float).SetInt(payload.fullFees), big.NewFloat(params.Ether)) if parent != nil {
oldState, oerr := chain.StateAt(parent.Root())
newState, nerr := chain.StateAt(block.Root())
log.Info("Plain block detected", "reward", feeInEther) if oerr == nil && nerr == nil {
blockIncludedFeeGauge.Update(new(big.Int).Div(payload.fullFees, bigGwei).Int64()) balanceDiff := new(uint256.Int).Sub(newState.GetBalance(block.Coinbase()), oldState.GetBalance(block.Coinbase()))
diffInEther := new(big.Float).Quo(new(big.Float).SetInt(balanceDiff.ToBig()), big.NewFloat(params.Ether))
feeInEther := new(big.Float).Quo(new(big.Float).SetInt(payload.fullFees), big.NewFloat(params.Ether))
log.Info("Plain block detected", "reward", diffInEther, "local", feeInEther)
blockIncludedFeeGauge.Update(new(big.Int).Div(balanceDiff.ToBig(), bigGwei).Int64())
} else {
log.Error("Missing state for reward metric", "old", oerr, "new", nerr)
}
}
} }
} }
} else if payload.full.Coinbase() != block.Coinbase() { } else if payload.full.Coinbase() != block.Coinbase() {
@ -224,12 +236,23 @@ func (miner *Miner) ReportFeeMetrics(payload *Payload, block *types.Block) {
log.Info("MEV reward received", "reward", mevInEther, "local", feeInEther) log.Info("MEV reward received", "reward", mevInEther, "local", feeInEther)
blockIncludedFeeGauge.Update(new(big.Int).Div(payout.Value(), bigGwei).Int64()) blockIncludedFeeGauge.Update(new(big.Int).Div(payout.Value(), bigGwei).Int64())
} else { } else {
// Unknown MEV block, report the boring mining fees // Unknown MEV block, pull in the balance change and report that
// TODO(karalabe): This is wrong, should do a block trace since our pool is not the same a the block parent := chain.GetBlock(block.ParentHash(), block.NumberU64()-1)
feeInEther := new(big.Float).Quo(new(big.Float).SetInt(payload.fullFees), big.NewFloat(params.Ether)) if parent != nil {
oldState, oerr := chain.StateAt(parent.Root())
newState, nerr := chain.StateAt(block.Root())
log.Warn("MEV block detected, unknown reward", "reward", "unknown", "local", feeInEther) if oerr == nil && nerr == nil {
blockIncludedFeeGauge.Update(new(big.Int).Div(payload.fullFees, bigGwei).Int64()) balanceDiff := new(uint256.Int).Sub(newState.GetBalance(payload.full.Coinbase()), oldState.GetBalance(payload.full.Coinbase()))
diffInEther := new(big.Float).Quo(new(big.Float).SetInt(balanceDiff.ToBig()), big.NewFloat(params.Ether))
feeInEther := new(big.Float).Quo(new(big.Float).SetInt(payload.fullFees), big.NewFloat(params.Ether))
log.Info("MEV hidden reward received", "reward", diffInEther, "local", feeInEther)
blockIncludedFeeGauge.Update(new(big.Int).Div(balanceDiff.ToBig(), bigGwei).Int64())
} else {
log.Error("Missing state for reward metric", "old", oerr, "new", nerr)
}
}
} }
} }
} else { } else {