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.
This commit is contained in:
carla 2021-12-13 13:56:40 +02:00
parent f01f440715
commit dad103530f
No known key found for this signature in database
GPG key ID: 4CA7FE54A6213C91
19 changed files with 603 additions and 493 deletions

View file

@ -16,7 +16,7 @@ import (
"github.com/btcsuite/btcutil"
"github.com/lightninglabs/aperture/lsat"
"github.com/lightninglabs/loop/loopdb"
"github.com/lightninglabs/loop/looprpc"
"github.com/lightninglabs/loop/swapserverrpc"
"github.com/lightningnetwork/lnd/lnrpc"
"github.com/lightningnetwork/lnd/lntypes"
"github.com/lightningnetwork/lnd/routing/route"
@ -89,7 +89,7 @@ type swapServerClient interface {
}
type grpcSwapServerClient struct {
server looprpc.SwapServerClient
server swapserverrpc.SwapServerClient
conn *grpc.ClientConn
wg sync.WaitGroup
@ -124,7 +124,7 @@ func newSwapServerClient(cfg *ClientConfig, lsatStore lsat.Store) (
return nil, err
}
server := looprpc.NewSwapServerClient(serverConn)
server := swapserverrpc.NewSwapServerClient(serverConn)
return &grpcSwapServerClient{
conn: serverConn,
@ -138,7 +138,7 @@ func (s *grpcSwapServerClient) GetLoopOutTerms(ctx context.Context) (
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel()
terms, err := s.server.LoopOutTerms(rpcCtx,
&looprpc.ServerLoopOutTermsRequest{
&swapserverrpc.ServerLoopOutTermsRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
},
)
@ -161,7 +161,7 @@ func (s *grpcSwapServerClient) GetLoopOutQuote(ctx context.Context,
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel()
quoteResp, err := s.server.LoopOutQuote(rpcCtx,
&looprpc.ServerLoopOutQuoteRequest{
&swapserverrpc.ServerLoopOutQuoteRequest{
Amt: uint64(amt),
SwapPublicationDeadline: swapPublicationDeadline.Unix(),
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
@ -195,7 +195,7 @@ func (s *grpcSwapServerClient) GetLoopInTerms(ctx context.Context) (
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel()
terms, err := s.server.LoopInTerms(rpcCtx,
&looprpc.ServerLoopInTermsRequest{
&swapserverrpc.ServerLoopInTermsRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
},
)
@ -221,7 +221,7 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel()
req := &looprpc.ServerLoopInQuoteRequest{
req := &swapserverrpc.ServerLoopInQuoteRequest{
Amt: uint64(amt),
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
Pubkey: pubKey[:],
@ -252,12 +252,12 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
// marshallRouteHints marshalls a list of route hints.
func marshallRouteHints(routeHints [][]zpay32.HopHint) (
[]*looprpc.RouteHint, error) {
[]*swapserverrpc.RouteHint, error) {
rpcRouteHints := make([]*looprpc.RouteHint, 0, len(routeHints))
rpcRouteHints := make([]*swapserverrpc.RouteHint, 0, len(routeHints))
for _, routeHint := range routeHints {
rpcRouteHint := make(
[]*looprpc.HopHint, 0, len(routeHint),
[]*swapserverrpc.HopHint, 0, len(routeHint),
)
for _, hint := range routeHint {
rpcHint, err := marshallHopHint(hint)
@ -267,7 +267,7 @@ func marshallRouteHints(routeHints [][]zpay32.HopHint) (
rpcRouteHint = append(rpcRouteHint, rpcHint)
}
rpcRouteHints = append(rpcRouteHints, &looprpc.RouteHint{
rpcRouteHints = append(rpcRouteHints, &swapserverrpc.RouteHint{
HopHints: rpcRouteHint,
})
}
@ -276,7 +276,7 @@ func marshallRouteHints(routeHints [][]zpay32.HopHint) (
}
// marshallHopHint marshalls a single hop hint.
func marshallHopHint(hint zpay32.HopHint) (*looprpc.HopHint, error) {
func marshallHopHint(hint zpay32.HopHint) (*swapserverrpc.HopHint, error) {
nodeID, err := route.NewVertexFromBytes(
hint.NodeID.SerializeCompressed(),
)
@ -284,7 +284,7 @@ func marshallHopHint(hint zpay32.HopHint) (*looprpc.HopHint, error) {
return nil, err
}
return &looprpc.HopHint{
return &swapserverrpc.HopHint{
ChanId: hint.ChannelID,
CltvExpiryDelta: uint32(hint.CLTVExpiryDelta),
FeeBaseMsat: hint.FeeBaseMSat,
@ -305,7 +305,7 @@ func (s *grpcSwapServerClient) Probe(ctx context.Context, amt btcutil.Amount,
return err
}
req := &looprpc.ServerProbeRequest{
req := &swapserverrpc.ServerProbeRequest{
Amt: uint64(amt),
Target: target[:],
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
@ -328,7 +328,7 @@ func (s *grpcSwapServerClient) NewLoopOutSwap(ctx context.Context,
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel()
swapResp, err := s.server.NewLoopOutSwap(rpcCtx,
&looprpc.ServerLoopOutRequest{
&swapserverrpc.ServerLoopOutRequest{
SwapHash: swapHash[:],
Amt: uint64(amount),
ReceiverKey: receiverKey[:],
@ -367,7 +367,7 @@ func (s *grpcSwapServerClient) PushLoopOutPreimage(ctx context.Context,
defer rpcCancel()
_, err := s.server.LoopOutPushPreimage(rpcCtx,
&looprpc.ServerLoopOutPushPreimageRequest{
&swapserverrpc.ServerLoopOutPushPreimageRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
Preimage: preimage[:],
},
@ -384,7 +384,7 @@ func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context,
rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout)
defer rpcCancel()
req := &looprpc.ServerLoopInRequest{
req := &swapserverrpc.ServerLoopInRequest{
SwapHash: swapHash[:],
Amt: uint64(amount),
SenderKey: senderKey[:],
@ -421,7 +421,7 @@ func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context,
// ServerUpdate summarizes an update from the swap server.
type ServerUpdate struct {
// State is the state that the server has sent us.
State looprpc.ServerSwapState
State swapserverrpc.ServerSwapState
// Timestamp is the time of the server state update.
Timestamp time.Time
@ -433,7 +433,7 @@ func (s *grpcSwapServerClient) SubscribeLoopInUpdates(ctx context.Context,
hash lntypes.Hash) (<-chan *ServerUpdate, <-chan error, error) {
resp, err := s.server.SubscribeLoopInUpdates(
ctx, &looprpc.SubscribeUpdatesRequest{
ctx, &swapserverrpc.SubscribeUpdatesRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
SwapHash: hash[:],
},
@ -464,7 +464,7 @@ func (s *grpcSwapServerClient) SubscribeLoopOutUpdates(ctx context.Context,
hash lntypes.Hash) (<-chan *ServerUpdate, <-chan error, error) {
resp, err := s.server.SubscribeLoopOutUpdates(
ctx, &looprpc.SubscribeUpdatesRequest{
ctx, &swapserverrpc.SubscribeUpdatesRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
SwapHash: hash[:],
},
@ -603,7 +603,7 @@ type outCancelDetails struct {
func (s *grpcSwapServerClient) CancelLoopOutSwap(ctx context.Context,
details *outCancelDetails) error {
req := &looprpc.CancelLoopOutSwapRequest{
req := &swapserverrpc.CancelLoopOutSwapRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
SwapHash: details.hash[:],
PaymentAddress: details.paymentAddr[:],
@ -620,22 +620,24 @@ func (s *grpcSwapServerClient) CancelLoopOutSwap(ctx context.Context,
}
func rpcRouteCancel(details *outCancelDetails) (
*looprpc.CancelLoopOutSwapRequest_RouteCancel, error) {
*swapserverrpc.CancelLoopOutSwapRequest_RouteCancel, error) {
attempts := make([]*looprpc.HtlcAttempt, len(details.metadata.attempts))
attempts := make(
[]*swapserverrpc.HtlcAttempt, len(details.metadata.attempts),
)
for i, remaining := range details.metadata.attempts {
attempts[i] = &looprpc.HtlcAttempt{
attempts[i] = &swapserverrpc.HtlcAttempt{
RemainingHops: remaining,
}
}
resp := &looprpc.CancelLoopOutSwapRequest_RouteCancel{
RouteCancel: &looprpc.RouteCancel{
resp := &swapserverrpc.CancelLoopOutSwapRequest_RouteCancel{
RouteCancel: &swapserverrpc.RouteCancel{
Attempts: attempts,
// We can cast our lnd failure reason to a loop payment
// failure reason because these values are copied 1:1
// from lnd.
Failure: looprpc.PaymentFailureReason(
Failure: swapserverrpc.PaymentFailureReason(
details.metadata.failureReason,
),
},
@ -643,10 +645,10 @@ func rpcRouteCancel(details *outCancelDetails) (
switch details.metadata.paymentType {
case paymentTypePrepay:
resp.RouteCancel.RouteType = looprpc.RoutePaymentType_PREPAY_ROUTE
resp.RouteCancel.RouteType = swapserverrpc.RoutePaymentType_PREPAY_ROUTE
case paymentTypeInvoice:
resp.RouteCancel.RouteType = looprpc.RoutePaymentType_INVOICE_ROUTE
resp.RouteCancel.RouteType = swapserverrpc.RoutePaymentType_INVOICE_ROUTE
default:
return nil, fmt.Errorf("unknown payment type: %v",