From b1fbbcf5622317575b0917593cfd16602043621d Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 29 Nov 2020 16:12:44 -0800 Subject: [PATCH 1/3] lncfg: add new legacy protocol option to turn off gossip throttling --- lncfg/protocol_legacy_off.go | 5 +++++ lncfg/protocol_legacy_on.go | 11 +++++++++++ 2 files changed, 16 insertions(+) diff --git a/lncfg/protocol_legacy_off.go b/lncfg/protocol_legacy_off.go index 060569d8..c0a8ef8d 100644 --- a/lncfg/protocol_legacy_off.go +++ b/lncfg/protocol_legacy_off.go @@ -20,3 +20,8 @@ func (l *LegacyProtocol) LegacyOnion() bool { func (l *LegacyProtocol) NoStaticRemoteKey() bool { return false } + +// NoGossipThrottle returns true if gossip updates shouldn't be throttled. +func (l *LegacyProtocol) NoGossipThrottle() bool { + return false +} diff --git a/lncfg/protocol_legacy_on.go b/lncfg/protocol_legacy_on.go index 712d5fed..ee0ee3b4 100644 --- a/lncfg/protocol_legacy_on.go +++ b/lncfg/protocol_legacy_on.go @@ -16,6 +16,12 @@ type LegacyProtocol struct { // remote party's output in the commitment. If set to true, then we // won't signal StaticRemoteKeyOptional. CommitmentTweak bool `long:"committweak" description:"force node to not advertise the new commitment format"` + + // NoGossipUpdateThrottle if true, then gossip updates won't be + // throttled using the current set of heuristics. This should mainly be + // used for integration tests where we want nearly instant propagation + // of gossip updates. + NoGossipUpdateThrottle bool `long:"no-gossip-throttle" description:"if true, then gossip updates will not be throttled to once per rebroadcast interval for non keep-alive updates"` } // LegacyOnion returns true if the old legacy onion format should be used when @@ -30,3 +36,8 @@ func (l *LegacyProtocol) LegacyOnion() bool { func (l *LegacyProtocol) NoStaticRemoteKey() bool { return l.CommitmentTweak } + +// NoGossipThrottle returns true if gossip updates shouldn't be throttled. +func (l *LegacyProtocol) NoGossipThrottle() bool { + return l.NoGossipUpdateThrottle +} From 13a2598ded5944c1bc91ecff2c2b1b156486bda5 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 29 Nov 2020 16:13:40 -0800 Subject: [PATCH 2/3] discovery: add new option to toggle gossip rate limiting In this commit, we add a new option to toggle gossip rate limiting. This new option can be useful in contexts that require near instant propagation of gossip messages like integration tests. --- discovery/gossiper.go | 10 ++++++++-- discovery/gossiper_test.go | 1 + server.go | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 87dcde7c..845bce46 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -228,6 +228,11 @@ type Config struct { // This prevents ranges with old start times from causing us to dump the // graph on connect. IgnoreHistoricalFilters bool + + // GossipUpdateThrottle if true, then the gossiper will throttle + // gossip updates to once per RebroadcastInterval for any keep-alive + // updates, and once per block for other types of updates. + GossipUpdateThrottle bool } // AuthenticatedGossiper is a subsystem which is responsible for receiving @@ -1965,8 +1970,9 @@ func (d *AuthenticatedGossiper) processNetworkAnnouncement( // If we have a previous version of the edge being updated, // we'll want to rate limit its updates to prevent spam - // throughout the network. - if nMsg.isRemote && edgeToUpdate != nil { + // throughout the network if we're currently throttling such + // updates. + if d.cfg.GossipUpdateThrottle && nMsg.isRemote && edgeToUpdate != nil { // If it's a keep-alive update, we'll only propagate one // if it's been a day since the previous. This follows // our own heuristic of sending keep-alive updates after diff --git a/discovery/gossiper_test.go b/discovery/gossiper_test.go index fc227148..728cf1ec 100644 --- a/discovery/gossiper_test.go +++ b/discovery/gossiper_test.go @@ -3957,6 +3957,7 @@ func TestRateLimitChannelUpdates(t *testing.T) { } defer cleanup() ctx.gossiper.cfg.RebroadcastInterval = time.Hour + ctx.gossiper.cfg.GossipUpdateThrottle = true // The graph should start empty. require.Empty(t, ctx.router.infos) diff --git a/server.go b/server.go index 13e1462b..72c9b612 100644 --- a/server.go +++ b/server.go @@ -804,6 +804,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, MinimumBatchSize: 10, SubBatchDelay: time.Second * 5, IgnoreHistoricalFilters: cfg.IgnoreHistoricalGossipFilters, + GossipUpdateThrottle: !cfg.ProtocolOptions.NoGossipThrottle(), }, s.identityECDH.PubKey(), ) From 447c9f2c0be2512b4af0ce1ce5314f661da6952f Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Sun, 29 Nov 2020 16:14:00 -0800 Subject: [PATCH 3/3] lntest: always turn off gossip throttling for nodes created in itests --- lntest/node.go | 1 + 1 file changed, 1 insertion(+) diff --git a/lntest/node.go b/lntest/node.go index d96fe995..2ea8e13a 100644 --- a/lntest/node.go +++ b/lntest/node.go @@ -255,6 +255,7 @@ func (cfg NodeConfig) genArgs() []string { args = append(args, fmt.Sprintf("--invoicemacaroonpath=%v", cfg.InvoiceMacPath)) args = append(args, fmt.Sprintf("--trickledelay=%v", trickleDelay)) args = append(args, fmt.Sprintf("--profile=%d", cfg.ProfilePort)) + args = append(args, fmt.Sprintf("--protocol.legacy.no-gossip-throttle")) if !cfg.HasSeed { args = append(args, "--noseedbackup")