From f467c6018b3716845a99f681485788ed69a73689 Mon Sep 17 00:00:00 2001 From: irrun Date: Thu, 13 Jun 2024 11:13:39 +0800 Subject: [PATCH] feat: add mev helper params and func (#2512) --- core/types/bid.go | 2 ++ eth/api_backend.go | 4 ++++ ethclient/ethclient.go | 7 +++++++ internal/ethapi/api_mev.go | 4 ++++ internal/ethapi/api_test.go | 3 ++- internal/ethapi/backend.go | 2 ++ internal/ethapi/transaction_args_test.go | 3 ++- miner/miner_mev.go | 8 ++++++++ 8 files changed, 31 insertions(+), 2 deletions(-) diff --git a/core/types/bid.go b/core/types/bid.go index e65ab0f00..d2b9a073f 100644 --- a/core/types/bid.go +++ b/core/types/bid.go @@ -193,5 +193,7 @@ type MevParams struct { ValidatorCommission uint64 // 100 means 1% BidSimulationLeftOver time.Duration GasCeil uint64 + GasPrice *big.Int // Minimum avg gas price for bid block BuilderFeeCeil *big.Int + Version string } diff --git a/eth/api_backend.go b/eth/api_backend.go index 840824039..ae698ade3 100644 --- a/eth/api_backend.go +++ b/eth/api_backend.go @@ -484,6 +484,10 @@ func (b *EthAPIBackend) RemoveBuilder(builder common.Address) error { return b.Miner().RemoveBuilder(builder) } +func (b *EthAPIBackend) HasBuilder(builder common.Address) bool { + return b.Miner().HasBuilder(builder) +} + func (b *EthAPIBackend) SendBid(ctx context.Context, bid *types.BidArgs) (common.Hash, error) { return b.Miner().SendBid(ctx, bid) } diff --git a/ethclient/ethclient.go b/ethclient/ethclient.go index 521add7e9..60879ce27 100644 --- a/ethclient/ethclient.go +++ b/ethclient/ethclient.go @@ -752,6 +752,13 @@ func (ec *Client) MevRunning(ctx context.Context) (bool, error) { return result, err } +// HasBuilder returns whether the builder is registered +func (ec *Client) HasBuilder(ctx context.Context, address common.Address) (bool, error) { + var result bool + err := ec.c.CallContext(ctx, &result, "mev_hasBuilder", address) + return result, err +} + // SendBid sends a bid func (ec *Client) SendBid(ctx context.Context, args types.BidArgs) (common.Hash, error) { var hash common.Hash diff --git a/internal/ethapi/api_mev.go b/internal/ethapi/api_mev.go index 057b6a3dc..1f2331f99 100644 --- a/internal/ethapi/api_mev.go +++ b/internal/ethapi/api_mev.go @@ -87,6 +87,10 @@ func (m *MevAPI) Params() *types.MevParams { return m.b.MevParams() } +func (m *MevAPI) HasBuilder(builder common.Address) bool { + return m.b.HasBuilder(builder) +} + // Running returns true if mev is running func (m *MevAPI) Running() bool { return m.b.MevRunning() diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index d1c05797f..8764f51fb 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -650,7 +650,8 @@ func (b testBackend) ServiceFilter(ctx context.Context, session *bloombits.Match panic("implement me") } -func (b *testBackend) MevRunning() bool { return false } +func (b *testBackend) MevRunning() bool { return false } +func (b *testBackend) HasBuilder(builder common.Address) bool { return false } func (b *testBackend) MevParams() *types.MevParams { return &types.MevParams{} } diff --git a/internal/ethapi/backend.go b/internal/ethapi/backend.go index 114f61fb1..fd778a3f6 100644 --- a/internal/ethapi/backend.go +++ b/internal/ethapi/backend.go @@ -115,6 +115,8 @@ type Backend interface { AddBuilder(builder common.Address, builderUrl string) error // RemoveBuilder removes a builder from the bid simulator. RemoveBuilder(builder common.Address) error + // HasBuilder returns true if the builder is in the builder list. + HasBuilder(builder common.Address) bool // SendBid receives bid from the builders. SendBid(ctx context.Context, bid *types.BidArgs) (common.Hash, error) // BestBidGasFee returns the gas fee of the best bid for the given parent hash. diff --git a/internal/ethapi/transaction_args_test.go b/internal/ethapi/transaction_args_test.go index 9079743ba..a4b758acf 100644 --- a/internal/ethapi/transaction_args_test.go +++ b/internal/ethapi/transaction_args_test.go @@ -416,7 +416,8 @@ func (b *backendMock) SubscribeRemovedLogsEvent(ch chan<- core.RemovedLogsEvent) func (b *backendMock) Engine() consensus.Engine { return nil } -func (b *backendMock) MevRunning() bool { return false } +func (b *backendMock) MevRunning() bool { return false } +func (b *backendMock) HasBuilder(builder common.Address) bool { return false } func (b *backendMock) MevParams() *types.MevParams { return &types.MevParams{} } diff --git a/miner/miner_mev.go b/miner/miner_mev.go index f4ced7f8d..4622cf640 100644 --- a/miner/miner_mev.go +++ b/miner/miner_mev.go @@ -9,6 +9,7 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/params" ) type BuilderConfig struct { @@ -59,6 +60,11 @@ func (miner *Miner) RemoveBuilder(builderAddr common.Address) error { return miner.bidSimulator.RemoveBuilder(builderAddr) } +// HasBuilder returns true if the builder is in the builder list. +func (miner *Miner) HasBuilder(builder common.Address) bool { + return miner.bidSimulator.ExistBuilder(builder) +} + func (miner *Miner) SendBid(ctx context.Context, bidArgs *types.BidArgs) (common.Hash, error) { builder, err := bidArgs.EcrecoverSender() if err != nil { @@ -117,6 +123,8 @@ func (miner *Miner) MevParams() *types.MevParams { ValidatorCommission: miner.worker.config.Mev.ValidatorCommission, BidSimulationLeftOver: miner.worker.config.Mev.BidSimulationLeftOver, GasCeil: miner.worker.config.GasCeil, + GasPrice: miner.worker.config.GasPrice, BuilderFeeCeil: builderFeeCeil, + Version: params.Version, } }