mirror of
https://github.com/lightningnetwork/lnd.git
synced 2025-06-23 07:11:11 +02:00
routing: add new method reloadPayment
To further shorten the lifecycle loop.
This commit is contained in:
parent
1fe2cdb765
commit
e1279aab20
@ -202,23 +202,18 @@ func (p *paymentLifecycle) resumePayment(ctx context.Context) ([32]byte,
|
|||||||
// critical error during path finding.
|
// critical error during path finding.
|
||||||
lifecycle:
|
lifecycle:
|
||||||
for {
|
for {
|
||||||
// We update the payment state on every iteration. Since the
|
// We update the payment state on every iteration.
|
||||||
// payment state is affected by multiple goroutines (ie,
|
currentPayment, ps, err := p.reloadPayment()
|
||||||
// collectResultAsync), it is NOT guaranteed that we always
|
|
||||||
// have the latest state here. This is fine as long as the
|
|
||||||
// state is consistent as a whole.
|
|
||||||
payment, err = p.router.cfg.Control.FetchPayment(p.identifier)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return exitWithErr(err)
|
return exitWithErr(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ps := payment.GetState()
|
// Reassign status so it can be read in `exitWithErr`.
|
||||||
remainingFees := p.calcFeeBudget(ps.FeesPaid)
|
status = currentPayment.GetStatus()
|
||||||
|
|
||||||
status = payment.GetStatus()
|
// Reassign payment such that when the lifecycle exits, the
|
||||||
log.Debugf("Payment %v: status=%v, active_shards=%v, "+
|
// latest payment can be read when we access its terminal info.
|
||||||
"rem_value=%v, fee_limit=%v", p.identifier, status,
|
payment = currentPayment
|
||||||
ps.NumAttemptsInFlight, ps.RemainingAmt, remainingFees)
|
|
||||||
|
|
||||||
// We now proceed our lifecycle with the following tasks in
|
// We now proceed our lifecycle with the following tasks in
|
||||||
// order,
|
// order,
|
||||||
@ -1096,3 +1091,23 @@ func (p *paymentLifecycle) reloadInflightAttempts() (DBMPPayment, error) {
|
|||||||
|
|
||||||
return payment, nil
|
return payment, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// reloadPayment returns the latest payment found in the db (control tower).
|
||||||
|
func (p *paymentLifecycle) reloadPayment() (DBMPPayment,
|
||||||
|
*channeldb.MPPaymentState, error) {
|
||||||
|
|
||||||
|
// Read the db to get the latest state of the payment.
|
||||||
|
payment, err := p.router.cfg.Control.FetchPayment(p.identifier)
|
||||||
|
if err != nil {
|
||||||
|
return nil, nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
ps := payment.GetState()
|
||||||
|
remainingFees := p.calcFeeBudget(ps.FeesPaid)
|
||||||
|
|
||||||
|
log.Debugf("Payment %v: status=%v, active_shards=%v, rem_value=%v, "+
|
||||||
|
"fee_limit=%v", p.identifier, payment.GetStatus(),
|
||||||
|
ps.NumAttemptsInFlight, ps.RemainingAmt, remainingFees)
|
||||||
|
|
||||||
|
return payment, ps, nil
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user