Skip to content

Commit

Permalink
feat: add bootstrap.json and load in config on build (#964)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ja7ad authored Jan 26, 2024
1 parent 22f935e commit 5bcf11f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
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"
}
]
31 changes: 24 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
bootstrapInfosBytes []byte
)

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

type BootstrapInfo 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"`
}
Expand Down Expand Up @@ -79,12 +92,16 @@ 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([]BootstrapInfo, 0)
if err := json.Unmarshal(bootstrapInfosBytes, &bootstrapNodes); err != nil {
panic(err)
}

for _, node := range bootstrapNodes {
conf.Network.DefaultBootstrapAddrStrings = append(conf.Network.DefaultBootstrapAddrStrings, node.Address)
}

conf.Network.MaxConns = 64
conf.Network.EnableNATService = false
conf.Network.EnableUPnP = false
Expand Down

0 comments on commit 5bcf11f

Please sign in to comment.