routing/router: correct SendToRoute's amount record in DB

Previously we would mistakenly use the payment value from the dummy
LightningPayment struct, which would obviously be 0 always. Now we
instead calculate the value from the given route.
This commit is contained in:
Johan T. Halseth 2019-06-04 10:13:33 +02:00
parent 4068e78af6
commit 1161d87eec
No known key found for this signature in database
GPG Key ID: 15BAADA29DA20D26

@ -1637,26 +1637,31 @@ func (r *ChannelRouter) SendToRoute(hash lntypes.Hash, route *route.Route) (
// Create a payment session for just this route. // Create a payment session for just this route.
paySession := r.cfg.MissionControl.NewPaymentSessionForRoute(route) paySession := r.cfg.MissionControl.NewPaymentSessionForRoute(route)
// Create a (mostly) dummy payment, as the created payment session is // Calculate amount paid to receiver.
// not going to do path finding. amt := route.TotalAmount - route.TotalFees()
payment := &LightningPayment{
PaymentHash: hash,
}
// Record this payment hash with the ControlTower, ensuring it is not // Record this payment hash with the ControlTower, ensuring it is not
// already in-flight. // already in-flight.
info := &channeldb.PaymentCreationInfo{ info := &channeldb.PaymentCreationInfo{
PaymentHash: payment.PaymentHash, PaymentHash: hash,
Value: payment.Amount, Value: amt,
CreationDate: time.Now(), CreationDate: time.Now(),
PaymentRequest: nil, PaymentRequest: nil,
} }
err := r.cfg.Control.InitPayment(payment.PaymentHash, info) err := r.cfg.Control.InitPayment(hash, info)
if err != nil { if err != nil {
return [32]byte{}, err return [32]byte{}, err
} }
// Create a (mostly) dummy payment, as the created payment session is
// not going to do path finding.
// TODO(halseth): sendPayment doesn't relly need LightningPayment, make
// it take just needed fields instead.
payment := &LightningPayment{
PaymentHash: hash,
}
// Since this is the first time this payment is being made, we pass nil // Since this is the first time this payment is being made, we pass nil
// for the existing attempt. // for the existing attempt.
preimage, _, err := r.sendPayment(nil, payment, paySession) preimage, _, err := r.sendPayment(nil, payment, paySession)