Skip to content

Commit 8e8d6e6

Browse files
ykaravasYiannis Karavas
authored and
Yiannis Karavas
committed
Have basics of a configuration generation tool for expanded testing. I foresee much more expanded functionality in the future and a lot of potential. This will require some possible rework of some existing code, however, as well as integration tests to make use of this proposed functionality. Also reorganized config files into their own directory which seems neater. Also needed to fix docker stff. Might need to revert docker stuff. Not sure how that will affect others.
Signed-off-by: Yiannis Karavas <[email protected]>
1 parent 46771a9 commit 8e8d6e6

28 files changed

+1378
-23
lines changed

CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -75,5 +75,6 @@ endif()
7575

7676
add_subdirectory(src)
7777
add_subdirectory(tests)
78+
add_subdirectory(tools/config_generator)
7879
add_subdirectory(tools/bench)
7980
add_subdirectory(tools/shard-seeder)

README.md

+11-11
Original file line numberDiff line numberDiff line change
@@ -121,38 +121,38 @@ Additionally, you can start the atomizer architecture by passing `--file docker-
121121
## Setup test wallets and test them
122122

123123
The following commands are all performed from within the second container we started in the previous step.
124-
In each of the below commands, you should pass `atomizer-compose.cfg` instead of `2pc-compose.cfg` if you started the atomizer architecture.
124+
In each of the below commands, you should pass `config/general/atomizer-compose.cfg` instead of `config/general/2pc-compose.cfg` if you started the atomizer architecture.
125125

126126
* Mint new coins (e.g., 10 new UTXOs each with a value of 5 atomic units of currency)
127127
```terminal
128-
# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool0.dat wallet0.dat mint 10 5
128+
# ./build/src/uhs/client/client-cli config/general/2pc-compose.cfg mempool0.dat wallet0.dat mint 10 5
129129
[2021-08-17 15:11:57.686] [WARN ] Existing wallet file not found
130130
[2021-08-17 15:11:57.686] [WARN ] Existing mempool not found
131131
4bc23da407c3a8110145c5b6c38199c8ec3b0e35ea66bbfd78f0ed65304ce6fa
132132
```
133133

134134
If using the atomizer architecture, you'll need to sync the wallet after:
135135
```terminal
136-
# ./build/src/uhs/client/client-cli atomizer-compose.cfg mempool0.dat wallet0.dat sync
136+
# ./build/src/uhs/client/client-cli config/general/atomizer-compose.cfg mempool0.dat wallet0.dat sync
137137
```
138138

139139
* Inspect the balance of a wallet
140140
```terminal
141-
# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool0.dat wallet0.dat info
141+
# ./build/src/uhs/client/client-cli config/general/2pc-compose.cfg mempool0.dat wallet0.dat info
142142
Balance: $0.50, UTXOs: 10, pending TXs: 0
143143
```
144144

145145
* Make a new wallet
146146
```terminal
147-
# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool1.dat wallet1.dat newaddress
147+
# ./build/src/uhs/client/client-cli config/general/2pc-compose.cfg mempool1.dat wallet1.dat newaddress
148148
[2021-08-17 15:13:16.148] [WARN ] Existing wallet file not found
149149
[2021-08-17 15:13:16.148] [WARN ] Existing mempool not found
150150
usd1qrw038lx5n4wxx3yvuwdndpr7gnm347d6pn37uywgudzq90w7fsuk52kd5u
151151
```
152152

153153
* Send currency from the first wallet to the second wallet created in the previous step (e.g., 30 atomic units of currency)
154154
```terminal
155-
# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool0.dat wallet0.dat send 30 usd1qrw038lx5n4wxx3yvuwdndpr7gnm347d6pn37uywgudzq90w7fsuk52kd5u
155+
# ./build/src/uhs/client/client-cli config/general/2pc-compose.cfg mempool0.dat wallet0.dat send 30 usd1qrw038lx5n4wxx3yvuwdndpr7gnm347d6pn37uywgudzq90w7fsuk52kd5u
156156
tx_id:
157157
cc1f7dc708be5b07e23e125cf0674002ff8546a9342928114bc97031d8b96e75
158158
Data for recipient importinput:
@@ -162,20 +162,20 @@ In each of the below commands, you should pass `atomizer-compose.cfg` instead of
162162

