Skip to content

Commit

Permalink
feat: add mev helper params and func
Browse files Browse the repository at this point in the history
  • Loading branch information
irrun committed Jun 13, 2024
1 parent c39283f commit 0166f65
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ require (
replace (
github.com/btcsuite/btcd => github.com/btcsuite/btcd v0.23.0
github.com/cometbft/cometbft => github.com/bnb-chain/greenfield-tendermint v0.0.0-20230417032003-4cda1f296fb2
github.com/ethereum/go-ethereum => github.com/bnb-chain/bsc v1.4.9
github.com/ethereum/go-ethereum => github.com/irrun/bsc v0.0.0-20240613013430-4192215665ec
github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210702154020-550e1cd83ec1
github.com/syndtr/goleveldb v1.0.1 => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
github.com/tendermint/tendermint => github.com/bnb-chain/tendermint v0.31.16
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -945,8 +945,6 @@ github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnweb
github.com/blang/semver/v4 v4.0.0/go.mod h1:IbckMUScFkM3pff0VJDNKRiT6TG/YpiHIM2yvyW5YoQ=
github.com/blizzy78/varnamelen v0.8.0/go.mod h1:V9TzQZ4fLJ1DSrjVDfl89H7aMnTvKkApdHeyESmyR7k=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bnb-chain/bsc v1.4.9 h1:FEr8LIhrp9c+AaoGXpn1fcrINX30d6/aCT+KPBPGz2M=
github.com/bnb-chain/bsc v1.4.9/go.mod h1:WgxebZxrlA8qZYmUN4w3v2HDISSB/acQp/93l5rvgXk=
github.com/bnb-chain/fastssz v0.1.2/go.mod h1:KcabV+OEw2QwgyY8Fc88ZG79CKYkFdu0kKWyfA3dI6o=
github.com/bnb-chain/greenfield-tendermint v0.0.0-20230417032003-4cda1f296fb2 h1:jubavYCs/mCFj/g6Utl+l4SfpykdBdWJFPsvb9FcEXU=
github.com/bnb-chain/greenfield-tendermint v0.0.0-20230417032003-4cda1f296fb2/go.mod h1:9q11eHNRY9FDwFH+4pompzPNGv//Z3VcfvkELaHJPMs=
Expand Down Expand Up @@ -2133,6 +2131,8 @@ github.com/iris-contrib/jade v1.1.4/go.mod h1:EDqR+ur9piDl6DUgs6qRrlfzmlx/D5Uybo
github.com/iris-contrib/pongo2 v0.0.1/go.mod h1:Ssh+00+3GAZqSQb30AvBRNxBx7rf0GqwkjqxNd0u65g=
github.com/iris-contrib/schema v0.0.1/go.mod h1:urYA3uvUNG1TIIjOSCzHr9/LmbQo8LrOcOqfqxa4hXw=
github.com/iris-contrib/schema v0.0.6/go.mod h1:iYszG0IOsuIsfzjymw1kMzTL8YQcCWlm65f3wX8J5iA=
github.com/irrun/bsc v0.0.0-20240613013430-4192215665ec h1:7YDPfla/02qaGKF7y44isarrKWjx5+uZWCc+lj+1bWo=
github.com/irrun/bsc v0.0.0-20240613013430-4192215665ec/go.mod h1:lL8ToOvVrlANTjI4adLcacafWolQjdid5x4v1xiipzE=
github.com/ishidawataru/sctp v0.0.0-20191218070446-00ab2ac2db07/go.mod h1:co9pwDoBCm1kGxawmb4sPq0cSIOOWNPT4KnHotMP1Zg=
github.com/ishidawataru/sctp v0.0.0-20210226210310-f2269e66cdee/go.mod h1:co9pwDoBCm1kGxawmb4sPq0cSIOOWNPT4KnHotMP1Zg=
github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA=
Expand Down
15 changes: 15 additions & 0 deletions node/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ var (
type Validator interface {
SendBid(context.Context, types.BidArgs) (common.Hash, error)
MevRunning() bool
HasBuilder(ctx context.Context, builder common.Address) (bool, error)
BestBidGasFee(ctx context.Context, parentHash common.Hash) (*big.Int, error)
MevParams(ctx context.Context) (*types.MevParams, error)
BuilderFeeCeil() *big.Int
Expand Down Expand Up @@ -135,6 +136,20 @@ func (n *validator) MevRunning() bool {
return atomic.LoadUint32(&n.mevRunning) == 1
}

func (n *validator) HasBuilder(ctx context.Context, builder common.Address) (bool, error) {
has, err := n.client.HasBuilder(ctx, builder)
if err != nil {
metrics.ChainError.Inc()
log.Errorw("failed to check if has builder", "err", err)

if strings.Contains(err.Error(), "timeout") {
err = errors.New("timeout when check if has builder")
}
}

return has, err
}

func (n *validator) refresh() {
chainID, err := n.client.ChainID(context.Background())
if err != nil {
Expand Down
29 changes: 28 additions & 1 deletion service/sentry.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,6 @@ func (s *MevSentry) Running(ctx context.Context) (running bool, err error) {
start := time.Now()
defer recordLatency(method, start)
defer timeoutCancel(&ctx, s.timeout)()
defer timeoutCancel(&ctx, s.timeout)()
defer func() {
if err != nil {
if rpcErr, ok := err.(rpc.Error); ok {
Expand All @@ -194,6 +193,34 @@ func (s *MevSentry) Running(ctx context.Context) (running bool, err error) {
return validator.MevRunning(), nil
}

func (s *MevSentry) HasBuilder(ctx context.Context, builder common.Address) (has bool, err error) {
method := "mev_hasBuilder"
start := time.Now()
defer recordLatency(method, start)
defer timeoutCancel(&ctx, s.timeout)()
defer func() {
if err != nil {
if rpcErr, ok := err.(rpc.Error); ok {
metrics.ApiErrorCounter.WithLabelValues(method, strconv.Itoa(rpcErr.ErrorCode())).Inc()
}
}
}()

hostname := rpc.PeerInfoFromContext(ctx).HTTP.Host
if strings.Contains(hostname, ":") {
hostname = hostname[:strings.Index(hostname, ":")]
}

validator, ok := s.validators[hostname]
if !ok {
log.Errorw("validator not found", "hostname", hostname)
err = types.NewInvalidBidError("validator hostname not found")
return
}

return validator.HasBuilder(ctx, builder)
}

func (s *MevSentry) ReportIssue(ctx context.Context, issue types.BidIssue) (err error) {
method := "mev_reportIssue"
start := time.Now()
Expand Down

0 comments on commit 0166f65

Please sign in to comment.