@@ -4,16 +4,19 @@ import (
44 "bufio"
55 "errors"
66 "fmt"
7- carmen "github.com/Fantom-foundation/Carmen/go/state"
8- "github.com/Fantom-foundation/go-opera/config/flags"
9- "github.com/Fantom-foundation/go-opera/gossip/evmstore"
10- "github.com/ethereum/go-ethereum/common/fdlimit"
7+ "net"
118 "os"
129 "path"
1310 "path/filepath"
1411 "reflect"
12+ "regexp"
1513 "strings"
1614
15+ carmen "github.com/Fantom-foundation/Carmen/go/state"
16+ "github.com/Fantom-foundation/go-opera/config/flags"
17+ "github.com/Fantom-foundation/go-opera/gossip/evmstore"
18+ "github.com/ethereum/go-ethereum/common/fdlimit"
19+
1720 "github.com/Fantom-foundation/lachesis-base/abft"
1821 "github.com/Fantom-foundation/lachesis-base/utils/cachescale"
1922 "github.com/ethereum/go-ethereum/common"
@@ -103,18 +106,61 @@ func loadAllConfigs(file string, cfg *Config) error {
103106func setBootnodes(ctx *cli.Context, urls []string, cfg *node.Config) {
104107 cfg.P2P.BootstrapNodesV5 = []*enode.Node{}
105108 for _, url := range urls {
106- if url != "" {
107- node, err := enode.Parse(enode.ValidSchemes, url)
108- if err != nil {
109- log.Error("Bootstrap URL invalid", "enode", url, "err", err)
110- continue
111- }
112- cfg.P2P.BootstrapNodesV5 = append(cfg.P2P.BootstrapNodesV5, node)
109+ if url == "" {
110+ continue
111+ }
112+
113+ _, modified, err := resolveHostNameInEnodeURL(url)
114+ if err != nil {
115+ log.Error("Failed to resolve hostname Bootnode", "url", url, "err", err)
116+ continue
113117 }
118+
119+ bootNode, err := enode.Parse(enode.ValidSchemes, modified)
120+ if err != nil {
121+ log.Error("Bootstrap URL invalid", "enode", modified, "err", err)
122+ continue
123+ }
124+ cfg.P2P.BootstrapNodesV5 = append(cfg.P2P.BootstrapNodesV5, bootNode)
114125 }
115126 cfg.P2P.BootstrapNodes = cfg.P2P.BootstrapNodesV5
116127}
117128
129+ func resolveHostNameInEnodeURL(url string) (hostname string, modified string, err error) {
130+ return resolveHostNameInEnodeURLInternal(url, func(hostname string) (string, error) {
131+ ips, err := net.LookupIP(hostname)
132+ if err != nil {
133+ return "", err
134+ }
135+ if len(ips) == 0 {
136+ return "", fmt.Errorf("no IPs found for hostname %v", hostname)
137+ }
138+ return ips[0].String(), nil
139+ })
140+ }
141+
142+ var _enodeHostnameRE = regexp.MustCompile(`enode:\/\/[0-9a-f]+@([^:]+):[0-9]+`)
143+
144+ func resolveHostNameInEnodeURLInternal(
145+ url string,
146+ resolve func(string) (string, error),
147+ ) (
148+ hostname string,
149+ modified string,
150+ err error,
151+ ) {
152+ match := _enodeHostnameRE.FindStringSubmatch(url)
153+ if len(match) != 2 {
154+ return "", "", fmt.Errorf("failed to match enode URL")
155+ }
156+ hostname = match[1]
157+ ip, err := resolve(hostname)
158+ if err != nil {
159+ return "", "", fmt.Errorf("failed to resolve hostname %v: %v", hostname, err)
160+ }
161+ return hostname, strings.Replace(url, hostname, ip, 1), nil
162+ }
163+
118164func setTxPool(ctx *cli.Context, cfg *evmcore.TxPoolConfig) error {
119165 if ctx.GlobalIsSet(flags.TxPoolLocalsFlag.Name) {
120166 locals := strings.Split(ctx.GlobalString(flags.TxPoolLocalsFlag.Name), ",")
@@ -187,7 +233,7 @@ func gossipConfigWithFlags(ctx *cli.Context, src gossip.Config) gossip.Config {
187233 return cfg
188234}
189235
190- func setEvmStore(ctx *cli.Context, datadir string, src evmstore.StoreConfig) (evmstore.StoreConfig, error) {
236+ func setEvmStore(ctx *cli.Context, datadir string, src evmstore.StoreConfig) (evmstore.StoreConfig, error) {
191237 cfg := src
192238 cfg.StateDb.Directory = filepath.Join(datadir, "carmen")
193239
0 commit comments