Skip to content

Commit 896e23a

Browse files
committed
Remove outdated code, add support for seeding
Removes identification of build directory, as sending file to build directory has been replaced by priting config file to stdout. Also adds support for seeding by generating a seed key if necessary. Signed-off-by: Michael Maurer <[email protected]>
1 parent 44ab494 commit 896e23a

File tree

5 files changed

+74
-106
lines changed

5 files changed

+74
-106
lines changed

2pc-compose.cfg

+51-15
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,57 @@
11
2pc=1
2-
sentinel_count=1
3-
sentinel0_endpoint="sentinel0:5555"
4-
sentinel0_loglevel="WARN"
5-
sentinel0_private_key="0000000000000001000000000000000000000000000000000000000000000000"
6-
sentinel0_public_key="eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3"
2+
avg_mint_count=10
3+
avg_mint_value=10
4+
avg_redemption_count=5
5+
avg_redemption_value=5
6+
batch_delay=1
7+
batch_size=100000
78
coordinator_count=1
8-
coordinator0_count=1
9-
coordinator0_loglevel="INFO"
10-
coordinator0_0_endpoint="coordinator0:7777"
11-
coordinator0_0_raft_endpoint="coordinator0:7778"
12-
coordinator_max_threads=100
9+
coordinator_max_threads=1
10+
coordinator_offline_probability=0.01
11+
election_timeout_lower=3000
12+
election_timeout_upper=4000
13+
heartbeat=1000
14+
initial_mint_count=20000
15+
initial_mint_value=100
16+
loadgen_count=1
17+
loadgen_fixed_tx_rate=0.0001
18+
loadgen_invalid_tx_rate=0
19+
loadgen_sendtx_input_count=2
20+
loadgen_sendtx_output_count=2
21+
mint_frequency=0.1
22+
num_minters=1
23+
num_redeemers=1
24+
num_wallets=10
25+
raft_max_batch=100000
26+
randomize_execution=0
27+
redemption_frequency=0.05
28+
seed_from=0
29+
seed_to=1000000
30+
seed_value=1000000
31+
sentinel_count=1
32+
sentinel_offline_probability=0.01
1333
shard_count=1
34+
shard_offline_probability=0.01
35+
snapshot_distance=1000000000
36+
total_number_of_transactions=100
37+
transaction_frequency=5
38+
wait_for_followers=0
39+
sentinel0_endpoint="127.0.0.1:1024"
40+
sentinel0_loglevel="INFO"
41+
sentinel0_private_key="e217d0beb93dc4b10419444add3737df83589e917dfb5d1adbb2f727e7a6ce49"
42+
sentinel0_public_key="e77070c046ad45810dcce93bb9aa56439f15a797531116198382f8d95916de8e"
43+
shard0_db="shard0_db"
44+
shard0_loglevel="INFO"
45+
shard0_count=1
1446
shard0_start=0
1547
shard0_end=255
16-
shard0_count=1
17-
shard0_loglevel="INFO"
18-
shard0_0_endpoint="shard0:6666"
19-
shard0_0_raft_endpoint="shard0:6667"
20-
shard0_0_readonly_endpoint="shard0:6767"
48+
shard0_0_endpoint="127.0.0.1:1025"
49+
shard0_0_raft_endpoint="127.0.0.1:1026"
50+
shard0_0_readonly_endpoint="127.0.0.1:1027"
51+
coordinator0_loglevel="INFO"
52+
coordinator0_count=1
53+
coordinator0_max_threads=1
54+
coordinator0_0_endpoint="127.0.0.1:1028"
55+
coordinator0_0_raft_endpoint="127.0.0.1:1029"
56+
seed_privkey="2e90331d63ea6fdce35ae6463fe9d0ae8b13f5162ee56d1b42a500321cf05cbc"
2157

