Skip to content

Commit

Permalink
turn off strict routability every time
Browse files Browse the repository at this point in the history
previously, we're turning it off only when --populate-persistent-peers
flag was used, which is obviously incorrect.

Fixes cosmos/cosmos-sdk#2983
  • Loading branch information
melekes committed Dec 7, 2018
1 parent 2f64717 commit 03e8675
Showing 1 changed file with 21 additions and 16 deletions.
37 changes: 21 additions & 16 deletions cmd/tendermint/commands/testnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,31 @@ func testnetFiles(cmd *cobra.Command, args []string) error {
}
}

// Gather persistent peer addresses.
var (
persistentPeers string
err error
)
if populatePersistentPeers {
err := populatePersistentPeersInConfigAndWriteIt(config)
persistentPeers, err = persistentPeersString(config)
if err != nil {
_ = os.RemoveAll(outputDir)
return err
}
}

// Overwrite default config.
for i := 0; i < nValidators+nNonValidators; i++ {
nodeDir := filepath.Join(outputDir, fmt.Sprintf("%s%d", nodeDirPrefix, i))
config.SetRoot(nodeDir)
config.P2P.AddrBookStrict = false
if populatePersistentPeers {
config.P2P.PersistentPeers = persistentPeers
}

cfg.WriteConfigFile(filepath.Join(nodeDir, "config", "config.toml"), config)
}

fmt.Printf("Successfully initialized %v node directories\n", nValidators+nNonValidators)
return nil
}
Expand All @@ -157,28 +174,16 @@ func hostnameOrIP(i int) string {
return fmt.Sprintf("%s%d", hostnamePrefix, i)
}

func populatePersistentPeersInConfigAndWriteIt(config *cfg.Config) error {
func persistentPeersString(config *cfg.Config) (string, error) {
persistentPeers := make([]string, nValidators+nNonValidators)
for i := 0; i < nValidators+nNonValidators; i++ {
nodeDir := filepath.Join(outputDir, fmt.Sprintf("%s%d", nodeDirPrefix, i))
config.SetRoot(nodeDir)
nodeKey, err := p2p.LoadNodeKey(config.NodeKeyFile())
if err != nil {
return err
return "", err
}
persistentPeers[i] = p2p.IDAddressString(nodeKey.ID(), fmt.Sprintf("%s:%d", hostnameOrIP(i), p2pPort))
}
persistentPeersList := strings.Join(persistentPeers, ",")

for i := 0; i < nValidators+nNonValidators; i++ {
nodeDir := filepath.Join(outputDir, fmt.Sprintf("%s%d", nodeDirPrefix, i))
config.SetRoot(nodeDir)
config.P2P.PersistentPeers = persistentPeersList
config.P2P.AddrBookStrict = false

// overwrite default config
cfg.WriteConfigFile(filepath.Join(nodeDir, "config", "config.toml"), config)
}

return nil
return strings.Join(persistentPeers, ","), nil
}

0 comments on commit 03e8675

Please sign in to comment.