routing: move default cltv assignment out of router

This commit lifts default setting up to the rpc server level, in line
with other payment defaults.
This commit is contained in:
Joost Jager 2019-04-18 09:45:21 +02:00
parent afd86763ac
commit 19d5f8f82c
No known key found for this signature in database
GPG Key ID: A61B9D4C393C59C7
4 changed files with 11 additions and 21 deletions

@ -222,7 +222,7 @@ func (s *Server) SendPayment(ctx context.Context,
Amount: *payReq.MilliSat, Amount: *payReq.MilliSat,
FeeLimit: lnwire.MilliSatoshi(req.FeeLimitSat), FeeLimit: lnwire.MilliSatoshi(req.FeeLimitSat),
PaymentHash: *payReq.PaymentHash, PaymentHash: *payReq.PaymentHash,
FinalCLTVDelta: &finalDelta, FinalCLTVDelta: finalDelta,
PayAttemptTimeout: time.Second * time.Duration(req.TimeoutSeconds), PayAttemptTimeout: time.Second * time.Duration(req.TimeoutSeconds),
RouteHints: payReq.RouteHints, RouteHints: payReq.RouteHints,
} }

@ -45,7 +45,7 @@ func TestRequestRoute(t *testing.T) {
payment := &LightningPayment{ payment := &LightningPayment{
CltvLimit: &cltvLimit, CltvLimit: &cltvLimit,
FinalCLTVDelta: &finalCltvDelta, FinalCLTVDelta: finalCltvDelta,
} }
route, err := session.RequestRoute(payment, height, finalCltvDelta) route, err := session.RequestRoute(payment, height, finalCltvDelta)

@ -1565,10 +1565,8 @@ type LightningPayment struct {
// FinalCLTVDelta is the CTLV expiry delta to use for the _final_ hop // FinalCLTVDelta is the CTLV expiry delta to use for the _final_ hop
// in the route. This means that the final hop will have a CLTV delta // in the route. This means that the final hop will have a CLTV delta
// of at least: currentHeight + FinalCLTVDelta. If this value is // of at least: currentHeight + FinalCLTVDelta.
// unspecified, then a default value of DefaultFinalCLTVDelta will be FinalCLTVDelta uint16
// used.
FinalCLTVDelta *uint16
// PayAttemptTimeout is a timeout value that we'll use to determine // PayAttemptTimeout is a timeout value that we'll use to determine
// when we should should abandon the payment attempt after consecutive // when we should should abandon the payment attempt after consecutive
@ -1732,13 +1730,6 @@ func (r *ChannelRouter) sendPayment(
return [32]byte{}, nil, err return [32]byte{}, nil, err
} }
var finalCLTVDelta uint16
if payment.FinalCLTVDelta == nil {
finalCLTVDelta = zpay32.DefaultFinalCLTVDelta
} else {
finalCLTVDelta = *payment.FinalCLTVDelta
}
var payAttemptTimeout time.Duration var payAttemptTimeout time.Duration
if payment.PayAttemptTimeout == time.Duration(0) { if payment.PayAttemptTimeout == time.Duration(0) {
payAttemptTimeout = defaultPayAttemptTimeout payAttemptTimeout = defaultPayAttemptTimeout
@ -1756,7 +1747,7 @@ func (r *ChannelRouter) sendPayment(
paySession: paySession, paySession: paySession,
timeoutChan: timeoutChan, timeoutChan: timeoutChan,
currentHeight: currentHeight, currentHeight: currentHeight,
finalCLTVDelta: finalCLTVDelta, finalCLTVDelta: uint16(payment.FinalCLTVDelta),
attempt: existingAttempt, attempt: existingAttempt,
circuit: nil, circuit: nil,
lastError: nil, lastError: nil,

@ -2998,7 +2998,11 @@ func extractPaymentIntent(rpcPayReq *rpcPaymentRequest) (rpcPaymentIntent, error
rpcPayReq.FeeLimit, payIntent.msat, rpcPayReq.FeeLimit, payIntent.msat,
) )
payIntent.cltvDelta = uint16(rpcPayReq.FinalCltvDelta) if rpcPayReq.FinalCltvDelta != 0 {
payIntent.cltvDelta = uint16(rpcPayReq.FinalCltvDelta)
} else {
payIntent.cltvDelta = zpay32.DefaultFinalCLTVDelta
}
// If the user is manually specifying payment details, then the payment // If the user is manually specifying payment details, then the payment
// hash may be encoded as a string. // hash may be encoded as a string.
@ -3069,6 +3073,7 @@ func (r *rpcServer) dispatchPaymentIntent(
payment := &routing.LightningPayment{ payment := &routing.LightningPayment{
Target: payIntent.dest, Target: payIntent.dest,
Amount: payIntent.msat, Amount: payIntent.msat,
FinalCLTVDelta: payIntent.cltvDelta,
FeeLimit: payIntent.feeLimit, FeeLimit: payIntent.feeLimit,
CltvLimit: payIntent.cltvLimit, CltvLimit: payIntent.cltvLimit,
PaymentHash: payIntent.rHash, PaymentHash: payIntent.rHash,
@ -3077,12 +3082,6 @@ func (r *rpcServer) dispatchPaymentIntent(
PaymentRequest: payIntent.payReq, PaymentRequest: payIntent.payReq,
} }
// If the final CLTV value was specified, then we'll use that
// rather than the default.
if payIntent.cltvDelta != 0 {
payment.FinalCLTVDelta = &payIntent.cltvDelta
}
preImage, route, routerErr = r.server.chanRouter.SendPayment( preImage, route, routerErr = r.server.chanRouter.SendPayment(
payment, payment,
) )