From a325afb5c7b0cb2194104277a0730d2a1417b914 Mon Sep 17 00:00:00 2001 From: Andras Banki-Horvath Date: Wed, 10 Mar 2021 18:08:14 +0100 Subject: [PATCH] loop-in: await probe from the server on loop-in quote --- loopdb/protocol_version.go | 4 +- loopdb/protocol_version_test.go | 2 + looprpc/server.pb.go | 183 +++++++++++++++++--------------- looprpc/server.proto | 5 + swap_server_client.go | 65 ++++++++++-- 5 files changed, 167 insertions(+), 92 deletions(-) diff --git a/loopdb/protocol_version.go b/loopdb/protocol_version.go index bf612f0..362c16c 100644 --- a/loopdb/protocol_version.go +++ b/loopdb/protocol_version.go @@ -39,13 +39,15 @@ const ( // invoice so that the server can perform a multi-path probe. ProtocolVersionMultiLoopIn ProtocolVersion = 6 + ProtocolVersionMultiLoopInV2 ProtocolVersion = 7 + // ProtocolVersionUnrecorded is set for swaps were created before we // started saving protocol version with swaps. ProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32 // CurrentRPCProtocolVersion defines the version of the RPC protocol // that is currently supported by the loop client. - CurrentRPCProtocolVersion = looprpc.ProtocolVersion_MULTI_LOOP_IN + CurrentRPCProtocolVersion = looprpc.ProtocolVersion_MULTI_LOOP_IN_V2 // CurrentInternalProtocolVersion defines the RPC current protocol in // the internal representation. diff --git a/loopdb/protocol_version_test.go b/loopdb/protocol_version_test.go index 130fcb5..9b3e650 100644 --- a/loopdb/protocol_version_test.go +++ b/loopdb/protocol_version_test.go @@ -21,6 +21,7 @@ func TestProtocolVersionSanity(t *testing.T) { ProtocolVersionUserExpiryLoopOut, ProtocolVersionHtlcV2, ProtocolVersionMultiLoopIn, + ProtocolVersionMultiLoopInV2, } rpcVersions := [...]looprpc.ProtocolVersion{ @@ -31,6 +32,7 @@ func TestProtocolVersionSanity(t *testing.T) { looprpc.ProtocolVersion_USER_EXPIRY_LOOP_OUT, looprpc.ProtocolVersion_HTLC_V2, looprpc.ProtocolVersion_MULTI_LOOP_IN, + looprpc.ProtocolVersion_MULTI_LOOP_IN_V2, } require.Equal(t, len(versions), len(rpcVersions)) diff --git a/looprpc/server.pb.go b/looprpc/server.pb.go index dd9bbba..eaae257 100644 --- a/looprpc/server.pb.go +++ b/looprpc/server.pb.go @@ -54,6 +54,8 @@ const ( // The client creates a probe invoice so that the server can perform a // multi-path probe. ProtocolVersion_MULTI_LOOP_IN ProtocolVersion = 6 + // The client creates a probe invoice in the loop-in quote. + ProtocolVersion_MULTI_LOOP_IN_V2 ProtocolVersion = 7 ) var ProtocolVersion_name = map[int32]string{ @@ -64,6 +66,7 @@ var ProtocolVersion_name = map[int32]string{ 4: "USER_EXPIRY_LOOP_OUT", 5: "HTLC_V2", 6: "MULTI_LOOP_IN", + 7: "MULTI_LOOP_IN_V2", } var ProtocolVersion_value = map[string]int32{ @@ -74,6 +77,7 @@ var ProtocolVersion_value = map[string]int32{ "USER_EXPIRY_LOOP_OUT": 4, "HTLC_V2": 5, "MULTI_LOOP_IN": 6, + "MULTI_LOOP_IN_V2": 7, } func (x ProtocolVersion) String() string { @@ -770,6 +774,7 @@ type ServerLoopInQuoteRequest struct { Amt uint64 `protobuf:"varint,1,opt,name=amt,proto3" json:"amt,omitempty"` /// The protocol version that the client adheres to. ProtocolVersion ProtocolVersion `protobuf:"varint,2,opt,name=protocol_version,json=protocolVersion,proto3,enum=looprpc.ProtocolVersion" json:"protocol_version,omitempty"` + ProbeInvoice string `protobuf:"bytes,3,opt,name=probe_invoice,json=probeInvoice,proto3" json:"probe_invoice,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -814,6 +819,13 @@ func (m *ServerLoopInQuoteRequest) GetProtocolVersion() ProtocolVersion { return ProtocolVersion_LEGACY } +func (m *ServerLoopInQuoteRequest) GetProbeInvoice() string { + if m != nil { + return m.ProbeInvoice + } + return "" +} + type ServerLoopInQuoteResponse struct { SwapFee int64 `protobuf:"varint,1,opt,name=swap_fee,json=swapFee,proto3" json:"swap_fee,omitempty"` SwapFeeRate int64 `protobuf:"varint,2,opt,name=swap_fee_rate,json=swapFeeRate,proto3" json:"swap_fee_rate,omitempty"` // Deprecated: Do not use. @@ -1232,91 +1244,92 @@ func init() { func init() { proto.RegisterFile("server.proto", fileDescriptor_ad098daeda4239f7) } var fileDescriptor_ad098daeda4239f7 = []byte{ - // 1336 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4f, 0x73, 0xda, 0x46, - 0x14, 0xaf, 0xc4, 0x1f, 0x9b, 0x07, 0xd8, 0xf2, 0x26, 0x71, 0x30, 0x89, 0x53, 0xac, 0x34, 0x29, - 0xf5, 0xc1, 0xc9, 0xa4, 0xb7, 0xde, 0x14, 0x90, 0x63, 0x4d, 0xb0, 0xa0, 0x02, 0x9c, 0xe4, 0xb4, - 0x5d, 0xe3, 0xad, 0xad, 0x29, 0x48, 0x8a, 0x24, 0x1c, 0x7b, 0x7a, 0xec, 0xe7, 0xe8, 0x4c, 0xa7, - 0xc7, 0x5e, 0xda, 0x4b, 0x3f, 0x41, 0x67, 0xfa, 0x0d, 0xfa, 0x7d, 0x3a, 0xbb, 0x5a, 0x81, 0x04, - 0xb2, 0x13, 0x77, 0xdc, 0x1b, 0x7a, 0xef, 0xb7, 0xef, 0xcf, 0xef, 0xbd, 0xfd, 0x2d, 0x50, 0x09, - 0xa8, 0x7f, 0x4e, 0xfd, 0x3d, 0xcf, 0x77, 0x43, 0x17, 0xad, 0x8c, 0x5d, 0xd7, 0xf3, 0xbd, 0x51, - 0xfd, 0xe1, 0xa9, 0xeb, 0x9e, 0x8e, 0xe9, 0x33, 0xe2, 0xd9, 0xcf, 0x88, 0xe3, 0xb8, 0x21, 0x09, - 0x6d, 0xd7, 0x09, 0x22, 0x98, 0xfa, 0x8b, 0x0c, 0x77, 0xfb, 0xfc, 0x5c, 0xc7, 0x75, 0xbd, 0xee, - 0x34, 0xb4, 0xe8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f, 0x04, 0xc6, 0xd5, 0x5c, 0xee, 0x3e, 0xf6, 0x24, 0xcc, 0x2f, 0xad, - 0x9c, 0x92, 0xd8, 0x65, 0x91, 0xca, 0x65, 0x89, 0xd4, 0x7b, 0xa8, 0x25, 0x33, 0x7f, 0x44, 0xa2, - 0xb2, 0x08, 0x93, 0x6f, 0xba, 0xcc, 0xff, 0xa4, 0x74, 0x71, 0x96, 0x53, 0xb4, 0x9c, 0x54, 0x0a, - 0xe9, 0x23, 0x4a, 0x21, 0x67, 0x2b, 0x45, 0x86, 0x14, 0xe4, 0x6f, 0x20, 0x05, 0x85, 0xab, 0xa4, - 0x60, 0x3b, 0x25, 0x05, 0xd1, 0x8b, 0x96, 0x90, 0x01, 0x9c, 0xa6, 0xf2, 0xf6, 0x55, 0x60, 0x04, - 0x1b, 0x4b, 0x09, 0x6e, 0x5b, 0x03, 0xd4, 0x9f, 0x24, 0x68, 0xa4, 0xa4, 0xa6, 0x37, 0x0d, 0xce, - 0x7a, 0x3e, 0xb5, 0x27, 0xe4, 0x94, 0xde, 0x66, 0x3b, 0xa8, 0x0e, 0xab, 0x9e, 0x88, 0x1b, 0xdf, - 0xf4, 0xf8, 0x5b, 0x7d, 0x0c, 0x3b, 0xd7, 0x14, 0x11, 0xad, 0x8a, 0xfa, 0x23, 0xdc, 0xef, 0x4f, - 0x8f, 0x83, 0x91, 0x6f, 0x1f, 0xd3, 0xa1, 0x77, 0x42, 0x42, 0x7a, 0xab, 0x7c, 0x5f, 0xab, 0x45, - 0x6a, 0x08, 0x9f, 0xcf, 0x92, 0x8b, 0x22, 0x67, 0x35, 0xcc, 0x6f, 0x6f, 0x68, 0x4f, 0x68, 0x10, - 0x92, 0x89, 0x87, 0x9d, 0x40, 0xac, 0x73, 0x79, 0x66, 0x33, 0x03, 0xb4, 0x07, 0x85, 0x20, 0x8c, - 0x57, 0x39, 0x59, 0x5c, 0xd4, 0x3d, 0x9b, 0x4b, 0x9f, 0xf9, 0xad, 0x08, 0xa6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81, 0x4d, 0xbf, 0x1d, 0xf5, 0xfa, 0xd5, - 0x10, 0xd4, 0x81, 0xaa, 0x60, 0xd7, 0xe0, 0x62, 0x8f, 0x1e, 0x66, 0x82, 0xe3, 0x50, 0xdb, 0x57, - 0x78, 0x45, 0xb3, 0x83, 0xb8, 0xb6, 0xa8, 0xd4, 0xec, 0xda, 0x52, 0xad, 0xaa, 0xd7, 0x41, 0x44, - 0xd4, 0xd3, 0x84, 0x4c, 0xa7, 0x95, 0x12, 0x35, 0xe6, 0xc7, 0xb3, 0x85, 0xbc, 0xde, 0x5c, 0x46, - 0x64, 0xab, 0xed, 0x73, 0x09, 0x51, 0xd8, 0xcc, 0x16, 0xc7, 0x4f, 0xc8, 0xf3, 0x65, 0x76, 0x9e, - 0x25, 0x7d, 0x7d, 0x2e, 0x1d, 0x17, 0xf9, 0x3b, 0xf1, 0xf5, 0xbf, 0x01, 0x00, 0x00, 0xff, 0xff, - 0xbd, 0x37, 0x63, 0xb1, 0xfe, 0x0f, 0x00, 0x00, + // 1350 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x56, 0x4f, 0x73, 0xdb, 0xd4, + 0x17, 0xfd, 0x49, 0xfe, 0x17, 0x5f, 0xdb, 0x89, 0xf2, 0xda, 0xa6, 0x8e, 0xdb, 0xf4, 0xe7, 0xa8, + 0xb4, 0x98, 0x2c, 0xd2, 0x4e, 0xd9, 0xb1, 0x53, 0x6d, 0xa5, 0xd1, 0xd4, 0x91, 0x8d, 0x2c, 0xa7, + 0xed, 0xea, 0xa1, 0x38, 0x8f, 0x44, 0x83, 0x2d, 0x09, 0x49, 0x4e, 0x93, 0x61, 0xc9, 0x77, 0x60, + 0xc7, 0x0c, 0x6b, 0x36, 0xb0, 0x61, 0x86, 0x3d, 0x33, 0x7c, 0x03, 0xbe, 0x0f, 0xf3, 0x9e, 0x9e, + 0x6c, 0xc9, 0x96, 0x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 0x42, + 0x3e, 0x90, 0x0d, 0x56, 0x67, 0x84, 0x77, 0x68, 0xb7, 0xdb, 0xc0, 0xf6, 0x14, 0x7f, 0x4d, 0xe2, + 0x56, 0x4a, 0xf4, 0xf9, 0x80, 0x10, 0xf4, 0x14, 0x6a, 0x71, 0x08, 0xfb, 0x56, 0x48, 0x58, 0xdd, + 0x39, 0x26, 0x78, 0x85, 0x73, 0x0c, 0x2b, 0x64, 0x03, 0xe3, 0x73, 0xa5, 0xba, 0xe5, 0x99, 0x6e, + 0xe5, 0x08, 0x51, 0x26, 0x21, 0xda, 0x83, 0x8d, 0x89, 0xed, 0x60, 0x76, 0x94, 0x35, 0x71, 0xa7, + 0x4e, 0xc8, 0xa6, 0x92, 0x67, 0x07, 0xd5, 0x26, 0xb6, 0x33, 0x78, 0x6f, 0x79, 0x0a, 0x0b, 0x30, + 0xae, 0x75, 0x99, 0xe2, 0x16, 0x13, 0x5c, 0xeb, 0x32, 0xc1, 0xdd, 0x05, 0x18, 0x8d, 0xc3, 0x0b, + 0x7c, 0x4a, 0xc6, 0xa1, 0xc5, 0x56, 0x35, 0x5a, 0x86, 0x32, 0x45, 0x3b, 0x14, 0x94, 0xbf, 0x5a, + 0x98, 0xb3, 0x49, 0xfc, 0x49, 0x10, 0xcf, 0x39, 0x6b, 0x32, 0xc2, 0x0d, 0x27, 0x23, 0xff, 0x2a, + 0x2c, 0x4c, 0x80, 0xa5, 0x40, 0x4f, 0x97, 0x7b, 0x8e, 0xf6, 0x69, 0xa1, 0xdf, 0xa7, 0xcb, 0xfd, + 0x8a, 0x9c, 0x97, 0xea, 0xf5, 0x13, 0x58, 0xa7, 0xe7, 0x25, 0xfa, 0xcd, 0xb1, 0x45, 0xa8, 0x4e, + 0x6c, 0xa7, 0x1d, 0xb7, 0xcb, 0x58, 0xd6, 0x65, 0x92, 0x95, 0xe7, 0x2c, 0xeb, 0x72, 0xc6, 0x92, + 0x7f, 0x16, 0xe1, 0xce, 0xbc, 0x64, 0xcd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x14, 0x63, 0xda, 0xa1, 0x1e, 0x54, + 0x53, 0x7f, 0x4f, 0xe4, 0x85, 0x95, 0xc9, 0xf8, 0x7b, 0xd4, 0x78, 0x70, 0x0d, 0x07, 0xf5, 0x60, + 0x5d, 0x27, 0xef, 0x39, 0x44, 0x13, 0xa1, 0x9d, 0x6c, 0x7a, 0x7c, 0xda, 0xa3, 0x55, 0x61, 0xbe, + 0xf6, 0x63, 0xb8, 0x93, 0x61, 0x15, 0xe8, 0xb3, 0xec, 0xd7, 0x32, 0x3c, 0xad, 0xb1, 0xf7, 0x31, + 0x54, 0x9e, 0x6d, 0xae, 0x47, 0xf4, 0x87, 0x79, 0x85, 0x1e, 0xc9, 0x2b, 0x77, 0x95, 0x1e, 0xd1, + 0x01, 0x5d, 0xa8, 0x24, 0x4d, 0x7d, 0x37, 0x83, 0x9b, 0xbe, 0x51, 0x1a, 0x8d, 0xd5, 0x14, 0xd4, + 0x85, 0x1a, 0x57, 0x57, 0x63, 0x57, 0x00, 0x7a, 0x98, 0x49, 0x8e, 0x8f, 0xda, 0x59, 0x11, 0xe5, + 0xcd, 0x9a, 0x71, 0x6d, 0x51, 0xa9, 0xd9, 0xb5, 0xa5, 0x5a, 0x95, 0xaf, 0xa3, 0xf0, 0x53, 0xcf, + 0x12, 0xe6, 0x9d, 0xf6, 0x4f, 0xd4, 0x9c, 0xbf, 0x9e, 0x6d, 0xef, 0x8d, 0xd6, 0x32, 0x23, 0xdb, + 0x83, 0x9f, 0x0b, 0x88, 0xc0, 0x56, 0xb6, 0x65, 0x7e, 0x44, 0x9e, 0x4f, 0xb3, 0xf3, 0x2c, 0xb9, + 0xee, 0x73, 0xe1, 0xa4, 0xc8, 0x6e, 0x8f, 0xcf, 0xff, 0x0e, 0x00, 0x00, 0xff, 0xff, 0xa5, 0x3a, + 0xa4, 0xc5, 0x3a, 0x10, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. diff --git a/looprpc/server.proto b/looprpc/server.proto index c4febbc..a536dd3 100644 --- a/looprpc/server.proto +++ b/looprpc/server.proto @@ -64,6 +64,9 @@ enum ProtocolVersion { // The client creates a probe invoice so that the server can perform a // multi-path probe. MULTI_LOOP_IN = 6; + + // The client creates a probe invoice in the loop-in quote. + MULTI_LOOP_IN_V2 = 7; } message ServerLoopOutRequest { @@ -197,6 +200,8 @@ message ServerLoopInQuoteRequest { /// The protocol version that the client adheres to. ProtocolVersion protocol_version = 2; + + string probe_invoice = 3; } message ServerLoopInQuoteResponse { diff --git a/swap_server_client.go b/swap_server_client.go index 1f62c05..ae69940 100644 --- a/swap_server_client.go +++ b/swap_server_client.go @@ -2,6 +2,8 @@ package loop import ( "context" + "crypto/rand" + "crypto/sha256" "crypto/tls" "encoding/hex" "errors" @@ -14,10 +16,13 @@ import ( "github.com/btcsuite/btcd/btcec" "github.com/btcsuite/btcutil" + "github.com/lightninglabs/lndclient" "github.com/lightninglabs/loop/loopdb" "github.com/lightninglabs/loop/looprpc" "github.com/lightninglabs/loop/lsat" + "github.com/lightningnetwork/lnd/lnrpc/invoicesrpc" "github.com/lightningnetwork/lnd/lntypes" + "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/routing/route" "github.com/lightningnetwork/lnd/tor" "google.golang.org/grpc" @@ -79,6 +84,7 @@ type swapServerClient interface { type grpcSwapServerClient struct { server looprpc.SwapServerClient conn *grpc.ClientConn + lnd *lndclient.LndServices wg sync.WaitGroup } @@ -117,6 +123,7 @@ func newSwapServerClient(cfg *ClientConfig, lsatStore lsat.Store) ( return &grpcSwapServerClient{ conn: serverConn, server: server, + lnd: cfg.Lnd, }, nil } @@ -202,16 +209,62 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context, rpcCtx, rpcCancel := context.WithTimeout(ctx, globalCallTimeout) defer rpcCancel() - quoteResp, err := s.server.LoopInQuote(rpcCtx, - &looprpc.ServerLoopInQuoteRequest{ - Amt: uint64(amt), - ProtocolVersion: loopdb.CurrentRPCProtocolVersion, - }, - ) + + quoteReq := &looprpc.ServerLoopInQuoteRequest{ + Amt: uint64(amt), + ProtocolVersion: loopdb.CurrentRPCProtocolVersion, + } + + var probeHash lntypes.Hash + if loopdb.CurrentRPCProtocolVersion == looprpc.ProtocolVersion_MULTI_LOOP_IN_V2 { + // Generate random preimage. + var preimage lntypes.Preimage + if _, err := rand.Read(preimage[:]); err != nil { + log.Error("Cannot generate preimage") + } + + probeHash := lntypes.Hash(sha256.Sum256(preimage[:])) + + log.Infof("Creating quote probe invoice %v", probeHash) + probeInvoice, err := s.lnd.Invoices.AddHoldInvoice( + rpcCtx, &invoicesrpc.AddInvoiceData{ + Hash: &probeHash, + Value: lnwire.NewMSatFromSatoshis(amt), + Memo: "loop in quote probe", + Expiry: 3600, + }, + ) + if err != nil { + return nil, err + } + + quoteReq.ProbeInvoice = probeInvoice + } + + quoteResp, err := s.server.LoopInQuote(rpcCtx, quoteReq) if err != nil { return nil, err } + if loopdb.CurrentRPCProtocolVersion == looprpc.ProtocolVersion_MULTI_LOOP_IN_V2 { + // Create a cancellable context that is used for monitoring the probe. + probeWaitCtx, probeWaitCancel := context.WithCancel(ctx) + defer probeWaitCancel() + + // Launch a goroutine to monitor the probe. + probeResult, err := awaitProbe(probeWaitCtx, *s.lnd, probeHash) + if err != nil { + return nil, fmt.Errorf("loop in quote probe failed: %v", err) + } + + // Because the context is cancelled, it is guaranteed that we will be + // able to read from the probeResult channel. + err = <-probeResult + if err != nil { + return nil, fmt.Errorf("probe error: %v", err) + } + } + return &LoopInQuote{ SwapFee: btcutil.Amount(quoteResp.SwapFee), CltvDelta: quoteResp.CltvDelta,