Skip to content

Commit

Permalink
Linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcdee committed Mar 30, 2024
1 parent a68e875 commit d09c40d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "^1.20"
go-version: "^1.21"
- uses: actions/checkout@v3
- name: golangci-lint
uses: golangci/golangci-lint-action@v3
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ jobs:
steps:
- uses: actions/setup-go@v3
with:
go-version: "^1.20"
go-version: "^1.21"
- uses: actions/checkout@v3
- uses: n8maninger/action-golang-test@v1
11 changes: 1 addition & 10 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ run:
# Define the Go version limit.
# Mainly related to generics support since go1.18.
# Default: use Go version from the go.mod file, fallback on the env var `GOVERSION`, fallback on 1.18
go: '1.19'
go: '1.21'


# output configuration options
Expand Down Expand Up @@ -133,18 +133,12 @@ linters:
- deadcode
- depguard
- dupl
- exhaustive
- exhaustivestruct
- exhaustruct
- forcetypeassert
- funlen
- gci
- gochecknoglobals
- gochecknoinits
- gocognit
- goconst
- goerr113
- goheader
- golint
- gomnd
- ifshort
Expand All @@ -154,11 +148,8 @@ linters:
- maligned
- nosnakecase
- perfsprint
- rowserrcheck
- scopelint
- sqlclosecheck
- structcheck
- varcheck
- varnamelen
- wastedassign
- wsl
46 changes: 34 additions & 12 deletions grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -597,8 +597,12 @@ func (a *account) SignBeaconAttestationsGRPC(ctx context.Context,
Requests: make([]*pb.SignBeaconAttestationRequest, len(accounts)),
}
for i := range accounts {
account, isAccount := accounts[i].(*account)
if !isAccount {
return nil, errors.New("account not of required type")
}
req.Requests[i] = &pb.SignBeaconAttestationRequest{
Id: &pb.SignBeaconAttestationRequest_Account{Account: fmt.Sprintf("%s/%s", accounts[i].(*account).wallet.Name(), accounts[i].Name())},
Id: &pb.SignBeaconAttestationRequest_Account{Account: fmt.Sprintf("%s/%s", account.wallet.Name(), accounts[i].Name())},
Data: &pb.AttestationData{
Slot: slot,
CommitteeIndex: committeeIndices[i],
Expand Down Expand Up @@ -684,9 +688,13 @@ func (a *distributedAccount) SignBeaconAttestationsGRPC(ctx context.Context,
Requests: make([]*pb.SignBeaconAttestationRequest, len(accounts)),
}
for i := range accounts {
thresholds[i] = accounts[i].(*distributedAccount).signingThreshold
account, isAccount := accounts[i].(*distributedAccount)
if !isAccount {
return nil, errors.New("account not of required type")
}
thresholds[i] = account.signingThreshold
req.Requests[i] = &pb.SignBeaconAttestationRequest{
Id: &pb.SignBeaconAttestationRequest_Account{Account: fmt.Sprintf("%s/%s", accounts[i].(*distributedAccount).wallet.Name(), accounts[i].Name())},
Id: &pb.SignBeaconAttestationRequest_Account{Account: fmt.Sprintf("%s/%s", account.wallet.Name(), accounts[i].Name())},
Data: &pb.AttestationData{
Slot: slot,
CommitteeIndex: committeeIndices[i],
Expand Down Expand Up @@ -748,15 +756,17 @@ func (w *wallet) GenerateDistributedAccount(ctx context.Context,
return nil, errors.Wrap(err, "failed to access dirk")
}

if resp.GetState() != pb.ResponseState_SUCCEEDED {
switch resp.GetState() {
case pb.ResponseState_DENIED:
return nil, fmt.Errorf("generate request denied: %s", resp.GetMessage())
case pb.ResponseState_FAILED:
return nil, fmt.Errorf("generate request failed: %s", resp.GetMessage())
default:
return nil, fmt.Errorf("generate request failed: %s", resp.GetMessage())
}
switch resp.GetState() {
case pb.ResponseState_SUCCEEDED:
// Good.
case pb.ResponseState_DENIED:
return nil, fmt.Errorf("generate request denied: %s", resp.GetMessage())
case pb.ResponseState_FAILED:
return nil, fmt.Errorf("generate request failed: %s", resp.GetMessage())
case pb.ResponseState_UNKNOWN:
return nil, fmt.Errorf("generate request unexpected response: %s", resp.GetMessage())
default:
return nil, fmt.Errorf("generate request failed: %s", resp.GetMessage())
}

// Fetch the account to ensure it has been created.
Expand Down Expand Up @@ -839,6 +849,9 @@ func (a *distributedAccount) thresholdSign(ctx context.Context, req *pb.SignRequ
denied++
case pb.ResponseState_FAILED:
failed++
case pb.ResponseState_UNKNOWN:
// We consider unknown to be failed.
failed++
case pb.ResponseState_SUCCEEDED:
ids[signed] = *blsID(resp.id)
if err := signatures[signed].Deserialize(resp.resp.GetSignature()); err != nil {
Expand Down Expand Up @@ -931,6 +944,9 @@ func (a *distributedAccount) thresholdSignBeaconAttestation(ctx context.Context,
denied++
case pb.ResponseState_FAILED:
failed++
case pb.ResponseState_UNKNOWN:
// We consider unknown to be failed.
failed++
case pb.ResponseState_SUCCEEDED:
ids[signed] = *blsID(resp.id)
if err := signatures[signed].Deserialize(resp.resp.GetSignature()); err != nil {
Expand Down Expand Up @@ -1032,6 +1048,9 @@ func (a *distributedAccount) thresholdSignBeaconAttestations(ctx context.Context
denied[i]++
case pb.ResponseState_FAILED:
failed[i]++
case pb.ResponseState_UNKNOWN:
// We consider unknown to be failed.
failed[i]++
case pb.ResponseState_SUCCEEDED:
signed[i]++
ids[i] = append(ids[i], *blsID(resp.id))
Expand Down Expand Up @@ -1162,6 +1181,9 @@ func (a *distributedAccount) thresholdSignBeaconProposal(ctx context.Context, re
denied++
case pb.ResponseState_FAILED:
failed++
case pb.ResponseState_UNKNOWN:
// We consider unknown to be failed.
failed++
case pb.ResponseState_SUCCEEDED:
ids[signed] = *blsID(resp.id)
if err := signatures[signed].Deserialize(resp.resp.GetSignature()); err != nil {
Expand Down
8 changes: 4 additions & 4 deletions grpc_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ type ErroringConnectionProvider struct {
}

// Connection returns a connection and release function.
func (c *ErroringConnectionProvider) Connection(ctx context.Context, endpoint *Endpoint) (*grpc.ClientConn, func(), error) {
func (c *ErroringConnectionProvider) Connection(_ context.Context, _ *Endpoint) (*grpc.ClientConn, func(), error) {
return nil, nil, errors.New("mock error")
}

// ListAccounts returns an error.
func (c *ErroringConnectionProvider) ListAccounts(ctx context.Context, in *pb.ListAccountsRequest) (*pb.ListAccountsResponse, error) {
func (c *ErroringConnectionProvider) ListAccounts(_ context.Context, _ *pb.ListAccountsRequest) (*pb.ListAccountsResponse, error) {
return nil, errors.New("mock error")
}

Expand All @@ -58,7 +58,7 @@ type BufConnectionProvider struct {
const bufSize = 1024 * 1024

// NewBufConnectionProvider creates a new buffer connection provider.
func NewBufConnectionProvider(ctx context.Context,
func NewBufConnectionProvider(_ context.Context,
listerServers []pb.ListerServer,
) (*BufConnectionProvider, error) {
return &BufConnectionProvider{
Expand All @@ -68,7 +68,7 @@ func NewBufConnectionProvider(ctx context.Context,
}, nil
}

func (c *BufConnectionProvider) bufDialer(ctx context.Context, in string) (net.Conn, error) {
func (c *BufConnectionProvider) bufDialer(_ context.Context, in string) (net.Conn, error) {
return c.listeners[in].Dial()
}

Expand Down

0 comments on commit d09c40d

Please sign in to comment.