tests/unit/config_gen_test.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ TEST_F(config_generation_validation_test,
3232
// Assumes build dir is "build". Cannot find a way around this since unit
3333
// tests can be run from either root dir or build dir and we don't
3434
// necessarily know which one
35-
std::string build_dir = "build";
3635
cbdc::generate_config::config_generator new_config_gen(
3736
template_file_atomizer,
38-
port_num,
39-
build_dir);
37+
port_num);
4038
auto cfg_or_err = new_config_gen.generate_configuration_file();
4139
ASSERT_EQ(cfg_or_err, "SUCCESS");
4240
// TODO
@@ -49,10 +47,8 @@ TEST_F(config_generation_validation_test,
4947
// Assumes build dir is "build". Cannot find a way around this since unit
5048
// tests can be run from either root dir or build dir and we don't
5149
// necessarily know which one
52-
std::string build_dir = "build";
5350
cbdc::generate_config::config_generator new_config_gen(template_file_2pc,
54-
port_num,
55-
build_dir);
51+
port_num);
5652
auto cfg_or_err = new_config_gen.generate_configuration_file();
5753
ASSERT_EQ(cfg_or_err, "SUCCESS");
5854
// TODO

tools/config_generator/config_generator.cpp

+16-69
Original file line numberDiff line numberDiff line change
@@ -74,77 +74,16 @@ static const std::set<std::string> log_levels
7474
namespace cbdc::generate_config {
7575

7676
config_generator::config_generator(std::string& _template_config_file,
77-
const size_t _start_port,
78-
std::string _build_dir)
77+
const size_t _start_port)
7978
: m_template_config_file(_template_config_file),
8079
m_current_port(_start_port) {
8180
// Get Project root dir and build dir
8281
std::filesystem::path build_dir = std::filesystem::current_path();
83-
if(_build_dir.at(_build_dir.size() - 1) == '/') {
84-
_build_dir.erase(_build_dir.end() - 1);
85-
}
8682
// This config generator class assumes project root is "opencbdc-tx"
87-
while(build_dir.has_parent_path()) {
88-
if(build_dir.filename() != "opencbdc-tx") {
89-
build_dir = build_dir.parent_path();
90-
} else {
91-
m_project_root_dir = build_dir;
92-
std::string delimiter = "/";
93-
std::string tmp_str = _build_dir;
94-
size_t pos = 0;
95-
std::string token;
96-
while((pos = tmp_str.find('/')) != std::string::npos) {
97-
token = tmp_str.substr(0, pos);
98-
build_dir = build_dir.append(token);
99-
tmp_str.erase(0, pos + delimiter.length());
100-
}
101-
token = tmp_str.substr(0, pos);
102-
build_dir = build_dir.append(token);
103-
tmp_str.erase(0, pos + delimiter.length());
104-
m_build_dir = build_dir;
105-
std::cerr << "Build directory determined to be "
106-
<< m_build_dir.string() << std::endl;
107-
std::cerr << "Project Root directory determined to be "
108-
<< m_project_root_dir.string() << std::endl;
109-
break;
110-
}
111-
}
112-
template_file_is_valid = true;
11383
if(!std::filesystem::exists(m_template_config_file)) {
114-
template_file_is_valid = false;
115-
std::filesystem::path temp_config_tools_dir = m_project_root_dir;
116-
temp_config_tools_dir.append("config").append("tools");
117-
std::filesystem::path temp_build_config_tools_dir = m_build_dir;
118-
temp_build_config_tools_dir.append("config").append("tools");
119-
std::cerr << "Warning: File provided, " << m_template_config_file
120-
<< ", does not exist. Attempting to copy it from its "
121-
"original location, "
122-
<< temp_config_tools_dir.string() << " to "
123-
<< temp_build_config_tools_dir.string() << std::endl;
124-
copy_templates_to_build_dir();
125-
// Try to use newly copied template files
126-
std::string delimiter = "/";
127-
std::string tmp_str = m_template_config_file;
128-
size_t pos = 0;
129-
std::string template_filename;
130-
while((pos = tmp_str.find('/')) != std::string::npos) {
131-
template_filename = tmp_str.substr(0, pos);
132-
tmp_str.erase(0, pos + delimiter.length());
133-
}
134-
template_filename = tmp_str.substr(0, pos);
135-
std::filesystem::path full_template_path_and_filename
136-
= temp_build_config_tools_dir.append(template_filename);
137-
if(std::filesystem::exists(full_template_path_and_filename)) {
138-
m_template_config_file
139-
= full_template_path_and_filename.string();
140-
template_file_is_valid = true;
141-
std::cerr << "Successfully copied " << template_filename
142-
<< " from " << temp_config_tools_dir.string()
143-
<< " to " << temp_build_config_tools_dir.string()
144-
<< ". Using "
145-
<< full_template_path_and_filename.string()
146-
<< " as template file." << std::endl;
147-
}
84+
m_template_file_is_valid = false;
85+
std::cerr << "template file cannot be found at "
86+
<< _template_config_file << std::endl;
14887
}
14988
}
15089