163163
If using the atomizer architecture, you'll need to sync the sending wallet after:
164164
```terminal
165-
# ./build/src/uhs/client/client-cli atomizer-compose.cfg mempool0.dat wallet0.dat sync
165+
# ./build/src/uhs/client/client-cli config/general/atomizer-compose.cfg mempool0.dat wallet0.dat sync
166166
```
167167

168168
* Check that the currency is no longer available in the sending wallet
169169
```terminal
170-
# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool0.dat wallet0.dat info
170+
# ./build/src/uhs/client/client-cli config/general/2pc-compose.cfg mempool0.dat wallet0.dat info
171171
Balance: $0.20, UTXOs: 4, pending TXs: 0
172172
```
173173

174174
* Import coins to the receiving wallet using the string after `importinput` from the currency transfer step above
175175
```terminal
176-
# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool1.dat wallet1.dat importinput cc1f7dc708be5b07e23e125cf0674002ff8546a9342928114bc97031d8b96e750000000000000000d0e4f689b550f623e9370edae235de50417860be0f2f8e924eca9f402fcefeaa1e00000000000000
177-
# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool1.dat wallet1.dat sync
178-
# ./build/src/uhs/client/client-cli 2pc-compose.cfg mempool1.dat wallet1.dat info
176+
# ./build/src/uhs/client/client-cli config/general/2pc-compose.cfg mempool1.dat wallet1.dat importinput cc1f7dc708be5b07e23e125cf0674002ff8546a9342928114bc97031d8b96e750000000000000000d0e4f689b550f623e9370edae235de50417860be0f2f8e924eca9f402fcefeaa1e00000000000000
177+
# ./build/src/uhs/client/client-cli config/general/2pc-compose.cfg mempool1.dat wallet1.dat sync
178+
# ./build/src/uhs/client/client-cli config/general/2pc-compose.cfg mempool1.dat wallet1.dat info
179179
Balance: $0.30, UTXOs: 1, pending TXs: 0
180180
```
181181

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2pc=1
2+
sentinel_count=1
3+
shard_count=1
4+
coordinator_count=1
5+
coordinator_max_threads=1
6+
election_timeout_upper=4000
7+
election_timeout_lower=3000
8+
heartbeat=1000
9+
raft_max_batch=100000
10+
snapshot_distance=1000000000
11+
batch_size=1
12+
wait_for_followers=0
13+
loadgen_invalid_tx_rate=0.00
14+
loadgen_fixed_tx_rate=0.01
15+
loadgen_sendtx_output_count=1
16+
loadgen_sendtx_input_count=1
17+
initial_mint_count=20000
18+
initial_mint_value=100
19+
tmpl_randomize_values=1
20+
tmpl_shard_start=0
21+
tmpl_shard_size=255
22+
tmpl_max_shard_raft_replication_count=1
23+
tmpl_avg_shard_start_end_overlap_percent=0.15
24+
tmpl_max_coordinator_raft_replication_count=1
25+
tmpl_default_log_level="INFO"
26+
tmpl_universal_override_log_level="WARN"
27+
tmpl_sentinel_log_level="WARN"
28+
tmpl_coordinator_log_level="DEBUG"
29+
tmpl_shard_log_level="DEBUG"
30+
num_wallets=10
31+
num_minters=1
32+
num_redeemers=1
33+
total_number_of_transactions=100
34+
avg_mint_value=10
35+
avg_mint_count=10
36+
avg_redemption_value=5
37+
avg_redemption_count=5
38+
transaction_frequency=5
39+
mint_frequency=0.1
40+
redemption_frequency=0.05
41+
sentinel_offline_probability=0.01
42+
shard_offline_probability=0.01
43+
coordinator_offline_probability=0.01
44+
randomize_execution=0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2pc=0
2+
archiver_count=1
3+
atomizer_count=1
4+
shard_count=1
5+
sentinel_count=1
6+
watchtower_count=1
7+
target_block_interval=3000
8+
stxo_cache_depth=2
9+
target_block_interval=250
10+
election_timeout_upper=4000
11+
election_timeout_lower=3000
12+
heartbeat=1000
13+
raft_max_batch=100000
14+
snapshot_distance=1000000000
15+
batch_size=1
16+
wait_for_followers=0
17+
loadgen_invalid_tx_rate=0.00
18+
loadgen_fixed_tx_rate=0.01
19+
loadgen_sendtx_output_count=1
20+
loadgen_sendtx_input_count=1
21+
initial_mint_count=20000
22+
initial_mint_value=100
23+
tmpl_randomize_values=1
24+
tmpl_shard_start=0
25+
tmpl_shard_size=255
26+
tmpl_avg_shard_start_end_overlap_percent=0.15
27+
tmpl_default_log_level="INFO"
28+
tmpl_sentinel_log_level="DEBUG"
29+
tmpl_shard_log_level="INFO"
30+
tmpl_watchtower_log_level="DEBUG"
31+
tmpl_archiver_log_level="DEBUG"
32+
tmpl_atomizer_log_level="DEBUG"
File renamed without changes.

