OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
runtime_locking_shardd.cpp
Go to the documentation of this file.
1// Copyright (c) 2021 MIT Digital Currency Initiative,
2// Federal Reserve Bank of Boston
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include "controller.hpp"
7#include "util.hpp"
9
10#include <csignal>
11
12auto main(int argc, char** argv) -> int {
13 auto log
14 = std::make_shared<cbdc::logging::log>(cbdc::logging::log_level::warn);
15 auto cfg = cbdc::parsec::read_config(argc, argv);
16 if(!cfg.has_value()) {
17 log->error("Error parsing options");
18 return 1;
19 }
20 log->set_loglevel(cfg->m_loglevel);
21
22 if(cfg->m_shard_endpoints.size() <= cfg->m_component_id) {
23 log->error("No endpoint for component id");
24 return 1;
25 }
26
27 if(cfg->m_shard_endpoints[cfg->m_component_id].size() <= *cfg->m_node_id) {
28 log->error("No endpoint for node id");
29 return 1;
30 }
31
32 auto raft_endpoints = std::vector<cbdc::network::endpoint_t>();
33 for(auto& e : cfg->m_shard_endpoints[cfg->m_component_id]) {
34 auto new_ep = e;
35 new_ep.second++;
36 raft_endpoints.push_back(new_ep);
37 }
38
40 cfg->m_component_id,
41 *cfg->m_node_id,
42 cfg->m_shard_endpoints[cfg->m_component_id][*cfg->m_node_id],
43 raft_endpoints,
44 log);
45 if(!controller.init()) {
46 log->error("Failed to start raft server");
47 return 1;
48 }
49
50 static auto running = std::atomic_bool{true};
51
52 std::signal(SIGINT, [](int /* signal */) {
53 running = false;
54 });
55
56 log->info("Shard running");
57
58 while(running) {
59 std::this_thread::sleep_for(std::chrono::seconds(1));
60 }
61
62 log->info("Shutting down...");
63 return 0;
64}
Manages a replicated runtime locking shard using Raft.
@ warn
Potentially unintended, unexpected, or undesirable behavior.
auto read_config(int argc, char **argv) -> std::optional< config >
Reads the configuration parameters from the program arguments.
Definition util.cpp:100
auto main(int argc, char **argv) -> int