@@ -749,7 +688,7 @@ namespace cbdc::generate_config {
749688
// Cumulative return message
750689
std::string return_msg;
751690

752-
if(!template_file_is_valid) {
691+
if(!m_template_file_is_valid) {
753692
std::filesystem::path temp_build_dir = m_build_dir;
754693
temp_build_dir.append("config").append("tools");
755694
return_msg += "File provided, " + m_template_config_file
@@ -855,9 +794,17 @@ namespace cbdc::generate_config {
855794
}
856795
// add support for pre-seeding
857796
// only has effect if pre-seeding is active
858-
std::pair<std::string, std::string> key_pair = create_key_pair();
859-
set_param_to_config_file(seed_privkey, key_pair.first);
860-
write_generated_config_to_file();
797+
const auto seed_begin
798+
= get_param_from_template_file(seed_from, config_map);
799+
const auto seed_end
800+
= get_param_from_template_file(seed_to, config_map);
801+
if(!std::holds_alternative<std::string>(seed_begin)
802+
&& !std::holds_alternative<std::string>(seed_end)
803+
&& std::get<size_t>(seed_begin) != std::get<size_t>(seed_end)) {
804+
std::pair<std::string, std::string> key_pair = create_key_pair();
805+
set_param_to_config_file(seed_privkey, key_pair.first);
806+
write_generated_config_to_file();
807+
}
861808
return_msg += "SUCCESS";
862809
return return_msg;
863810
}

tools/config_generator/config_generator.hpp

+2-3
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ namespace cbdc::generate_config {
4646
/// \param _start_port Port to begin using and incrementing from for generated
4747
/// configuration file's endpoints
4848
config_generator(std::string& _template_config_file,
49-
size_t _start_port,
50-
std::string _build_dir);
49+
size_t _start_port);
5150

5251
/// \brief generate_configuration_file
5352
/// Main workhorse method of this class. This method will generate a
@@ -59,7 +58,7 @@ namespace cbdc::generate_config {
5958

6059
private:
6160
// Boolean that tells us if file is valid or not
62-
bool template_file_is_valid;
61+
bool m_template_file_is_valid{true};
6362
// Whether to randomize things that can be randomized
6463
bool m_randomize{false};
6564
// Template file loaded to create configuration file from

tools/config_generator/generate_config.cpp

+3-13
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ auto main(int argc, char** argv) -> int {
1818
// Help string
1919
std::string help_string
2020
= "Usage: " + args[0]
21-
+ " <config template file> <starting port number> <build "
22-
"directory> \n\nPARAM 1, <config template file> : The relative "
21+
+ " <config template file> <starting port number> > <config "
22+
"file name> \n\nPARAM 1, <config template file> : The relative "
2323
"path from current working directory to the template configuration "
2424
"file including the filename itself.\nPARAM 2, <starting port "
2525
"number> : The first port number to use and increment from. Must be "
@@ -41,14 +41,6 @@ auto main(int argc, char** argv) -> int {
4141
<< std::endl
4242
<< "Rerun with proper parameters." << std::endl;
4343
valid_config = false;
44-
} else if(args.size() == min_param_num) {
45-
// Case where user does not input a build dir
46-
std::cerr << "No build directory name specified as third. Using "
47-
"default name of 'build'"
48-
<< std::endl;
49-
} else if(args.size() == max_param_num) {
50-
// Case where user DOES input build dir
51-
build_dir = args[max_param_num - 1];
5244
}
5345
if(!valid_config) {
5446
return -1;
@@ -69,9 +61,7 @@ auto main(int argc, char** argv) -> int {
6961
<< ", is too large. Exiting..." << std::endl;
7062
return -1;
7163
}
72-
cbdc::generate_config::config_generator new_config_gen(args[1],
73-
port_num,
74-
build_dir);
64+
cbdc::generate_config::config_generator new_config_gen(args[1], port_num);
7565
auto cfg_or_err = new_config_gen.generate_configuration_file();
7666
std::cerr << cfg_or_err << std::endl;
7767
std::cout << std::endl;

0 commit comments

Comments
 (0)