/
config.go
266 lines (244 loc) · 10.3 KB
/
config.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package types
import (
"path"
"sync"
"time"
"github.com/tendermint/tendermint/config"
db "github.com/tendermint/tm-db"
)
// TmConfig is the structure that holds the SDK configuration parameters.
// This could be used to initialize certain configuration parameters for the SDK.
type SDKConfig struct {
mtx sync.RWMutex
sealed bool
txEncoder TxEncoder
addressVerifier func([]byte) error
}
type PocketConfig struct {
DataDir string `json:"data_dir"`
GenesisName string `json:"genesis_file"`
ChainsName string `json:"chains_name"`
EvidenceDBName string `json:"evidence_db_name"`
TendermintURI string `json:"tendermint_uri"`
KeybaseName string `json:"keybase_name"`
RPCPort string `json:"rpc_port"`
ClientBlockSyncAllowance int `json:"client_block_sync_allowance"`
ClientSessionSyncAllowance int64 `json:"client_session_sync_allowance"`
MaxEvidenceCacheEntires int `json:"max_evidence_cache_entries"`
MaxSessionCacheEntries int `json:"max_session_cache_entries"`
JSONSortRelayResponses bool `json:"json_sort_relay_responses"`
RemoteCLIURL string `json:"remote_cli_url"`
UserAgent string `json:"user_agent"`
ValidatorCacheSize int64 `json:"validator_cache_size"`
ApplicationCacheSize int64 `json:"application_cache_size"`
RPCTimeout int64 `json:"rpc_timeout"`
PrometheusAddr string `json:"pocket_prometheus_port"`
PrometheusMaxOpenfiles int `json:"prometheus_max_open_files"`
MaxClaimAgeForProofRetry int `json:"max_claim_age_for_proof_retry"`
ProofPrevalidation bool `json:"proof_prevalidation"`
CtxCacheSize int `json:"ctx_cache_size"`
ABCILogging bool `json:"abci_logging"`
RelayErrors bool `json:"show_relay_errors"`
DisableTxEvents bool `json:"disable_tx_events"`
Cache bool `json:"-"`
IavlCacheSize int64 `json:"iavl_cache_size"`
ChainsHotReload bool `json:"chains_hot_reload"`
GenerateTokenOnStart bool `json:"generate_token_on_start"`
LeanPocket bool `json:"lean_pocket"`
LeanPocketUserKeyFileName string `json:"lean_pocket_user_key_file"`
PreventNegativeRewardClaim bool `json:"prevent_negative_reward_claim"`
}
func (c PocketConfig) GetLeanPocketUserKeyFilePath() string {
return path.Join(c.DataDir, c.LeanPocketUserKeyFileName)
}
type Config struct {
TendermintConfig config.Config `json:"tendermint_config"`
PocketConfig PocketConfig `json:"pocket_config"`
}
type AuthToken struct {
Value string
Issued time.Time
}
const (
DefaultDDName = ".pocket"
DefaultKeybaseName = "pocket-keybase"
DefaultPVKName = "priv_val_key.json"
DefaultPVSName = "priv_val_state.json"
DefaultPVKNameLean = "priv_val_key_lean.json"
DefaultPVSNameLean = "priv_val_state_lean.json"
DefaultNKNameLean = "node_key_lean.json"
DefaultNKName = "node_key.json"
DefaultChainsName = "chains.json"
DefaultGenesisName = "genesis.json"
DefaultRPCPort = "8081"
DefaultEvidenceDBName = "pocket_evidence"
DefaultTMURI = "tcp://localhost:26657"
DefaultMaxSessionCacheEntries = 500
DefaultMaxEvidenceCacheEntries = 500
DefaultListenAddr = "tcp://0.0.0.0:"
DefaultClientBlockSyncAllowance = 10
DefaultSessionSyncAllowance = 0 // This config represents a session unit (irrespective of num blocks per session)
DefaultJSONSortRelayResponses = true
DefaultTxIndexer = "kv"
DefaultRPCDisableTransactionEvents = true
DefaultTxIndexTags = "tx.hash,tx.height,message.sender,transfer.recipient"
ConfigDirName = "config"
ConfigFileName = "config.json"
ApplicationDBName = "application"
TransactionIndexerDBName = "txindexer"
PlaceholderHash = "0001"
PlaceholderURL = "http://127.0.0.1:8081"
PlaceholderServiceURL = PlaceholderURL
DefaultRemoteCLIURL = "http://localhost:8081"
DefaultUserAgent = ""
DefaultValidatorCacheSize = 40000
DefaultApplicationCacheSize = DefaultValidatorCacheSize / 4
DefaultPocketPrometheusListenAddr = "8083"
DefaultPrometheusMaxOpenFile = 3
DefaultRPCTimeout = 30000
DefaultMaxClaimProofRetryAge = 32
DefaultProofPrevalidation = false
DefaultCtxCacheSize = 20
DefaultABCILogging = false
DefaultRelayErrors = true
AuthFileName = "auth.json"
DefaultIavlCacheSize = 5000000
DefaultChainHotReload = false
DefaultGenerateTokenOnStart = true
DefaultLeanPocket = false
DefaultLeanPocketUserKeyFileName = "lean_nodes_keys.json"
)
func DefaultConfig(dataDir string) Config {
c := Config{
TendermintConfig: *config.DefaultConfig(),
PocketConfig: PocketConfig{
DataDir: dataDir,
GenesisName: DefaultGenesisName,
ChainsName: DefaultChainsName,
EvidenceDBName: DefaultEvidenceDBName,
TendermintURI: DefaultTMURI,
KeybaseName: DefaultKeybaseName,
RPCPort: DefaultRPCPort,
ClientBlockSyncAllowance: DefaultClientBlockSyncAllowance,
ClientSessionSyncAllowance: DefaultSessionSyncAllowance,
MaxEvidenceCacheEntires: DefaultMaxEvidenceCacheEntries,
MaxSessionCacheEntries: DefaultMaxSessionCacheEntries,
JSONSortRelayResponses: DefaultJSONSortRelayResponses,
RemoteCLIURL: DefaultRemoteCLIURL,
UserAgent: DefaultUserAgent,
ValidatorCacheSize: DefaultValidatorCacheSize,
ApplicationCacheSize: DefaultApplicationCacheSize,
RPCTimeout: DefaultRPCTimeout,
PrometheusAddr: DefaultPocketPrometheusListenAddr,
PrometheusMaxOpenfiles: DefaultPrometheusMaxOpenFile,
MaxClaimAgeForProofRetry: DefaultMaxClaimProofRetryAge,
ProofPrevalidation: DefaultProofPrevalidation,
CtxCacheSize: DefaultCtxCacheSize,
ABCILogging: DefaultABCILogging,
RelayErrors: DefaultRelayErrors,
DisableTxEvents: DefaultRPCDisableTransactionEvents,
IavlCacheSize: DefaultIavlCacheSize,
ChainsHotReload: DefaultChainHotReload,
GenerateTokenOnStart: DefaultGenerateTokenOnStart,
LeanPocket: DefaultLeanPocket,
LeanPocketUserKeyFileName: DefaultLeanPocketUserKeyFileName,
},
}
c.TendermintConfig.LevelDBOptions = config.DefaultLevelDBOpts()
c.TendermintConfig.SetRoot(dataDir)
c.TendermintConfig.NodeKey = DefaultNKName
c.TendermintConfig.PrivValidatorKey = DefaultPVKName
c.TendermintConfig.PrivValidatorState = DefaultPVSName
c.TendermintConfig.P2P.AddrBookStrict = false
c.TendermintConfig.P2P.MaxNumInboundPeers = 28
c.TendermintConfig.P2P.MaxNumOutboundPeers = 7
c.TendermintConfig.LogLevel = "*:info, *:error"
c.TendermintConfig.TxIndex.Indexer = DefaultTxIndexer
c.TendermintConfig.TxIndex.IndexKeys = DefaultTxIndexTags
c.TendermintConfig.DBBackend = string(db.GoLevelDBBackend)
c.TendermintConfig.RPC.GRPCMaxOpenConnections = 2500
c.TendermintConfig.RPC.MaxOpenConnections = 2500
c.TendermintConfig.Mempool.Size = 18000
c.TendermintConfig.Mempool.CacheSize = 18000
c.TendermintConfig.Mempool.MaxTxsBytes = 2147483648
c.TendermintConfig.Mempool.MaxTxBytes = 2097152
c.TendermintConfig.FastSync = &config.FastSyncConfig{
Version: "v1",
}
DefaultPocketConsensusConfig(c.TendermintConfig.Consensus)
c.TendermintConfig.P2P.AllowDuplicateIP = true
return c
}
// Default Consensus Configs
func DefaultPocketConsensusConfig(cconfig *config.ConsensusConfig) {
cconfig.TimeoutPropose = 120000000000
cconfig.TimeoutProposeDelta = 10000000000
cconfig.TimeoutPrevote = 60000000000
cconfig.TimeoutPrevoteDelta = 10000000000
cconfig.TimeoutPrecommit = 60000000000
cconfig.TimeoutPrecommitDelta = 10000000000
cconfig.TimeoutCommit = 780000000000
cconfig.SkipTimeoutCommit = false
cconfig.CreateEmptyBlocks = true
cconfig.CreateEmptyBlocksInterval = 900000000000
cconfig.PeerGossipSleepDuration = 30000000000
cconfig.PeerQueryMaj23SleepDuration = 20000000000
}
func DefaultTestingPocketConfig() Config {
c := DefaultConfig("data")
c.PocketConfig.MaxClaimAgeForProofRetry = 1000
t := config.TestConfig()
t.LevelDBOptions = config.DefaultLevelDBOpts()
return Config{
TendermintConfig: *t,
PocketConfig: c.PocketConfig,
}
}
var (
// Initializing an instance of TmConfig
sdkConfig = &SDKConfig{
sealed: false,
txEncoder: nil,
}
)
// GetConfig returns the config instance for the SDK.
func GetConfig() *SDKConfig {
return sdkConfig
}
func (config *SDKConfig) assertNotSealed() {
config.mtx.Lock()
defer config.mtx.Unlock()
if config.sealed {
panic("TmConfig is sealed")
}
}
// SetTxEncoder builds the TmConfig with TxEncoder used to marshal StdTx to bytes
func (config *SDKConfig) SetTxEncoder(encoder TxEncoder) {
config.assertNotSealed()
config.txEncoder = encoder
}
// SetAddressVerifier builds the TmConfig with the provided function for verifying that Addresses
// have the correct format
func (config *SDKConfig) SetAddressVerifier(addressVerifier func([]byte) error) {
config.assertNotSealed()
config.addressVerifier = addressVerifier
}
// Set the BIP-0044 CoinType code on the config
func (config *SDKConfig) SetCoinType(coinType uint32) {
config.assertNotSealed()
}
// Seal seals the config such that the config state could not be modified further
func (config *SDKConfig) Seal() *SDKConfig {
config.mtx.Lock()
defer config.mtx.Unlock()
config.sealed = true
return config
}
// GetTxEncoder return function to encode transactions
func (config *SDKConfig) GetTxEncoder() TxEncoder {
return config.txEncoder
}
// GetAddressVerifier returns the function to verify that Addresses have the correct format
func (config *SDKConfig) GetAddressVerifier() func([]byte) error {
return config.addressVerifier
}