12#ifndef OPENCBDC_TX_SRC_COMMON_CONFIG_H_
13#define OPENCBDC_TX_SRC_COMMON_CONFIG_H_
24#include <unordered_map>
25#include <unordered_set>
31 static constexpr const char* random_source{
"/dev/urandom"};
34 static const std::string bech32_hrp =
"usd";
37 static constexpr const char* currency_symbol{
"$"};
44 static constexpr uint64_t maximum_reservation
45 =
static_cast<uint64_t
>(1024 * 1024);
48 static constexpr size_t stxo_cache_depth{1};
49 static constexpr size_t window_size{10000};
50 static constexpr size_t shard_completed_txs_cache_size{10000000};
51 static constexpr size_t batch_size{2000};
52 static constexpr size_t target_block_interval{250};
53 static constexpr int32_t election_timeout_upper_bound{4000};
54 static constexpr int32_t election_timeout_lower_bound{2000};
55 static constexpr int32_t heartbeat{1000};
56 static constexpr int32_t raft_max_batch{100000};
57 static constexpr size_t coordinator_max_threads{75};
58 static constexpr size_t initial_mint_count{20000};
59 static constexpr size_t initial_mint_value{100};
60 static constexpr size_t watchtower_block_cache_size{100};
61 static constexpr size_t watchtower_error_cache_size{1000000};
62 static constexpr size_t input_count{2};
63 static constexpr size_t output_count{2};
64 static constexpr double fixed_tx_rate{1.0};
65 static constexpr size_t attestation_threshold{1};
70 static constexpr auto endpoint_postfix =
"endpoint";
71 static constexpr auto loglevel_postfix =
"loglevel";
72 static constexpr auto raft_endpoint_postfix =
"raft_endpoint";
73 static constexpr auto stxo_cache_key =
"stxo_cache_depth";
74 static constexpr auto shard_count_key =
"shard_count";
75 static constexpr auto shard_prefix =
"shard";
76 static constexpr auto seed_privkey =
"seed_privkey";
77 static constexpr auto seed_value =
"seed_value";
78 static constexpr auto seed_from =
"seed_from";
79 static constexpr auto seed_to =
"seed_to";
80 static constexpr auto atomizer_prefix =
"atomizer";
81 static constexpr auto sentinel_count_key =
"sentinel_count";
82 static constexpr auto sentinel_prefix =
"sentinel";
83 static constexpr auto config_separator =
"_";
84 static constexpr auto db_postfix =
"db";
85 static constexpr auto start_postfix =
"start";
86 static constexpr auto end_postfix =
"end";
87 static constexpr auto atomizer_count_key =
"atomizer_count";
88 static constexpr auto archiver_prefix =
"archiver";
89 static constexpr auto batch_size_key =
"batch_size";
90 static constexpr auto window_size_key =
"window_size";
91 static constexpr auto target_block_interval_key =
"target_block_interval";
92 static constexpr auto election_timeout_upper_key
93 =
"election_timeout_upper";
94 static constexpr auto election_timeout_lower_key
95 =
"election_timeout_lower";
96 static constexpr auto heartbeat_key =
"heartbeat";
97 static constexpr auto snapshot_distance_key =
"snapshot_distance";
98 static constexpr auto raft_batch_size_key =
"raft_max_batch";
99 static constexpr auto input_count_key =
"loadgen_sendtx_input_count";
100 static constexpr auto output_count_key =
"loadgen_sendtx_output_count";
101 static constexpr auto invalid_rate_key =
"loadgen_invalid_tx_rate";
102 static constexpr auto fixed_tx_rate_key =
"loadgen_fixed_tx_rate";
103 static constexpr auto archiver_count_key =
"archiver_count";
104 static constexpr auto watchtower_count_key =
"watchtower_count";
105 static constexpr auto watchtower_prefix =
"watchtower";
106 static constexpr auto watchtower_client_ep_postfix =
"client_endpoint";
107 static constexpr auto watchtower_internal_ep_postfix =
"internal_endpoint";
108 static constexpr auto watchtower_block_cache_size_key
109 =
"watchtower_block_cache_size";
110 static constexpr auto watchtower_error_cache_size_key
111 =
"watchtower_error_cache_size";
112 static constexpr auto two_phase_mode =
"2pc";
113 static constexpr auto count_postfix =
"count";
114 static constexpr auto readonly =
"readonly";
115 static constexpr auto coordinator_prefix =
"coordinator";
116 static constexpr auto coordinator_count_key =
"coordinator_count";
117 static constexpr auto coordinator_max_threads =
"coordinator_max_threads";
118 static constexpr auto initial_mint_count_key =
"initial_mint_count";
119 static constexpr auto initial_mint_value_key =
"initial_mint_value";
120 static constexpr auto loadgen_count_key =
"loadgen_count";
121 static constexpr auto shard_completed_txs_cache_size
122 =
"shard_completed_txs_cache_size";
123 static constexpr auto wait_for_followers_key =
"wait_for_followers";
124 static constexpr auto private_key_postfix =
"private_key";
125 static constexpr auto public_key_postfix =
"public_key";
126 static constexpr auto attestation_threshold_key =
"attestation_threshold";
149 defaults::shard_completed_txs_cache_size};
174 defaults::election_timeout_upper_bound};
177 defaults::election_timeout_lower_bound};
215 std::vector<std::vector<network::endpoint_t>>
219 std::vector<std::vector<network::endpoint_t>>
223 std::vector<std::vector<network::endpoint_t>>
229 std::vector<std::vector<network::endpoint_t>>
244 defaults::watchtower_block_cache_size};
248 defaults::watchtower_error_cache_size};
269 -> std::variant<options, std::string>;
275 -> std::variant<options, std::string>;
282 auto check_options(
const options& opts) -> std::optional<std::string>;
298 -> std::pair<size_t, size_t>;
302 auto get_args(
int argc,
char** argv) -> std::vector<std::string>;
327 explicit parser(
const std::string& filename);
331 explicit parser(std::istream& stream);
337 [[nodiscard]]
auto get_string(
const std::string& key)
const
338 -> std::optional<std::string>;
344 [[nodiscard]]
auto get_ulong(
const std::string& key)
const
345 -> std::optional<size_t>;
351 [[nodiscard]]
auto get_endpoint(
const std::string& key)
const
352 -> std::optional<network::endpoint_t>;
358 [[nodiscard]]
auto get_loglevel(
const std::string& key)
const
359 -> std::optional<logging::log_level>;
365 [[nodiscard]]
auto get_decimal(
const std::string& key)
const
366 -> std::optional<double>;
369 using value_t = std::variant<std::string, size_t, double>;
371 [[nodiscard]]
auto find_or_env(
const std::string& key)
const
372 -> std::optional<value_t>;
375 [[nodiscard]]
auto get_val(
const std::string& key)
const
376 -> std::optional<T> {
377 const auto it = find_or_env(key);
379 const auto* val = std::get_if<T>(&it.value());
388 void init(std::istream& stream);
390 [[nodiscard]]
static auto parse_value(
const std::string& val)
393 std::map<std::string, value_t> m_options;
Reads configuration parameters line-by-line from a file.
auto get_endpoint(const std::string &key) const -> std::optional< network::endpoint_t >
Return the value for the given key if its value is an endpoint.
auto get_string(const std::string &key) const -> std::optional< std::string >
Returns the given key if its value is a string.
auto get_decimal(const std::string &key) const -> std::optional< double >
Return the value for the given key if its value is a double.
auto get_ulong(const std::string &key) const -> std::optional< size_t >
Return the value for the given key if its value is a long.
parser(const std::string &filename)
Constructor.
auto get_loglevel(const std::string &key) const -> std::optional< logging::log_level >
Return the value for the given key if its value is a loglevel.
auto check_options(const options &opts) -> std::optional< std::string >
Checks a fully populated options struct for invariants.
auto load_options(const std::string &config_file) -> std::variant< options, std::string >
Loads options from the given config file and check for invariants.
auto read_options(const std::string &config_file) -> std::variant< options, std::string >
Read options from the given config file without checking invariants.
auto parse_ip_port(const std::string &in_str) -> network::endpoint_t
auto hash_in_shard_range(const shard_range_t &range, const hash_t &val) -> bool
Checks if a hash is in the given range handled.
auto get_args(int argc, char **argv) -> std::vector< std::string >
Converts c-args from an executable's main function into a vector of strings.
auto loadgen_seed_range(const options &opts, size_t gen_id) -> std::pair< size_t, size_t >
Calculates the sub-range of total seeded outputs for a particular load generator ID.
std::pair< uint8_t, uint8_t > shard_range_t
[start, end] inclusive.
@ warn
Potentially unintended, unexpected, or undesirable behavior.
std::pair< ip_address, port_number_t > endpoint_t
[host name, port number].
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
Project-wide configuration options.
size_t m_input_count
Number of inputs in fixed-size transactions from atomizer-cli.
std::vector< network::endpoint_t > m_watchtower_client_endpoints
List of watchtower client endpoints, ordered by watchtower ID.
size_t m_window_size
Maximum number of unconfirmed transactions in atomizer-cli.
std::vector< network::endpoint_t > m_archiver_endpoints
List of archiver endpoints, ordered by archiver ID.
int32_t m_raft_max_batch
Maximum number of raft log entries to batch into one RPC message.
std::vector< network::endpoint_t > m_atomizer_endpoints
List of atomizer endpoints, ordered by atomizer ID.
size_t m_loadgen_count
Number of load generators over which to split pre-seeded UTXOs.
std::vector< std::vector< network::endpoint_t > > m_locking_shard_readonly_endpoints
List of locking shard read-only endpoints, ordered by shard ID then node ID.
std::optional< privkey_t > m_seed_privkey
private key used for initial seed.
size_t m_stxo_cache_depth
Depth of the spent transaction cache in the atomizer, in blocks.
size_t m_seed_to
ending index for faked input used for initial seed.
std::vector< network::endpoint_t > m_shard_endpoints
List of shard endpoints, ordered by shard ID.
size_t m_initial_mint_count
Number of outputs in the initial mint transaction.
std::vector< logging::log_level > m_coordinator_loglevels
List of coordinator log levels, ordered by coordinator ID.
size_t m_coordinator_max_threads
Coordinator thread count limit.
size_t m_shard_completed_txs_cache_size
The number of completed transactions that each locking shard (2PC) keeps in memory for responding to ...
size_t m_batch_size
Maximum transaction batch size for one log entry in the raft atomizer or one batch in the coordinator...
int32_t m_snapshot_distance
Raft snapshot distance, in number of log entries.
double m_fixed_tx_rate
Proportion of fixed transactions sent from atomizer-cli.
std::vector< shard_range_t > m_shard_ranges
List of shard UHS ID ranges by shard ID.
std::vector< network::endpoint_t > m_watchtower_internal_endpoints
List of watchtower internal endpoints, ordered by watchtower ID.
size_t m_attestation_threshold
Number of sentinel attestations needed for a compact transaction.
std::vector< logging::log_level > m_atomizer_loglevels
List of atomizer log levels by atomizer ID.
std::vector< std::string > m_shard_db_dirs
List of shard DB paths by shard ID.
int32_t m_election_timeout_lower
Raft election timeout lower bound in milliseconds.
std::vector< std::vector< network::endpoint_t > > m_coordinator_endpoints
List of coordinator endpoints, ordered by shard ID then node ID.
std::unordered_map< size_t, privkey_t > m_sentinel_private_keys
Private keys for sentinels.
std::vector< std::vector< network::endpoint_t > > m_locking_shard_raft_endpoints
List of locking shard raft endpoints, ordered by shard ID then node ID.
bool m_twophase_mode
Flag set if the architecture is two-phase commit.
size_t m_watchtower_block_cache_size
Number of blocks to store in watchtower block caches.
std::vector< std::vector< network::endpoint_t > > m_locking_shard_endpoints
List of locking shard endpoints, ordered by shard ID then node ID.
std::vector< logging::log_level > m_sentinel_loglevels
List of sentinel log levels by sentinel ID.
std::vector< std::string > m_archiver_db_dirs
List of archiver DB paths by archiver ID.
std::unordered_set< pubkey_t, hashing::null > m_sentinel_public_keys
Public keys for sentinels.
size_t m_seed_value
output value to use for initial seed.
std::vector< std::vector< network::endpoint_t > > m_coordinator_raft_endpoints
List of coordinator raft endpoints, ordered by shard ID then node ID.
size_t m_seed_from
starting index for faked input used for initial seed.
std::vector< logging::log_level > m_archiver_loglevels
List of archiver log levels by archiver ID.
std::vector< logging::log_level > m_shard_loglevels
List of shard log levels by shard ID.
double m_invalid_rate
Proportion of invalid transactions sent from atomizer-cli.
bool m_fixed_tx_mode
Flag set if m_input_count or m_output_count are greater than zero.
size_t m_initial_mint_value
Value for all outputs in the initial mint transaction.
int32_t m_election_timeout_upper
Raft election timeout upper bound in milliseconds.
int32_t m_heartbeat
Raft heartbeat timeout in milliseconds.
size_t m_target_block_interval
Target block creation interval in the atomizer in milliseconds.
size_t m_output_count
Number of outputs in fixed-size transactions from atomizer-cli.
size_t m_watchtower_error_cache_size
Number of errors to store in watchtower error caches.
std::vector< logging::log_level > m_watchtower_loglevels
List of archiver log levels by watchtower ID.
std::vector< network::endpoint_t > m_sentinel_endpoints
List of sentinel endpoints, ordered by sentinel ID.
std::vector< network::endpoint_t > m_atomizer_raft_endpoints
List of atomizer raft endpoints, ordered by atomizer ID.