forked from ruesandora/celestia-node-TR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.go
60 lines (55 loc) · 1.75 KB
/
default.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package params
import (
"fmt"
"os"
"strings"
)
const (
EnvCustomNetwork = "CELESTIA_CUSTOM"
EnvPrivateGenesis = "CELESTIA_PRIVATE_GENESIS"
)
// defaultNetwork defines a default network for the Celestia Node.
var defaultNetwork = Mamaki
// DefaultNetwork returns the network of the current build.
func DefaultNetwork() Network {
return defaultNetwork
}
func init() {
// check if custom network option set
// format: CELESTIA_CUSTOM=<netID>:<genesisHash>:<bootstrapPeerList>
if custom, ok := os.LookupEnv(EnvCustomNetwork); ok {
fmt.Print("\n\nWARNING: Celestia custom network specified. Only use this option if the node is " +
"freshly created and initialized.\n**DO NOT** run a custom network over an already-existing node " +
"store!\n\n")
// ensure at least custom network is set
params := strings.Split(custom, ":")
if len(params) == 0 {
panic("params: must provide at least <network_ID> to use a custom network")
}
netID := params[0]
defaultNetwork = Network(netID)
networksList[defaultNetwork] = struct{}{}
// check if genesis hash provided and register it if exists
if len(params) == 2 {
genHash := params[1]
genesisList[defaultNetwork] = strings.ToUpper(genHash)
}
// check if bootstrappers were provided and register
if len(params) == 3 {
bootstrappers := params[2]
// validate bootstrappers
bs := strings.Split(bootstrappers, ",")
_, err := parseAddrInfos(bs)
if err != nil {
println(fmt.Sprintf("params: env %s: contains invalid multiaddress", EnvCustomNetwork))
panic(err)
}
bootstrapList[Network(netID)] = bs
}
}
// check if private network option set
if genesis, ok := os.LookupEnv(EnvPrivateGenesis); ok {
defaultNetwork = Private
genesisList[Private] = strings.ToUpper(genesis)
}
}