Skip to content

Commit b381060

Browse files
committed
multi: add new config peer-msg-rate-bytes
1 parent 6c8974d commit b381060

File tree

6 files changed

+29
-0
lines changed

6 files changed

+29
-0
lines changed

config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,6 +719,7 @@ func DefaultConfig() Config {
719719
AnnouncementConf: discovery.DefaultProofMatureDelta,
720720
MsgRateBytes: discovery.DefaultMsgBytesPerSecond,
721721
MsgBurstBytes: discovery.DefaultMsgBytesBurst,
722+
PeerMsgRateBytes: discovery.DefaultPeerMsgBytesPerSecond,
722723
},
723724
Invoices: &lncfg.Invoices{
724725
HoldExpiryDelta: lncfg.DefaultHoldInvoiceExpiryDelta,

discovery/gossiper.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ type Config struct {
399399
// MsgBurstBytes is the allotted burst amount in bytes. This is the
400400
// number of starting tokens in our token bucket algorithm.
401401
MsgBurstBytes uint64
402+
403+
// PeerMsgRateBytes is the rate limit for the number of bytes per second
404+
// that we'll allocate to outbound gossip messages for a single peer.
405+
PeerMsgRateBytes uint64
402406
}
403407

404408
// processedNetworkMsg is a wrapper around networkMsg and a boolean. It is
@@ -600,6 +604,7 @@ func New(cfg Config, selfKeyDesc *keychain.KeyDescriptor) *AuthenticatedGossiper
600604
IsStillZombieChannel: cfg.IsStillZombieChannel,
601605
AllotedMsgBytesPerSecond: cfg.MsgRateBytes,
602606
AllotedMsgBytesBurst: cfg.MsgBurstBytes,
607+
PeerMsgBytesPerSecond: cfg.PeerMsgRateBytes,
603608
})
604609

605610
gossiper.reliableSender = newReliableSender(&reliableSenderCfg{

discovery/sync_manager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,12 @@ type SyncManagerCfg struct {
141141
// AllotedMsgBytesBurst is the amount of burst bytes we'll permit, if
142142
// we've exceeded the hard upper limit.
143143
AllotedMsgBytesBurst uint64
144+
145+
// PeerMsgBytesPerSecond is the allotted bandwidth rate, expressed in
146+
// bytes/second that the a single gossip syncer can consume. Once we
147+
// exceed this rate, message sending will block until we're below the
148+
// rate.
149+
PeerMsgBytesPerSecond uint64
144150
}
145151

146152
// SyncManager is a subsystem of the gossiper that manages the gossip syncers
@@ -665,6 +671,7 @@ func (m *SyncManager) createGossipSyncer(peer lnpeer.Peer) *GossipSyncer {
665671
maxQueryChanRangeReplies: maxQueryChanRangeReplies,
666672
noTimestampQueryOption: m.cfg.NoTimestampQueries,
667673
isStillZombieChannel: m.cfg.IsStillZombieChannel,
674+
msgBytesPerSecond: m.cfg.PeerMsgBytesPerSecond,
668675
}, m.gossipFilterSema)
669676

670677
// Gossip syncers are initialized by default in a PassiveSync type

lncfg/gossip.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ type Gossip struct {
3737
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."`
3838

3939
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"`
40+
41+
PeerMsgRateBytes uint64 `long:"peer-msg-rate-bytes" description:"The peer-specific rate of outbound gossip messages, expressed in bytes per second. This setting controls the long-term average speed of gossip traffic sent from your node. The rate limit is applied to each peer. If the rate of outgoing messages exceeds this value, lnd will start to queue and delay messages sending to that peer to stay within the limit."`
4042
}
4143

4244
// Parse the pubkeys for the pinned syncers.
@@ -68,6 +70,12 @@ func (g *Gossip) Validate() error {
6870
g.MsgBurstBytes, lnwire.MaxSliceLength)
6971
}
7072

73+
if g.MsgRateBytes < g.PeerMsgRateBytes {
74+
return fmt.Errorf("msg-rate-bytes=%v must be at greater than "+
75+
"peer-msg-rate-bytes=%v", g.MsgRateBytes,
76+
g.PeerMsgRateBytes)
77+
}
78+
7179
return nil
7280
}
7381

sample-lnd.conf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1774,6 +1774,13 @@
17741774
; can never be sent.
17751775
; gossip.msg-burst-bytes=204800
17761776

1777+
; The peer-specific rate of outbound gossip messages, expressed in bytes per
1778+
; second. This setting controls the long-term average speed of gossip traffic
1779+
; sent from your node. The rate limit is applied to each peer. If the rate of
1780+
; outgoing messages exceeds this value, lnd will start to queue and delay
1781+
; messages sending to that peer to stay within the limit.
1782+
; gossip.peer-msg-rate-bytes=102400
1783+
17771784
[invoices]
17781785

17791786
; If a hold invoice has accepted htlcs that reach their expiry height and are

server.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,6 +1225,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr,
12251225
AssumeChannelValid: cfg.Routing.AssumeChannelValid,
12261226
MsgRateBytes: cfg.Gossip.MsgRateBytes,
12271227
MsgBurstBytes: cfg.Gossip.MsgBurstBytes,
1228+
PeerMsgRateBytes: cfg.Gossip.PeerMsgRateBytes,
12281229
}, nodeKeyDesc)
12291230

12301231
accessCfg := &accessManConfig{

0 commit comments

Comments
 (0)