From c7ed5d65c6bcae82728f8af220583a7e1d73b704 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Thu, 20 Mar 2025 14:54:26 -0700 Subject: [PATCH] multi: add new config options to tune gossip msg allocated bandwidth We go with the defaults of if no values are set. --- config.go | 2 ++ discovery/gossiper.go | 30 ++++++++++++++++++++---------- lncfg/gossip.go | 10 ++++++++++ sample-lnd.conf | 11 +++++++++++ server.go | 2 ++ 5 files changed, 45 insertions(+), 10 deletions(-) diff --git a/config.go b/config.go index 2390a3ee2..824bcc55f 100644 --- a/config.go +++ b/config.go @@ -707,6 +707,8 @@ func DefaultConfig() Config { ChannelUpdateInterval: discovery.DefaultChannelUpdateInterval, SubBatchDelay: discovery.DefaultSubBatchDelay, AnnouncementConf: discovery.DefaultProofMatureDelta, + MsgRateBytes: discovery.DefaultMsgBytesPerSecond, + MsgBurstBytes: discovery.DefaultMsgBytesBurst, }, Invoices: &lncfg.Invoices{ HoldExpiryDelta: lncfg.DefaultHoldInvoiceExpiryDelta, diff --git a/discovery/gossiper.go b/discovery/gossiper.go index 1a74e3e15..cdeaa2942 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -390,6 +390,14 @@ type Config struct { // spent-ness of channel outpoints. For neutrino, this saves long // rescans from blocking initial usage of the daemon. AssumeChannelValid bool + + // MsgRateBytes is the rate limit for the number of bytes per second + // that we'll allocate to outbound gossip messages. + MsgRateBytes uint64 + + // MsgBurstBytes is the allotted burst amount in bytes. This is the + // number of starting tokens in our token bucket algorithm. + MsgBurstBytes uint64 } // processedNetworkMsg is a wrapper around networkMsg and a boolean. It is @@ -574,16 +582,18 @@ func New(cfg Config, selfKeyDesc *keychain.KeyDescriptor) *AuthenticatedGossiper gossiper.vb = NewValidationBarrier(1000, gossiper.quit) gossiper.syncMgr = newSyncManager(&SyncManagerCfg{ - ChainHash: cfg.ChainHash, - ChanSeries: cfg.ChanSeries, - RotateTicker: cfg.RotateTicker, - HistoricalSyncTicker: cfg.HistoricalSyncTicker, - NumActiveSyncers: cfg.NumActiveSyncers, - NoTimestampQueries: cfg.NoTimestampQueries, - IgnoreHistoricalFilters: cfg.IgnoreHistoricalFilters, - BestHeight: gossiper.latestHeight, - PinnedSyncers: cfg.PinnedSyncers, - IsStillZombieChannel: cfg.IsStillZombieChannel, + ChainHash: cfg.ChainHash, + ChanSeries: cfg.ChanSeries, + RotateTicker: cfg.RotateTicker, + HistoricalSyncTicker: cfg.HistoricalSyncTicker, + NumActiveSyncers: cfg.NumActiveSyncers, + NoTimestampQueries: cfg.NoTimestampQueries, + IgnoreHistoricalFilters: cfg.IgnoreHistoricalFilters, + BestHeight: gossiper.latestHeight, + PinnedSyncers: cfg.PinnedSyncers, + IsStillZombieChannel: cfg.IsStillZombieChannel, + AllotedMsgBytesPerSecond: cfg.MsgRateBytes, + AllotedMsgBytesBurst: cfg.MsgBurstBytes, }) gossiper.reliableSender = newReliableSender(&reliableSenderCfg{ diff --git a/lncfg/gossip.go b/lncfg/gossip.go index b8cab2c5f..37595e439 100644 --- a/lncfg/gossip.go +++ b/lncfg/gossip.go @@ -5,6 +5,7 @@ import ( "time" "github.com/lightningnetwork/lnd/discovery" + "github.com/lightningnetwork/lnd/lnwire" "github.com/lightningnetwork/lnd/routing/route" ) @@ -32,6 +33,10 @@ type Gossip struct { SubBatchDelay time.Duration `long:"sub-batch-delay" description:"The duration to wait before sending the next announcement batch if there are multiple. Use a small value if there are a lot announcements and they need to be broadcast quickly."` AnnouncementConf uint32 `long:"announcement-conf" description:"The number of confirmations required before processing channel announcements."` + + MsgRateBytes uint64 `long:"msg-rate-bytes" description:"The maximum number of bytes of gossip messages that will be sent per second. This is a global limit that applies to all peers."` + + MsgBurstBytes uint64 `long:"msg-burst-bytes" description:"The maximum number of bytes of gossip messages that will be sent in a burst. This is a global limit that applies to all peers. This value should be set to something greater than 130 KB"` } // Parse the pubkeys for the pinned syncers. @@ -58,6 +63,11 @@ func (g *Gossip) Validate() error { "%v", g.AnnouncementConf, minAnnouncementConf) } + if g.MsgBurstBytes < lnwire.MaxSliceLength { + return fmt.Errorf("msg-burst-bytes=%v must be at least %v", + g.MsgBurstBytes, lnwire.MaxSliceLength) + } + return nil } diff --git a/sample-lnd.conf b/sample-lnd.conf index 53be66404..af4923846 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -1746,6 +1746,17 @@ ; The number of confirmations required before processing channel announcements. ; gossip.announcement-conf=6 +; The allotted bandwidth rate expressed in bytes/second that will be allocated +; towards outbound gossip messages. Realized rates above this value will be +; throttled. This value is shared across all peers. +; gossip.msg-rate-bytes=102400 + +; The amount of bytes of gossip messages that can be sent at a given time. This +; is used as the amount of tokens in the token bucket algorithm. This value +; MUST be set to something about 65 KB, otherwise a single max sized message +; can never be sent. +; gossip.msg-burst-bytes=204800 + [invoices] ; If a hold invoice has accepted htlcs that reach their expiry height and are diff --git a/server.go b/server.go index 19d836a4e..38243c289 100644 --- a/server.go +++ b/server.go @@ -1188,6 +1188,8 @@ func newServer(cfg *Config, listenAddrs []net.Addr, IsStillZombieChannel: s.graphBuilder.IsZombieChannel, ScidCloser: scidCloserMan, AssumeChannelValid: cfg.Routing.AssumeChannelValid, + MsgRateBytes: cfg.Gossip.MsgRateBytes, + MsgBurstBytes: cfg.Gossip.MsgBurstBytes, }, nodeKeyDesc) accessCfg := &accessManConfig{