8 //"github.com/bytom/types"
12 // Top level options use an anonymous struct
13 BaseConfig `mapstructure:",squash"`
15 // Options for services
16 RPC *RPCConfig `mapstructure:"rpc"`
17 P2P *P2PConfig `mapstructure:"p2p"`
20 func DefaultConfig() *Config {
22 BaseConfig: DefaultBaseConfig(),
23 RPC: DefaultRPCConfig(),
24 P2P: DefaultP2PConfig(),
28 func TestConfig() *Config {
30 BaseConfig: TestBaseConfig(),
36 // Set the RootDir for all Config structs
37 func (cfg *Config) SetRoot(root string) *Config {
38 cfg.BaseConfig.RootDir = root
39 cfg.RPC.RootDir = root
40 cfg.P2P.RootDir = root
44 //-----------------------------------------------------------------------------
47 type BaseConfig struct {
48 // The root directory for all data.
49 // This should be set in viper so it can unmarshal into this struct
50 RootDir string `mapstructure:"home"`
52 // The ID of the chain to join (should be signed with every transaction and vote)
53 ChainID string `mapstructure:"chain_id"`
55 // A JSON file containing the initial validator set and other meta data
56 Genesis string `mapstructure:"genesis_file"`
58 // A JSON file containing the private key to use as a validator in the consensus protocol
59 PrivateKey string `mapstructure:"private_key"`
61 // A custom human readable name for this node
62 Moniker string `mapstructure:"moniker"`
64 // Output level for logging
65 LogLevel string `mapstructure:"log_level"`
67 // TCP or UNIX socket address for the profiling server to listen on
68 ProfListenAddress string `mapstructure:"prof_laddr"`
70 // If this node is many blocks behind the tip of the chain, FastSync
71 // allows them to catchup quickly by downloading blocks in parallel
72 // and verifying their commits
73 FastSync bool `mapstructure:"fast_sync"`
75 FilterPeers bool `mapstructure:"filter_peers"` // false
77 // What indexer to use for transactions
78 TxIndex string `mapstructure:"tx_index"`
80 // Database backend: leveldb | memdb
81 DBBackend string `mapstructure:"db_backend"`
84 DBPath string `mapstructure:"db_dir"`
86 ApiAddress string `mapstructure:"api_addr"`
91 func DefaultBaseConfig() BaseConfig {
93 Genesis: "genesis.json",
95 LogLevel: DefaultPackageLogLevels(),
96 ProfListenAddress: "",
100 DBBackend: "leveldb",
105 func TestBaseConfig() BaseConfig {
106 conf := DefaultBaseConfig()
107 conf.ChainID = "bytom_test"
108 conf.FastSync = false
109 conf.DBBackend = "memdb"
113 func (b BaseConfig) GenesisFile() string {
114 return rootify(b.Genesis, b.RootDir)
117 func (b BaseConfig) DBDir() string {
118 return rootify(b.DBPath, b.RootDir)
121 func DefaultLogLevel() string {
125 func DefaultPackageLogLevels() string {
126 return fmt.Sprintf("state:info,*:%s", DefaultLogLevel())
129 //-----------------------------------------------------------------------------
132 type RPCConfig struct {
133 RootDir string `mapstructure:"home"`
135 // TCP or UNIX socket address for the RPC server to listen on
136 ListenAddress string `mapstructure:"laddr"`
138 // TCP or UNIX socket address for the gRPC server to listen on
139 // NOTE: This server only supports /broadcast_tx_commit
140 GRPCListenAddress string `mapstructure:"grpc_laddr"`
142 // Activate unsafe RPC commands like /dial_seeds and /unsafe_flush_mempool
143 Unsafe bool `mapstructure:"unsafe"`
146 func DefaultRPCConfig() *RPCConfig {
148 ListenAddress: "tcp://0.0.0.0:46657",
149 GRPCListenAddress: "",
154 func TestRPCConfig() *RPCConfig {
155 conf := DefaultRPCConfig()
156 conf.ListenAddress = "tcp://0.0.0.0:36657"
157 conf.GRPCListenAddress = "tcp://0.0.0.0:36658"
162 //-----------------------------------------------------------------------------
165 type P2PConfig struct {
166 RootDir string `mapstructure:"home"`
167 ListenAddress string `mapstructure:"laddr"`
168 Seeds string `mapstructure:"seeds"`
169 SkipUPNP bool `mapstructure:"skip_upnp"`
170 AddrBook string `mapstructure:"addr_book_file"`
171 AddrBookStrict bool `mapstructure:"addr_book_strict"`
172 PexReactor bool `mapstructure:"pex"`
173 MaxNumPeers int `mapstructure:"max_num_peers"`
176 func DefaultP2PConfig() *P2PConfig {
178 ListenAddress: "tcp://0.0.0.0:46656",
179 AddrBook: "addrbook.json",
180 AddrBookStrict: true,
185 func TestP2PConfig() *P2PConfig {
186 conf := DefaultP2PConfig()
187 conf.ListenAddress = "tcp://0.0.0.0:36656"
192 func (p *P2PConfig) AddrBookFile() string {
193 return rootify(p.AddrBook, p.RootDir)
196 //-----------------------------------------------------------------------------
199 // helper function to make config creation independent of root dir
200 func rootify(path, root string) string {
201 if filepath.IsAbs(path) {
204 return filepath.Join(root, path)