discovery: let reject cache use gossip version in key
Since the gossip protocols are completely disjoint, we need to treat messages on the two protocols completely separately and should not let rejections on one protocol affect how we treat messages on the other.
This commit is contained in:
1 parent
b57714b00c
commit
f35c295bd8
2 files changed
+34
-8
No files matched your search
+33
-8
@@ -437,15 +437,19 @@ func (c *cachedNetworkMsg) Size() (uint64, error) {
|
|||||||
// rejectCacheKey is the cache key that we'll use to track announcements we've
|
// rejectCacheKey is the cache key that we'll use to track announcements we've
|
||||||
// recently rejected.
|
// recently rejected.
|
||||||
type rejectCacheKey struct {
|
type rejectCacheKey struct {
|
||||||
pubkey [33]byte
|
gossipVersion lnwire.GossipVersion
|
||||||
chanID uint64
|
pubkey [33]byte
|
||||||
|
chanID uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
// newRejectCacheKey returns a new cache key for the reject cache.
|
// newRejectCacheKey returns a new cache key for the reject cache.
|
||||||
func newRejectCacheKey(cid uint64, pub [33]byte) rejectCacheKey {
|
func newRejectCacheKey(v lnwire.GossipVersion, cid uint64,
|
||||||
|
pub [33]byte) rejectCacheKey {
|
||||||
|
|
||||||
k := rejectCacheKey{
|
k := rejectCacheKey{
|
||||||
chanID: cid,
|
gossipVersion: v,
|
||||||
pubkey: pub,
|
chanID: cid,
|
||||||
|
pubkey: pub,
|
||||||
}
|
}
|
||||||
|
|
||||||
return k
|
return k
|
||||||
@@ -1688,8 +1692,15 @@ func (d *AuthenticatedGossiper) PruneSyncState(peer route.Vertex) {
|
|||||||
func (d *AuthenticatedGossiper) isRecentlyRejectedMsg(msg lnwire.Message,
|
func (d *AuthenticatedGossiper) isRecentlyRejectedMsg(msg lnwire.Message,
|
||||||
peerPub [33]byte) bool {
|
peerPub [33]byte) bool {
|
||||||
|
|
||||||
|
// We only cache rejections for gossip messages. So if it is not
|
||||||
|
// a gossip message, we return false.
|
||||||
|
gMsg, ok := msg.(lnwire.GossipMessage)
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
var scid uint64
|
var scid uint64
|
||||||
switch m := msg.(type) {
|
switch m := gMsg.(type) {
|
||||||
case *lnwire.ChannelUpdate1:
|
case *lnwire.ChannelUpdate1:
|
||||||
scid = m.ShortChannelID.ToUint64()
|
scid = m.ShortChannelID.ToUint64()
|
||||||
|
|
||||||
@@ -1700,8 +1711,11 @@ func (d *AuthenticatedGossiper) isRecentlyRejectedMsg(msg lnwire.Message,
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := d.recentRejects.Get(newRejectCacheKey(scid, peerPub))
|
_, err := d.recentRejects.Get(newRejectCacheKey(
|
||||||
return err != cache.ErrElementNotFound
|
gMsg.GossipVersion(), scid, peerPub,
|
||||||
|
))
|
||||||
|
|
||||||
|
return !errors.Is(err, cache.ErrElementNotFound)
|
||||||
}
|
}
|
||||||
|
|
||||||
// retransmitStaleAnns examines all outgoing channels that the source node is
|
// retransmitStaleAnns examines all outgoing channels that the source node is
|
||||||
@@ -2571,6 +2585,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
|||||||
log.Errorf(err.Error())
|
log.Errorf(err.Error())
|
||||||
|
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
ann.GossipVersion(),
|
||||||
scid.ToUint64(),
|
scid.ToUint64(),
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
@@ -2588,6 +2603,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
|||||||
log.Errorf(err.Error())
|
log.Errorf(err.Error())
|
||||||
|
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
ann.GossipVersion(),
|
||||||
scid.ToUint64(),
|
scid.ToUint64(),
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
@@ -2662,6 +2678,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
|||||||
"%v", err)
|
"%v", err)
|
||||||
|
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
ann.GossipVersion(),
|
||||||
scid.ToUint64(),
|
scid.ToUint64(),
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
@@ -2741,6 +2758,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
|||||||
errors.Is(err, ErrInvalidFundingOutput):
|
errors.Is(err, ErrInvalidFundingOutput):
|
||||||
|
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
ann.GossipVersion(),
|
||||||
scid.ToUint64(),
|
scid.ToUint64(),
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
@@ -2750,6 +2768,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
|||||||
|
|
||||||
case errors.Is(err, ErrChannelSpent):
|
case errors.Is(err, ErrChannelSpent):
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
ann.GossipVersion(),
|
||||||
scid.ToUint64(),
|
scid.ToUint64(),
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
@@ -2776,6 +2795,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
|||||||
// edge. We won't increase the ban score for the
|
// edge. We won't increase the ban score for the
|
||||||
// remote peer.
|
// remote peer.
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
ann.GossipVersion(),
|
||||||
scid.ToUint64(),
|
scid.ToUint64(),
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
@@ -2839,6 +2859,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
|||||||
anns, rErr := d.processRejectedEdge(ctx, ann, proof)
|
anns, rErr := d.processRejectedEdge(ctx, ann, proof)
|
||||||
if rErr != nil {
|
if rErr != nil {
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
ann.GossipVersion(),
|
||||||
scid.ToUint64(),
|
scid.ToUint64(),
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
@@ -2866,6 +2887,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
|||||||
|
|
||||||
// Otherwise, this is just a regular rejected edge.
|
// Otherwise, this is just a regular rejected edge.
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
ann.GossipVersion(),
|
||||||
scid.ToUint64(),
|
scid.ToUint64(),
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
@@ -2998,6 +3020,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
|
|||||||
log.Errorf(err.Error())
|
log.Errorf(err.Error())
|
||||||
|
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
upd.GossipVersion(),
|
||||||
upd.ShortChannelID.ToUint64(),
|
upd.ShortChannelID.ToUint64(),
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
@@ -3178,6 +3201,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
|
|||||||
nMsg.err <- err
|
nMsg.err <- err
|
||||||
|
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
upd.GossipVersion(),
|
||||||
upd.ShortChannelID.ToUint64(),
|
upd.ShortChannelID.ToUint64(),
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
@@ -3307,6 +3331,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
|
|||||||
// Since we know the stored SCID in the graph, we'll
|
// Since we know the stored SCID in the graph, we'll
|
||||||
// cache that SCID.
|
// cache that SCID.
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
upd.GossipVersion(),
|
||||||
chanInfo.ChannelID,
|
chanInfo.ChannelID,
|
||||||
sourceToPub(nMsg.source),
|
sourceToPub(nMsg.source),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -4717,6 +4717,7 @@ func TestChanAnnBanningNonChanPeer(t *testing.T) {
|
|||||||
|
|
||||||
// Remove the scid from the reject cache.
|
// Remove the scid from the reject cache.
|
||||||
key := newRejectCacheKey(
|
key := newRejectCacheKey(
|
||||||
|
ca.GossipVersion(),
|
||||||
ca.ShortChannelID.ToUint64(),
|
ca.ShortChannelID.ToUint64(),
|
||||||
sourceToPub(nodePeer2.IdentityKey()),
|
sourceToPub(nodePeer2.IdentityKey()),
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in new issue
Block a user