Skip to content

Commit

Permalink
Transition off removed GRPC endpoint BlockHeadersRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
adaszko committed Nov 21, 2023
1 parent 0ddaf28 commit 8dc5f88
Show file tree
Hide file tree
Showing 6 changed files with 248 additions and 154 deletions.
37 changes: 37 additions & 0 deletions beaconchain/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package beaconchain

import (
"context"
"time"

eth2client "github.com/attestantio/go-eth2-client"
eth2http "github.com/attestantio/go-eth2-client/http"
)

type BeaconChain struct {
service eth2client.Service
timeout time.Duration
}

func New(ctx context.Context, address string, timeout time.Duration) (*BeaconChain, error) {
service, err := eth2http.New(ctx, eth2http.WithAddress(address), eth2http.WithTimeout(time.Minute))

if err != nil {
return nil, err
}

result := &BeaconChain{
service: service,
timeout: timeout,
}

return result, nil
}

func (beacon *BeaconChain) Service() eth2client.Service {
return beacon.service
}

func (beacon *BeaconChain) Timeout() time.Duration {
return beacon.timeout
}
1 change: 1 addition & 0 deletions cmd/opts/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package opts
var (
LogLevel string
BeaconNode string
BeaconChainAPI string
MetricsPort string
SlackURL string
SlackUsername string
Expand Down
12 changes: 10 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"
"time"

"eth2-monitor/beaconchain"
"eth2-monitor/cmd/opts"
"eth2-monitor/pkg"
"eth2-monitor/prysmgrpc"
Expand Down Expand Up @@ -59,13 +60,16 @@ var (
prysmgrpc.WithTimeout(time.Minute))
pkg.Must(err)

beacon, err := beaconchain.New(ctx, opts.BeaconChainAPI, time.Minute)
pkg.Must(err)

plainPubkeys, err := pkg.LoadKeys(args)
pkg.Must(err)

var wg sync.WaitGroup
wg.Add(2)
go pkg.SubscribeToEpochs(ctx, s, true, &wg)
go pkg.MonitorAttestationsAndProposals(ctx, s, plainPubkeys, &wg)
go pkg.MonitorAttestationsAndProposals(ctx, s, beacon, plainPubkeys, &wg)

//Create Prometheus Metrics Client
http.Handle("/metrics", promhttp.Handler())
Expand All @@ -87,10 +91,13 @@ var (
prysmgrpc.WithTimeout(time.Minute))
pkg.Must(err)

beacon, err := beaconchain.New(ctx, opts.BeaconChainAPI, time.Minute)
pkg.Must(err)

var wg sync.WaitGroup
wg.Add(2)
go pkg.SubscribeToEpochs(ctx, s, true, &wg)
go pkg.MonitorSlashings(ctx, s, &wg)
go pkg.MonitorSlashings(ctx, s, beacon, &wg)
defer wg.Wait()
},
}
Expand Down Expand Up @@ -140,6 +147,7 @@ func Execute() error {
func init() {
rootCmd.PersistentFlags().StringVarP(&opts.LogLevel, "log-level", "l", "info", "log level (error, warn, info, debug, trace)")
rootCmd.PersistentFlags().StringVar(&opts.BeaconNode, "beacon-node", "localhost:4000", "Prysm beacon node GRPC address")
rootCmd.PersistentFlags().StringVar(&opts.BeaconChainAPI, "beacon-chain-api", "localhost:3500", "Beacon Chain API HTTP address")
rootCmd.PersistentFlags().StringVar(&opts.MetricsPort, "metrics-port", "1337", "Metrics port to expose metrics for Prometheus")
rootCmd.PersistentFlags().StringVar(&opts.SlackURL, "slack-url", "", "Slack Webhook URL")
rootCmd.PersistentFlags().StringVar(&opts.SlackUsername, "slack-username", "", "Slack username")
Expand Down
43 changes: 27 additions & 16 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,25 @@ module eth2-monitor
go 1.19

require (
github.com/attestantio/go-eth2-client v0.19.5
github.com/dghubble/go-twitter v0.0.0-20220716041154-837915ec2f79
github.com/dghubble/oauth1 v0.7.1
github.com/ethereum/go-ethereum v1.13.2
github.com/mattn/go-isatty v0.0.16
github.com/mattn/go-isatty v0.0.18
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/client_golang v1.16.0
github.com/prysmaticlabs/go-bitfield v0.0.0-20210809151128-385d8c5e3fb7
github.com/prysmaticlabs/prysm/v4 v4.0.1
github.com/rs/zerolog v1.27.0
github.com/prysmaticlabs/prysm/v4 v4.1.1
github.com/rs/zerolog v1.29.1
github.com/spf13/cobra v1.5.0
golang.org/x/exp v0.0.0-20230810033253-352e893a4cad
google.golang.org/grpc v1.48.0
google.golang.org/protobuf v1.28.1
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.30.0
)

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/bits-and-blooms/bitset v1.5.0 // indirect
github.com/bits-and-blooms/bitset v1.7.0 // indirect
github.com/btcsuite/btcd/btcec/v2 v2.3.2 // indirect
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
Expand All @@ -30,11 +31,17 @@ require (
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/dghubble/sling v1.4.0 // indirect
github.com/ethereum/c-kzg-4844 v0.3.1 // indirect
github.com/fatih/color v1.10.0 // indirect
github.com/ferranbt/fastssz v0.1.3 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-stack/stack v1.8.1 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/goccy/go-yaml v1.9.2 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-querystring v1.1.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.2 // indirect
github.com/holiman/uint256 v1.2.3 // indirect
github.com/huandu/go-clone v1.6.0 // indirect
github.com/inconshreveable/mousetrap v1.0.1 // indirect
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
Expand All @@ -43,24 +50,28 @@ require (
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/prometheus/client_model v0.3.0 // indirect
github.com/prometheus/common v0.39.0 // indirect
github.com/prometheus/procfs v0.9.0 // indirect
github.com/prysmaticlabs/fastssz v0.0.0-20220628131814-351fdcbb9964 // indirect
github.com/prometheus/common v0.42.0 // indirect
github.com/prometheus/procfs v0.10.1 // indirect
github.com/prysmaticlabs/fastssz v0.0.0-20221107182844-78142813af44 // indirect
github.com/prysmaticlabs/gohashtree v0.0.3-alpha // indirect
github.com/r3labs/sse/v2 v2.10.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/supranational/blst v0.3.11 // indirect
github.com/thomaso-mirodin/intmath v0.0.0-20160323211736-5dc6d854e46e // indirect
go.opentelemetry.io/otel v1.16.0 // indirect
go.opentelemetry.io/otel/metric v1.16.0 // indirect
go.opentelemetry.io/otel/trace v1.16.0 // indirect
golang.org/x/crypto v0.12.0 // indirect
golang.org/x/net v0.10.0 // indirect
golang.org/x/sync v0.3.0 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.12.0 // indirect
google.golang.org/genproto v0.0.0-20220812140447-cec7f5303424 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
google.golang.org/genproto v0.0.0-20230110181048-76db0878b65f // indirect
gopkg.in/cenkalti/backoff.v1 v1.1.0 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
rsc.io/tmplfunc v0.0.3 // indirect
)

replace github.com/ferranbt/fastssz => github.com/ferranbt/fastssz v0.0.0-20210526181520-7df50c8568f8

// See: https://github.com/prysmaticlabs/grpc-gateway/issues/2
replace github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20210524202756-cefc26c3f2bf
// See https://github.com/prysmaticlabs/prysm/blob/d035be29cd549ca38b257e67bb6d9e6e76e9fba7/go.mod#L270
replace github.com/grpc-ecosystem/grpc-gateway/v2 => github.com/prysmaticlabs/grpc-gateway/v2 v2.3.1-0.20230315201114-09284ba20446
Loading

0 comments on commit 8dc5f88

Please sign in to comment.