|
|
@ -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 { |
|
|
|