Skip to content

Commit dad1035

Browse files
committed
multi: move server proto files to their own directory
Protobuf does not allow naming conflicts for files within the same process, because all proto messages register themselves in a global registry. This is problematic because the server's itests import the client's looprpc package to make rpc queries to the loopd client, thus importing duplicate common.proto and server.proto from the client's looprc package (since they're both in there as well). This change moves the server's proto files into their own directory so that they are not imported when we want to use the client's files. We cannot change the package name for the server, because that would be a breaking change (the package name is included in URIS). Fortunately, we have the go_package option which allows us to place generated files in a different location.
1 parent f01f440 commit dad1035

19 files changed

+603
-493
lines changed

Makefile

+4
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ install:
7575

7676
rpc:
7777
@$(call print, "Compiling protos.")
78+
cd ./swapserverrpc; ./gen_protos_docker.sh
7879
cd ./looprpc; ./gen_protos_docker.sh
7980

8081
rpc-check: rpc
@@ -85,6 +86,9 @@ rpc-js-compile:
8586
@$(call print, "Compiling JSON/WASM stubs.")
8687
GOOS=js GOARCH=wasm $(GOBUILD) $(PKG)/looprpc
8788

89+
rpc-format:
90+
cd ./looprpc; find . -name "*.proto" | xargs clang-format --style=file -i
91+
cd ./swapserverrpc; find . -name "*.proto" | xargs clang-format --style=file -i
8892

8993
clean:
9094
@$(call print, "Cleaning up.")

cmd/loop/utils.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import (
44
"encoding/json"
55
"fmt"
66

7-
"github.com/lightninglabs/loop/looprpc"
7+
"github.com/lightninglabs/loop/swapserverrpc"
88
"github.com/urfave/cli"
99
)
1010

