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

[HOTFIX] fix boot node instability issue, refactor p2p host configurations and add new features #4674

Merged
merged 6 commits into from
May 24, 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
13 changes: 13 additions & 0 deletions cmd/bootnode/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"fmt"
"os"
"path"
"time"

"github.com/ethereum/go-ethereum/log"
net "github.com/libp2p/go-libp2p/core/network"
Expand Down Expand Up @@ -90,6 +91,9 @@ func printVersion(me string) {
}

func main() {
timestamp := time.Now().Format("20060102150405")
defUserAgent := fmt.Sprintf("bootnode-%s", timestamp)

ip := flag.String("ip", "127.0.0.1", "IP of the node")
port := flag.String("port", "9876", "port of the node.")
console := flag.Bool("console_only", false, "Output to console only")
Expand All @@ -103,6 +107,9 @@ func main() {
logConn := flag.Bool("log_conn", false, "log incoming/outgoing connections")
maxConnPerIP := flag.Int("max_conn_per_ip", 10, "max connections number for same ip")
forceReachabilityPublic := flag.Bool("force_public", false, "forcing the local node to believe it is reachable externally")
noTransportSecurity := flag.Bool("no_transport_security", true, "disable TLS encrypted transport")
userAgent := flag.String("user_agent", defUserAgent, "explicitly set the user-agent, so we can differentiate from other Go libp2p users")
noRelay := flag.Bool("no_relay", true, "no relay services, direct connections between peers only")

flag.Parse()

Expand Down Expand Up @@ -133,6 +140,12 @@ func main() {
DataStoreFile: &dataStorePath,
MaxConnPerIP: *maxConnPerIP,
ForceReachabilityPublic: *forceReachabilityPublic,
NoTransportSecurity: *noTransportSecurity,
NAT: true,
UserAgent: *userAgent,
DialTimeout: time.Minute,
MuxerType: p2p.Mplex,
NoRelay: *noRelay,
})
if err != nil {
utils.FatalErrMsg(err, "cannot initialize network")
Expand Down
23 changes: 23 additions & 0 deletions cmd/harmony/config_migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,29 @@ func init() {
return confTree
}

migrations["2.6.1"] = func(confTree *toml.Tree) *toml.Tree {
if confTree.Get("P2P.NoTransportSecurity") == nil {
confTree.Set("P2P.NoTransportSecurity", defaultConfig.P2P.NoTransportSecurity)
}
if confTree.Get("P2P.NAT") == nil {
confTree.Set("P2P.NAT", defaultConfig.P2P.NAT)
}
if confTree.Get("P2P.UserAgent") == nil {
confTree.Set("P2P.UserAgent", defaultConfig.P2P.UserAgent)
}
if confTree.Get("P2P.DialTimeout") == nil {
confTree.Set("P2P.DialTimeout", defaultConfig.P2P.DialTimeout)
}
if confTree.Get("P2P.MuxerType") == nil {
confTree.Set("P2P.MuxerType", defaultConfig.P2P.MuxerType)
}
if confTree.Get("P2P.NoRelay") == nil {
confTree.Set("P2P.NoRelay", defaultConfig.P2P.NoRelay)
}
confTree.Set("Version", "2.6.2")
return confTree
}

// check that the latest version here is the same as in default.go
largestKey := getNextVersion(migrations)
if largestKey != tomlConfigVersion {
Expand Down
8 changes: 7 additions & 1 deletion cmd/harmony/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
nodeconfig "github.com/harmony-one/harmony/internal/configs/node"
)

const tomlConfigVersion = "2.6.1"
const tomlConfigVersion = "2.6.2"

const (
defNetworkType = nodeconfig.Mainnet
Expand Down Expand Up @@ -39,6 +39,12 @@ var defaultConfig = harmonyconfig.HarmonyConfig{
ConnManagerLowWatermark: nodeconfig.DefaultConnManagerLowWatermark,
ConnManagerHighWatermark: nodeconfig.DefaultConnManagerHighWatermark,
WaitForEachPeerToConnect: nodeconfig.DefaultWaitForEachPeerToConnect,
NoTransportSecurity: nodeconfig.DefaultNoTransportSecurity,
NAT: nodeconfig.DefaultNAT,
UserAgent: nodeconfig.DefaultUserAgent,
DialTimeout: nodeconfig.DefaultDialTimeout,
MuxerType: nodeconfig.DefaultMuxerType,
NoRelay: nodeconfig.DefaultNoRelay,
},
HTTP: harmonyconfig.HttpConfig{
Enabled: true,
Expand Down
50 changes: 50 additions & 0 deletions cmd/harmony/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ var (
maxPeersFlag,
connManagerLowWatermarkFlag,
connManagerHighWatermarkFlag,
noTransportSecurityFlag,
natFlag,
userAgentFlag,
muxerTypeFlag,
noRelayFlag,
}

httpFlags = []cli.Flag{
Expand Down Expand Up @@ -637,6 +642,31 @@ var (
Usage: "node waits for each single peer to connect and it doesn't add them to peers list after timeout",
DefValue: defaultConfig.P2P.WaitForEachPeerToConnect,
}
noTransportSecurityFlag = cli.BoolFlag{
Name: "p2p.no-transport-security",
Usage: "disable TLS encrypted transport",
DefValue: defaultConfig.P2P.NoTransportSecurity,
}
natFlag = cli.BoolFlag{
Name: "p2p.nat",
Usage: "enable NAT Manager. it takes care of setting NAT port mappings, and discovering external addresses",
DefValue: defaultConfig.P2P.NAT,
}
userAgentFlag = cli.StringFlag{
Name: "p2p.user-agent",
Usage: "explicitly set the user-agent, so we can differentiate from other Go libp2p users",
DefValue: defaultConfig.P2P.UserAgent,
}
muxerTypeFlag = cli.IntFlag{
Name: "p2p.muxer",
Usage: "protocol muxer to mux per-protocol streams (0:Mplex, 1:Yamux, default:0)",
DefValue: defaultConfig.P2P.MuxerType,
}
noRelayFlag = cli.BoolFlag{
Name: "p2p.no-relay",
Usage: "no relay services, direct connections between peers only",
DefValue: defaultConfig.P2P.NoRelay,
}
)

func applyP2PFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
Expand Down Expand Up @@ -688,6 +718,26 @@ func applyP2PFlags(cmd *cobra.Command, config *harmonyconfig.HarmonyConfig) {
if cli.IsFlagChanged(cmd, p2pDisablePrivateIPScanFlag) {
config.P2P.DisablePrivateIPScan = cli.GetBoolFlagValue(cmd, p2pDisablePrivateIPScanFlag)
}

if cli.IsFlagChanged(cmd, noTransportSecurityFlag) {
config.P2P.NoTransportSecurity = cli.GetBoolFlagValue(cmd, noTransportSecurityFlag)
}

if cli.IsFlagChanged(cmd, natFlag) {
config.P2P.NAT = cli.GetBoolFlagValue(cmd, natFlag)
}

if cli.IsFlagChanged(cmd, userAgentFlag) {
config.P2P.UserAgent = cli.GetStringFlagValue(cmd, userAgentFlag)
}

if cli.IsFlagChanged(cmd, muxerTypeFlag) {
config.P2P.MuxerType = cli.GetIntFlagValue(cmd, muxerTypeFlag)
}

if cli.IsFlagChanged(cmd, noRelayFlag) {
config.P2P.NoRelay = cli.GetBoolFlagValue(cmd, noRelayFlag)
}
}

// http flags
Expand Down
174 changes: 174 additions & 0 deletions cmd/harmony/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ func TestHarmonyFlags(t *testing.T) {
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
HTTP: harmonyconfig.HttpConfig{
Enabled: true,
Expand Down Expand Up @@ -410,6 +416,12 @@ func TestP2PFlags(t *testing.T) {
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
Expand All @@ -424,6 +436,12 @@ func TestP2PFlags(t *testing.T) {
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
Expand All @@ -439,6 +457,12 @@ func TestP2PFlags(t *testing.T) {
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
Expand All @@ -454,6 +478,12 @@ func TestP2PFlags(t *testing.T) {
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
Expand All @@ -469,6 +499,12 @@ func TestP2PFlags(t *testing.T) {
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
Expand All @@ -484,6 +520,12 @@ func TestP2PFlags(t *testing.T) {
ConnManagerLowWatermark: 100,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
Expand All @@ -499,6 +541,138 @@ func TestP2PFlags(t *testing.T) {
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: 400,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
args: []string{"--p2p.connmgr-high", "400"},
expConfig: harmonyconfig.P2pConfig{
Port: nodeconfig.DefaultP2PPort,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./.hmykey",
DiscConcurrency: nodeconfig.DefaultP2PConcurrency,
MaxConnsPerIP: nodeconfig.DefaultMaxConnPerIP,
DisablePrivateIPScan: defaultConfig.P2P.DisablePrivateIPScan,
MaxPeers: defaultConfig.P2P.MaxPeers,
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: 400,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
args: []string{"--p2p.no-transport-security=false"},
expConfig: harmonyconfig.P2pConfig{
Port: nodeconfig.DefaultP2PPort,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./.hmykey",
DiscConcurrency: nodeconfig.DefaultP2PConcurrency,
MaxConnsPerIP: nodeconfig.DefaultMaxConnPerIP,
DisablePrivateIPScan: defaultConfig.P2P.DisablePrivateIPScan,
MaxPeers: defaultConfig.P2P.MaxPeers,
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: false,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
args: []string{"--p2p.nat=false"},
expConfig: harmonyconfig.P2pConfig{
Port: nodeconfig.DefaultP2PPort,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./.hmykey",
DiscConcurrency: nodeconfig.DefaultP2PConcurrency,
MaxConnsPerIP: nodeconfig.DefaultMaxConnPerIP,
DisablePrivateIPScan: defaultConfig.P2P.DisablePrivateIPScan,
MaxPeers: defaultConfig.P2P.MaxPeers,
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: false,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
args: []string{"--p2p.user-agent", "test1"},
expConfig: harmonyconfig.P2pConfig{
Port: nodeconfig.DefaultP2PPort,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./.hmykey",
DiscConcurrency: nodeconfig.DefaultP2PConcurrency,
MaxConnsPerIP: nodeconfig.DefaultMaxConnPerIP,
DisablePrivateIPScan: defaultConfig.P2P.DisablePrivateIPScan,
MaxPeers: defaultConfig.P2P.MaxPeers,
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: "test1",
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
args: []string{"--p2p.muxer", "1"},
expConfig: harmonyconfig.P2pConfig{
Port: nodeconfig.DefaultP2PPort,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./.hmykey",
DiscConcurrency: nodeconfig.DefaultP2PConcurrency,
MaxConnsPerIP: nodeconfig.DefaultMaxConnPerIP,
DisablePrivateIPScan: defaultConfig.P2P.DisablePrivateIPScan,
MaxPeers: defaultConfig.P2P.MaxPeers,
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: 1,
NoRelay: defaultConfig.P2P.NoRelay,
},
},
{
args: []string{"--p2p.no-relay=false"},
expConfig: harmonyconfig.P2pConfig{
Port: nodeconfig.DefaultP2PPort,
IP: nodeconfig.DefaultPublicListenIP,
KeyFile: "./.hmykey",
DiscConcurrency: nodeconfig.DefaultP2PConcurrency,
MaxConnsPerIP: nodeconfig.DefaultMaxConnPerIP,
DisablePrivateIPScan: defaultConfig.P2P.DisablePrivateIPScan,
MaxPeers: defaultConfig.P2P.MaxPeers,
ConnManagerLowWatermark: defaultConfig.P2P.ConnManagerLowWatermark,
ConnManagerHighWatermark: defaultConfig.P2P.ConnManagerHighWatermark,
WaitForEachPeerToConnect: false,
NoTransportSecurity: defaultConfig.P2P.NoTransportSecurity,
NAT: defaultConfig.P2P.NAT,
UserAgent: defaultConfig.P2P.UserAgent,
DialTimeout: defaultConfig.P2P.DialTimeout,
MuxerType: defaultConfig.P2P.MuxerType,
NoRelay: false,
},
},
}
Expand Down
Loading