Skip to content

Commit

Permalink
Merge pull request #126 from unicornultrafoundation/fix/bootnodes
Browse files Browse the repository at this point in the history
Fix bootnodes flag unable to read
  • Loading branch information
trinhdn97 authored Dec 5, 2024
2 parents 0dea076 + b8a5024 commit a755d48
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 2 deletions.
1 change: 1 addition & 0 deletions cmd/u2u/launcher/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var (
"main": {
"enode://21dfee41ddd127ebbd68fb14b39945f6e993ad9eb35c57e5e2e17ec1740960400d6d174f6c119fb9940072eec2d468ee5d767752bf9a44900ac8ac6d6de61330@18.143.208.170:5050",
"enode://a1e1999ab32c7ea71b3fb4fd4e2143beadc3f71365e2a5a0e54e15780d28e5a80576a387406d9b60eee7c31289618c6a5ef93bfe295215518cecbf23bc50211e@3.1.11.147:5050",
"enode://89f9063d0ce1eb0780a82f258cc89acae3ad14e744680a7fb5ea8be468835ad388fdce26bb8ee781b11b0f2dcf5bc9f88964a18a5cd138e9ab3d6bbb0489a254@13.215.34.27:5050",
},
"test": {},
}
Expand Down
65 changes: 63 additions & 2 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import (
"github.com/unicornultrafoundation/go-u2u/p2p/enode"
"github.com/unicornultrafoundation/go-u2u/p2p/nat"
"github.com/unicornultrafoundation/go-u2u/p2p/netutil"
"github.com/unicornultrafoundation/go-u2u/params"
)

func init() {
Expand Down Expand Up @@ -702,6 +703,66 @@ func setListenAddress(ctx *cli.Context, cfg *p2p.Config) {
}
}

// setBootstrapNodes creates a list of bootstrap nodes from the command line
// flags, reverting to pre-configured ones if none have been specified.
func setBootstrapNodes(ctx *cli.Context, cfg *p2p.Config) {
urls := params.MainnetBootnodes
switch {
case ctx.GlobalIsSet(BootnodesFlag.Name):
urls = splitAndTrim(ctx.GlobalString(BootnodesFlag.Name))
case cfg.BootstrapNodes != nil:
return // already set, don't apply defaults.
}

cfg.BootstrapNodes = make([]*enode.Node, 0, len(urls))
for _, url := range urls {
if url != "" {
node, err := enode.Parse(enode.ValidSchemes, url)
if err != nil {
log.Crit("Bootstrap URL invalid", "enode", url, "err", err)
continue
}
cfg.BootstrapNodes = append(cfg.BootstrapNodes, node)
}
}
}

// setBootstrapNodesV5 creates a list of bootstrap nodes from the command line
// flags, reverting to pre-configured ones if none have been specified.
func setBootstrapNodesV5(ctx *cli.Context, cfg *p2p.Config) {
urls := params.V5Bootnodes
switch {
case ctx.GlobalIsSet(BootnodesFlag.Name):
urls = splitAndTrim(ctx.GlobalString(BootnodesFlag.Name))
case cfg.BootstrapNodesV5 != nil:
return // already set, don't apply defaults.
}

cfg.BootstrapNodesV5 = make([]*enode.Node, 0, len(urls))
for _, url := range urls {
if url != "" {
node, err := enode.Parse(enode.ValidSchemes, url)
if err != nil {
log.Error("Bootstrap URL invalid", "enode", url, "err", err)
continue
}
cfg.BootstrapNodesV5 = append(cfg.BootstrapNodesV5, node)
}
}
}

// splitAndTrim splits input separated by a comma
// and trims excessive white space from the substrings.
func splitAndTrim(input string) (ret []string) {
l := strings.Split(input, ",")
for _, r := range l {
if r = strings.TrimSpace(r); r != "" {
ret = append(ret, r)
}
}
return ret
}

// setNAT creates a port mapper from command line flags.
func setNAT(ctx *cli.Context, cfg *p2p.Config) {
if ctx.GlobalIsSet(NATFlag.Name) {
Expand Down Expand Up @@ -858,8 +919,8 @@ func SetP2PConfig(ctx *cli.Context, cfg *p2p.Config) {
setNodeKey(ctx, cfg)
setNAT(ctx, cfg)
setListenAddress(ctx, cfg)
// setBootstrapNodes(ctx, cfg)
// setBootstrapNodesV5(ctx, cfg)
setBootstrapNodes(ctx, cfg)
setBootstrapNodesV5(ctx, cfg)

lightClient := ctx.GlobalString(SyncModeFlag.Name) == "light"
lightServer := (ctx.GlobalInt(LightServeFlag.Name) != 0)
Expand Down
15 changes: 15 additions & 0 deletions params/bootnodes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package params

// MainnetBootnodes are the enode URLs of the P2P bootstrap nodes running on
// the main U2U network.
var MainnetBootnodes = []string{
"enode://21dfee41ddd127ebbd68fb14b39945f6e993ad9eb35c57e5e2e17ec1740960400d6d174f6c119fb9940072eec2d468ee5d767752bf9a44900ac8ac6d6de61330@18.143.208.170:5050", // bootnode-1
"enode://a1e1999ab32c7ea71b3fb4fd4e2143beadc3f71365e2a5a0e54e15780d28e5a80576a387406d9b60eee7c31289618c6a5ef93bfe295215518cecbf23bc50211e@3.1.11.147:5050", // bootnode-2
"enode://89f9063d0ce1eb0780a82f258cc89acae3ad14e744680a7fb5ea8be468835ad388fdce26bb8ee781b11b0f2dcf5bc9f88964a18a5cd138e9ab3d6bbb0489a254@13.215.34.27:5050", // bootnode-3
}

var V5Bootnodes = []string{
"enr:-J24QHysbJGPA_BL2-ZJ2un6yASWpSv5HWkXXndRM-gm-X6zGIF4DEYYSdxxAG-QwWi1emB_YlgD11wihDs5M3RkwDMFgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQIh3-5B3dEn671o-xSzmUX26ZOtnrNcV-Xi4X7BdAlgQIRzbmFwwIN0Y3CCE7qDdTJ1x8aE0bui44CDdWRwghO6", // bootnode-1
"enr:-J24QGnMbFIW5e_AQV5Rh0DXP-YahvvLALy7-cXMC5p2QrD3W9SYGNgLf3f4dWYfB4YU9j4qE5L1w0aeODmR5NgO9QMHgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQKh4Zmasyx-pxs_tP1OIUO-rcP3E2XipaDlThV4DSjlqIRzbmFwwIN0Y3CCE7qDdTJ1x8aE0bui44CDdWRwghO6", // bootnode-2
"enr:-J24QCkBwE_32Dot66xbHlJlw9pQwtqN4GOlz0DM7tFcqC3vArNRSK8kmvgZRwfAnQcEuUY_to6bZmJXUuxKvwsu49oEgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQKJ-QY9DOHrB4CoLyWMyJrK460U50RoCn-16ovkaINa04RzbmFwwIN0Y3CCE7qDdTJ1x8aE0bui44CDdWRwghO6", // bootnode-3
}

0 comments on commit a755d48

Please sign in to comment.