1111
// validateRouteHints ensures that the Private flag isn't set along with
1212
// the RouteHints flag. We don't allow both options to be set as these options
1313
// are alternatives to each other. Private autogenerates hopHints while
1414
// RouteHints are manually passed.
15-
func validateRouteHints(ctx *cli.Context) ([]*looprpc.RouteHint, error) {
16-
var hints []*looprpc.RouteHint
15+
func validateRouteHints(ctx *cli.Context) ([]*swapserverrpc.RouteHint, error) {
16+
var hints []*swapserverrpc.RouteHint
1717

1818
if ctx.IsSet(routeHintsFlag.Name) {
1919
if ctx.IsSet(privateFlag.Name) {

loopd/swapclient_server.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"github.com/lightninglabs/loop/loopdb"
2020
"github.com/lightninglabs/loop/looprpc"
2121
"github.com/lightninglabs/loop/swap"
22+
"github.com/lightninglabs/loop/swapserverrpc"
2223
"github.com/lightningnetwork/lnd/lntypes"
2324
"github.com/lightningnetwork/lnd/lnwallet/chainfee"
2425
"github.com/lightningnetwork/lnd/lnwire"
@@ -525,7 +526,7 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
525526
}
526527

527528
// unmarshallRouteHints unmarshalls a list of route hints.
528-
func unmarshallRouteHints(rpcRouteHints []*looprpc.RouteHint) (
529+
func unmarshallRouteHints(rpcRouteHints []*swapserverrpc.RouteHint) (
529530
[][]zpay32.HopHint, error) {
530531

531532
routeHints := make([][]zpay32.HopHint, 0, len(rpcRouteHints))
@@ -548,7 +549,7 @@ func unmarshallRouteHints(rpcRouteHints []*looprpc.RouteHint) (
548549
}
549550

550551
// unmarshallHopHint unmarshalls a single hop hint.
551-
func unmarshallHopHint(rpcHint *looprpc.HopHint) (zpay32.HopHint, error) {
552+
func unmarshallHopHint(rpcHint *swapserverrpc.HopHint) (zpay32.HopHint, error) {
552553
pubBytes, err := hex.DecodeString(rpcHint.NodeId)
553554
if err != nil {
554555
return zpay32.HopHint{}, err

loopdb/protocol_version.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package loopdb
33
import (
44
"math"
55

6-
"github.com/lightninglabs/loop/looprpc"
6+
"github.com/lightninglabs/loop/swapserverrpc"
77
)
88

99
// ProtocolVersion represents the protocol version (declared on rpc level) that
@@ -53,7 +53,7 @@ const (
5353

5454
// CurrentRPCProtocolVersion defines the version of the RPC protocol
5555
// that is currently supported by the loop client.
56-
CurrentRPCProtocolVersion = looprpc.ProtocolVersion_PROBE
56+
CurrentRPCProtocolVersion = swapserverrpc.ProtocolVersion_PROBE
5757

5858
// CurrentInternalProtocolVersion defines the RPC current protocol in
5959
// the internal representation.

loopdb/protocol_version_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package loopdb
33
import (
44
"testing"
55

6-
"github.com/lightninglabs/loop/looprpc"
6+
"github.com/lightninglabs/loop/swapserverrpc"
77
"github.com/stretchr/testify/require"
88
)
99

@@ -25,16 +25,16 @@ func TestProtocolVersionSanity(t *testing.T) {
2525
ProtocolVersionProbe,
2626
}
2727

28-
rpcVersions := [...]looprpc.ProtocolVersion{
29-
looprpc.ProtocolVersion_LEGACY,
30-
looprpc.ProtocolVersion_MULTI_LOOP_OUT,
31-
looprpc.ProtocolVersion_NATIVE_SEGWIT_LOOP_IN,
32-
looprpc.ProtocolVersion_PREIMAGE_PUSH_LOOP_OUT,
33-
looprpc.ProtocolVersion_USER_EXPIRY_LOOP_OUT,
34-
looprpc.ProtocolVersion_HTLC_V2,
35-
looprpc.ProtocolVersion_MULTI_LOOP_IN,
36-
looprpc.ProtocolVersion_LOOP_OUT_CANCEL,
37-
looprpc.ProtocolVersion_PROBE,
28+
rpcVersions := [...]swapserverrpc.ProtocolVersion{
29+
swapserverrpc.ProtocolVersion_LEGACY,
30+
swapserverrpc.ProtocolVersion_MULTI_LOOP_OUT,
31+
swapserverrpc.ProtocolVersion_NATIVE_SEGWIT_LOOP_IN,
32+
swapserverrpc.ProtocolVersion_PREIMAGE_PUSH_LOOP_OUT,
33+
swapserverrpc.ProtocolVersion_USER_EXPIRY_LOOP_OUT,
34+
swapserverrpc.ProtocolVersion_HTLC_V2,
35+
swapserverrpc.ProtocolVersion_MULTI_LOOP_IN,
36+
swapserverrpc.ProtocolVersion_LOOP_OUT_CANCEL,
37+
swapserverrpc.ProtocolVersion_PROBE,
3838
}
3939

4040
require.Equal(t, len(versions), len(rpcVersions))

looprpc/.clang-format

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ BasedOnStyle: Google
44
IndentWidth: 4
55
AllowShortFunctionsOnASingleLine: None
66
SpaceBeforeParens: Always
7-
CompactNamespaces: false
7+
CompactNamespaces: false

looprpc/client.pb.go

+427-426
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

looprpc/client.proto

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
syntax = "proto3";
22

3-
import "common.proto";
3+
import "swapserverrpc/common.proto";
44

55
package looprpc;
66

@@ -268,7 +268,7 @@ message LoopInRequest {
268268
/*
269269
Optional route hints to reach the destination through private channels.
270270
*/
271-
repeated RouteHint route_hints = 9;
271+
repeated looprpc.RouteHint route_hints = 9;
272272

273273
/*
274274
Private indicates whether the destination node should be considered
@@ -591,7 +591,7 @@ message QuoteRequest {
591591
/*
592592
Optional route hints to reach the destination through private channels.
593593
*/
594-
repeated RouteHint loop_in_route_hints = 6;
594+
repeated looprpc.RouteHint loop_in_route_hints = 6;
595595

596596
/*
597597
Private indicates whether the destination node should be considered
@@ -678,7 +678,7 @@ message ProbeRequest {
678678
/*
679679
Optional route hints to reach the destination through private channels.
680680
*/
681-
repeated RouteHint route_hints = 3;
681+
repeated looprpc.RouteHint route_hints = 3;
682682
}
683683

684684
message ProbeResponse {

looprpc/gen_protos.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@ function generate() {
77
# Generate the gRPC bindings for all proto files.
88
for file in ./*.proto
99
do
10-
protoc -I/usr/local/include -I. \
10+
protoc -I/usr/local/include -I. -I.. \
1111
--go_out . --go_opt paths=source_relative \
1212
--go-grpc_out . --go-grpc_opt paths=source_relative \
1313
"${file}"
1414
done
1515

1616
# Generate the REST reverse proxy for the client only.
17-
protoc -I/usr/local/include -I. \
17+
protoc -I/usr/local/include -I. -I.. \
1818
--grpc-gateway_out . \
1919
--grpc-gateway_opt logtostderr=true \
2020
--grpc-gateway_opt paths=source_relative \
2121
--grpc-gateway_opt grpc_api_configuration=client.yaml \
2222
client.proto
2323

2424
# Finally, generate the swagger file which describes the REST API in detail.
25-
protoc -I/usr/local/include -I. \
25+
protoc -I/usr/local/include -I. -I.. \
2626
--openapiv2_out . \
2727
--openapiv2_opt logtostderr=true \
2828
--openapiv2_opt grpc_api_configuration=client.yaml \

0 commit comments

Comments
 (0)