mirror of
https://github.com/lightningnetwork/lnd.git
synced 2024-11-20 02:27:21 +01:00
routing: move logging into applyChannelUpdate
To remove code duplicated at all call sites to check err and log.
This commit is contained in:
parent
fc4fe07010
commit
dd7e2e9e04
@ -1804,11 +1804,7 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
|
|||||||
// correct block height is.
|
// correct block height is.
|
||||||
case *lnwire.FailExpiryTooSoon:
|
case *lnwire.FailExpiryTooSoon:
|
||||||
update := onionErr.Update
|
update := onionErr.Update
|
||||||
err := r.applyChannelUpdate(&update, errSource)
|
r.applyChannelUpdate(&update, errSource)
|
||||||
if err != nil {
|
|
||||||
log.Errorf("unable to apply channel "+
|
|
||||||
"update for onion error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pruneVertexFailure(
|
pruneVertexFailure(
|
||||||
paySession, route, errSource, false,
|
paySession, route, errSource, false,
|
||||||
@ -1830,11 +1826,7 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
|
|||||||
// and continue with the rest of the routes.
|
// and continue with the rest of the routes.
|
||||||
case *lnwire.FailAmountBelowMinimum:
|
case *lnwire.FailAmountBelowMinimum:
|
||||||
update := onionErr.Update
|
update := onionErr.Update
|
||||||
err := r.applyChannelUpdate(&update, errSource)
|
r.applyChannelUpdate(&update, errSource)
|
||||||
if err != nil {
|
|
||||||
log.Errorf("unable to apply channel "+
|
|
||||||
"update for onion error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return preImage, nil, sendError
|
return preImage, nil, sendError
|
||||||
|
|
||||||
@ -1843,11 +1835,8 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
|
|||||||
// newly updated fees.
|
// newly updated fees.
|
||||||
case *lnwire.FailFeeInsufficient:
|
case *lnwire.FailFeeInsufficient:
|
||||||
update := onionErr.Update
|
update := onionErr.Update
|
||||||
err := r.applyChannelUpdate(&update, errSource)
|
updateOk := r.applyChannelUpdate(&update, errSource)
|
||||||
if err != nil {
|
if !updateOk {
|
||||||
log.Errorf("unable to apply channel "+
|
|
||||||
"update for onion error: %v", err)
|
|
||||||
|
|
||||||
pruneEdgeFailure(
|
pruneEdgeFailure(
|
||||||
paySession, route, errSource,
|
paySession, route, errSource,
|
||||||
)
|
)
|
||||||
@ -1877,11 +1866,7 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
|
|||||||
// finding.
|
// finding.
|
||||||
case *lnwire.FailIncorrectCltvExpiry:
|
case *lnwire.FailIncorrectCltvExpiry:
|
||||||
update := onionErr.Update
|
update := onionErr.Update
|
||||||
err := r.applyChannelUpdate(&update, errSource)
|
r.applyChannelUpdate(&update, errSource)
|
||||||
if err != nil {
|
|
||||||
log.Errorf("unable to apply channel "+
|
|
||||||
"update for onion error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pruneVertexFailure(
|
pruneVertexFailure(
|
||||||
paySession, route, errSource, false,
|
paySession, route, errSource, false,
|
||||||
@ -1893,11 +1878,7 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
|
|||||||
// the update and continue.
|
// the update and continue.
|
||||||
case *lnwire.FailChannelDisabled:
|
case *lnwire.FailChannelDisabled:
|
||||||
update := onionErr.Update
|
update := onionErr.Update
|
||||||
err := r.applyChannelUpdate(&update, errSource)
|
r.applyChannelUpdate(&update, errSource)
|
||||||
if err != nil {
|
|
||||||
log.Errorf("unable to apply channel "+
|
|
||||||
"update for onion error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pruneEdgeFailure(paySession, route, errSource)
|
pruneEdgeFailure(paySession, route, errSource)
|
||||||
continue
|
continue
|
||||||
@ -1907,11 +1888,7 @@ func (r *ChannelRouter) sendPayment(payment *LightningPayment,
|
|||||||
// now, and continue onwards with our path finding.
|
// now, and continue onwards with our path finding.
|
||||||
case *lnwire.FailTemporaryChannelFailure:
|
case *lnwire.FailTemporaryChannelFailure:
|
||||||
update := onionErr.Update
|
update := onionErr.Update
|
||||||
err := r.applyChannelUpdate(update, errSource)
|
r.applyChannelUpdate(update, errSource)
|
||||||
if err != nil {
|
|
||||||
log.Errorf("unable to apply channel "+
|
|
||||||
"update for onion error: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
pruneEdgeFailure(paySession, route, errSource)
|
pruneEdgeFailure(paySession, route, errSource)
|
||||||
continue
|
continue
|
||||||
@ -2048,17 +2025,18 @@ func pruneEdgeFailure(paySession *paymentSession, route *Route,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// applyChannelUpdate validates a channel update and if valid, applies it to the
|
// applyChannelUpdate validates a channel update and if valid, applies it to the
|
||||||
// database.
|
// database. It returns a bool indicating whether the updates was successful.
|
||||||
func (r *ChannelRouter) applyChannelUpdate(msg *lnwire.ChannelUpdate,
|
func (r *ChannelRouter) applyChannelUpdate(msg *lnwire.ChannelUpdate,
|
||||||
pubKey *btcec.PublicKey) error {
|
pubKey *btcec.PublicKey) bool {
|
||||||
// If we get passed a nil channel update (as it's optional with some
|
// If we get passed a nil channel update (as it's optional with some
|
||||||
// onion errors), then we'll exit early with a nil error.
|
// onion errors), then we'll exit early with a success result.
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return nil
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := ValidateChannelUpdateAnn(pubKey, msg); err != nil {
|
if err := ValidateChannelUpdateAnn(pubKey, msg); err != nil {
|
||||||
return err
|
log.Errorf("Unable to validate channel update: %v", err)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
err := r.UpdateEdge(&channeldb.ChannelEdgePolicy{
|
err := r.UpdateEdge(&channeldb.ChannelEdgePolicy{
|
||||||
@ -2072,10 +2050,11 @@ func (r *ChannelRouter) applyChannelUpdate(msg *lnwire.ChannelUpdate,
|
|||||||
FeeProportionalMillionths: lnwire.MilliSatoshi(msg.FeeRate),
|
FeeProportionalMillionths: lnwire.MilliSatoshi(msg.FeeRate),
|
||||||
})
|
})
|
||||||
if err != nil && !IsError(err, ErrIgnored, ErrOutdated) {
|
if err != nil && !IsError(err, ErrIgnored, ErrOutdated) {
|
||||||
return fmt.Errorf("Unable to apply channel update: %v", err)
|
log.Errorf("Unable to apply channel update: %v", err)
|
||||||
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
// AddNode is used to add information about a node to the router database. If
|
// AddNode is used to add information about a node to the router database. If
|
||||||
|
Loading…
Reference in New Issue
Block a user