multi: make the next protocol version optional

pull/497/head
Andras Banki-Horvath 2 years ago
parent 9b37d744a0
commit 00cf4bf71c
No known key found for this signature in database
GPG Key ID: 80E5375C094198D8

@ -149,6 +149,8 @@ type Config struct {
TotalPaymentTimeout time.Duration `long:"totalpaymenttimeout" description:"The timeout to use for off-chain payments."` TotalPaymentTimeout time.Duration `long:"totalpaymenttimeout" description:"The timeout to use for off-chain payments."`
MaxPaymentRetries int `long:"maxpaymentretries" description:"The maximum number of times an off-chain payment may be retried."` MaxPaymentRetries int `long:"maxpaymentretries" description:"The maximum number of times an off-chain payment may be retried."`
EnableExperimental bool `long:"experimental" description:"Enable experimental features: taproot HTLCs and MuSig2 loop out sweeps."`
Lnd *lndConfig `group:"lnd" namespace:"lnd"` Lnd *lndConfig `group:"lnd" namespace:"lnd"`
Server *loopServerConfig `group:"server" namespace:"server"` Server *loopServerConfig `group:"server" namespace:"server"`
@ -185,6 +187,7 @@ func DefaultConfig() Config {
LoopOutMaxParts: defaultLoopOutMaxParts, LoopOutMaxParts: defaultLoopOutMaxParts,
TotalPaymentTimeout: defaultTotalPaymentTimeout, TotalPaymentTimeout: defaultTotalPaymentTimeout,
MaxPaymentRetries: defaultMaxPaymentRetries, MaxPaymentRetries: defaultMaxPaymentRetries,
EnableExperimental: false,
Lnd: &lndConfig{ Lnd: &lndConfig{
Host: "localhost:10009", Host: "localhost:10009",
MacaroonPath: DefaultLndMacaroonPath, MacaroonPath: DefaultLndMacaroonPath,

@ -348,6 +348,12 @@ func (d *Daemon) startWebServers() error {
// this method fails with an error then no goroutine was started yet and no // this method fails with an error then no goroutine was started yet and no
// cleanup is necessary. If it succeeds, then goroutines have been spawned. // cleanup is necessary. If it succeeds, then goroutines have been spawned.
func (d *Daemon) initialize(withMacaroonService bool) error { func (d *Daemon) initialize(withMacaroonService bool) error {
if d.cfg.EnableExperimental {
loopdb.EnableExperimentalProtocol()
}
log.Infof("Protocol version: %v", loopdb.CurrentProtocolVersion())
// If no swap server is specified, use the default addresses for mainnet // If no swap server is specified, use the default addresses for mainnet
// and testnet. // and testnet.
if d.cfg.Server.Host == "" { if d.cfg.Server.Host == "" {

@ -59,18 +59,50 @@ const (
// started saving protocol version with swaps. // started saving protocol version with swaps.
ProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32 ProtocolVersionUnrecorded ProtocolVersion = math.MaxUint32
// CurrentRPCProtocolVersion defines the version of the RPC protocol // stableRPCProtocolVersion defines the current stable RPC protocol
// that is currently supported by the loop client. // version.
CurrentRPCProtocolVersion = looprpc.ProtocolVersion_HTLC_V3 stableRPCProtocolVersion = looprpc.ProtocolVersion_ROUTING_PLUGIN
// CurrentInternalProtocolVersion defines the RPC current protocol in // experimentalRPCProtocolVersion defines the RPC protocol version that
// the internal representation. // includes all currently experimentally released features.
CurrentInternalProtocolVersion = ProtocolVersion(CurrentRPCProtocolVersion) experimentalRPCProtocolVersion = looprpc.ProtocolVersion_HTLC_V3
) )
var (
// currentRPCProtocolVersion holds the version of the RPC protocol
// that the client selected to use for new swaps. Shouldn't be lower
// than the previous protocol version.
currentRPCProtocolVersion = stableRPCProtocolVersion
)
// CurrentRPCProtocolVersion returns the RPC protocol version selected to be
// used for new swaps.
func CurrentRPCProtocolVersion() looprpc.ProtocolVersion {
return currentRPCProtocolVersion
}
// CurrentProtocolVersion returns the internal protocol version selected to be
// used for new swaps.
func CurrentProtocolVersion() ProtocolVersion {
return ProtocolVersion(currentRPCProtocolVersion)
}
// EnableExperimentalProtocol sets the current protocol version to include all
// experimental features. Do not call this function directly: used in loopd and
// unit tests only.
func EnableExperimentalProtocol() {
currentRPCProtocolVersion = experimentalRPCProtocolVersion
}
// ResetCurrentProtocolVersion resets the current protocol version to the stable
// protocol. Note: used in integration tests only!
func ResetCurrentProtocolVersion() {
currentRPCProtocolVersion = stableRPCProtocolVersion
}
// Valid returns true if the value of the ProtocolVersion is valid. // Valid returns true if the value of the ProtocolVersion is valid.
func (p ProtocolVersion) Valid() bool { func (p ProtocolVersion) Valid() bool {
return p <= CurrentInternalProtocolVersion return p <= ProtocolVersion(experimentalRPCProtocolVersion)
} }
// String returns the string representation of a protocol version. // String returns the string representation of a protocol version.

@ -48,12 +48,19 @@ func TestProtocolVersionSanity(t *testing.T) {
// Finally test that the current version contants are up to date // Finally test that the current version contants are up to date
require.Equal(t, require.Equal(t,
CurrentInternalProtocolVersion, CurrentProtocolVersion(),
versions[len(versions)-1], versions[len(versions)-2],
) )
require.Equal(t, require.Equal(t,
uint32(CurrentInternalProtocolVersion), uint32(CurrentProtocolVersion()),
uint32(CurrentRPCProtocolVersion), uint32(CurrentRPCProtocolVersion()),
)
EnableExperimentalProtocol()
require.Equal(t,
CurrentProtocolVersion(),
ProtocolVersion(experimentalRPCProtocolVersion),
) )
} }

@ -244,7 +244,7 @@ func newLoopInSwap(globalCtx context.Context, cfg *swapConfig,
MaxMinerFee: request.MaxMinerFee, MaxMinerFee: request.MaxMinerFee,
MaxSwapFee: request.MaxSwapFee, MaxSwapFee: request.MaxSwapFee,
Label: request.Label, Label: request.Label,
ProtocolVersion: loopdb.CurrentInternalProtocolVersion, ProtocolVersion: loopdb.CurrentProtocolVersion(),
}, },
} }

@ -177,7 +177,7 @@ func newLoopOutSwap(globalCtx context.Context, cfg *swapConfig,
MaxMinerFee: request.MaxMinerFee, MaxMinerFee: request.MaxMinerFee,
MaxSwapFee: request.MaxSwapFee, MaxSwapFee: request.MaxSwapFee,
Label: request.Label, Label: request.Label,
ProtocolVersion: loopdb.CurrentInternalProtocolVersion, ProtocolVersion: loopdb.CurrentProtocolVersion(),
}, },
OutgoingChanSet: chanSet, OutgoingChanSet: chanSet,
} }

@ -174,7 +174,7 @@ func (s *grpcSwapServerClient) GetLoopOutTerms(ctx context.Context) (
defer rpcCancel() defer rpcCancel()
terms, err := s.server.LoopOutTerms(rpcCtx, terms, err := s.server.LoopOutTerms(rpcCtx,
&looprpc.ServerLoopOutTermsRequest{ &looprpc.ServerLoopOutTermsRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
}, },
) )
if err != nil { if err != nil {
@ -199,7 +199,7 @@ func (s *grpcSwapServerClient) GetLoopOutQuote(ctx context.Context,
&looprpc.ServerLoopOutQuoteRequest{ &looprpc.ServerLoopOutQuoteRequest{
Amt: uint64(amt), Amt: uint64(amt),
SwapPublicationDeadline: swapPublicationDeadline.Unix(), SwapPublicationDeadline: swapPublicationDeadline.Unix(),
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
Expiry: expiry, Expiry: expiry,
}, },
) )
@ -231,7 +231,7 @@ func (s *grpcSwapServerClient) GetLoopInTerms(ctx context.Context) (
defer rpcCancel() defer rpcCancel()
terms, err := s.server.LoopInTerms(rpcCtx, terms, err := s.server.LoopInTerms(rpcCtx,
&looprpc.ServerLoopInTermsRequest{ &looprpc.ServerLoopInTermsRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
}, },
) )
if err != nil { if err != nil {
@ -258,7 +258,7 @@ func (s *grpcSwapServerClient) GetLoopInQuote(ctx context.Context,
req := &looprpc.ServerLoopInQuoteRequest{ req := &looprpc.ServerLoopInQuoteRequest{
Amt: uint64(amt), Amt: uint64(amt),
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
Pubkey: pubKey[:], Pubkey: pubKey[:],
} }
@ -343,7 +343,7 @@ func (s *grpcSwapServerClient) Probe(ctx context.Context, amt btcutil.Amount,
req := &looprpc.ServerProbeRequest{ req := &looprpc.ServerProbeRequest{
Amt: uint64(amt), Amt: uint64(amt),
Target: target[:], Target: target[:],
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
RouteHints: rpcRouteHints, RouteHints: rpcRouteHints,
} }
@ -368,7 +368,7 @@ func (s *grpcSwapServerClient) NewLoopOutSwap(ctx context.Context,
Amt: uint64(amount), Amt: uint64(amount),
ReceiverKey: receiverKey[:], ReceiverKey: receiverKey[:],
SwapPublicationDeadline: swapPublicationDeadline.Unix(), SwapPublicationDeadline: swapPublicationDeadline.Unix(),
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
Expiry: expiry, Expiry: expiry,
UserAgent: UserAgent(initiator), UserAgent: UserAgent(initiator),
}, },
@ -403,7 +403,7 @@ func (s *grpcSwapServerClient) PushLoopOutPreimage(ctx context.Context,
_, err := s.server.LoopOutPushPreimage(rpcCtx, _, err := s.server.LoopOutPushPreimage(rpcCtx,
&looprpc.ServerLoopOutPushPreimageRequest{ &looprpc.ServerLoopOutPushPreimageRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
Preimage: preimage[:], Preimage: preimage[:],
}, },
) )
@ -424,7 +424,7 @@ func (s *grpcSwapServerClient) NewLoopInSwap(ctx context.Context,
Amt: uint64(amount), Amt: uint64(amount),
SenderKey: senderKey[:], SenderKey: senderKey[:],
SwapInvoice: swapInvoice, SwapInvoice: swapInvoice,
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
ProbeInvoice: probeInvoice, ProbeInvoice: probeInvoice,
UserAgent: UserAgent(initiator), UserAgent: UserAgent(initiator),
} }
@ -469,7 +469,7 @@ func (s *grpcSwapServerClient) SubscribeLoopInUpdates(ctx context.Context,
resp, err := s.server.SubscribeLoopInUpdates( resp, err := s.server.SubscribeLoopInUpdates(
ctx, &looprpc.SubscribeUpdatesRequest{ ctx, &looprpc.SubscribeUpdatesRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
SwapHash: hash[:], SwapHash: hash[:],
}, },
) )
@ -500,7 +500,7 @@ func (s *grpcSwapServerClient) SubscribeLoopOutUpdates(ctx context.Context,
resp, err := s.server.SubscribeLoopOutUpdates( resp, err := s.server.SubscribeLoopOutUpdates(
ctx, &looprpc.SubscribeUpdatesRequest{ ctx, &looprpc.SubscribeUpdatesRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
SwapHash: hash[:], SwapHash: hash[:],
}, },
) )
@ -639,7 +639,7 @@ func (s *grpcSwapServerClient) CancelLoopOutSwap(ctx context.Context,
details *outCancelDetails) error { details *outCancelDetails) error {
req := &looprpc.CancelLoopOutSwapRequest{ req := &looprpc.CancelLoopOutSwapRequest{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
SwapHash: details.hash[:], SwapHash: details.hash[:],
PaymentAddress: details.paymentAddr[:], PaymentAddress: details.paymentAddr[:],
} }
@ -660,7 +660,7 @@ func (s *grpcSwapServerClient) RecommendRoutingPlugin(ctx context.Context,
swapHash lntypes.Hash, paymentAddr [32]byte) (RoutingPluginType, error) { swapHash lntypes.Hash, paymentAddr [32]byte) (RoutingPluginType, error) {
req := &looprpc.RecommendRoutingPluginReq{ req := &looprpc.RecommendRoutingPluginReq{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
SwapHash: swapHash[:], SwapHash: swapHash[:],
PaymentAddress: paymentAddr[:], PaymentAddress: paymentAddr[:],
} }
@ -704,7 +704,7 @@ func (s *grpcSwapServerClient) ReportRoutingResult(ctx context.Context,
} }
req := &looprpc.ReportRoutingResultReq{ req := &looprpc.ReportRoutingResultReq{
ProtocolVersion: loopdb.CurrentRPCProtocolVersion, ProtocolVersion: loopdb.CurrentRPCProtocolVersion(),
SwapHash: swapHash[:], SwapHash: swapHash[:],
PaymentAddress: paymentAddr[:], PaymentAddress: paymentAddr[:],
Plugin: rpcRoutingPlugin, Plugin: rpcRoutingPlugin,

Loading…
Cancel
Save