From a6be939bfa4dd99d6ff7d912220f6300a4ad681e Mon Sep 17 00:00:00 2001 From: yyforyongyu Date: Mon, 13 Feb 2023 14:34:06 +0800 Subject: [PATCH] routing: add `newPaymentLifecycle` to properly init lifecycle This commit adds a new method to properly init a payment lifecycle so we can easily see the default values used here. --- routing/payment_lifecycle.go | 25 +++++++++++++++++++++++++ routing/router.go | 19 ++++--------------- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/routing/payment_lifecycle.go b/routing/payment_lifecycle.go index 5c3d0e6c9..7f7beb232 100644 --- a/routing/payment_lifecycle.go +++ b/routing/payment_lifecycle.go @@ -31,6 +31,31 @@ type paymentLifecycle struct { currentHeight int32 } +// newPaymentLifecycle initiates a new payment lifecycle and returns it. +func newPaymentLifecycle(r *ChannelRouter, feeLimit lnwire.MilliSatoshi, + identifier lntypes.Hash, paySession PaymentSession, + shardTracker shards.ShardTracker, timeout time.Duration, + currentHeight int32) *paymentLifecycle { + + p := &paymentLifecycle{ + router: r, + feeLimit: feeLimit, + identifier: identifier, + paySession: paySession, + shardTracker: shardTracker, + currentHeight: currentHeight, + } + + // If a timeout is specified, create a timeout channel. If no timeout is + // specified, the channel is left nil and will never abort the payment + // loop. + if timeout != 0 { + p.timeoutChan = time.After(timeout) + } + + return p +} + // calcFeeBudget returns the available fee to be used for sending HTLC // attempts. func (p *paymentLifecycle) calcFeeBudget( diff --git a/routing/router.go b/routing/router.go index 8e4ed7d4e..77dd9ceb0 100644 --- a/routing/router.go +++ b/routing/router.go @@ -2415,21 +2415,10 @@ func (r *ChannelRouter) sendPayment(feeLimit lnwire.MilliSatoshi, // Now set up a paymentLifecycle struct with these params, such that we // can resume the payment from the current state. - p := &paymentLifecycle{ - router: r, - feeLimit: feeLimit, - identifier: identifier, - paySession: paySession, - shardTracker: shardTracker, - currentHeight: currentHeight, - } - - // If a timeout is specified, create a timeout channel. If no timeout is - // specified, the channel is left nil and will never abort the payment - // loop. - if timeout != 0 { - p.timeoutChan = time.After(timeout) - } + p := newPaymentLifecycle( + r, feeLimit, identifier, paySession, + shardTracker, timeout, currentHeight, + ) return p.resumePayment() }