Skip to content

Commit 00cf4bf

Browse files
committed
multi: make the next protocol version optional
1 parent 9b37d74 commit 00cf4bf

File tree

7 files changed

+74
-26
lines changed

7 files changed

+74
-26
lines changed

loopd/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ type Config struct {
149149
TotalPaymentTimeout time.Duration `long:"totalpaymenttimeout" description:"The timeout to use for off-chain payments."`
150150
MaxPaymentRetries int `long:"maxpaymentretries" description:"The maximum number of times an off-chain payment may be retried."`
151151

152+
EnableExperimental bool `long:"experimental" description:"Enable experimental features: taproot HTLCs and MuSig2 loop out sweeps."`
153+
152154
Lnd *lndConfig `group:"lnd" namespace:"lnd"`
153155

154156
Server *loopServerConfig `group:"server" namespace:"server"`
@@ -185,6 +187,7 @@ func DefaultConfig() Config {
185187
LoopOutMaxParts: defaultLoopOutMaxParts,
186188
TotalPaymentTimeout: defaultTotalPaymentTimeout,
187189
MaxPaymentRetries: defaultMaxPaymentRetries,
190+
EnableExperimental: false,
188191
Lnd: &lndConfig{
189192
Host: "localhost:10009",
190193
MacaroonPath: DefaultLndMacaroonPath,

loopd/daemon.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,12 @@ func (d *Daemon) startWebServers() error {
348348
// this method fails with an error then no goroutine was started yet and no
349349
// cleanup is necessary. If it succeeds, then goroutines have been spawned.
350350
func (d *Daemon) initialize(withMacaroonService bool) error {
351+
if d.cfg.EnableExperimental {
352+
loopdb.EnableExperimentalProtocol()
353+
}
354+
355+
log.Infof("Protocol version: %v", loopdb.CurrentProtocolVersion())
356+
351357
// If no swap server is specified, use the default addresses for mainnet
352358
// and testnet.
353359
if d.cfg.Server.Host == "" {

loopdb/protocol_version.go

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,50 @@ const (
5959
// started saving protocol version with swaps.
6060
ProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32
6161

62-
// CurrentRPCProtocolVersion defines the version of the RPC protocol
63-
// that is currently supported by the loop client.
64-
CurrentRPCProtocolVersion = looprpc.ProtocolVersion_HTLC_V3
62+
// stableRPCProtocolVersion defines the current stable RPC protocol
63+
// version.
64+
stableRPCProtocolVersion = looprpc.ProtocolVersion_ROUTING_PLUGIN
6565

66-
// CurrentInternalProtocolVersion defines the RPC current protocol in
67-
// the internal representation.
68-
CurrentInternalProtocolVersion = ProtocolVersion(CurrentRPCProtocolVersion)
66+
// experimentalRPCProtocolVersion defines the RPC protocol version that
67+
// includes all currently experimentally released features.
68+
experimentalRPCProtocolVersion = looprpc.ProtocolVersion_HTLC_V3
6969
)
7070

71+
var (
72+
// currentRPCProtocolVersion holds the version of the RPC protocol
73+
// that the client selected to use for new swaps. Shouldn't be lower
74+
// than the previous protocol version.
75+
currentRPCProtocolVersion = stableRPCProtocolVersion
76+
)
77+
78+
// CurrentRPCProtocolVersion returns the RPC protocol version selected to be
79+
// used for new swaps.
80+
func CurrentRPCProtocolVersion() looprpc.ProtocolVersion {
81+
return currentRPCProtocolVersion
82+
}
83+
84+
// CurrentProtocolVersion returns the internal protocol version selected to be
85+
// used for new swaps.
86+
func CurrentProtocolVersion() ProtocolVersion {
87+
return ProtocolVersion(currentRPCProtocolVersion)
88+
}
89+
90+
// EnableExperimentalProtocol sets the current protocol version to include all
91+
// experimental features. Do not call this function directly: used in loopd and
92+
// unit tests only.
93+
func EnableExperimentalProtocol() {
94+
currentRPCProtocolVersion = experimentalRPCProtocolVersion
95+
}
96+
97+
// ResetCurrentProtocolVersion resets the current protocol version to the stable
98+
// protocol. Note: used in integration tests only!
99+
func ResetCurrentProtocolVersion() {
100+
currentRPCProtocolVersion = stableRPCProtocolVersion
101+
}
102+
71103
// Valid returns true if the value of the ProtocolVersion is valid.
72104
func (p ProtocolVersion) Valid() bool {
73-
return p <= CurrentInternalProtocolVersion
105+
return p <= ProtocolVersion(experimentalRPCProtocolVersion)
74106
}
75107

76108
// String returns the string representation of a protocol version.

loopdb/protocol_version_test.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,19 @@ func TestProtocolVersionSanity(t *testing.T) {
4848

4949
// Finally test that the current version contants are up to date
5050
require.Equal(t,
51-
CurrentInternalProtocolVersion,
52-
versions[len(versions)-1],
51+
CurrentProtocolVersion(),
52+
versions[len(versions)-2],
5353
)
5454

5555
require.Equal(t,
56-
uint32(CurrentInternalProtocolVersion),
57-
uint32(CurrentRPCProtocolVersion),
56+
uint32(CurrentProtocolVersion()),
57+
uint32(CurrentRPCProtocolVersion()),
58+
)
59+
60+
EnableExperimentalProtocol()
61+
62+
require.Equal(t,
63+
CurrentProtocolVersion(),
64+
ProtocolVersion(experimentalRPCProtocolVersion),
5865
)
5966
}

loopin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
244244
MaxMinerFee: request.MaxMinerFee,
245245
MaxSwapFee: request.MaxSwapFee,
246246
Label: request.Label,
247-
ProtocolVersion: loopdb.CurrentInternalProtocolVersion,
247+
ProtocolVersion: loopdb.CurrentProtocolVersion(),
248248
},
249249
}
250250

loopout.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
177177
MaxMinerFee: request.MaxMinerFee,
178178
MaxSwapFee: request.MaxSwapFee,
179179
Label: request.Label,
180-
ProtocolVersion: loopdb.CurrentInternalProtocolVersion,
180+
ProtocolVersion: loopdb.CurrentProtocolVersion(),
181181
},
182182
OutgoingChanSet: chanSet,
183183
}

swap_server_client.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ func (s *grpcSwapServerClient) GetLoopOutTerms(ctx context.Context) (
174174
defer rpcCancel()
175175
terms, err := s.server.LoopOutTerms(rpcCtx,
176176
&looprpc.ServerLoopOutTermsRequest{
177-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
177+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
178178
},
179179
)
180180
if err != nil {
@@ -199,7 +199,7 @@ func (s *grpcSwapServerClient) GetLoopOutQuote(ctx context.Context,
199199
&looprpc.ServerLoopOutQuoteRequest{
200200
Amt: uint64(amt),
201201
SwapPublicationDeadline: swapPublicationDeadline.Unix(),
202-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
202+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
203203
Expiry: expiry,
204204
},
205205
)
@@ -231,7 +231,7 @@ func (s *grpcSwapServerClient) GetLoopInTerms(ctx context.Context) (
231231
defer rpcCancel()
232232
terms, err := s.server.LoopInTerms(rpcCtx,
233233
&looprpc.ServerLoopInTermsRequest{
234-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
234+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
235235
},
236236
)
237237
if err != nil {
@@ -258,7 +258,7 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
258258

259259
req := &looprpc.ServerLoopInQuoteRequest{
260260
Amt: uint64(amt),
261-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
261+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
262262
Pubkey: pubKey[:],
263263
}
264264

@@ -343,7 +343,7 @@ func (s *grpcSwapServerClient) Probe(ctx context.Context, amt btcutil.Amount,
343343
req := &looprpc.ServerProbeRequest{
344344
Amt: uint64(amt),
345345
Target: target[:],
346-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
346+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
347347
RouteHints: rpcRouteHints,
348348
}
349349

@@ -368,7 +368,7 @@ func (s *grpcSwapServerClient) NewLoopOutSwap(ctx context.Context,
368368
Amt: uint64(amount),
369369
ReceiverKey: receiverKey[:],
370370
SwapPublicationDeadline: swapPublicationDeadline.Unix(),
371-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
371+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
372372
Expiry: expiry,
373373
UserAgent: UserAgent(initiator),
374374
},
@@ -403,7 +403,7 @@ func (s *grpcSwapServerClient) PushLoopOutPreimage(ctx context.Context,
403403

404404
_, err := s.server.LoopOutPushPreimage(rpcCtx,
405405
&looprpc.ServerLoopOutPushPreimageRequest{
406-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
406+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
407407
Preimage: preimage[:],
408408
},
409409
)
@@ -424,7 +424,7 @@ func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context,
424424
Amt: uint64(amount),
425425
SenderKey: senderKey[:],
426426
SwapInvoice: swapInvoice,
427-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
427+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
428428
ProbeInvoice: probeInvoice,
429429
UserAgent: UserAgent(initiator),
430430
}
@@ -469,7 +469,7 @@ func (s *grpcSwapServerClient) SubscribeLoopInUpdates(ctx context.Context,
469469

470470
resp, err := s.server.SubscribeLoopInUpdates(
471471
ctx, &looprpc.SubscribeUpdatesRequest{
472-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
472+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
473473
SwapHash: hash[:],
474474
},
475475
)
@@ -500,7 +500,7 @@ func (s *grpcSwapServerClient) SubscribeLoopOutUpdates(ctx context.Context,
500500

501501
resp, err := s.server.SubscribeLoopOutUpdates(
502502
ctx, &looprpc.SubscribeUpdatesRequest{
503-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
503+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
504504
SwapHash: hash[:],
505505
},
506506
)
@@ -639,7 +639,7 @@ func (s *grpcSwapServerClient) CancelLoopOutSwap(ctx context.Context,
639639
details *outCancelDetails) error {
640640

641641
req := &looprpc.CancelLoopOutSwapRequest{
642-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
642+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
643643
SwapHash: details.hash[:],
644644
PaymentAddress: details.paymentAddr[:],
645645
}
@@ -660,7 +660,7 @@ func (s *grpcSwapServerClient) RecommendRoutingPlugin(ctx context.Context,
660660
swapHash lntypes.Hash, paymentAddr [32]byte) (RoutingPluginType, error) {
661661

662662
req := &looprpc.RecommendRoutingPluginReq{
663-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
663+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
664664
SwapHash: swapHash[:],
665665
PaymentAddress: paymentAddr[:],
666666
}
@@ -704,7 +704,7 @@ func (s *grpcSwapServerClient) ReportRoutingResult(ctx context.Context,
704704
}
705705

706706
req := &looprpc.ReportRoutingResultReq{
707-
ProtocolVersion: loopdb.CurrentRPCProtocolVersion,
707+
ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
708708
SwapHash: swapHash[:],
709709
PaymentAddress: paymentAddr[:],
710710
Plugin: rpcRoutingPlugin,

0 commit comments

Comments
 (0)