docker-compose-2pc.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ services:
77
image: opencbdc-tx
88
tty: true
99
restart: always
10-
command: ./build/src/uhs/twophase/sentinel_2pc/sentineld-2pc 2pc-compose.cfg 0
10+
command: ./build/src/uhs/twophase/sentinel_2pc/sentineld-2pc ./config/general/2pc-compose.cfg 0
1111
ports:
1212
- 5555:5555
1313
depends_on:
@@ -25,7 +25,7 @@ services:
2525
build: .
2626
image: opencbdc-tx
2727
tty: true
28-
command: ./build/src/uhs/twophase/coordinator/coordinatord 2pc-compose.cfg 0 0
28+
command: ./build/src/uhs/twophase/coordinator/coordinatord ./config/general/2pc-compose.cfg 0 0
2929
expose:
3030
- "7777"
3131
depends_on:
@@ -43,7 +43,7 @@ services:
4343
build: .
4444
image: opencbdc-tx
4545
tty: true
46-
command: ./build/src/uhs/twophase/locking_shard/locking-shardd 2pc-compose.cfg 0 0
46+
command: ./build/src/uhs/twophase/locking_shard/locking-shardd ./config/general/2pc-compose.cfg 0 0
4747
expose:
4848
- "6666"
4949
ports:

