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.
This commit is contained in:
yyforyongyu 2023-02-13 14:34:06 +08:00 committed by Olaoluwa Osuntokun
parent 34d0e5d4c5
commit a6be939bfa
2 changed files with 29 additions and 15 deletions

View file

@ -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(

View file

@ -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()
}