Browse Source

localnet: fix localnet by excluding self from persistent peers list (#6209)

Closes #6205
pull/6220/head
Anton Kaliaev 4 years ago
committed by GitHub
parent
commit
4540bef665
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 8 deletions
  1. +16
    -8
      cmd/tendermint/commands/testnet.go

+ 16
- 8
cmd/tendermint/commands/testnet.go View File

@ -207,11 +207,11 @@ func testnetFiles(cmd *cobra.Command, args []string) error {
// Gather persistent peer addresses.
var (
persistentPeers string
persistentPeers = make([]string, 0)
err error
)
if populatePersistentPeers {
persistentPeers, err = persistentPeersString(config)
persistentPeers, err = persistentPeersArray(config)
if err != nil {
_ = os.RemoveAll(outputDir)
return err
@ -225,7 +225,14 @@ func testnetFiles(cmd *cobra.Command, args []string) error {
config.P2P.AddrBookStrict = false
config.P2P.AllowDuplicateIP = true
if populatePersistentPeers {
config.P2P.PersistentPeers = persistentPeers
persistentPeersWithoutSelf := make([]string, 0)
for j := 0; j < len(persistentPeers); j++ {
if j == i {
continue
}
persistentPeersWithoutSelf = append(persistentPeersWithoutSelf, persistentPeers[j])
}
config.P2P.PersistentPeers = strings.Join(persistentPeersWithoutSelf, ",")
}
config.Moniker = moniker(i)
@ -256,18 +263,19 @@ func hostnameOrIP(i int) string {
return ip.String()
}
func persistentPeersString(config *cfg.Config) (string, error) {
persistentPeers := make([]string, nValidators+nNonValidators)
// get an array of persistent peers
func persistentPeersArray(config *cfg.Config) ([]string, error) {
peers := 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 []string{}, err
}
persistentPeers[i] = p2p.IDAddressString(nodeKey.ID, fmt.Sprintf("%s:%d", hostnameOrIP(i), p2pPort))
peers[i] = p2p.IDAddressString(nodeKey.ID, fmt.Sprintf("%s:%d", hostnameOrIP(i), p2pPort))
}
return strings.Join(persistentPeers, ","), nil
return peers, nil
}
func moniker(i int) string {


Loading…
Cancel
Save