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 bootstrap.json and load in config on build #964

Merged
merged 5 commits into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
26 changes: 26 additions & 0 deletions config/bootstrap.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
{
"name": "Pactus",
"email": "[email protected]",
"website": "https://pactus.org",
"address": "/dns/bootstrap1.pactus.org/tcp/21888/p2p/12D3KooWMnDsu8TDTk2VV8uD8zsNSB6eUkqtQs6ttg4bHq9zNaBe"
},
{
"name": "Pactus",
"email": "[email protected]",
"website": "https://pactus.org",
"address": "/dns/bootstrap2.pactus.org/tcp/21888/p2p/12D3KooWM39ag7ghta49qybf7McADgT8FLakTYkCsiBvwdnjuG5q"
},
{
"name": "Pactus",
"email": "[email protected]",
"website": "https://pactus.org",
"address": "/dns/bootstrap3.pactus.org/tcp/21888/p2p/12D3KooWBCPSZWheet6tMoHbVBCDfBwQm4yzCwcQ8hJ6NMCN97sj"
},
{
"name": "Pactus",
"email": "[email protected]",
"website": "https://pactus.org",
"address": "/dns/bootstrap4.pactus.org/tcp/21888/p2p/12D3KooWKg6aLa77yAaqMCb45aH5iQuTr5GzRUWUCJ1sZYB5vnoL"
}
]
29 changes: 22 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package config
import (
"bytes"
_ "embed"
"encoding/json"
"os"

"github.com/pactus-project/pactus/consensus"
Expand All @@ -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
Ja7ad marked this conversation as resolved.
Show resolved Hide resolved
)

type Config struct {
Node *NodeConfig `toml:"node"`
Expand All @@ -36,6 +42,13 @@ type Config struct {
Nanomsg *nanomsg.Config `toml:"nanomsg"`
}

type Bootstrap struct {
Ja7ad marked this conversation as resolved.
Show resolved Hide resolved
Name string `json:"name"`
Email string `json:"email"`
Website string `json:"website"`
Address string `json:"address"`
}

type NodeConfig struct {
RewardAddresses []string `toml:"reward_addresses"`
}
Expand Down Expand Up @@ -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 {
Ja7ad marked this conversation as resolved.
Show resolved Hide resolved
Ja7ad marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down
Loading