diff --git a/config.go b/config.go index 335fb5646..c70ab04f6 100644 --- a/config.go +++ b/config.go @@ -309,6 +309,8 @@ type Config struct { Routing *lncfg.Routing `group:"routing" namespace:"routing"` + Gossip *lncfg.Gossip `group:"gossip" namespace:"gossip"` + Workers *lncfg.Workers `group:"workers" namespace:"workers"` Caches *lncfg.Caches `group:"caches" namespace:"caches"` @@ -477,6 +479,7 @@ func DefaultConfig() Config { Backoff: defaultTLSBackoff, }, }, + Gossip: &lncfg.Gossip{}, MaxOutgoingCltvExpiry: htlcswitch.DefaultMaxOutgoingCltvExpiry, MaxChannelFeeAllocation: htlcswitch.DefaultMaxLinkFeeAllocation, MaxCommitFeeRateAnchors: lnwallet.DefaultAnchorsCommitMaxFeeRateSatPerVByte, @@ -1289,6 +1292,10 @@ func ValidateConfig(cfg Config, usageMessage string) (*Config, error) { maxRemoteHtlcs) } + if err := cfg.Gossip.Parse(); err != nil { + return nil, err + } + // Validate the subconfigs for workers, caches, and the tower client. err = lncfg.Validate( cfg.Workers, diff --git a/discovery/gossiper.go b/discovery/gossiper.go index b5e4bcb62..8a79a4a72 100644 --- a/discovery/gossiper.go +++ b/discovery/gossiper.go @@ -237,6 +237,11 @@ type Config struct { // gossip updates to once per RebroadcastInterval for any keep-alive // updates, and once per block for other types of updates. GossipUpdateThrottle bool + + // PinnedSyncers is a set of peers that will always transition to + // ActiveSync upon connection. These peers will never transition to + // PassiveSync. + PinnedSyncers PinnedSyncers } // AuthenticatedGossiper is a subsystem which is responsible for receiving @@ -338,6 +343,7 @@ func New(cfg Config, selfKey *btcec.PublicKey) *AuthenticatedGossiper { NumActiveSyncers: cfg.NumActiveSyncers, IgnoreHistoricalFilters: cfg.IgnoreHistoricalFilters, BestHeight: gossiper.latestHeight, + PinnedSyncers: cfg.PinnedSyncers, }) gossiper.reliableSender = newReliableSender(&reliableSenderCfg{ diff --git a/lncfg/gossip.go b/lncfg/gossip.go new file mode 100644 index 000000000..bf8473a70 --- /dev/null +++ b/lncfg/gossip.go @@ -0,0 +1,28 @@ +package lncfg + +import ( + "github.com/lightningnetwork/lnd/discovery" + "github.com/lightningnetwork/lnd/routing/route" +) + +type Gossip struct { + PinnedSyncersRaw []string `long:"pinned-syncers" description:"A set of peers that should always remain in an active sync state, which can be used to closely synchronize the routing tables of two nodes. The value should be comma separated list of hex-encoded pubkeys. Connected peers matching this pubkey will remain active for the duration of the connection and not count towards the NumActiveSyncer count."` + + PinnedSyncers discovery.PinnedSyncers +} + +// Parse the pubkeys for the pinned syncers. +func (g *Gossip) Parse() error { + pinnedSyncers := make(discovery.PinnedSyncers) + for _, pubkeyStr := range g.PinnedSyncersRaw { + vertex, err := route.NewVertexFromStr(pubkeyStr) + if err != nil { + return err + } + pinnedSyncers[vertex] = struct{}{} + } + + g.PinnedSyncers = pinnedSyncers + + return nil +} diff --git a/sample-lnd.conf b/sample-lnd.conf index 38275bfd2..2925b5eea 100644 --- a/sample-lnd.conf +++ b/sample-lnd.conf @@ -1019,3 +1019,20 @@ litecoin.node=ltcd ; Specify the timeout to be used when opening the database. ; db.bolt.dbtimeout=60s + +[gossip] +; Specify a set of pinned gossip syncers, which will always be actively syncing +; whenever the corresponding peer is online. A pinned syncer does not count +; towards the configured `numgraphsyncpeers` since pinned syncers are not +; rotated. Configuring a pinned syncer does not ensure a persistent connection +; to the target peer, they will only be pinned if the connection remains active +; via some other mechanism, e.g. having an open channel. +; +; This feature is useful when trying to ensure that a node keeps its +; routing table tightly synchronized with a set of remote peers, e.g. multiple +; lightning nodes operated by the same service. +; +; Each value should be a hex-encoded pubkey of the pinned peer. Multiple pinned +; peers can be specified by setting multiple flags/fields in the config. +; gossip.pinned-syncers=pubkey1 +; gossip.pinned-syncers=pubkey2 diff --git a/server.go b/server.go index 2e4fb8b0b..8bf77cc63 100644 --- a/server.go +++ b/server.go @@ -820,6 +820,7 @@ func newServer(cfg *Config, listenAddrs []net.Addr, SubBatchDelay: time.Second * 5, IgnoreHistoricalFilters: cfg.IgnoreHistoricalGossipFilters, GossipUpdateThrottle: !cfg.ProtocolOptions.NoGossipThrottle(), + PinnedSyncers: cfg.Gossip.PinnedSyncers, }, s.identityECDH.PubKey(), )