docker-compose-atomizer.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services:
66
build: .
77
image: opencbdc-tx
88
tty: true
9-
command: ./build/src/uhs/atomizer/watchtower/watchtowerd atomizer-compose.cfg 0
9+
command: ./build/src/uhs/atomizer/watchtower/watchtowerd ./config/general/atomizer-compose.cfg 0
1010
ports:
1111
- 8555:8555
1212
expose:
@@ -23,7 +23,7 @@ services:
2323
build: .
2424
image: opencbdc-tx
2525
tty: true
26-
command: ./build/src/uhs/atomizer/atomizer/atomizer-raftd atomizer-compose.cfg 0
26+
command: ./build/src/uhs/atomizer/atomizer/atomizer-raftd ./config/general/atomizer-compose.cfg 0
2727
expose:
2828
- "5555"
2929
depends_on:
@@ -40,7 +40,7 @@ services:
4040
build: .
4141
image: opencbdc-tx
4242
tty: true
43-
command: ./build/src/uhs/atomizer/archiver/archiverd atomizer-compose.cfg 0
43+
command: ./build/src/uhs/atomizer/archiver/archiverd ./config/general/atomizer-compose.cfg 0
4444
expose:
4545
- "4555"
4646
depends_on:
@@ -59,7 +59,7 @@ services:
5959
build: .
6060
image: opencbdc-tx
6161
tty: true
62-
command: ./build/src/uhs/atomizer/shard/shardd atomizer-compose.cfg 0
62+
command: ./build/src/uhs/atomizer/shard/shardd ./config/general/atomizer-compose.cfg 0
6363
expose:
6464
- "6555"
6565
depends_on:
@@ -79,7 +79,7 @@ services:
7979
build: .
8080
image: opencbdc-tx
8181
tty: true
82-
command: ./build/src/uhs/atomizer/sentinel/sentineld atomizer-compose.cfg 0
82+
command: ./build/src/uhs/atomizer/sentinel/sentineld ./config/general/atomizer-compose.cfg 0
8383
ports:
8484
- 7555:7555
8585
depends_on:

docker-compose-test-2pc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ services:
66
build: .
77
image: opencbdc-tx
88
tty: true
9-
command: sh ./scripts/test-transaction.sh 2pc-compose.cfg
9+
command: sh ./scripts/test-transaction.sh ./config/general/2pc-compose.cfg
1010
networks:
1111
- 2pc-network

