From 4f1abb92ae48fccc325dfd8272f9c77d53cc6f0a Mon Sep 17 00:00:00 2001 From: Javad Date: Fri, 26 Jan 2024 19:14:03 +0330 Subject: [PATCH 1/5] feat: add bootstrap.json and load in config on build --- config/bootstrap.json | 26 ++++++++++++++++++++++++++ config/config.go | 29 ++++++++++++++++++++++------- 2 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 config/bootstrap.json diff --git a/config/bootstrap.json b/config/bootstrap.json new file mode 100644 index 000000000..65197dc9c --- /dev/null +++ b/config/bootstrap.json @@ -0,0 +1,26 @@ +[ + { + "name": "Pactus", + "email": "info@pactus.org", + "website": "https://pactus.org", + "address": "/dns/bootstrap1.pactus.org/tcp/21888/p2p/12D3KooWMnDsu8TDTk2VV8uD8zsNSB6eUkqtQs6ttg4bHq9zNaBe" + }, + { + "name": "Pactus", + "email": "info@pactus.org", + "website": "https://pactus.org", + "address": "/dns/bootstrap2.pactus.org/tcp/21888/p2p/12D3KooWM39ag7ghta49qybf7McADgT8FLakTYkCsiBvwdnjuG5q" + }, + { + "name": "Pactus", + "email": "info@pactus.org", + "website": "https://pactus.org", + "address": "/dns/bootstrap3.pactus.org/tcp/21888/p2p/12D3KooWBCPSZWheet6tMoHbVBCDfBwQm4yzCwcQ8hJ6NMCN97sj" + }, + { + "name": "Pactus", + "email": "info@pactus.org", + "website": "https://pactus.org", + "address": "/dns/bootstrap4.pactus.org/tcp/21888/p2p/12D3KooWKg6aLa77yAaqMCb45aH5iQuTr5GzRUWUCJ1sZYB5vnoL" + } +] diff --git a/config/config.go b/config/config.go index cdd21a116..57b3aaac7 100644 --- a/config/config.go +++ b/config/config.go @@ -3,6 +3,7 @@ package config import ( "bytes" _ "embed" + "encoding/json" "os" "github.com/pactus-project/pactus/consensus" @@ -20,8 +21,13 @@ import ( "github.com/pelletier/go-toml" ) -//go:embed example_config.toml -var exampleConfigBytes []byte +var ( + //go:embed example_config.toml + exampleConfigBytes []byte + + //go:embed bootstrap.json + bootstrapNodesBytes []byte +) type Config struct { Node *NodeConfig `toml:"node"` @@ -36,6 +42,13 @@ type Config struct { Nanomsg *nanomsg.Config `toml:"nanomsg"` } +type Bootstrap struct { + Name string `json:"name"` + Email string `json:"email"` + Website string `json:"website"` + Address string `json:"address"` +} + type NodeConfig struct { RewardAddresses []string `toml:"reward_addresses"` } @@ -79,12 +92,14 @@ func defaultConfig() *Config { func DefaultConfigMainnet() *Config { conf := defaultConfig() - conf.Network.DefaultBootstrapAddrStrings = []string{ - "/dns/bootstrap1.pactus.org/tcp/21888/p2p/12D3KooWMnDsu8TDTk2VV8uD8zsNSB6eUkqtQs6ttg4bHq9zNaBe", - "/dns/bootstrap2.pactus.org/tcp/21888/p2p/12D3KooWM39ag7ghta49qybf7McADgT8FLakTYkCsiBvwdnjuG5q", - "/dns/bootstrap3.pactus.org/tcp/21888/p2p/12D3KooWBCPSZWheet6tMoHbVBCDfBwQm4yzCwcQ8hJ6NMCN97sj", - "/dns/bootstrap4.pactus.org/tcp/21888/p2p/12D3KooWKg6aLa77yAaqMCb45aH5iQuTr5GzRUWUCJ1sZYB5vnoL", + + bootstrapNodes := make([]Bootstrap, 0) + if err := json.Unmarshal(bootstrapNodesBytes, &bootstrapNodes); err == nil { + for _, node := range bootstrapNodes { + conf.Network.BootstrapAddrStrings = append(conf.Network.BootstrapAddrStrings, node.Address) + } } + conf.Network.MaxConns = 64 conf.Network.EnableNATService = false conf.Network.EnableUPnP = false From 13819f846fd21450f1d27a6ec03d4aae19fdd378 Mon Sep 17 00:00:00 2001 From: Javad Date: Fri, 26 Jan 2024 19:30:51 +0330 Subject: [PATCH 2/5] fix: rename Bootstrap to BootstrapInfo --- config/config.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 57b3aaac7..e9510fc68 100644 --- a/config/config.go +++ b/config/config.go @@ -26,7 +26,7 @@ var ( exampleConfigBytes []byte //go:embed bootstrap.json - bootstrapNodesBytes []byte + bootstrapInfosBytes []byte ) type Config struct { @@ -42,7 +42,7 @@ type Config struct { Nanomsg *nanomsg.Config `toml:"nanomsg"` } -type Bootstrap struct { +type BootstrapInfo struct { Name string `json:"name"` Email string `json:"email"` Website string `json:"website"` @@ -93,8 +93,8 @@ func defaultConfig() *Config { func DefaultConfigMainnet() *Config { conf := defaultConfig() - bootstrapNodes := make([]Bootstrap, 0) - if err := json.Unmarshal(bootstrapNodesBytes, &bootstrapNodes); err == nil { + bootstrapNodes := make([]BootstrapInfo, 0) + if err := json.Unmarshal(bootstrapInfosBytes, &bootstrapNodes); err == nil { for _, node := range bootstrapNodes { conf.Network.BootstrapAddrStrings = append(conf.Network.BootstrapAddrStrings, node.Address) } From ee123161a89ebf582b4b94bb5642db8f78ef93ee Mon Sep 17 00:00:00 2001 From: Javad Date: Fri, 26 Jan 2024 19:35:38 +0330 Subject: [PATCH 3/5] fix: set bootstrap node on DefaultBootstrapAddrStrings --- config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index e9510fc68..947da8ac2 100644 --- a/config/config.go +++ b/config/config.go @@ -96,7 +96,7 @@ func DefaultConfigMainnet() *Config { bootstrapNodes := make([]BootstrapInfo, 0) if err := json.Unmarshal(bootstrapInfosBytes, &bootstrapNodes); err == nil { for _, node := range bootstrapNodes { - conf.Network.BootstrapAddrStrings = append(conf.Network.BootstrapAddrStrings, node.Address) + conf.Network.DefaultBootstrapAddrStrings = append(conf.Network.BootstrapAddrStrings, node.Address) } } From e6060010c0bcfe9c42b67fdf9cf91ec212c1ec50 Mon Sep 17 00:00:00 2001 From: Javad Date: Fri, 26 Jan 2024 19:49:39 +0330 Subject: [PATCH 4/5] fix: add panic for error unmarshal --- config/config.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index 947da8ac2..2be1ed20a 100644 --- a/config/config.go +++ b/config/config.go @@ -94,10 +94,12 @@ func DefaultConfigMainnet() *Config { conf := defaultConfig() bootstrapNodes := make([]BootstrapInfo, 0) - if err := json.Unmarshal(bootstrapInfosBytes, &bootstrapNodes); err == nil { - for _, node := range bootstrapNodes { - conf.Network.DefaultBootstrapAddrStrings = append(conf.Network.BootstrapAddrStrings, node.Address) - } + if err := json.Unmarshal(bootstrapInfosBytes, &bootstrapNodes); err != nil { + panic(err) + } + + for _, node := range bootstrapNodes { + conf.Network.DefaultBootstrapAddrStrings = append(conf.Network.BootstrapAddrStrings, node.Address) } conf.Network.MaxConns = 64 From 3d79d8efc7e1f19a3b9d2d463627825215ab65e2 Mon Sep 17 00:00:00 2001 From: Javad Date: Fri, 26 Jan 2024 19:51:03 +0330 Subject: [PATCH 5/5] fix: change append slice to DefaultBootstrapAddrStrings --- config/config.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 2be1ed20a..546ff9210 100644 --- a/config/config.go +++ b/config/config.go @@ -99,7 +99,7 @@ func DefaultConfigMainnet() *Config { } for _, node := range bootstrapNodes { - conf.Network.DefaultBootstrapAddrStrings = append(conf.Network.BootstrapAddrStrings, node.Address) + conf.Network.DefaultBootstrapAddrStrings = append(conf.Network.DefaultBootstrapAddrStrings, node.Address) } conf.Network.MaxConns = 64