@@ -361,9 +361,16 @@ func (s *swapClientServer) GetLoopInQuote(ctx context.Context,
361361
362362 log .Infof ("Loop in quote request received" )
363363
364+ htlcConfTarget , err := validateLoopInRequest (
365+ req .ConfTarget , req .ExternalHtlc ,
366+ )
367+ if err != nil {
368+ return nil , err
369+ }
370+
364371 quote , err := s .impl .LoopInQuote (ctx , & loop.LoopInQuoteRequest {
365372 Amount : btcutil .Amount (req .Amt ),
366- HtlcConfTarget : defaultConfTarget ,
373+ HtlcConfTarget : htlcConfTarget ,
367374 ExternalHtlc : req .ExternalHtlc ,
368375 })
369376 if err != nil {
@@ -381,11 +388,18 @@ func (s *swapClientServer) LoopIn(ctx context.Context,
381388
382389 log .Infof ("Loop in request received" )
383390
391+ htlcConfTarget , err := validateLoopInRequest (
392+ in .HtlcConfTarget , in .ExternalHtlc ,
393+ )
394+ if err != nil {
395+ return nil , err
396+ }
397+
384398 req := & loop.LoopInRequest {
385399 Amount : btcutil .Amount (in .Amt ),
386400 MaxMinerFee : btcutil .Amount (in .MaxMinerFee ),
387401 MaxSwapFee : btcutil .Amount (in .MaxSwapFee ),
388- HtlcConfTarget : defaultConfTarget ,
402+ HtlcConfTarget : htlcConfTarget ,
389403 ExternalHtlc : in .ExternalHtlc ,
390404 }
391405 if in .LastHop != nil {
@@ -477,6 +491,9 @@ func (s *swapClientServer) processStatusUpdates(mainCtx context.Context) {
477491// isn't specified (0 value), then the default target is used.
478492func validateConfTarget (target , defaultTarget int32 ) (int32 , error ) {
479493 switch {
494+ case target == 0 :
495+ return defaultTarget , nil
496+
480497 // Ensure the target respects our minimum threshold.
481498 case target < minConfTarget :
482499 return 0 , fmt .Errorf ("a confirmation target of at least %v " +
@@ -486,3 +503,22 @@ func validateConfTarget(target, defaultTarget int32) (int32, error) {
486503 return target , nil
487504 }
488505}
506+
507+ // validateLoopInRequest fails if the mutually exclusive conf target and
508+ // external parameters are both set.
509+ func validateLoopInRequest (htlcConfTarget int32 , external bool ) (int32 , error ) {
510+ // If the htlc is going to be externally set, the htlcConfTarget should
511+ // not be set, because it has no relevance when the htlc is external.
512+ if external && htlcConfTarget != 0 {
513+ return 0 , errors .New ("external and htlc conf target cannot " +
514+ "both be set" )
515+ }
516+
517+ // If the htlc is being externally published, we do not need to set a
518+ // confirmation target.
519+ if external {
520+ return 0 , nil
521+ }
522+
523+ return validateConfTarget (htlcConfTarget , loop .DefaultHtlcConfTarget )
524+ }
0 commit comments