Skip to content

Commit

Permalink
lint: fix staticcheck
Browse files Browse the repository at this point in the history
  • Loading branch information
dennis-tra committed Mar 27, 2024
1 parent 7762cb1 commit 473ba1d
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 36 deletions.
15 changes: 0 additions & 15 deletions cmd/hermes/cmd_eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"log/slog"
"time"

"github.com/libp2p/go-libp2p/core/peer"
"github.com/prysmaticlabs/prysm/v5/config/params"
"github.com/prysmaticlabs/prysm/v5/network/forks"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -232,20 +231,6 @@ func validateKeyFlag(c *cli.Context, s string) error {
return nil
}

// validateBeaconAddrInfoFlag verifies that if a addrinfo multi address was
// given, that it has the correct format
func validateBeaconAddrInfoFlag(c *cli.Context, s string) error {
if s == "" {
return nil
}

if _, err := peer.AddrInfoFromString(s); err != nil {
return fmt.Errorf("invalid delegate addrinfo: %w", err)
}

return nil
}

func printEthConfig() {
cfgCopy := *ethConfig
if cfgCopy.PrivateKeyStr != "" {
Expand Down
2 changes: 1 addition & 1 deletion cmd/hermes/cmd_eth_chains.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func cmdEthChainsAction(c *cli.Context) error {
if err != nil {
return fmt.Errorf("get config for %s: %w", chain, err)
}
slog.Info(fmt.Sprintf("%s", chain))
slog.Info(chain)

forkVersions := [][]byte{
beaConfig.GenesisForkVersion,
Expand Down
4 changes: 2 additions & 2 deletions eth/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (d *Discovery) Serve(ctx context.Context) (err error) {
continue
}

if bytes.Compare(forkEntry.CurrentForkDigest, digest[:]) != 0 {
if !bytes.Equal(forkEntry.CurrentForkDigest, digest[:]) {
// irrelevant network
continue
}
Expand Down Expand Up @@ -225,7 +225,7 @@ func NewDiscoveredPeer(node *enode.Node) (*DiscoveredPeer, error) {
return nil, fmt.Errorf("no public key")
}

pubBytes := elliptic.Marshal(secp256k1.S256(), pubKey.X, pubKey.Y)
pubBytes := elliptic.Marshal(secp256k1.S256(), pubKey.X, pubKey.Y) //lint:ignore SA1019 couldn't figure out the alternative
secpKey, err := crypto.UnmarshalSecp256k1PublicKey(pubBytes)
if err != nil {
return nil, fmt.Errorf("unmarshal secp256k1 public key: %w", err)
Expand Down
2 changes: 0 additions & 2 deletions eth/discovery_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ type DiscoveryConfig struct {
TCPPort int
Tracer trace.Tracer
Meter metric.Meter

forkDigest []byte
}

// enrEth2Entry generates an Ethereum 2.0 entry for the Ethereum Node Record
Expand Down
3 changes: 1 addition & 2 deletions eth/node_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"github.com/libp2p/go-libp2p/core/crypto"
"github.com/libp2p/go-libp2p/core/peer"
rcmgr "github.com/libp2p/go-libp2p/p2p/host/resource-manager"
rcmgrObs "github.com/libp2p/go-libp2p/p2p/host/resource-manager/obs"
"github.com/libp2p/go-libp2p/p2p/security/noise"
"github.com/libp2p/go-libp2p/p2p/transport/tcp"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p"
Expand Down Expand Up @@ -243,7 +242,7 @@ func (n *NodeConfig) libp2pOptions() ([]libp2p.Option, error) {
return nil, fmt.Errorf("construct libp2p listen maddr: %w", err)
}

str, err := rcmgrObs.NewStatsTraceReporter()
str, err := rcmgr.NewStatsTraceReporter()
if err != nil {
return nil, err
}
Expand Down
2 changes: 0 additions & 2 deletions eth/node_notifiee.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,5 @@ func (n *Node) handleNewConnection(pid peer.ID) {
// the handshake failed, we disconnect and remove it from our pool
ps.RemovePeer(pid)
_ = n.host.Network().ClosePeer(pid)
} else {
// handshake succeeded, add this peer to our pool
}
}
2 changes: 1 addition & 1 deletion eth/prysm.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (p *PrysmClient) ChainHead(ctx context.Context) (chainHead *eth.ChainHead,
ctx, cancel := context.WithTimeout(ctx, p.timeout)
defer cancel()

return p.beaconClient.GetChainHead(ctx, &emptypb.Empty{})
return p.beaconClient.GetChainHead(ctx, &emptypb.Empty{}) //lint:ignore SA1019

Check failure on line 243 in eth/prysm.go

View workflow job for this annotation

GitHub Actions / go-check / All

malformed linter directive; missing the required reason field? (compile)

Check failure on line 243 in eth/prysm.go

View workflow job for this annotation

GitHub Actions / go-check / All

p.beaconClient.GetChainHead is deprecated: Do not use. (SA1019)
}

func (p *PrysmClient) Identity(ctx context.Context) (addrInfo *peer.AddrInfo, err error) {
Expand Down
21 changes: 10 additions & 11 deletions eth/reqresp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/encoder"
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/types"
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
pb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
Expand Down Expand Up @@ -59,7 +58,7 @@ type ReqResp struct {
metaData *pb.MetaDataV1

statusMu sync.RWMutex
status *eth.Status
status *pb.Status
statusLim *rate.Limiter

// metrics
Expand Down Expand Up @@ -124,7 +123,7 @@ func (r *ReqResp) SetMetaData(seq uint64) {
}
}

func (r *ReqResp) SetStatus(status *eth.Status) {
func (r *ReqResp) SetStatus(status *pb.Status) {
r.statusMu.Lock()
defer r.statusMu.Unlock()

Expand Down Expand Up @@ -153,15 +152,15 @@ func (r *ReqResp) SetStatus(status *eth.Status) {
r.status = status
}

func (r *ReqResp) cpyStatus() *eth.Status {
func (r *ReqResp) cpyStatus() *pb.Status {
r.statusMu.RLock()
defer r.statusMu.RUnlock()

if r.status == nil {
return nil
}

return &eth.Status{
return &pb.Status{
ForkDigest: bytes.Clone(r.status.ForkDigest),
FinalizedRoot: bytes.Clone(r.status.FinalizedRoot),
FinalizedEpoch: r.status.FinalizedEpoch,
Expand Down Expand Up @@ -331,7 +330,7 @@ func (r *ReqResp) goodbyeHandler(ctx context.Context, stream network.Stream) (ma
}

func (r *ReqResp) statusHandler(ctx context.Context, upstream network.Stream) (map[string]any, error) {
statusTraceData := func(status *eth.Status) map[string]any {
statusTraceData := func(status *pb.Status) map[string]any {
return map[string]any{
"ForkDigest": hex.EncodeToString(status.ForkDigest),
"HeadRoot": hex.EncodeToString(status.HeadRoot),
Expand All @@ -345,7 +344,7 @@ func (r *ReqResp) statusHandler(ctx context.Context, upstream network.Stream) (m
// its own status back and update our latest known status.
if upstream.Conn().RemotePeer() == r.delegate {

resp := &eth.Status{}
resp := &pb.Status{}
if err := r.readRequest(ctx, upstream, resp); err != nil {
return nil, fmt.Errorf("read status data from delegate: %w", err)
}
Expand All @@ -367,7 +366,7 @@ func (r *ReqResp) statusHandler(ctx context.Context, upstream network.Stream) (m
}

// first, read the status from the remote peer
req := &eth.Status{}
req := &pb.Status{}
if err := r.readRequest(ctx, upstream, req); err != nil {
return nil, fmt.Errorf("read status data from delegate: %w", err)
}
Expand Down Expand Up @@ -547,7 +546,7 @@ func (r *ReqResp) delegateStream(ctx context.Context, upstream network.Stream) e
return nil
}

func (r *ReqResp) Status(ctx context.Context, pid peer.ID) (status *eth.Status, err error) {
func (r *ReqResp) Status(ctx context.Context, pid peer.ID) (status *pb.Status, err error) {
defer func() {
reqData := map[string]any{
"PeerID": pid.String(),
Expand Down Expand Up @@ -601,7 +600,7 @@ func (r *ReqResp) Status(ctx context.Context, pid peer.ID) (status *eth.Status,
}

// read and decode status response
resp := &eth.Status{}
resp := &pb.Status{}
if err := r.readResponse(ctx, stream, resp); err != nil {
return nil, fmt.Errorf("read status response: %w", err)
}
Expand Down Expand Up @@ -709,7 +708,7 @@ func (r *ReqResp) MetaData(ctx context.Context, pid peer.ID) (resp *pb.MetaDataV
defer logDeferErr(stream.Reset, "failed closing stream") // no-op if closed

// read and decode status response
resp = &eth.MetaDataV1{}
resp = &pb.MetaDataV1{}
if err := r.readResponse(ctx, stream, resp); err != nil {
return resp, fmt.Errorf("read ping response: %w", err)
}
Expand Down

0 comments on commit 473ba1d

Please sign in to comment.