From f12588aab1f1b52ffa82ed143676d69e2fab7bf4 Mon Sep 17 00:00:00 2001 From: Callum Waters Date: Thu, 10 Nov 2022 16:59:10 +0100 Subject: [PATCH] config: add bootstrap peers (#9680) --- CHANGELOG_PENDING.md | 3 +++ UPGRADING.md | 9 +++++++++ cmd/tendermint/commands/run_node.go | 1 + config/config.go | 5 +++++ config/toml.go | 5 +++++ node/node.go | 11 +++++++++++ spec/p2p/config.md | 8 ++++++++ 7 files changed, 42 insertions(+) diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index d7de0a301..dfc66460f 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -23,6 +23,9 @@ ### FEATURES +- [config] \#9680 Introduce `BootstrapPeers` to the config to allow nodes to list peers to be added to + the addressbook upon start up (@cmwaters) + ### IMPROVEMENTS - [pubsub] \#7319 Performance improvements for the event query API (@creachadair) diff --git a/UPGRADING.md b/UPGRADING.md index 001f1b7eb..27b267a28 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -5,6 +5,15 @@ Tendermint Core. ## Unreleased +## Config Changes + +* A new config field, `BootstrapPeers` has been introduced as a means of + adding a list of addresses to the addressbook upon initializing a node. This is an + alternative to `PersistentPeers`. `PersistentPeers` shold be only used for + nodes that you want to keep a constant connection with i.e. sentry nodes + +---- + ### ABCI Changes * The `ABCIVersion` is now `1.0.0`. diff --git a/cmd/tendermint/commands/run_node.go b/cmd/tendermint/commands/run_node.go index ac2984111..5bb2a6d45 100644 --- a/cmd/tendermint/commands/run_node.go +++ b/cmd/tendermint/commands/run_node.go @@ -66,6 +66,7 @@ func AddNodeFlags(cmd *cobra.Command) { cmd.Flags().String("p2p.external-address", config.P2P.ExternalAddress, "ip:port address to advertise to peers for them to dial") cmd.Flags().String("p2p.seeds", config.P2P.Seeds, "comma-delimited ID@host:port seed nodes") cmd.Flags().String("p2p.persistent_peers", config.P2P.PersistentPeers, "comma-delimited ID@host:port persistent peers") + cmd.Flags().String("p2p.bootstrap_peers", config.P2P.BootstrapPeers, "comma-delimited ID@host:port peers to be added to the addressbook on startup") cmd.Flags().String("p2p.unconditional_peer_ids", config.P2P.UnconditionalPeerIDs, "comma-delimited IDs of unconditional peers") cmd.Flags().Bool("p2p.upnp", config.P2P.UPNP, "enable/disable UPNP port forwarding") diff --git a/config/config.go b/config/config.go index bcf083463..c1ad2e229 100644 --- a/config/config.go +++ b/config/config.go @@ -548,6 +548,11 @@ type P2PConfig struct { //nolint: maligned // We only use these if we can’t connect to peers in the addrbook Seeds string `mapstructure:"seeds"` + // Comma separated list of peers to be added to the peer store + // on startup. Either BootstrapPeers or PersistentPeers are + // needed for peer discovery + BootstrapPeers string `mapstructure:"bootstrap_peers"` + // Comma separated list of nodes to keep persistent connections to PersistentPeers string `mapstructure:"persistent_peers"` diff --git a/config/toml.go b/config/toml.go index d5c2ab710..6041b92c3 100644 --- a/config/toml.go +++ b/config/toml.go @@ -283,6 +283,11 @@ external_address = "{{ .P2P.ExternalAddress }}" # Comma separated list of seed nodes to connect to seeds = "{{ .P2P.Seeds }}" +# Comma separated list of peers to be added to the peer store +# on startup. Either BootstrapPeers or PersistentPeers are +# needed for peer discovery +bootstrap_peers = "{{ .P2P.BootstrapPeers }}" + # Comma separated list of nodes to keep persistent connections to persistent_peers = "{{ .P2P.PersistentPeers }}" diff --git a/node/node.go b/node/node.go index 18f3f1e84..90a9356db 100644 --- a/node/node.go +++ b/node/node.go @@ -308,6 +308,17 @@ func NewNode(config *cfg.Config, return nil, fmt.Errorf("could not create addrbook: %w", err) } + for _, addr := range splitAndTrimEmpty(config.P2P.BootstrapPeers, ",", " ") { + netAddrs, err := p2p.NewNetAddressString(addr) + if err != nil { + return nil, fmt.Errorf("invalid bootstrap peer address: %w", err) + } + err = addrBook.AddAddress(netAddrs, netAddrs) + if err != nil { + return nil, fmt.Errorf("adding bootstrap address to addressbook: %w", err) + } + } + // Optionally, start the pex reactor // // TODO: diff --git a/spec/p2p/config.md b/spec/p2p/config.md index b63c04f28..966a04c7e 100644 --- a/spec/p2p/config.md +++ b/spec/p2p/config.md @@ -17,6 +17,14 @@ and upon incoming connection shares some peers and disconnects. Dials these seeds when we need more peers. They should return a list of peers and then disconnect. If we already have enough peers in the address book, we may never need to dial them. +## Bootstrap Peers + +`--p2p.bootstrap_peers “id100000000000000000000000000000000@1.2.3.4:26656,id200000000000000000000000000000000@2.3.4.5:26656”` + +A list of peers to be added to the addressbook upon startup to ensure that the node has some peers to initially dial. +Unlike persistent peers, these addresses don't have any extra privileges. The node may not necessarily connect on redial +these peers. + ## Persistent Peers `--p2p.persistent_peers “id100000000000000000000000000000000@1.2.3.4:26656,id200000000000000000000000000000000@2.3.4.5:26656”`