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
|
||||
// recently rejected.
|
||||
type rejectCacheKey struct {
|
||||
pubkey [33]byte
|
||||
chanID uint64
|
||||
gossipVersion lnwire.GossipVersion
|
||||
pubkey [33]byte
|
||||
chanID uint64
|
||||
}
|
||||
|
||||
// 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{
|
||||
chanID: cid,
|
||||
pubkey: pub,
|
||||
gossipVersion: v,
|
||||
chanID: cid,
|
||||
pubkey: pub,
|
||||
}
|
||||
|
||||
return k
|
||||
@@ -1688,8 +1692,15 @@ func (d *AuthenticatedGossiper) PruneSyncState(peer route.Vertex) {
|
||||
func (d *AuthenticatedGossiper) isRecentlyRejectedMsg(msg lnwire.Message,
|
||||
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
|
||||
switch m := msg.(type) {
|
||||
switch m := gMsg.(type) {
|
||||
case *lnwire.ChannelUpdate1:
|
||||
scid = m.ShortChannelID.ToUint64()
|
||||
|
||||
@@ -1700,8 +1711,11 @@ func (d *AuthenticatedGossiper) isRecentlyRejectedMsg(msg lnwire.Message,
|
||||
return false
|
||||
}
|
||||
|
||||
_, err := d.recentRejects.Get(newRejectCacheKey(scid, peerPub))
|
||||
return err != cache.ErrElementNotFound
|
||||
_, err := d.recentRejects.Get(newRejectCacheKey(
|
||||
gMsg.GossipVersion(), scid, peerPub,
|
||||
))
|
||||
|
||||
return !errors.Is(err, cache.ErrElementNotFound)
|
||||
}
|
||||
|
||||
// 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())
|
||||
|
||||
key := newRejectCacheKey(
|
||||
ann.GossipVersion(),
|
||||
scid.ToUint64(),
|
||||
sourceToPub(nMsg.source),
|
||||
)
|
||||
@@ -2588,6 +2603,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
||||
log.Errorf(err.Error())
|
||||
|
||||
key := newRejectCacheKey(
|
||||
ann.GossipVersion(),
|
||||
scid.ToUint64(),
|
||||
sourceToPub(nMsg.source),
|
||||
)
|
||||
@@ -2662,6 +2678,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
||||
"%v", err)
|
||||
|
||||
key := newRejectCacheKey(
|
||||
ann.GossipVersion(),
|
||||
scid.ToUint64(),
|
||||
sourceToPub(nMsg.source),
|
||||
)
|
||||
@@ -2741,6 +2758,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
||||
errors.Is(err, ErrInvalidFundingOutput):
|
||||
|
||||
key := newRejectCacheKey(
|
||||
ann.GossipVersion(),
|
||||
scid.ToUint64(),
|
||||
sourceToPub(nMsg.source),
|
||||
)
|
||||
@@ -2750,6 +2768,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
||||
|
||||
case errors.Is(err, ErrChannelSpent):
|
||||
key := newRejectCacheKey(
|
||||
ann.GossipVersion(),
|
||||
scid.ToUint64(),
|
||||
sourceToPub(nMsg.source),
|
||||
)
|
||||
@@ -2776,6 +2795,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
||||
// edge. We won't increase the ban score for the
|
||||
// remote peer.
|
||||
key := newRejectCacheKey(
|
||||
ann.GossipVersion(),
|
||||
scid.ToUint64(),
|
||||
sourceToPub(nMsg.source),
|
||||
)
|
||||
@@ -2839,6 +2859,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
||||
anns, rErr := d.processRejectedEdge(ctx, ann, proof)
|
||||
if rErr != nil {
|
||||
key := newRejectCacheKey(
|
||||
ann.GossipVersion(),
|
||||
scid.ToUint64(),
|
||||
sourceToPub(nMsg.source),
|
||||
)
|
||||
@@ -2866,6 +2887,7 @@ func (d *AuthenticatedGossiper) handleChanAnnouncement(ctx context.Context,
|
||||
|
||||
// Otherwise, this is just a regular rejected edge.
|
||||
key := newRejectCacheKey(
|
||||
ann.GossipVersion(),
|
||||
scid.ToUint64(),
|
||||
sourceToPub(nMsg.source),
|
||||
)
|
||||
@@ -2998,6 +3020,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
|
||||
log.Errorf(err.Error())
|
||||
|
||||
key := newRejectCacheKey(
|
||||
upd.GossipVersion(),
|
||||
upd.ShortChannelID.ToUint64(),
|
||||
sourceToPub(nMsg.source),
|
||||
)
|
||||
@@ -3178,6 +3201,7 @@ func (d *AuthenticatedGossiper) handleChanUpdate(ctx context.Context,
|
||||
nMsg.err <- err
|
||||
|
||||
key := newRejectCacheKey(
|
||||
upd.GossipVersion(),
|
||||
upd.ShortChannelID.ToUint64(),
|
||||
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
|
||||
// cache that SCID.
|
||||
key := newRejectCacheKey(
|
||||
upd.GossipVersion(),
|
||||
chanInfo.ChannelID,
|
||||
sourceToPub(nMsg.source),
|
||||
)
|
||||
|
||||
@@ -4717,6 +4717,7 @@ func TestChanAnnBanningNonChanPeer(t *testing.T) {
|
||||
|
||||
// Remove the scid from the reject cache.
|
||||
key := newRejectCacheKey(
|
||||
ca.GossipVersion(),
|
||||
ca.ShortChannelID.ToUint64(),
|
||||
sourceToPub(nodePeer2.IdentityKey()),
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user