Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:add default bootnodes #124

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
![AppVeyor Build (with branch)](https://ci.appveyor.com/api/projects/status/github/optimism-java/shisui?branch=portal&svg=true)
[![Discord](https://img.shields.io/badge/discord-join%20chat-blue.svg)](https://discord.gg/HBAgaHCBuY)

Shisui is an [Ethereum portal client](https://github.com/ethereum/portal-network-specs) written in Go language based on [go-ethereum](https://github.com/ethereum/go-ethereum).
Shisui is an [Ethereum portal client](https://github.com/ethereum/portal-network-specs) written in Go language based
on [go-ethereum](https://github.com/ethereum/go-ethereum).
The name is inspired by Uchiha Shisui from the anime Naruto, who is renowned as "Shisui of the Body Flicker".

> **Note:** Shisui is still **under heavy development** and is not yet ready for production use.

## Building the source

For prerequisites and detailed build instructions please read the [Installation Instructions](https://geth.ethereum.org/docs/getting-started/installing-geth).
For prerequisites and detailed build instructions please read
the [Installation Instructions](https://geth.ethereum.org/docs/getting-started/installing-geth).

Building `shisui` requires both a Go (version 1.19 or later) and a C compiler. You can install
them using your favourite package manager. Once the dependencies are installed, run
Expand Down Expand Up @@ -48,14 +50,14 @@ docker run -d -p 8545:8545 -p 9009:9009/udp ghcr.io/optimism-java/shisui:latest
* `--nat` p2p address(default `none`)
* `none`, find local address
* `any` uses the first auto-detected mechanism
* `extip:77.12.33.4` will assume the local machine is reachable on the given IP
* `upnp` uses the Universal Plug and Play protocol
* `pmp` uses NAT-PMP with an auto-detected gateway address
* `pmp:192.168.0.1` uses NAT-PMP with the given gateway address
* `extip:77.12.33.4` will assume the local machine is reachable on the given IP
* `upnp` uses the Universal Plug and Play protocol
* `pmp` uses NAT-PMP with an auto-detected gateway address
* `pmp:192.168.0.1` uses NAT-PMP with the given gateway address
* `--udp.addr` protocol UDP server listening port(default: `9009`)
* `--loglevel` loglevel of portal network, `1` to `5`, from `error` to `trace`(default: `1`)
* `--private.key` private key of p2p node, hex format without `0x` prifix
* `--bootnodes` bootnode of p2p network with ENR format
* `--bootnodes` bootnode of p2p network with ENR format, use `none` to config empty bootnodes
* `--networks` portal sub networks: history, beacon, state

all the options above can be set with envs.
Expand Down
37 changes: 26 additions & 11 deletions cmd/shisui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/ethereum/go-ethereum/p2p/discover/portalwire"
"github.com/ethereum/go-ethereum/p2p/enode"
"github.com/ethereum/go-ethereum/p2p/nat"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/portalnetwork/beacon"
"github.com/ethereum/go-ethereum/portalnetwork/history"
"github.com/ethereum/go-ethereum/portalnetwork/storage"
Expand Down Expand Up @@ -269,17 +270,7 @@ func getPortalConfig(ctx *cli.Context) (*Config, error) {
config.Protocol.NAT = natInterface
}

bootNodes := ctx.StringSlice(utils.PortalBootNodesFlag.Name)
if len(bootNodes) > 0 {
for _, node := range bootNodes {
bootNode := new(enode.Node)
err = bootNode.UnmarshalText([]byte(node))
if err != nil {
return config, err
}
config.Protocol.BootstrapNodes = append(config.Protocol.BootstrapNodes, bootNode)
}
}
setPortalBootstrapNodes(ctx, config)
config.Networks = ctx.StringSlice(utils.PortalNetworksFlag.Name)
return config, nil
}
Expand All @@ -306,3 +297,27 @@ func setPrivateKey(ctx *cli.Context, config *Config) error {
config.PrivateKey = privateKey
return nil
}

// setPortalBootstrapNodes creates a list of bootstrap nodes from the command line
// flags, reverting to pre-configured ones if none have been specified.
func setPortalBootstrapNodes(ctx *cli.Context, config *Config) {
urls := params.PortalBootnodes
if ctx.IsSet(utils.PortalBootNodesFlag.Name) {
flag := ctx.String(utils.PortalBootNodesFlag.Name)
if flag == "none" {
return
}
urls = utils.SplitAndTrim(flag)
}

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
}
config.Protocol.BootstrapNodes = append(config.Protocol.BootstrapNodes, node)
}
}
}
18 changes: 9 additions & 9 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -976,14 +976,14 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.

PortalDataDirFlag = &cli.StringFlag{
Name: "data.dir",
Usage: "data dir of where the data file located",
Usage: "Data dir of where the data file located",
Value: "./",
Category: flags.PortalNetworkCategory,
}

PortalDataCapacityFlag = &cli.Uint64Flag{
Name: "data.capacity",
Usage: "the capacity of the data stored, the unit is MB",
Usage: "The capacity of the data stored, the unit is MB",
Value: 1000 * 10, // 10 GB
Category: flags.PortalNetworkCategory,
}
Expand All @@ -997,40 +997,40 @@ Please note that --` + MetricsHTTPFlag.Name + ` must be set to start the server.

PortalUDPListenAddrFlag = &cli.StringFlag{
Name: "udp.addr",
Usage: "protocol UDP server listening interface",
Usage: "Protocol UDP server listening interface",
Value: "",
Category: flags.PortalNetworkCategory,
}

PortalUDPPortFlag = &cli.IntFlag{
Name: "udp.port",
Usage: "protocol UDP server listening port",
Usage: "Protocol UDP server listening port",
Value: node.DefaultUDPPort,
Category: flags.PortalNetworkCategory,
}

PortalLogLevelFlag = &cli.IntFlag{
Name: "loglevel",
Usage: "loglevel of portal network",
Usage: "Loglevel of portal network",
Value: node.DefaultLoglevel,
Category: flags.PortalNetworkCategory,
}

PortalPrivateKeyFlag = &cli.StringFlag{
Name: "private.key",
Usage: "private key of p2p node, hex format without 0x prifix",
Usage: "Private key of p2p node, hex format without 0x prifix",
Category: flags.PortalNetworkCategory,
}

PortalBootNodesFlag = &cli.StringSliceFlag{
PortalBootNodesFlag = &cli.StringFlag{
Name: "bootnodes",
Usage: "bootnode of p2p network with ENR format for portal hive test",
Usage: "Comma separated enode URLs for P2P discovery bootstrap",
Category: flags.PortalNetworkCategory,
}

PortalNetworksFlag = &cli.StringSliceFlag{
Name: "networks",
Usage: "portal sub networks: history, beacon, state",
Usage: "Portal sub networks: history, beacon, state",
Category: flags.PortalNetworkCategory,
Value: cli.NewStringSlice(portalwire.HistoryNetworkName),
}
Expand Down
17 changes: 17 additions & 0 deletions params/bootnodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,23 @@ var V5Bootnodes = []string{
"enr:-LK4QKWrXTpV9T78hNG6s8AM6IO4XH9kFT91uZtFg1GcsJ6dKovDOr1jtAAFPnS2lvNltkOGA9k29BUN7lFh_sjuc9QBh2F0dG5ldHOIAAAAAAAAAACEZXRoMpC1MD8qAAAAAP__________gmlkgnY0gmlwhANAdd-Jc2VjcDI1NmsxoQLQa6ai7y9PMN5hpLe5HmiJSlYzMuzP7ZhwRiwHvqNXdoN0Y3CCI4yDdWRwgiOM", // 3.64.117.223 | aws-eu-central-1-frankfurt}
}

var PortalBootnodes = []string{
// Trin team's bootnodes
"enr:-Jy4QIs2pCyiKna9YWnAF0zgf7bT0GzlAGoF8MEKFJOExmtofBIqzm71zDvmzRiiLkxaEJcs_Amr7XIhLI74k1rtlXICY5Z0IDAuMS4xLWFscGhhLjEtMTEwZjUwgmlkgnY0gmlwhKEjVaWJc2VjcDI1NmsxoQLSC_nhF1iRwsCw0n3J4jRjqoaRxtKgsEe5a-Dz7y0JloN1ZHCCIyg",
"enr:-Jy4QKSLYMpku9F0Ebk84zhIhwTkmn80UnYvE4Z4sOcLukASIcofrGdXVLAUPVHh8oPCfnEOZm1W1gcAxB9kV2FJywkCY5Z0IDAuMS4xLWFscGhhLjEtMTEwZjUwgmlkgnY0gmlwhJO2oc6Jc2VjcDI1NmsxoQLMSGVlxXL62N3sP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w7qiCGAbHf6LxB-xPQCktyrCEZX-b-7PikMOIKkBg-frHRBkfwhI3XaYo_T-HxBYmOOQGNwThkBBHYDgmlkgnY0gmlwhKRc9_OJc2VjcDI1NmsxoQKHPt5CQ0D66ueTtSUqwGjfhscU_LiwS28QvJ0GgJFd-YN1ZHCCE4k",
"enr:-IS4QDpUz2hQBNt0DECFm8Zy58Hi59PF_7sw780X3qA0vzJEB2IEd5RtVdPUYZUbeg4f0LMradgwpyIhYUeSxz2Tfa8DgmlkgnY0gmlwhKRc9_OJc2VjcDI1NmsxoQJd4NAVKOXfbdxyjSOUJzmA4rjtg43EDeEJu1f8YRhb_4N1ZHCCE4o",
"enr:-IS4QGG6moBhLW1oXz84NaKEHaRcim64qzFn1hAG80yQyVGNLoKqzJe887kEjthr7rJCNlt6vdVMKMNoUC9OCeNK-EMDgmlkgnY0gmlwhKRc9-KJc2VjcDI1NmsxoQLJhXByb3LmxHQaqgLDtIGUmpANXaBbFw3ybZWzGqb9-IN1ZHCCE4k",
"enr:-IS4QA5hpJikeDFf1DD1_Le6_ylgrLGpdwn3SRaneGu9hY2HUI7peHep0f28UUMzbC0PvlWjN8zSfnqMG07WVcCyBhADgmlkgnY0gmlwhKRc9-KJc2VjcDI1NmsxoQJMpHmGj1xSP1O-Mffk_jYIHVcg6tY5_CjmWVg1gJEsPIN1ZHCCE4o",
}

const dnsPrefix = "enrtree://AKA3AM6LPBYEUDMVNU3BSVQJ5AD45Y7YPOHJLEF6W26QOE4VTUDPE@"

// KnownDNSNetwork returns the address of a public DNS-based node list for the given
Expand Down