scripts/test.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ run_test_suite () {
164164
if [[ "$RUN_UNIT_TESTS" == "true" ]]
165165
then
166166
echo "Running unit tests..."
167-
find "${REPO_TOP_DIR}"/tests/unit/ -name '*.cfg' \
167+
find "${REPO_TOP_DIR}"/config/unit/ -name '*.cfg' \
168168
-exec rsync \{\} "$BUILD_DIR" \;
169169
run_test_suite "tests/unit/run_unit_tests" "unit_tests_coverage"
170170
else
@@ -175,7 +175,8 @@ echo
175175
if [[ "$RUN_INTEGRATION_TESTS" == "true" ]]
176176
then
177177
echo "Running integration tests..."
178-
cp "${REPO_TOP_DIR}"/tests/integration/*.cfg "$BUILD_DIR"
178+
cp "${REPO_TOP_DIR}"/config/integration/*.cfg "${BUILD_DIR}"
179+
cp "${REPO_TOP_DIR}"/tools/config_generator/*.tmpl "${BUILD_DIR}"/tools/config_generator
179180
run_test_suite "tests/integration/run_integration_tests" \
180181
"integration_tests_coverage"
181182
else

tests/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
project(tests)
22

3-
include_directories(. ../src ../tools/watchtower ../3rdparty ../3rdparty/secp256k1/include)
3+
include_directories(. ../src ../ ../tools/config_generator ../tools/watchtower ../3rdparty ../3rdparty/secp256k1/include)
44
set(SECP256K1_LIBRARY $<TARGET_FILE:secp256k1>)
55

66
add_library(util util.cpp)

tests/unit/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ add_executable(run_unit_tests archiver_test.cpp
55
atomizer_test.cpp
66
buffer_test.cpp
77
common/hash_test.cpp
8+
config_gen_test.cpp
89
config_test.cpp
910
coordinator/messages_test.cpp
1011
locking_shard/format_test.cpp
@@ -50,6 +51,7 @@ target_link_libraries(run_unit_tests ${GTEST_LIBRARY}
5051
transaction
5152
network
5253
common
54+
config_generator
5355
serialization
5456
crypto
5557
secp256k1

tests/unit/config_gen_test.cpp

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) 2022 MIT Digital Currency Initiative,
2+
// Federal Reserve Bank of Boston
3+
// MITRE Corporation
4+
// Distributed under the MIT software license, see the accompanying
5+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
6+
7+
#include "tools/config_generator/config_generator.hpp"
8+
#include "util/common/config.hpp"
9+
10+
#include <filesystem>
11+
#include <gtest/gtest.h>
12+
#include <string>
13+
14+
// TODO: Add file parsing tests.
15+
16+
class config_generation_validation_test : public ::testing::Test {
17+
protected:
18+
void SetUp() override {
19+
template_file_atomizer
20+
= "../config/unit/atomizer_template_unit_test.tmpl";
21+
template_file_2pc = "../config/unit/2pc_template_unit_test.tmpl";
22+
port_num = 5555;
23+
}
24+
25+
std::string template_file_atomizer;
26+
std::string template_file_2pc;
27+
size_t port_num;
28+
};
29+
30+
TEST_F(config_generation_validation_test,
31+
generate_configuration_file_atomizer_test) {
32+
// Assumes build dir is "build". Cannot find a way around this since unit
33+
// tests can be run from either root dir or build dir and we don't
34+
// necessarily know which one
35+
std::string build_dir = "build";
36+
cbdc::generate_config::config_generator new_config_gen(
37+
template_file_atomizer,
38+
port_num,
39+
build_dir);
40+
auto cfg_or_err = new_config_gen.generate_configuration_file();
41+
ASSERT_EQ(cfg_or_err, "SUCCESS");
42+
// TODO
43+
// Reload generate file and check values
44+
// Delete generated file
45+
}
46+
47+
TEST_F(config_generation_validation_test,
48+
generate_configuration_file_two_phase_test) {
49+
// Assumes build dir is "build". Cannot find a way around this since unit
50+
// tests can be run from either root dir or build dir and we don't
51+
// necessarily know which one
52+
std::string build_dir = "build";
53+
cbdc::generate_config::config_generator new_config_gen(template_file_2pc,
54+
port_num,
55+
build_dir);
56+
auto cfg_or_err = new_config_gen.generate_configuration_file();
57+
ASSERT_EQ(cfg_or_err, "SUCCESS");
58+
// TODO
59+
// Reload generate file and check values
60+
// Delete generated file
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2pc=1
2+
sentinel_count=1
3+
shard_count=1
4+
coordinator_count=1
5+
coordinator_max_threads=1
6+
election_timeout_upper=4000
7+
election_timeout_lower=3000
8+
heartbeat=1000
9+
raft_max_batch=100000
10+
snapshot_distance=1000000000
11+
batch_size=1
12+
wait_for_followers=0
13+
loadgen_invalid_tx_rate=0.00
14+
loadgen_fixed_tx_rate=0.01
15+
loadgen_sendtx_output_count=1
16+
loadgen_sendtx_input_count=1
17+
initial_mint_count=20000
18+
initial_mint_value=100
19+
tmpl_randomize_values=1
20+
tmpl_shard_start=0
21+
tmpl_shard_size=255
22+
tmpl_max_shard_raft_replication_count=1
23+
tmpl_avg_shard_start_end_overlap_percent=0.15
24+
tmpl_max_coordinator_raft_replication_count=1
25+
tmpl_default_log_level="INFO"
26+
tmpl_universal_override_log_level="WARN"
27+
tmpl_sentinel_log_level="WARN"
28+
tmpl_coordinator_log_level="DEBUG"
29+
tmpl_shard_log_level="DEBUG"
30+
num_wallets=10
31+
num_minters=1
32+
num_redeemers=1
33+
total_number_of_transactions=100
34+
avg_mint_value=10
35+
avg_mint_count=10
36+
avg_redemption_value=5
37+
avg_redemption_count=5
38+
transaction_frequency=5
39+
mint_frequency=0.1
40+
redemption_frequency=0.05
41+
sentinel_offline_probability=0.01
42+
shard_offline_probability=0.01
43+
coordinator_offline_probability=0.01
44+
randomize_execution=0

0 commit comments

Comments
 (0)