Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
aeddi committed Jan 20, 2025
1 parent bdaddaf commit 4948bd8
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
24 changes: 13 additions & 11 deletions contribs/gnokms/internal/common/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func NewSignerServer(
commonFlags.LogFormat,
)
if err != nil {
return nil, nil, fmt.Errorf("unable to initialize zap logger, %w", err)
return nil, nil, fmt.Errorf("unable to initialize zap logger: %w", err)
}

// Keep a reference to the zap logger flush function.
Expand All @@ -47,24 +47,26 @@ func NewSignerServer(
return nil, nil, err
}

endpoint := privval.NewSignerDialerEndpoint(
logger,
dialer,
privval.SignerDialerEndpointMaxDialRetries(commonFlags.DialMaxRetries),
privval.SignerDialerEndpointDialRetryInterval(commonFlags.DialRetryInterval),
privval.SignerDialerEndpointReadWriteTimeout(commonFlags.ReadWriteTimeout),
// Initialize the server with the dialer, the connection parameters and the private validator.
server := privval.NewSignerServer(
privval.NewSignerDialerEndpoint(
logger,
dialer,
privval.SignerDialerEndpointMaxDialRetries(commonFlags.DialMaxRetries),
privval.SignerDialerEndpointDialRetryInterval(commonFlags.DialRetryInterval),
privval.SignerDialerEndpointReadWriteTimeout(commonFlags.ReadWriteTimeout),
),
commonFlags.ChainID,
privVal,
)

// Initialize the remote signer server with the dialer and the gnokey private validator.
server := privval.NewSignerServer(endpoint, commonFlags.ChainID, privVal)

return server, flush, nil
}

// RunSignerServer initializes and start a remote signer server with the given private validator.
// It then waits for the server to finish.
func RunSignerServer(io commands.IO, commonFlags *Flags, privVal types.PrivValidator) error {
// Initialize the remote signer server with the gnokey private validator.
// Initialize the remote signer server with the private validator.
server, flush, err := NewSignerServer(io, commonFlags, privVal)
if err != nil {
return err
Expand Down
8 changes: 4 additions & 4 deletions contribs/gnokms/internal/gnokey/gnokey.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (gk *gnokeyPrivVal) SignProposal(chainID string, proposal *types.Proposal)
// Sign the proposal.
sig, _, err := gk.keyBase.Sign(gk.keyInfo.GetName(), gk.password, proposal.SignBytes(chainID))
if err != nil {
return fmt.Errorf("unable to sign proposal bytes, %w", err)
return fmt.Errorf("unable to sign proposal bytes: %w", err)
}

// Save the signature (the proposal will be returned to the client).
Expand All @@ -42,7 +42,7 @@ func (gk *gnokeyPrivVal) SignVote(chainID string, vote *types.Vote) error {
// Sign the vote.
sig, _, err := gk.keyBase.Sign(gk.keyInfo.GetName(), gk.password, vote.SignBytes(chainID))
if err != nil {
return fmt.Errorf("unable to sign vote bytes, %w", err)
return fmt.Errorf("unable to sign vote bytes: %w", err)
}

// Save the vote (the vote will be returned to the client).
Expand Down Expand Up @@ -83,7 +83,7 @@ func newGnokeyPrivVal(
gnFlags.insecurePasswordStdin,
)
if err != nil {
return nil, fmt.Errorf("unable to get decryption key, %w", err)
return nil, fmt.Errorf("unable to get decryption key: %w", err)
}

// Check if the password is correct.
Expand All @@ -95,7 +95,7 @@ func newGnokeyPrivVal(
break
}
default: // Offline and Multi types are not supported.
return nil, fmt.Errorf("unsupported key type, %s", info.GetType())
return nil, fmt.Errorf("unsupported key type: %s", info.GetType())
}

return &gnokeyPrivVal{
Expand Down
2 changes: 1 addition & 1 deletion tm2/pkg/bft/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,7 +976,7 @@ func createAndStartPrivValidatorSocketClient(
listenAddr string,
logger *slog.Logger,
) (types.PrivValidator, error) {
// TODO: pass in the mutual auth keys
// TODO: pass in the mutual auth keys
listener, err := privval.NewListener(listenAddr, ed25519.GenPrivKey(), nil)
if err != nil {
return nil, errors.Wrap(err, "failed to start private validator")
Expand Down
22 changes: 16 additions & 6 deletions tm2/pkg/bft/privval/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ import (
osm "github.com/gnolang/gno/tm2/pkg/os"
)

// Protocols supported by the privval package.
const (
unix = "unix"
tcp = "tcp"
)

// IsConnTimeout returns a boolean indicating whether the error is known to
// report that a connection timeout occurred. This detects both fundamental
// network timeouts, as well as ErrConnTimeout errors.
Expand Down Expand Up @@ -40,13 +46,15 @@ func NewListener(
return nil, err
}
switch protocol {
case "unix":
case unix:
listener = NewUnixListener(ln)
case "tcp":
case tcp:
listener = NewTCPListener(ln, listenerKey, authorizedKeys)
default:
return nil, fmt.Errorf(
"wrong listen address: expected either 'tcp' or 'unix' protocols, got %s",
"wrong listen address: expected either '%s' or '%s' protocols, got %s",
unix,
tcp,

Check warning on line 57 in tm2/pkg/bft/privval/utils.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/privval/utils.go#L55-L57

Added lines #L55 - L57 were not covered by tests
protocol,
)
}
Expand All @@ -66,13 +74,15 @@ func NewDialer(

protocol, address := osm.ProtocolAndAddress(dialAddr)
switch protocol {
case "unix":
case unix:
dialer = DialUnixFn(address)
case "tcp":
case tcp:
dialer = DialTCPFn(address, tcpTimeout, dialerKey, authorizedKeys)
default:
return nil, fmt.Errorf(
"wrong listen address: expected either 'tcp' or 'unix' protocols, got %s",
"wrong dialer address: expected either '%s' or '%s' protocols, got %s",
unix,
tcp,
protocol,
)

Check warning on line 87 in tm2/pkg/bft/privval/utils.go

View check run for this annotation

Codecov / codecov/patch

tm2/pkg/bft/privval/utils.go#L72-L87

Added lines #L72 - L87 were not covered by tests
}
Expand Down

0 comments on commit 4948bd8

Please sign in to comment.