• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

lightningnetwork / lnd / 13412100018

19 Feb 2025 12:05PM UTC coverage: 44.914% (-13.9%) from 58.794%
13412100018

Pull #9521

github

web-flow
Merge 861d6970e into 0e8786348
Pull Request #9521: unit: remove GOACC, use Go 1.20 native coverage functionality

101023 of 224923 relevant lines covered (44.91%)

19479.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lnrpc/verrpc/server.go
1
package verrpc
2

3
import (
4
        "context"
5

6
        "github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
7
        "github.com/lightningnetwork/lnd/build"
8
        "github.com/lightningnetwork/lnd/lnrpc"
9
        "google.golang.org/grpc"
10
        "gopkg.in/macaroon-bakery.v2/bakery"
11
)
12

13
const subServerName = "VersionRPC"
14

15
var macPermissions = map[string][]bakery.Op{
16
        "/verrpc.Versioner/GetVersion": {{
17
                Entity: "info",
18
                Action: "read",
19
        }},
20
}
21

22
// ServerShell is a shell struct holding a reference to the actual sub-server.
23
// It is used to register the gRPC sub-server with the root server before we
24
// have the necessary dependencies to populate the actual sub-server.
25
type ServerShell struct {
26
        VersionerServer
27
}
28

29
// Server is an rpc server that supports querying for information about the
30
// running binary.
31
type Server struct {
32
        // Required by the grpc-gateway/v2 library for forward compatibility.
33
        UnimplementedVersionerServer
34
}
35

36
// Start launches any helper goroutines required for the rpcServer to function.
37
//
38
// NOTE: This is part of the lnrpc.SubServer interface.
39
func (s *Server) Start() error {
×
40
        return nil
×
41
}
×
42

43
// Stop signals any active goroutines for a graceful closure.
44
//
45
// NOTE: This is part of the lnrpc.SubServer interface.
46
func (s *Server) Stop() error {
×
47
        return nil
×
48
}
×
49

50
// Name returns a unique string representation of the sub-server. This can be
51
// used to identify the sub-server and also de-duplicate them.
52
//
53
// NOTE: This is part of the lnrpc.SubServer interface.
54
func (s *Server) Name() string {
×
55
        return subServerName
×
56
}
×
57

58
// RegisterWithRootServer will be called by the root gRPC server to direct a
59
// sub RPC server to register itself with the main gRPC root server. Until this
60
// is called, each sub-server won't be able to have requests routed towards it.
61
//
62
// NOTE: This is part of the lnrpc.GrpcHandler interface.
63
func (r *ServerShell) RegisterWithRootServer(grpcServer *grpc.Server) error {
×
64
        RegisterVersionerServer(grpcServer, r)
×
65

×
66
        log.Debugf("Versioner RPC server successfully registered with root " +
×
67
                "gRPC server")
×
68

×
69
        return nil
×
70
}
×
71

72
// RegisterWithRestServer will be called by the root REST mux to direct a sub
73
// RPC server to register itself with the main REST mux server. Until this is
74
// called, each sub-server won't be able to have requests routed towards it.
75
//
76
// NOTE: This is part of the lnrpc.GrpcHandler interface.
77
func (r *ServerShell) RegisterWithRestServer(ctx context.Context,
78
        mux *runtime.ServeMux, dest string, opts []grpc.DialOption) error {
×
79

×
80
        // We make sure that we register it with the main REST server to ensure
×
81
        // all our methods are routed properly.
×
82
        err := RegisterVersionerHandlerFromEndpoint(ctx, mux, dest, opts)
×
83
        if err != nil {
×
84
                log.Errorf("Could not register Versioner REST server "+
×
85
                        "with root REST server: %v", err)
×
86
                return err
×
87
        }
×
88

89
        log.Debugf("Versioner REST server successfully registered with " +
×
90
                "root REST server")
×
91
        return nil
×
92
}
93

94
// CreateSubServer populates the subserver's dependencies using the passed
95
// SubServerConfigDispatcher. This method should fully initialize the
96
// sub-server instance, making it ready for action. It returns the macaroon
97
// permissions that the sub-server wishes to pass on to the root server for all
98
// methods routed towards it.
99
//
100
// NOTE: This is part of the lnrpc.GrpcHandler interface.
101
func (r *ServerShell) CreateSubServer(_ lnrpc.SubServerConfigDispatcher) (
102
        lnrpc.SubServer, lnrpc.MacaroonPerms, error) {
×
103

×
104
        subServer := &Server{}
×
105
        r.VersionerServer = subServer
×
106
        return subServer, macPermissions, nil
×
107
}
×
108

109
// GetVersion returns information about the compiled binary.
110
func (s *Server) GetVersion(_ context.Context,
111
        _ *VersionRequest) (*Version, error) {
×
112

×
113
        return &Version{
×
114
                Commit:        build.Commit,
×
115
                CommitHash:    build.CommitHash,
×
116
                Version:       build.Version(),
×
117
                AppMajor:      uint32(build.AppMajor),
×
118
                AppMinor:      uint32(build.AppMinor),
×
119
                AppPatch:      uint32(build.AppPatch),
×
120
                AppPreRelease: build.AppPreRelease,
×
121
                BuildTags:     build.Tags(),
×
122
                GoVersion:     build.GoVersion,
×
123
        }, nil
×
124
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc