Skip to content

Commit

Permalink
multi: add a --gossip.no-sync option
Browse files Browse the repository at this point in the history
When set, LND will not advertise the gossip queries feature bit and it
will not initiate gossip syncing with any peer.
  • Loading branch information
ellemouton committed Nov 8, 2024
1 parent 2fe92e5 commit f283058
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 0 deletions.
31 changes: 31 additions & 0 deletions discovery/gossiper.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,13 @@ var (
// the remote peer.
ErrGossipSyncerNotFound = errors.New("gossip syncer not found")

// ErrUnexpectedGossipQueries is an error that is returned if we receive
// gossip queries from a peer when we have disabled gossip syncing and
// in other words have not advertised that we support gossip queries.
ErrUnexpectedGossipQueries = errors.New(
"unexpected gossip queries received",
)

// emptyPubkey is used to compare compressed pubkeys against an empty
// byte array.
emptyPubkey [33]byte
Expand Down Expand Up @@ -360,6 +367,11 @@ type Config struct {
// updates for a channel and returns true if the channel should be
// considered a zombie based on these timestamps.
IsStillZombieChannel func(time.Time, time.Time) bool

// NoGossipSync is true if gossip syncing has been disabled. It
// indicates that we have not advertised the gossip queries feature bit,
// and so we should not receive any gossip queries from our peers.
NoGossipSync bool
}

// processedNetworkMsg is a wrapper around networkMsg and a boolean. It is
Expand Down Expand Up @@ -820,6 +832,25 @@ func (d *AuthenticatedGossiper) ProcessRemoteAnnouncement(msg lnwire.Message,
// TODO(elle): let ProcessRemoteAnnouncement take a context.
ctx := context.TODO()

// If gossip syncing has been disabled, we expect not to receive any
// gossip queries from our peer.
if d.cfg.NoGossipSync {
switch m := msg.(type) {
case *lnwire.QueryShortChanIDs,
*lnwire.QueryChannelRange,
*lnwire.ReplyChannelRange,
*lnwire.ReplyShortChanIDsEnd,
*lnwire.GossipTimestampRange:

log.Warnf("Gossip syncing was disabled, "+
"skipping message: %v", m)
errChan <- ErrUnexpectedGossipQueries

return errChan
default:
}
}

// For messages in the known set of channel series queries, we'll
// dispatch the message directly to the GossipSyncer, and skip the main
// processing loop.
Expand Down
7 changes: 7 additions & 0 deletions feature/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ type Config struct {
// NoTaprootOverlay unsets the taproot overlay channel feature bits.
NoTaprootOverlay bool

// NoGossipQueries unsets the gossip queries feature bit.
NoGossipQueries bool

// CustomFeatures is a set of custom features to advertise in each
// set.
CustomFeatures map[Set][]lnwire.FeatureBit
Expand Down Expand Up @@ -199,6 +202,10 @@ func newManager(cfg Config, desc setDesc) (*Manager, error) {
raw.Unset(lnwire.SimpleTaprootOverlayChansOptional)
raw.Unset(lnwire.SimpleTaprootOverlayChansRequired)
}
if cfg.NoGossipQueries {
raw.Unset(lnwire.GossipQueriesOptional)
raw.Unset(lnwire.GossipQueriesRequired)
}
for _, custom := range cfg.CustomFeatures[set] {
if custom > set.Maximum() {
return nil, fmt.Errorf("feature bit: %v "+
Expand Down
2 changes: 2 additions & 0 deletions lncfg/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Gossip struct {
ChannelUpdateInterval time.Duration `long:"channel-update-interval" description:"The interval used to determine how often lnd should allow a burst of new updates for a specific channel and direction."`

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."`

NoSync bool `long:"no-sync" description:"If set, lnd will not request graph updates from its peers and wont advertise the gossip queries feature bit. This is useful if LND has been provided with an external graph source that it may use for pathfinding."`
}

// Parse the pubkeys for the pinned syncers.
Expand Down
8 changes: 8 additions & 0 deletions peer/brontide.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ type Config struct {
// used to modify the way the co-op close transaction is constructed.
AuxChanCloser fn.Option[chancloser.AuxChanCloser]

// NoGossipSync is true if we should not sync gossip with this peer.
NoGossipSync bool

// Quit is the server's quit channel. If this is closed, we halt operation.
Quit chan struct{}
}
Expand Down Expand Up @@ -869,6 +872,11 @@ func (p *Brontide) Start() error {
// initGossipSync initializes either a gossip syncer or an initial routing
// dump, depending on the negotiated synchronization method.
func (p *Brontide) initGossipSync() {
// If gossip syncing has explicitly been disabled, we'll exit early.
if p.cfg.NoGossipSync {
return
}

// If the remote peer knows of the new gossip queries feature, then
// we'll create a new gossipSyncer in the AuthenticatedGossiper for it.
if p.remoteFeatures.HasFeature(lnwire.GossipQueriesOptional) {
Expand Down
4 changes: 4 additions & 0 deletions sample-lnd.conf
Original file line number Diff line number Diff line change
Expand Up @@ -1721,6 +1721,10 @@
; be broadcast quickly.
; gossip.sub-batch-delay=5s

; If set, LND will not request graph updates from its peers and wont advertise
; the gossip queries feature bit. This is useful if LND has been provided with
; an external graph source that it may use for pathfinding.
; gossip.no-sync=false

[invoices]

Expand Down
2 changes: 2 additions & 0 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ func newServer(ctx context.Context, cfg *Config, listenAddrs []net.Addr,
NoTaprootChans: !cfg.ProtocolOptions.TaprootChans,
NoTaprootOverlay: !cfg.ProtocolOptions.TaprootOverlayChans,
NoRouteBlinding: cfg.ProtocolOptions.NoRouteBlinding(),
NoGossipQueries: cfg.Gossip.NoSync,
})
if err != nil {
return nil, err
Expand Down Expand Up @@ -4195,6 +4196,7 @@ func (s *server) peerConnected(ctx context.Context, conn net.Conn,
MsgRouter: s.implCfg.MsgRouter,
AuxChanCloser: s.implCfg.AuxChanCloser,
AuxResolver: s.implCfg.AuxContractResolver,
NoGossipSync: s.cfg.Gossip.NoSync,
}

copy(pCfg.PubKeyBytes[:], peerAddr.IdentityKey.SerializeCompressed())
Expand Down

0 comments on commit f283058

Please sign in to comment.