You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
2.7 KiB

cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
cleanup: Reduce and normalize import path aliasing. (#6975) The code in the Tendermint repository makes heavy use of import aliasing. This is made necessary by our extensive reuse of common base package names, and by repetition of similar names across different subdirectories. Unfortunately we have not been very consistent about which packages we alias in various circumstances, and the aliases we use vary. In the spirit of the advice in the style guide and https://github.com/golang/go/wiki/CodeReviewComments#imports, his change makes an effort to clean up and normalize import aliasing. This change makes no API or behavioral changes. It is a pure cleanup intended o help make the code more readable to developers (including myself) trying to understand what is being imported where. Only unexported names have been modified, and the changes were generated and applied mechanically with gofmt -r and comby, respecting the lexical and syntactic rules of Go. Even so, I did not fix every inconsistency. Where the changes would be too disruptive, I left it alone. The principles I followed in this cleanup are: - Remove aliases that restate the package name. - Remove aliases where the base package name is unambiguous. - Move overly-terse abbreviations from the import to the usage site. - Fix lexical issues (remove underscores, remove capitalization). - Fix import groupings to more closely match the style guide. - Group blank (side-effecting) imports and ensure they are commented. - Add aliases to multiple imports with the same base package name.
3 years ago
  1. package grpc
  2. import (
  3. context "context"
  4. "google.golang.org/grpc/codes"
  5. "google.golang.org/grpc/status"
  6. "github.com/tendermint/tendermint/crypto"
  7. "github.com/tendermint/tendermint/crypto/encoding"
  8. "github.com/tendermint/tendermint/libs/log"
  9. privvalproto "github.com/tendermint/tendermint/proto/tendermint/privval"
  10. "github.com/tendermint/tendermint/types"
  11. )
  12. // SignerServer implements PrivValidatorAPIServer 9generated via protobuf services)
  13. // Handles remote validator connections that provide signing services
  14. type SignerServer struct {
  15. logger log.Logger
  16. chainID string
  17. privVal types.PrivValidator
  18. }
  19. func NewSignerServer(chainID string,
  20. privVal types.PrivValidator, log log.Logger) *SignerServer {
  21. return &SignerServer{
  22. logger: log,
  23. chainID: chainID,
  24. privVal: privVal,
  25. }
  26. }
  27. var _ privvalproto.PrivValidatorAPIServer = (*SignerServer)(nil)
  28. // PubKey receives a request for the pubkey
  29. // returns the pubkey on success and error on failure
  30. func (ss *SignerServer) GetPubKey(ctx context.Context, req *privvalproto.PubKeyRequest) (
  31. *privvalproto.PubKeyResponse, error) {
  32. var pubKey crypto.PubKey
  33. pubKey, err := ss.privVal.GetPubKey(ctx)
  34. if err != nil {
  35. return nil, status.Errorf(codes.NotFound, "error getting pubkey: %v", err)
  36. }
  37. pk, err := encoding.PubKeyToProto(pubKey)
  38. if err != nil {
  39. return nil, status.Errorf(codes.Internal, "error transitioning pubkey to proto: %v", err)
  40. }
  41. ss.logger.Info("SignerServer: GetPubKey Success")
  42. return &privvalproto.PubKeyResponse{PubKey: pk}, nil
  43. }
  44. // SignVote receives a vote sign requests, attempts to sign it
  45. // returns SignedVoteResponse on success and error on failure
  46. func (ss *SignerServer) SignVote(ctx context.Context, req *privvalproto.SignVoteRequest) (
  47. *privvalproto.SignedVoteResponse, error) {
  48. vote := req.Vote
  49. err := ss.privVal.SignVote(ctx, req.ChainId, vote)
  50. if err != nil {
  51. return nil, status.Errorf(codes.InvalidArgument, "error signing vote: %v", err)
  52. }
  53. ss.logger.Info("SignerServer: SignVote Success", "height", req.Vote.Height)
  54. return &privvalproto.SignedVoteResponse{Vote: *vote}, nil
  55. }
  56. // SignProposal receives a proposal sign requests, attempts to sign it
  57. // returns SignedProposalResponse on success and error on failure
  58. func (ss *SignerServer) SignProposal(ctx context.Context, req *privvalproto.SignProposalRequest) (
  59. *privvalproto.SignedProposalResponse, error) {
  60. proposal := req.Proposal
  61. err := ss.privVal.SignProposal(ctx, req.ChainId, proposal)
  62. if err != nil {
  63. return nil, status.Errorf(codes.InvalidArgument, "error signing proposal: %v", err)
  64. }
  65. ss.logger.Info("SignerServer: SignProposal Success", "height", req.Proposal.Height)
  66. return &privvalproto.SignedProposalResponse{Proposal: *proposal}, nil
  67. }