router: simplify edge outdated logic, return ErrOutdated if old.
This commit is contained in:
parent
47788c3cec
commit
18e680f192
@ -31,7 +31,7 @@ const (
|
|||||||
ErrTargetNotInNetwork
|
ErrTargetNotInNetwork
|
||||||
|
|
||||||
// ErrOutdated is returned when the routing update already have
|
// ErrOutdated is returned when the routing update already have
|
||||||
// been applied.
|
// been applied, or a newer update is already known.
|
||||||
ErrOutdated
|
ErrOutdated
|
||||||
|
|
||||||
// ErrIgnored is returned when the update have been ignored because
|
// ErrIgnored is returned when the update have been ignored because
|
||||||
|
@ -1080,30 +1080,31 @@ func (r *ChannelRouter) processUpdate(msg interface{}) error {
|
|||||||
// As edges are directional edge node has a unique policy for
|
// As edges are directional edge node has a unique policy for
|
||||||
// the direction of the edge they control. Therefore we first
|
// the direction of the edge they control. Therefore we first
|
||||||
// check if we already have the most up to date information for
|
// check if we already have the most up to date information for
|
||||||
// that edge. If so, then we can exit early.
|
// that edge. If this message has a timestamp not strictly
|
||||||
|
// newer than what we already know of we can exit early.
|
||||||
switch {
|
switch {
|
||||||
|
|
||||||
// A flag set of 0 indicates this is an announcement for the
|
// A flag set of 0 indicates this is an announcement for the
|
||||||
// "first" node in the channel.
|
// "first" node in the channel.
|
||||||
case msg.Flags&lnwire.ChanUpdateDirection == 0:
|
case msg.Flags&lnwire.ChanUpdateDirection == 0:
|
||||||
if edge1Timestamp.After(msg.LastUpdate) ||
|
|
||||||
edge1Timestamp.Equal(msg.LastUpdate) {
|
|
||||||
|
|
||||||
return newErrf(ErrIgnored, "Ignoring update "+
|
// Ignore outdated message.
|
||||||
"(flags=%v) for known chan_id=%v", msg.Flags,
|
if !edge1Timestamp.Before(msg.LastUpdate) {
|
||||||
msg.ChannelID)
|
return newErrf(ErrOutdated, "Ignoring "+
|
||||||
|
"outdated update (flags=%v) for known "+
|
||||||
|
"chan_id=%v", msg.Flags, msg.ChannelID)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similarly, a flag set of 1 indicates this is an announcement
|
// Similarly, a flag set of 1 indicates this is an announcement
|
||||||
// for the "second" node in the channel.
|
// for the "second" node in the channel.
|
||||||
case msg.Flags&lnwire.ChanUpdateDirection == 1:
|
case msg.Flags&lnwire.ChanUpdateDirection == 1:
|
||||||
if edge2Timestamp.After(msg.LastUpdate) ||
|
|
||||||
edge2Timestamp.Equal(msg.LastUpdate) {
|
|
||||||
|
|
||||||
return newErrf(ErrIgnored, "Ignoring update "+
|
// Ignore outdated message.
|
||||||
"(flags=%v) for known chan_id=%v", msg.Flags,
|
if !edge2Timestamp.Before(msg.LastUpdate) {
|
||||||
msg.ChannelID)
|
return newErrf(ErrOutdated, "Ignoring "+
|
||||||
|
"outdated update (flags=%v) for known "+
|
||||||
|
"chan_id=%v", msg.Flags, msg.ChannelID)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2021,7 +2022,7 @@ func (r *ChannelRouter) applyChannelUpdate(msg *lnwire.ChannelUpdate) error {
|
|||||||
FeeBaseMSat: lnwire.MilliSatoshi(msg.BaseFee),
|
FeeBaseMSat: lnwire.MilliSatoshi(msg.BaseFee),
|
||||||
FeeProportionalMillionths: lnwire.MilliSatoshi(msg.FeeRate),
|
FeeProportionalMillionths: lnwire.MilliSatoshi(msg.FeeRate),
|
||||||
})
|
})
|
||||||
if err != nil && !IsError(err, ErrIgnored) {
|
if err != nil && !IsError(err, ErrIgnored, ErrOutdated) {
|
||||||
return fmt.Errorf("Unable to apply channel update: %v", err)
|
return fmt.Errorf("Unable to apply channel update: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user