Skip to content

Commit

Permalink
feat: add mev ethclient
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun committed Mar 7, 2024
1 parent 0fd52bb commit 2dd66e6
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion eth/api_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ func (b *EthAPIBackend) MevRunning() bool {
return b.Miner().MevRunning()
}

func (b *EthAPIBackend) MevParams() types.MevParams {
func (b *EthAPIBackend) MevParams() *types.MevParams {
return b.Miner().MevParams()
}

Expand Down
20 changes: 20 additions & 0 deletions ethclient/ethclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,26 @@ func (ec *Client) SendBid(ctx context.Context, args types.BidArgs) (common.Hash,
return hash, nil
}

// BestBidGasFee returns the gas fee of the best bid for the given parent hash.
func (ec *Client) BestBidGasFee(ctx context.Context, parentHash common.Hash) (*big.Int, error) {
var fee *big.Int
err := ec.c.CallContext(ctx, &fee, "mev_bestBidGasFee", parentHash)
if err != nil {
return nil, err
}
return fee, nil
}

// MevParams returns the static params of mev
func (ec *Client) MevParams(ctx context.Context) (*types.MevParams, error) {
var params types.MevParams
err := ec.c.CallContext(ctx, &params, "mev_params")
if err != nil {
return nil, err
}
return &params, err
}

func toBlockNumArg(number *big.Int) string {
if number == nil {
return "latest"
Expand Down
6 changes: 3 additions & 3 deletions internal/ethapi/api_mev.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func NewMevAPI(b Backend) *MevAPI {
// SendBid receives bid from the builders.
// If mev is not running or bid is invalid, return error.
// Otherwise, creates a builder bid for the given argument, submit it to the miner.
func (m *MevAPI) SendBid(ctx context.Context, args types.BidArgs) (common.Hash, error) {
func (m *MevAPI) SendBid(ctx context.Context, args *types.BidArgs) (common.Hash, error) {
if !m.b.MevRunning() {
return common.Hash{}, types.ErrMevNotRunning
}
Expand Down Expand Up @@ -94,14 +94,14 @@ func (m *MevAPI) SendBid(ctx context.Context, args types.BidArgs) (common.Hash,
}
}

return m.b.SendBid(ctx, &args)
return m.b.SendBid(ctx, args)
}

func (m *MevAPI) BestBidGasFee(_ context.Context, parentHash common.Hash) *big.Int {
return m.b.BestBidGasFee(parentHash)
}

func (m *MevAPI) Params() types.MevParams {
func (m *MevAPI) Params() *types.MevParams {
return m.b.MevParams()
}

Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,8 @@ func (b testBackend) ServiceFilter(ctx context.Context, session *bloombits.Match
}

func (b *testBackend) MevRunning() bool { return false }
func (b *testBackend) MevParams() types.MevParams {
return types.MevParams{}
func (b *testBackend) MevParams() *types.MevParams {
return &types.MevParams{}
}
func (b *testBackend) StartMev() {}
func (b *testBackend) StopMev() {}
Expand Down
2 changes: 1 addition & 1 deletion internal/ethapi/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ type Backend interface {
// MevRunning return true if mev is running
MevRunning() bool
// MevParams returns the static params of mev
MevParams() types.MevParams
MevParams() *types.MevParams
// StartMev starts mev
StartMev()
// StopMev stops mev
Expand Down
4 changes: 2 additions & 2 deletions internal/ethapi/transaction_args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +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) MevParams() types.MevParams {
return types.MevParams{}
func (b *backendMock) MevParams() *types.MevParams {
return &types.MevParams{}
}
func (b *backendMock) StartMev() {}
func (b *backendMock) StopMev() {}
Expand Down
8 changes: 4 additions & 4 deletions miner/miner_mev.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ var DefaultMevConfig = MevConfig{
SentryURL: "",
Builders: nil,
ValidatorCommission: 100,
BidSimulationLeftOver: 100 * time.Millisecond,
BidSimulationLeftOver: 50 * time.Millisecond,
}

// MevRunning return true if mev is running.
Expand Down Expand Up @@ -97,14 +97,14 @@ func (miner *Miner) SendBid(ctx context.Context, bidArgs *types.BidArgs) (common
func (miner *Miner) BestPackedBlockReward(parentHash common.Hash) *big.Int {
bidRuntime := miner.bidSimulator.GetBestBid(parentHash)
if bidRuntime == nil {
return nil
return big.NewInt(0)
}

return bidRuntime.packedBlockReward
}

func (miner *Miner) MevParams() types.MevParams {
return types.MevParams{
func (miner *Miner) MevParams() *types.MevParams {
return &types.MevParams{
ValidatorCommission: miner.worker.config.Mev.ValidatorCommission,
BidSimulationLeftOver: miner.worker.config.Mev.BidSimulationLeftOver,
}
Expand Down

0 comments on commit 2dd66e6

Please sign in to comment.