|
@ -207,11 +207,11 @@ func testnetFiles(cmd *cobra.Command, args []string) error { |
|
|
|
|
|
|
|
|
// Gather persistent peer addresses.
|
|
|
// Gather persistent peer addresses.
|
|
|
var ( |
|
|
var ( |
|
|
persistentPeers string |
|
|
|
|
|
|
|
|
persistentPeers = make([]string, 0) |
|
|
err error |
|
|
err error |
|
|
) |
|
|
) |
|
|
if populatePersistentPeers { |
|
|
if populatePersistentPeers { |
|
|
persistentPeers, err = persistentPeersString(config) |
|
|
|
|
|
|
|
|
persistentPeers, err = persistentPeersArray(config) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
_ = os.RemoveAll(outputDir) |
|
|
_ = os.RemoveAll(outputDir) |
|
|
return err |
|
|
return err |
|
@ -225,7 +225,14 @@ func testnetFiles(cmd *cobra.Command, args []string) error { |
|
|
config.P2P.AddrBookStrict = false |
|
|
config.P2P.AddrBookStrict = false |
|
|
config.P2P.AllowDuplicateIP = true |
|
|
config.P2P.AllowDuplicateIP = true |
|
|
if populatePersistentPeers { |
|
|
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) |
|
|
config.Moniker = moniker(i) |
|
|
|
|
|
|
|
@ -256,18 +263,19 @@ func hostnameOrIP(i int) string { |
|
|
return ip.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++ { |
|
|
for i := 0; i < nValidators+nNonValidators; i++ { |
|
|
nodeDir := filepath.Join(outputDir, fmt.Sprintf("%s%d", nodeDirPrefix, i)) |
|
|
nodeDir := filepath.Join(outputDir, fmt.Sprintf("%s%d", nodeDirPrefix, i)) |
|
|
config.SetRoot(nodeDir) |
|
|
config.SetRoot(nodeDir) |
|
|
nodeKey, err := p2p.LoadNodeKey(config.NodeKeyFile()) |
|
|
nodeKey, err := p2p.LoadNodeKey(config.NodeKeyFile()) |
|
|
if err != nil { |
|
|
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 { |
|
|
func moniker(i int) string { |
|
|