2021-04-13 07:41:06 +00:00
|
|
|
package registration
|
|
|
|
|
|
|
|
import (
|
2022-04-18 20:42:07 +00:00
|
|
|
"os"
|
2021-04-13 07:41:06 +00:00
|
|
|
"path/filepath"
|
|
|
|
|
2024-03-15 11:08:19 +00:00
|
|
|
"github.com/pkg/errors"
|
2024-02-15 05:46:47 +00:00
|
|
|
"github.com/prysmaticlabs/prysm/v5/cmd"
|
|
|
|
"github.com/prysmaticlabs/prysm/v5/config/params"
|
2021-04-13 07:41:06 +00:00
|
|
|
"github.com/urfave/cli/v2"
|
|
|
|
"gopkg.in/yaml.v2"
|
|
|
|
)
|
|
|
|
|
|
|
|
// P2PPreregistration prepares data for p2p.Service's registration.
|
|
|
|
func P2PPreregistration(cliCtx *cli.Context) (bootstrapNodeAddrs []string, dataDir string, err error) {
|
|
|
|
// Bootnode ENR may be a filepath to a YAML file
|
|
|
|
bootnodesTemp := params.BeaconNetworkConfig().BootstrapNodes // actual CLI values
|
|
|
|
bootstrapNodeAddrs = make([]string, 0) // dest of final list of nodes
|
|
|
|
for _, addr := range bootnodesTemp {
|
|
|
|
if filepath.Ext(addr) == ".yaml" {
|
|
|
|
fileNodes, err := readbootNodes(addr)
|
|
|
|
if err != nil {
|
|
|
|
return nil, "", err
|
|
|
|
}
|
|
|
|
bootstrapNodeAddrs = append(bootstrapNodeAddrs, fileNodes...)
|
|
|
|
} else {
|
|
|
|
bootstrapNodeAddrs = append(bootstrapNodeAddrs, addr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dataDir = cliCtx.String(cmd.DataDirFlag.Name)
|
|
|
|
if dataDir == "" {
|
|
|
|
dataDir = cmd.DefaultDataDir()
|
|
|
|
if dataDir == "" {
|
2024-03-15 11:08:19 +00:00
|
|
|
err = errors.Errorf(
|
|
|
|
"Could not determine your system's HOME path, please specify a --%s you wish to use for your chain data",
|
|
|
|
cmd.DataDirFlag.Name,
|
2021-04-13 07:41:06 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
func readbootNodes(fileName string) ([]string, error) {
|
2022-04-18 20:42:07 +00:00
|
|
|
fileContent, err := os.ReadFile(fileName) // #nosec G304
|
2021-04-13 07:41:06 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
listNodes := make([]string, 0)
|
2021-08-01 03:26:24 +00:00
|
|
|
err = yaml.UnmarshalStrict(fileContent, &listNodes)
|
2021-04-13 07:41:06 +00:00
|
|
|
if err != nil {
|
2021-08-01 03:26:24 +00:00
|
|
|
if _, ok := err.(*yaml.TypeError); !ok {
|
|
|
|
return nil, err
|
|
|
|
} else {
|
|
|
|
log.WithError(err).Error("There were some issues parsing the bootnodes from a yaml file.")
|
|
|
|
}
|
2021-04-13 07:41:06 +00:00
|
|
|
}
|
|
|
|
return listNodes, nil
|
|
|
|
}
|