From 283235b4e961c51af548dae52d204babb81f6ed5 Mon Sep 17 00:00:00 2001 From: Alok Date: Tue, 24 Dec 2024 03:02:47 +0530 Subject: [PATCH 1/5] fix: validator check lag --- .../templates/jobs/mev-commit.nomad.j2 | 1 + p2p/cmd/main.go | 8 +++++++ p2p/pkg/node/node.go | 20 +++++++++++----- p2p/pkg/rpc/validator/service.go | 24 ++++++++++++++++--- p2p/pkg/rpc/validator/service_test.go | 21 ++++++++++++---- 5 files changed, 61 insertions(+), 13 deletions(-) diff --git a/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 b/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 index c238c43fc..eb6c9dddc 100644 --- a/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 +++ b/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 @@ -83,6 +83,7 @@ job "{{ job.name }}" { data = <<-EOH MEV_COMMIT_LOG_FMT="{{ job.env.get('log-format', 'json') }}" MEV_COMMIT_LOG_TAGS="{{ 'service.name:' + job.name + '-{{ env "NOMAD_ALLOC_INDEX" }}' + ',service.version:' + version }}" + MEV_ORACLE_LAGGERD_MODE="{{ job.env.get('laggerd-mode', '10') }}" MEV_COMMIT_OTEL_COLLECTOR_ENDPOINT_URL="{{ job.env.get('otel_collector_endpoint_url', '') }}" {%- raw %} MEV_COMMIT_KEYSTORE_PATH="/local/data-{{ env "NOMAD_ALLOC_INDEX" }}/keystore" diff --git a/p2p/cmd/main.go b/p2p/cmd/main.go index 64b71a980..1ef9bbe9a 100644 --- a/p2p/cmd/main.go +++ b/p2p/cmd/main.go @@ -430,6 +430,13 @@ var ( Value: 30 * time.Second, Category: categoryProvider, }) + + optionLaggerdMode = altsrc.NewIntFlag(&cli.IntFlag{ + Name: "laggerd-mode", + Usage: "No of blocks to lag behind for L1 chain", + EnvVars: []string{"MEV_COMMIT_LAGGERD_MODE"}, + Value: 10, + }) ) func main() { @@ -649,6 +656,7 @@ func launchNodeWithConfig(c *cli.Context) (err error) { OracleWindowOffset: big.NewInt(defaultOracleWindowOffset), BeaconAPIURL: c.String(optionBeaconAPIURL.Name), L1RPCURL: c.String(optionL1RPCURL.Name), + LaggeredMode: c.Int(optionLaggerdMode.Name), BidderBidTimeout: c.Duration(optionBidderBidTimeout.Name), ProviderDecisionTimeout: c.Duration(optionProviderDecisionTimeout.Name), }) diff --git a/p2p/pkg/node/node.go b/p2p/pkg/node/node.go index 6102284a6..27659979b 100644 --- a/p2p/pkg/node/node.go +++ b/p2p/pkg/node/node.go @@ -101,6 +101,7 @@ type Options struct { OracleWindowOffset *big.Int BeaconAPIURL string L1RPCURL string + LaggeredMode int BidderBidTimeout time.Duration ProviderDecisionTimeout time.Duration } @@ -416,17 +417,24 @@ func NewNode(opts *Options) (*Node, error) { return nil, err } - validatorRouterSession := &validatorrouter.ValidatoroptinrouterCallerSession{ - Contract: validatorRouterCaller, - CallOpts: bind.CallOpts{ - From: opts.KeySigner.GetAddress(), - }, + callOptsGetter := func() (*bind.CallOpts, error) { + blkNum, err := l1ContractRPC.BlockNumber(context.Background()) + if err != nil { + return nil, err + } + currentBlkNum := big.NewInt(0).SetUint64(blkNum) + queryBlkNum := big.NewInt(0).Sub(currentBlkNum, big.NewInt(int64(opts.LaggeredMode))) + return &bind.CallOpts{ + From: opts.KeySigner.GetAddress(), + BlockNumber: queryBlkNum, + }, nil } validatorAPI := validatorapi.NewService( opts.BeaconAPIURL, - validatorRouterSession, + validatorRouterCaller, opts.Logger.With("component", "validatorapi"), + callOptsGetter, ) validatorapiv1.RegisterValidatorServer(grpcServer, validatorAPI) diff --git a/p2p/pkg/rpc/validator/service.go b/p2p/pkg/rpc/validator/service.go index 80c1d99af..1c40f3d83 100644 --- a/p2p/pkg/rpc/validator/service.go +++ b/p2p/pkg/rpc/validator/service.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common/hexutil" validatoroptinrouter "github.com/primev/mev-commit/contracts-abi/clients/ValidatorOptInRouter" validatorapiv1 "github.com/primev/mev-commit/p2p/gen/go/validatorapi/v1" @@ -18,7 +19,7 @@ import ( ) type ValidatorRouterContract interface { - AreValidatorsOptedIn(valBLSPubKeys [][]byte) ([]validatoroptinrouter.IValidatorOptInRouterOptInStatus, error) + AreValidatorsOptedIn(opts *bind.CallOpts, valBLSPubKeys [][]byte) ([]validatoroptinrouter.IValidatorOptInRouterOptInStatus, error) } type Service struct { @@ -27,14 +28,21 @@ type Service struct { validatorRouter ValidatorRouterContract logger *slog.Logger metrics *metrics + optsGetter func() (*bind.CallOpts, error) } -func NewService(apiURL string, validatorRouter ValidatorRouterContract, logger *slog.Logger) *Service { +func NewService( + apiURL string, + validatorRouter ValidatorRouterContract, + logger *slog.Logger, + optsGetter func() (*bind.CallOpts, error), +) *Service { return &Service{ apiURL: apiURL, validatorRouter: validatorRouter, logger: logger, metrics: newMetrics(), + optsGetter: optsGetter, } } @@ -177,7 +185,17 @@ func (s *Service) processValidators(dutiesResp *ProposerDutiesResponse) (map[uin validatorsKeys = append(validatorsKeys, pubkeyBytes) } - areValidatorsOptedIn, err := s.validatorRouter.AreValidatorsOptedIn(validatorsKeys) + if len(validatorsKeys) == 0 { + return validators, nil + } + + opts, err := s.optsGetter() + if err != nil { + s.logger.Error("getting call opts", "error", err) + return nil, status.Errorf(codes.Internal, "getting call opts: %v", err) + } + + areValidatorsOptedIn, err := s.validatorRouter.AreValidatorsOptedIn(opts, validatorsKeys) if err != nil { s.logger.Error("checking if validators are opted in", "error", err) return nil, status.Errorf(codes.Internal, "checking if validators are opted in: %v", err) diff --git a/p2p/pkg/rpc/validator/service_test.go b/p2p/pkg/rpc/validator/service_test.go index 0b6e65794..e6b0fd45b 100644 --- a/p2p/pkg/rpc/validator/service_test.go +++ b/p2p/pkg/rpc/validator/service_test.go @@ -9,6 +9,7 @@ import ( "os" "testing" + "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common/hexutil" validatoroptinrouter "github.com/primev/mev-commit/contracts-abi/clients/ValidatorOptInRouter" validatorapiv1 "github.com/primev/mev-commit/p2p/gen/go/validatorapi/v1" @@ -22,7 +23,7 @@ type MockValidatorRouterContract struct { ExpectedCalls map[string]interface{} } -func (m *MockValidatorRouterContract) AreValidatorsOptedIn(valBLSPubKeys [][]byte) ([]validatoroptinrouter.IValidatorOptInRouterOptInStatus, error) { +func (m *MockValidatorRouterContract) AreValidatorsOptedIn(_ *bind.CallOpts, valBLSPubKeys [][]byte) ([]validatoroptinrouter.IValidatorOptInRouterOptInStatus, error) { results := make([]validatoroptinrouter.IValidatorOptInRouterOptInStatus, len(valBLSPubKeys)) for i, key := range valBLSPubKeys { if m.ExpectedCalls[string(key)] == nil { @@ -56,8 +57,12 @@ func TestGetValidators(t *testing.T) { }, } + optsGetter := func() (*bind.CallOpts, error) { + return &bind.CallOpts{}, nil + } + logger := util.NewTestLogger(os.Stdout) - service := validatorapi.NewService(mockServer.URL, mockValidatorRouter, logger) + service := validatorapi.NewService(mockServer.URL, mockValidatorRouter, logger, optsGetter) req := &validatorapiv1.GetValidatorsRequest{Epoch: 123} resp, err := service.GetValidators(context.Background(), req) @@ -85,9 +90,13 @@ func TestGetValidators_HTTPError(t *testing.T) { })) defer mockServer.Close() + optsGetter := func() (*bind.CallOpts, error) { + return &bind.CallOpts{}, nil + } + mockValidatorRouter := &MockValidatorRouterContract{} logger := util.NewTestLogger(os.Stdout) - service := validatorapi.NewService(mockServer.URL, mockValidatorRouter, logger) + service := validatorapi.NewService(mockServer.URL, mockValidatorRouter, logger, optsGetter) req := &validatorapiv1.GetValidatorsRequest{Epoch: 123} _, err := service.GetValidators(context.Background(), req) @@ -125,8 +134,12 @@ func TestGetValidators_EpochZero(t *testing.T) { }, } + optsGetter := func() (*bind.CallOpts, error) { + return &bind.CallOpts{}, nil + } + logger := util.NewTestLogger(os.Stdout) - service := validatorapi.NewService(mockServer.URL, mockValidatorRouter, logger) + service := validatorapi.NewService(mockServer.URL, mockValidatorRouter, logger, optsGetter) req := &validatorapiv1.GetValidatorsRequest{Epoch: 0} resp, err := service.GetValidators(context.Background(), req) From 6a12b04428b69a31d7f988940e5c273f9afd64d6 Mon Sep 17 00:00:00 2001 From: Alok Date: Tue, 24 Dec 2024 03:06:25 +0530 Subject: [PATCH 2/5] fix: validator check lag --- .../nomad/playbooks/templates/jobs/mev-commit.nomad.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 b/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 index eb6c9dddc..4db48c0bd 100644 --- a/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 +++ b/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 @@ -83,7 +83,7 @@ job "{{ job.name }}" { data = <<-EOH MEV_COMMIT_LOG_FMT="{{ job.env.get('log-format', 'json') }}" MEV_COMMIT_LOG_TAGS="{{ 'service.name:' + job.name + '-{{ env "NOMAD_ALLOC_INDEX" }}' + ',service.version:' + version }}" - MEV_ORACLE_LAGGERD_MODE="{{ job.env.get('laggerd-mode', '10') }}" + MEV_COMMIT_LAGGERD_MODE="{{ job.env.get('laggerd-mode', '10') }}" MEV_COMMIT_OTEL_COLLECTOR_ENDPOINT_URL="{{ job.env.get('otel_collector_endpoint_url', '') }}" {%- raw %} MEV_COMMIT_KEYSTORE_PATH="/local/data-{{ env "NOMAD_ALLOC_INDEX" }}/keystore" From d4c4f530fd939f2d3f646ed447740f01c1435614 Mon Sep 17 00:00:00 2001 From: Alok Date: Tue, 24 Dec 2024 11:43:29 +0530 Subject: [PATCH 3/5] fix: validator check lag --- p2p/cmd/main.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/p2p/cmd/main.go b/p2p/cmd/main.go index 1ef9bbe9a..4ad8b5599 100644 --- a/p2p/cmd/main.go +++ b/p2p/cmd/main.go @@ -432,10 +432,11 @@ var ( }) optionLaggerdMode = altsrc.NewIntFlag(&cli.IntFlag{ - Name: "laggerd-mode", - Usage: "No of blocks to lag behind for L1 chain", - EnvVars: []string{"MEV_COMMIT_LAGGERD_MODE"}, - Value: 10, + Name: "laggerd-mode", + Usage: "No of blocks to lag behind for L1 chain when fetching validator duties", + EnvVars: []string{"MEV_COMMIT_LAGGERD_MODE"}, + Value: 10, + Category: categoryEthRPC, }) ) From e07e5e687563732de9a74dfa52e2358b20ff6b92 Mon Sep 17 00:00:00 2001 From: Alok Date: Tue, 24 Dec 2024 12:08:07 +0530 Subject: [PATCH 4/5] fix: validator check lag --- .../nomad/playbooks/templates/jobs/mev-commit.nomad.j2 | 2 +- p2p/cmd/main.go | 8 ++++---- p2p/pkg/node/node.go | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 b/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 index 4db48c0bd..5a0843a3e 100644 --- a/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 +++ b/infrastructure/nomad/playbooks/templates/jobs/mev-commit.nomad.j2 @@ -83,7 +83,7 @@ job "{{ job.name }}" { data = <<-EOH MEV_COMMIT_LOG_FMT="{{ job.env.get('log-format', 'json') }}" MEV_COMMIT_LOG_TAGS="{{ 'service.name:' + job.name + '-{{ env "NOMAD_ALLOC_INDEX" }}' + ',service.version:' + version }}" - MEV_COMMIT_LAGGERD_MODE="{{ job.env.get('laggerd-mode', '10') }}" + MEV_COMMIT_LAGGARD_MODE="{{ job.env.get('laggard-mode', '10') }}" MEV_COMMIT_OTEL_COLLECTOR_ENDPOINT_URL="{{ job.env.get('otel_collector_endpoint_url', '') }}" {%- raw %} MEV_COMMIT_KEYSTORE_PATH="/local/data-{{ env "NOMAD_ALLOC_INDEX" }}/keystore" diff --git a/p2p/cmd/main.go b/p2p/cmd/main.go index 4ad8b5599..786869618 100644 --- a/p2p/cmd/main.go +++ b/p2p/cmd/main.go @@ -431,10 +431,10 @@ var ( Category: categoryProvider, }) - optionLaggerdMode = altsrc.NewIntFlag(&cli.IntFlag{ - Name: "laggerd-mode", + optionLaggardMode = altsrc.NewIntFlag(&cli.IntFlag{ + Name: "laggard-mode", Usage: "No of blocks to lag behind for L1 chain when fetching validator duties", - EnvVars: []string{"MEV_COMMIT_LAGGERD_MODE"}, + EnvVars: []string{"MEV_COMMIT_LAGGARD_MODE"}, Value: 10, Category: categoryEthRPC, }) @@ -657,7 +657,7 @@ func launchNodeWithConfig(c *cli.Context) (err error) { OracleWindowOffset: big.NewInt(defaultOracleWindowOffset), BeaconAPIURL: c.String(optionBeaconAPIURL.Name), L1RPCURL: c.String(optionL1RPCURL.Name), - LaggeredMode: c.Int(optionLaggerdMode.Name), + LaggardMode: c.Int(optionLaggardMode.Name), BidderBidTimeout: c.Duration(optionBidderBidTimeout.Name), ProviderDecisionTimeout: c.Duration(optionProviderDecisionTimeout.Name), }) diff --git a/p2p/pkg/node/node.go b/p2p/pkg/node/node.go index 27659979b..e1d30e321 100644 --- a/p2p/pkg/node/node.go +++ b/p2p/pkg/node/node.go @@ -101,7 +101,7 @@ type Options struct { OracleWindowOffset *big.Int BeaconAPIURL string L1RPCURL string - LaggeredMode int + LaggardMode int BidderBidTimeout time.Duration ProviderDecisionTimeout time.Duration } @@ -423,7 +423,7 @@ func NewNode(opts *Options) (*Node, error) { return nil, err } currentBlkNum := big.NewInt(0).SetUint64(blkNum) - queryBlkNum := big.NewInt(0).Sub(currentBlkNum, big.NewInt(int64(opts.LaggeredMode))) + queryBlkNum := big.NewInt(0).Sub(currentBlkNum, big.NewInt(int64(opts.LaggardMode))) return &bind.CallOpts{ From: opts.KeySigner.GetAddress(), BlockNumber: queryBlkNum, From 186d3531722a458215eb9a1a0602e13aa14b1536 Mon Sep 17 00:00:00 2001 From: Alok Date: Tue, 24 Dec 2024 12:10:10 +0530 Subject: [PATCH 5/5] fix: validator check lag --- p2p/cmd/main.go | 2 +- p2p/pkg/node/node.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/p2p/cmd/main.go b/p2p/cmd/main.go index 786869618..be7d81eba 100644 --- a/p2p/cmd/main.go +++ b/p2p/cmd/main.go @@ -657,7 +657,7 @@ func launchNodeWithConfig(c *cli.Context) (err error) { OracleWindowOffset: big.NewInt(defaultOracleWindowOffset), BeaconAPIURL: c.String(optionBeaconAPIURL.Name), L1RPCURL: c.String(optionL1RPCURL.Name), - LaggardMode: c.Int(optionLaggardMode.Name), + LaggardMode: big.NewInt(int64(c.Int(optionLaggardMode.Name))), BidderBidTimeout: c.Duration(optionBidderBidTimeout.Name), ProviderDecisionTimeout: c.Duration(optionProviderDecisionTimeout.Name), }) diff --git a/p2p/pkg/node/node.go b/p2p/pkg/node/node.go index e1d30e321..d5e7bd0d1 100644 --- a/p2p/pkg/node/node.go +++ b/p2p/pkg/node/node.go @@ -101,7 +101,7 @@ type Options struct { OracleWindowOffset *big.Int BeaconAPIURL string L1RPCURL string - LaggardMode int + LaggardMode *big.Int BidderBidTimeout time.Duration ProviderDecisionTimeout time.Duration } @@ -423,7 +423,7 @@ func NewNode(opts *Options) (*Node, error) { return nil, err } currentBlkNum := big.NewInt(0).SetUint64(blkNum) - queryBlkNum := big.NewInt(0).Sub(currentBlkNum, big.NewInt(int64(opts.LaggardMode))) + queryBlkNum := big.NewInt(0).Sub(currentBlkNum, opts.LaggardMode) return &bind.CallOpts{ From: opts.KeySigner.GetAddress(), BlockNumber: queryBlkNum,