forked from stellar/stellar-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfig.h
316 lines (251 loc) · 11.3 KB
/
Config.h
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#pragma once
// Copyright 2014 Stellar Development Foundation and contributors. Licensed
// under the Apache License, Version 2.0. See the COPYING file at the root
// of this distribution or at http://www.apache.org/licenses/LICENSE-2.0
#include "crypto/SecretKey.h"
#include "lib/util/cpptoml.h"
#include "overlay/StellarXDR.h"
#include "util/SecretValue.h"
#include "util/Timer.h"
#include "util/optional.h"
#include <map>
#include <memory>
#include <string>
#define DEFAULT_PEER_PORT 11625
namespace stellar
{
struct HistoryArchiveConfiguration
{
std::string mName;
std::string mGetCmd;
std::string mPutCmd;
std::string mMkdirCmd;
};
class Config : public std::enable_shared_from_this<Config>
{
enum class ValidatorQuality : int
{
VALIDATOR_LOW_QUALITY = 0,
VALIDATOR_MED_QUALITY = 1,
VALIDATOR_HIGH_QUALITY = 2
};
struct ValidatorEntry
{
std::string mName;
std::string mHomeDomain;
ValidatorQuality mQuality;
PublicKey mKey;
bool mHasHistory;
};
void validateConfig(bool mixed);
void loadQset(std::shared_ptr<cpptoml::table> group, SCPQuorumSet& qset,
int level);
void processConfig(std::shared_ptr<cpptoml::table>);
void parseNodeID(std::string configStr, PublicKey& retKey);
void parseNodeID(std::string configStr, PublicKey& retKey, SecretKey& sKey,
bool isSeed);
std::string expandNodeID(std::string const& s) const;
void addValidatorName(std::string const& pubKeyStr,
std::string const& name);
void addHistoryArchive(std::string const& name, std::string const& get,
std::string const& put, std::string const& mkdir);
std::string toString(ValidatorQuality q) const;
ValidatorQuality parseQuality(std::string const& q) const;
std::vector<ValidatorEntry>
parseValidators(std::shared_ptr<cpptoml::base> validators,
std::unordered_map<std::string, ValidatorQuality> const&
domainQualityMap);
std::unordered_map<std::string, ValidatorQuality>
parseDomainsQuality(std::shared_ptr<cpptoml::base> domainsQuality);
static SCPQuorumSet
generateQuorumSetHelper(std::vector<ValidatorEntry>::const_iterator begin,
std::vector<ValidatorEntry>::const_iterator end,
ValidatorQuality curQuality);
static SCPQuorumSet
generateQuorumSet(std::vector<ValidatorEntry> const& validators);
void
addSelfToValidators(std::vector<ValidatorEntry>& validators,
std::unordered_map<std::string, ValidatorQuality> const&
domainQualityMap);
void verifyHistoryValidatorsBlocking(
std::vector<ValidatorEntry> const& validators);
public:
static const uint32 CURRENT_LEDGER_PROTOCOL_VERSION;
typedef std::shared_ptr<Config> pointer;
enum TestDbMode
{
TESTDB_DEFAULT,
TESTDB_IN_MEMORY_SQLITE,
TESTDB_ON_DISK_SQLITE,
#ifdef USE_POSTGRES
TESTDB_POSTGRESQL,
#endif
TESTDB_MODES
};
// application config
// The default way stellar-core starts is to load the state from disk and
// catch
// up to the network before starting SCP.
// If you need different behavior you need to use --newdb or --force-scp
// which sets the following flags:
// SCP will start running immediately using the current local state to
// participate in consensus. DO NOT INCLUDE THIS IN A CONFIG FILE
bool FORCE_SCP;
// This is a mode for testing. It prevents you from trying to connect to
// other peers
bool RUN_STANDALONE;
// Mode for testing. Ledger will only close when told to over http
bool MANUAL_CLOSE;
// Whether to catchup "completely" (replaying all history); default is
// false,
// meaning catchup "minimally", using deltas to the most recent snapshot.
bool CATCHUP_COMPLETE;
// Number of "recent" ledgers before the current ledger to include in a
// "minimal" catchup. Default is 0, and if CATCHUP_COMPLETE is set to
// true, this is ignored.
//
// If you want, say, a week of history, set this to 120000.
uint32_t CATCHUP_RECENT;
// Interval between automatic maintenance executions
std::chrono::seconds AUTOMATIC_MAINTENANCE_PERIOD;
// Number of unneeded rows in each table that will be removed during one
// maintenance run
uint32_t AUTOMATIC_MAINTENANCE_COUNT;
// A config parameter that enables synthetic load generation on demand,
// using the `generateload` runtime command (see CommandHandler.cpp). This
// option only exists for stress-testing and should not be enabled in
// production networks.
bool ARTIFICIALLY_GENERATE_LOAD_FOR_TESTING;
// A config parameter that reduces ledger close time to 1s and checkpoint
// frequency to every 8 ledgers. Do not ever set this in production, as it
// will make your history archives incompatible with those of anyone else.
bool ARTIFICIALLY_ACCELERATE_TIME_FOR_TESTING;
// A config parameter to override the close time (in seconds). Do not use
// in production as it may render the network unstable.
uint32 ARTIFICIALLY_SET_CLOSE_TIME_FOR_TESTING;
// A config parameter that avoids resolving FutureBuckets before writing
// them to the database's persistent state; this option exists only
// for stress-testing the ability to resume from an interrupted merge,
// and should be false in all normal cases.
bool ARTIFICIALLY_PESSIMIZE_MERGES_FOR_TESTING;
// A config parameter that avoids counting level 0 merge events and those
// within Bucket::fresh; this option exists only for calculating adjustments
// to the expected count of merges when stopping and resuming merges,
// and should be false in all normal cases.
bool ARTIFICIALLY_REDUCE_MERGE_COUNTS_FOR_TESTING;
// A config to allow connections to localhost
// this should only be enabled when testing as it's a security issue
bool ALLOW_LOCALHOST_FOR_TESTING;
// Set to use config file values for genesis ledger
// not setable in config file - only tests are allowed to do this
bool USE_CONFIG_FOR_GENESIS;
// This is the number of failures you want to be able to tolerate.
// You will need at least 3f+1 nodes in your quorum set.
// If you don't have enough in your quorum set to tolerate the level you
// set here stellar-core won't run.
int32_t FAILURE_SAFETY;
// If set to true allows you to specify an unsafe quorum set.
// Otherwise it won't start if you have your threshold % set too low.
// You might want to set this if you are running your own network and
// aren't concerned with byzantine failures.
bool UNSAFE_QUORUM;
// If set to true, bucket GC will not be performed. It can lead to massive
// disk usage, but it is useful for recovering of nodes.
bool DISABLE_BUCKET_GC;
// Set of cursors added at each startup with value '1'.
std::vector<std::string> KNOWN_CURSORS;
uint32_t LEDGER_PROTOCOL_VERSION;
VirtualClock::time_point TESTING_UPGRADE_DATETIME;
// maximum allowed drift for close time when joining the network for the
// first time
uint64 MAXIMUM_LEDGER_CLOSETIME_DRIFT;
// note: all versions in the range
// [OVERLAY_PROTOCOL_MIN_VERSION, OVERLAY_PROTOCOL_VERSION] must be handled
uint32_t OVERLAY_PROTOCOL_MIN_VERSION; // min overlay version understood
uint32_t OVERLAY_PROTOCOL_VERSION; // max overlay version understood
std::string VERSION_STR;
std::string LOG_FILE_PATH;
std::string BUCKET_DIR_PATH;
uint32_t TESTING_UPGRADE_DESIRED_FEE; // in stroops
uint32_t TESTING_UPGRADE_RESERVE; // in stroops
uint32_t TESTING_UPGRADE_MAX_TX_SET_SIZE;
unsigned short HTTP_PORT; // what port to listen for commands
bool PUBLIC_HTTP_PORT; // if you accept commands from not localhost
int HTTP_MAX_CLIENT; // maximum number of http clients, i.e backlog
std::string NETWORK_PASSPHRASE; // identifier for the network
// overlay config
unsigned short PEER_PORT;
unsigned short TARGET_PEER_CONNECTIONS;
unsigned short MAX_PENDING_CONNECTIONS;
int MAX_ADDITIONAL_PEER_CONNECTIONS;
unsigned short MAX_INBOUND_PENDING_CONNECTIONS;
unsigned short MAX_OUTBOUND_PENDING_CONNECTIONS;
unsigned short PEER_AUTHENTICATION_TIMEOUT;
unsigned short PEER_TIMEOUT;
unsigned short PEER_STRAGGLER_TIMEOUT;
static constexpr auto const POSSIBLY_PREFERRED_EXTRA = 2;
static constexpr auto const REALLY_DEAD_NUM_FAILURES_CUTOFF = 120;
// Peers we will always try to stay connected to
std::vector<std::string> PREFERRED_PEERS;
std::vector<std::string> KNOWN_PEERS;
// Preference can also be expressed by peer pubkey
std::vector<std::string> PREFERRED_PEER_KEYS;
// Whether to exclude peers that are not preferred.
bool PREFERRED_PEERS_ONLY;
// Percentage, between 0 and 100, of system activity (measured in terms
// of both event-loop cycles and database time) below-which the system
// will consider itself "loaded" and attempt to shed load. Set this
// number low and the system will be tolerant of overloading. Set it
// high and the system will be intolerant. By default it is 0, meaning
// totally insensitive to overloading.
uint32_t MINIMUM_IDLE_PERCENT;
// thread-management config
int WORKER_THREADS;
// process-management config
int MAX_CONCURRENT_SUBPROCESSES;
// SCP config
SecretKey NODE_SEED;
bool NODE_IS_VALIDATOR;
stellar::SCPQuorumSet QUORUM_SET;
// this node's home domain
std::string NODE_HOME_DOMAIN;
// Whether to run online quorum intersection checks.
bool QUORUM_INTERSECTION_CHECKER;
// Invariants
std::vector<std::string> INVARIANT_CHECKS;
std::map<std::string, std::string> VALIDATOR_NAMES;
// History config
std::map<std::string, HistoryArchiveConfiguration> HISTORY;
// Database config
SecretValue DATABASE;
std::vector<std::string> COMMANDS;
std::vector<std::string> REPORT_METRICS;
// Data layer cache configuration
// - ENTRY_CACHE_SIZE controls the maximum number of LedgerEntry objects
// that will be stored in the cache
// - BEST_OFFERS_CACHE_SIZE controls the maximum number of Asset pairs that
// will be stored in the cache, although many LedgerEntry objects may be
// associated with a single Asset pair
size_t ENTRY_CACHE_SIZE;
size_t BEST_OFFERS_CACHE_SIZE;
// Data layer prefetcher configuration
// - PREFETCH_BATCH_SIZE determines how many records we'll prefetch per
// SQL load. Note that it should be significantly smaller than size of
// the entry cache
size_t PREFETCH_BATCH_SIZE;
Config();
void load(std::string const& filename);
void load(std::istream& in);
// fixes values of connection-relates settings
void adjust();
std::string toShortString(PublicKey const& pk) const;
std::string toStrKey(PublicKey const& pk, bool& isAlias) const;
std::string toStrKey(PublicKey const& pk) const;
bool resolveNodeID(std::string const& s, PublicKey& retKey) const;
std::chrono::seconds getExpectedLedgerCloseTime() const;
void logBasicInfo();
void setNoListen();
// function to stringify a quorum set
std::string toString(SCPQuorumSet const& qset);
};
}