Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tendermint unconditional peers #2855

Merged
merged 2 commits into from
Apr 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changelog/2855.feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
go/consensus/tendermint: Expose new config options added in Tendermint 0.33

Tendermint 0.33 added the concept of unconditional P2P peers. Support for
setting the unconditional peers via `tendermint.p2p.unconditional_peer_ids`
configuration flag is added. On sentry node, upstream nodes will automatically
be set as unconditional peers.

Tendermint 0.33 added support for setting maximum re-dial period when
ptrus marked this conversation as resolved.
Show resolved Hide resolved
dialing persistent peers. This adds support for setting the period via
`tendermint.p2p.persistent_peers_max_dial_period` flag.
25 changes: 18 additions & 7 deletions go/consensus/tendermint/tendermint.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ const (

// CfgP2PPersistentPeer configures tendermint's persistent peer(s).
CfgP2PPersistentPeer = "tendermint.p2p.persistent_peer"
// CfgP2PPersistenPeersMaxDialPeriod configures the tendermint's peristent peer max dial period.
CfgP2PPersistenPeersMaxDialPeriod = "tendermint.p2p.persistent_peers_max_dial_period"
// CfgP2PDisablePeerExchange disables tendermint's peer-exchange (Pex) reactor.
CfgP2PDisablePeerExchange = "tendermint.p2p.disable_peer_exchange"
// CfgP2PSeeds configures tendermint's seed node(s).
Expand All @@ -96,6 +98,8 @@ const (
CfgP2PSendRate = "tendermint.p2p.send_rate"
// CfgP2PRecvRate is the rate at which packets can be received, in bytes/second.
CfgP2PRecvRate = "tendermint.p2p.recv_rate"
// CfgP2PUnconditionalPeerIDs configures tendermint's unconditional peer(s).
CfgP2PUnconditionalPeerIDs = "tendermint.p2p.unconditional_peer_ids"

cfgLogDebug = "tendermint.log.debug"

Expand Down Expand Up @@ -960,6 +964,12 @@ func (t *tendermintService) lazyInit() error {
// Since persistent peers is expected to be in comma-delimited ID@host:port format,
// lowercasing the whole string is ok.
tenderConfig.P2P.PersistentPeers = strings.ToLower(strings.Join(viper.GetStringSlice(CfgP2PPersistentPeer), ","))
tenderConfig.P2P.PersistentPeersMaxDialPeriod = viper.GetDuration(CfgP2PPersistenPeersMaxDialPeriod)
// Unconditional peer IDs need to be lowercase as p2p/transport.go:MultiplexTransport.upgrade()
// uses a case sensitive string comparision to validate public keys.
// Since persistent peers is expected to be in comma-delimited ID format,
// lowercasing the whole string is ok.
tenderConfig.P2P.UnconditionalPeerIDs = strings.ToLower(strings.Join(viper.GetStringSlice(CfgP2PUnconditionalPeerIDs), ","))
tenderConfig.P2P.SeedMode = viper.GetBool(CfgP2PSeedMode)
// Seed Ids need to be lowercase as p2p/transport.go:MultiplexTransport.upgrade()
// uses a case sensitive string comparision to validate public keys.
Expand All @@ -974,9 +984,8 @@ func (t *tendermintService) lazyInit() error {
if len(sentryUpstreamAddrs) > 0 {
t.Logger.Info("Acting as a tendermint sentry", "addrs", sentryUpstreamAddrs)

// Append sentry addresses to persistent peers.
tenderConfig.P2P.PersistentPeers = tenderConfig.P2P.PersistentPeers + "," +
strings.ToLower(strings.Join(sentryUpstreamAddrs, ","))
// Append upstream addresses to persistent, private and unconditional peers.
tenderConfig.P2P.PersistentPeers += "," + strings.ToLower(strings.Join(sentryUpstreamAddrs, ","))

var sentryUpstreamIDs []string
for _, addr := range sentryUpstreamAddrs {
Expand All @@ -987,12 +996,12 @@ func (t *tendermintService) lazyInit() error {
sentryUpstreamIDs = append(sentryUpstreamIDs, parts[0])
}

// Convert persistent peer IDs to lowercase (like other IDs) since
// Convert upstream node IDs to lowercase (like other IDs) since
// Tendermint stores them in a map and uses a case sensitive string
// comparison to check ID equality.
tenderConfig.P2P.PrivatePeerIDs = strings.ToLower(strings.Join(sentryUpstreamIDs, ","))

// XXX: tendermint v0.33 adds: `unconditional_peer_ids` which should also be set here.
sentryUpstreamIDsStr := strings.ToLower(strings.Join(sentryUpstreamIDs, ","))
tenderConfig.P2P.PrivatePeerIDs += "," + sentryUpstreamIDsStr
tenderConfig.P2P.UnconditionalPeerIDs += "," + sentryUpstreamIDsStr
}

if !tenderConfig.P2P.PexReactor {
Expand Down Expand Up @@ -1377,8 +1386,10 @@ func init() {
Flags.Uint64(cfgABCIPruneNumKept, 3600, "ABCI state versions kept (when applicable)")
Flags.StringSlice(CfgSentryUpstreamAddress, []string{}, "Tendermint nodes for which we act as sentry of the form ID@ip:port")
Flags.StringSlice(CfgP2PPersistentPeer, []string{}, "Tendermint persistent peer(s) of the form ID@ip:port")
Flags.StringSlice(CfgP2PUnconditionalPeerIDs, []string{}, "Tendermint unconditional peer IDs")
Flags.Bool(CfgP2PDisablePeerExchange, false, "Disable Tendermint's peer-exchange reactor")
Flags.Bool(CfgP2PSeedMode, false, "run the tendermint node in seed mode")
Flags.Duration(CfgP2PPersistenPeersMaxDialPeriod, 0*time.Second, "Tendermint max timeout when redialing a persistent peer (default: unlimited)")
Flags.Int(CfgP2PMaxNumInboundPeers, 40, "Max number of inbound peers")
Flags.Int(CfgP2PMaxNumOutboundPeers, 20, "Max number of outbound peers (excluding persistent peers)")
Flags.Int64(CfgP2PSendRate, 5120000, "Rate at which packets can be sent (bytes/sec)")
Expand Down