From 828c7e6d08a54cf6559a1fa2dd465005310ebb66 Mon Sep 17 00:00:00 2001 From: Jacob Shufro Date: Thu, 23 Nov 2023 00:16:24 -0500 Subject: [PATCH] Add force-json flag for lodestar, bump attestantio dep --- Makefile | 2 +- config.go | 3 +++ consensuslayer/consensus-layer.go | 23 ++++++++++++++++------- consensuslayer/consensus-layer_test.go | 2 +- go.mod | 9 +++++---- go.sum | 9 +++++++-- service.go | 2 +- 7 files changed, 34 insertions(+), 16 deletions(-) diff --git a/Makefile b/Makefile index 827305c..d90880b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = v1.0.0 +VERSION = v1.0.1 SOURCES := $(shell find $(SOURCEDIR) -name '*.go') PROTO_IN := proto diff --git a/config.go b/config.go index ea95515..a7a2653 100644 --- a/config.go +++ b/config.go @@ -24,6 +24,7 @@ type Config struct { CachePath string EnableSoloValidators bool Debug bool + ForceBNJSON bool } func initFlags() *Config { @@ -44,6 +45,7 @@ func initFlags() *Config { authValidityWindowFlag := flag.String("auth-valid-for", "360h", "The duration after which a credential should be considered invalid, eg, 360h for 15 days") cachePathFlag := flag.String("cache-path", "", "A path to cache EL data in. Leave blank to disable caching.") enableSoloValidatorsFlag := flag.Bool("enable-solo-validators", true, "Whether or not to allow solo validators access.") + forceBNJSONFlag := flag.Bool("force-bn-json", false, "Disables SSZ in the BN.") flag.Parse() @@ -147,5 +149,6 @@ func initFlags() *Config { config.RocketStorageAddr = *rocketStorageAddrFlag config.EnableSoloValidators = *enableSoloValidatorsFlag config.Debug = *debug + config.ForceBNJSON = *forceBNJSONFlag return config } diff --git a/consensuslayer/consensus-layer.go b/consensuslayer/consensus-layer.go index e2328a5..a156266 100644 --- a/consensuslayer/consensus-layer.go +++ b/consensuslayer/consensus-layer.go @@ -9,6 +9,7 @@ import ( "github.com/Rocket-Pool-Rescue-Node/rescue-proxy/metrics" "github.com/allegro/bigcache/v3" + "github.com/attestantio/go-eth2-client/api" apiv1 "github.com/attestantio/go-eth2-client/api/v1" "github.com/attestantio/go-eth2-client/http" "github.com/attestantio/go-eth2-client/spec/phase0" @@ -40,6 +41,9 @@ type CachingConsensusLayer struct { // Disconnects from the bn disconnect func() + // Force attestantio client to use json + forceJSON bool + m *metrics.MetricsRegistry slotsPerEpoch uint64 } @@ -51,10 +55,11 @@ type ValidatorInfo struct { } // NewConsensusLayer creates a new consensus layer client using the provided url and logger -func NewCachingConsensusLayer(bnURL *url.URL, logger *zap.Logger) *CachingConsensusLayer { +func NewCachingConsensusLayer(bnURL *url.URL, logger *zap.Logger, forceJSON bool) *CachingConsensusLayer { out := &CachingConsensusLayer{} out.bnURL = bnURL out.logger = logger + out.forceJSON = forceJSON out.m = metrics.NewMetricsRegistry("consensus_layer") return out @@ -86,7 +91,8 @@ func (c *CachingConsensusLayer) Init(ctx context.Context) error { // It's very chatty if we don't quiet it down http.WithLogLevel(zerolog.WarnLevel), // Set a sensible timeout. This is used as a maximum. Requests can set their own via ctx. - http.WithTimeout(5*time.Minute)) + http.WithTimeout(5*time.Minute), + http.WithEnforceJSON(c.forceJSON)) if err != nil { return err } @@ -164,11 +170,14 @@ func (c *CachingConsensusLayer) GetValidatorInfo(validatorIndices []string) (map vCtx, cancel := context.WithTimeout(context.Background(), 30*time.Second) defer cancel() // Grab the index->validator map from the client if missing from the cache - resp, err := c.client.Validators(vCtx, "head", missing) + resp, err := c.client.Validators(vCtx, &api.ValidatorsOpts{ + State: "head", + Indices: missing, + }) if err != nil { return nil, err } - for index, validator := range resp { + for index, validator := range resp.Data { strIndex := strconv.FormatUint(uint64(index), 10) pubkey := rptypes.ValidatorPubkey(validator.Validator.PublicKey) withdrawalCredentials := validator.Validator.WithdrawalCredentials @@ -204,13 +213,13 @@ func (c *CachingConsensusLayer) GetValidators() ([]*apiv1.Validator, error) { ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute) defer cancel() - vmap, err := c.client.Validators(ctx, "finalized", nil) + vmap, err := c.client.Validators(ctx, &api.ValidatorsOpts{State: "finalized"}) if err != nil { return nil, err } - out := make([]*apiv1.Validator, 0, len(vmap)) - for _, v := range vmap { + out := make([]*apiv1.Validator, 0, len(vmap.Data)) + for _, v := range vmap.Data { out = append(out, v) } diff --git a/consensuslayer/consensus-layer_test.go b/consensuslayer/consensus-layer_test.go index 5994181..f898648 100644 --- a/consensuslayer/consensus-layer_test.go +++ b/consensuslayer/consensus-layer_test.go @@ -72,7 +72,7 @@ func setup(t *testing.T, url *url.URL) ccTest { t.Cleanup(cancel) return ccTest{ - ccl: NewCachingConsensusLayer(url, zaptest.NewLogger(t)), + ccl: NewCachingConsensusLayer(url, zaptest.NewLogger(t), false), ctx: ctx, } } diff --git a/go.mod b/go.mod index 18b6c8b..5b75837 100644 --- a/go.mod +++ b/go.mod @@ -6,14 +6,17 @@ require ( github.com/Rocket-Pool-Rescue-Node/credentials v0.0.0-20230909140515-dbe2112cbe11 github.com/Rocket-Rescue-Node/guarded-beacon-proxy v0.1.1 github.com/allegro/bigcache/v3 v3.1.0 - github.com/attestantio/go-eth2-client v0.18.3 + github.com/attestantio/go-eth2-client v0.19.5 github.com/ethereum/go-ethereum v1.12.2 github.com/gorilla/mux v1.8.0 + github.com/gorilla/websocket v1.5.0 github.com/mattn/go-sqlite3 v1.14.17 github.com/prometheus/client_golang v1.16.0 github.com/rocket-pool/rocketpool-go v1.8.0 github.com/rs/zerolog v1.30.0 go.uber.org/zap v1.25.0 + golang.org/x/exp v0.0.0-20230905200255-921286631fa9 + golang.org/x/sync v0.3.0 google.golang.org/grpc v1.58.3 google.golang.org/protobuf v1.31.0 ) @@ -35,10 +38,10 @@ require ( github.com/goccy/go-yaml v1.11.0 // indirect github.com/golang/protobuf v1.5.3 // indirect github.com/google/uuid v1.3.1 // indirect - github.com/gorilla/websocket v1.5.0 // indirect github.com/grpc-ecosystem/grpc-gateway/v2 v2.17.1 // indirect github.com/hashicorp/go-version v1.6.0 // indirect github.com/holiman/uint256 v1.2.3 // indirect + github.com/huandu/go-clone v1.6.0 // indirect github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect @@ -65,9 +68,7 @@ require ( go.opentelemetry.io/otel/trace v1.17.0 // indirect go.uber.org/multierr v1.11.0 // indirect golang.org/x/crypto v0.14.0 // indirect - golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect golang.org/x/net v0.17.0 // indirect - golang.org/x/sync v0.3.0 // indirect golang.org/x/sys v0.13.0 // indirect golang.org/x/text v0.13.0 // indirect golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect diff --git a/go.sum b/go.sum index a347b06..7c4ca86 100644 --- a/go.sum +++ b/go.sum @@ -8,8 +8,8 @@ github.com/Rocket-Rescue-Node/guarded-beacon-proxy v0.1.1/go.mod h1:p4CMEZjb+V4h github.com/VictoriaMetrics/fastcache v1.12.0 h1:vnVi/y9yKDcD9akmc4NqAoqgQhJrOwUF+j9LTgn4QDE= github.com/allegro/bigcache/v3 v3.1.0 h1:H2Vp8VOvxcrB91o86fUSVJFqeuz8kpyyB02eH3bSzwk= github.com/allegro/bigcache/v3 v3.1.0/go.mod h1:aPyh7jEvrog9zAwx5N7+JUQX5dZTSGpxF1LAR4dr35I= -github.com/attestantio/go-eth2-client v0.18.3 h1:hUSYh+uMLyw4mJcXWcvrPLd8ozJl61aWMdx5Cpq9hxk= -github.com/attestantio/go-eth2-client v0.18.3/go.mod h1:KSVlZSW1A3jUg5H8O89DLtqxgJprRfTtI7k89fLdhu0= +github.com/attestantio/go-eth2-client v0.19.5 h1:4V+vhXsCYji5jWrlONbr03GV7qoLRdzq96dLgXaqmek= +github.com/attestantio/go-eth2-client v0.19.5/go.mod h1:mZve1kV9Ctj0I1HH9gdg+MnI8lZ+Cb2EktEtOYrBlsM= github.com/benbjohnson/clock v1.3.0 h1:ip6w0uFQkncKQ979AypyG0ER7mqUSBdKLOgAle/AT8A= github.com/benbjohnson/clock v1.3.0/go.mod h1:J11/hYXuz8f4ySSvYwY0FKfm+ezbsZBKZxNJlLklBHA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= @@ -36,6 +36,7 @@ github.com/crate-crypto/go-kzg-4844 v0.3.0 h1:UBlWE0CgyFqqzTI+IFyCzA7A3Zw4iip6uz github.com/d4l3k/messagediff v1.2.1 h1:ZcAIMYsUg0EAp9X+tt8/enBE/Q8Yd5kzPynLyKptt9U= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/deckarep/golang-set/v2 v2.3.1 h1:vjmkvJt/IV27WXPyYQpAh4bRyWJc5Y435D17XQ9QU5A= github.com/deckarep/golang-set/v2 v2.3.1/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= @@ -117,7 +118,10 @@ github.com/holiman/billy v0.0.0-20230718173358-1c7e68d277a7 h1:3JQNjnMRil1yD0IfZ github.com/holiman/bloomfilter/v2 v2.0.3 h1:73e0e/V0tCydx14a0SCYS/EWCxgwLZ18CZcZKVu0fao= github.com/holiman/uint256 v1.2.3 h1:K8UWO1HUJpRMXBxbmaY1Y8IAMZC/RsKB+ArEnnK4l5o= github.com/holiman/uint256 v1.2.3/go.mod h1:SC8Ryt4n+UBbPbIBKaG9zbbDlp4jOru9xFZmPzLUTxw= +github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c= +github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U= github.com/huandu/go-clone v1.6.0 h1:HMo5uvg4wgfiy5FoGOqlFLQED/VGRm2D9Pi8g1FXPGc= +github.com/huandu/go-clone v1.6.0/go.mod h1:ReGivhG6op3GYr+UY3lS6mxjKp7MIGTknuU5TbTVaXE= github.com/huandu/go-clone/generic v1.6.0 h1:Wgmt/fUZ28r16F2Y3APotFD59sHk1p78K0XLdbUYN5U= github.com/huin/goupnp v1.1.0 h1:gEe0Dp/lZmPZiDFzJJaOfUpOvv2MKUkoBX8lDrn9vKU= github.com/jackpal/go-nat-pmp v1.0.2 h1:KzKSgb7qkJvOUTqYl9/Hg/me3pWgBmERKrTGD7BdWus= @@ -188,6 +192,7 @@ github.com/shirou/gopsutil v3.21.11+incompatible/go.mod h1:5b4v6he4MtMOwMlS0TUMT github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0= github.com/status-im/keycard-go v0.2.0 h1:QDLFswOQu1r5jsycloeQh3bVU8n/NatHHaZobtDnDzA= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= diff --git a/service.go b/service.go index d294ea3..1d34217 100644 --- a/service.go +++ b/service.go @@ -108,7 +108,7 @@ func (s *Service) run(ctx context.Context, errs chan error) { }() // Connect to and initialize the consensus layer - cl := consensuslayer.NewCachingConsensusLayer(s.Config.BeaconURL, s.Logger) + cl := consensuslayer.NewCachingConsensusLayer(s.Config.BeaconURL, s.Logger, s.Config.ForceBNJSON) s.cl = cl s.Logger.Info("Starting CL monitor") // Consensus Layer is non-blocking/synchronous only.