OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
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 "crypto/sha256.h"
9
10#include <csignal>
11#include <iostream>
12
13// LCOV_EXCL_START
14auto main(int argc, char** argv) -> int {
15 auto args = cbdc::config::get_args(argc, argv);
16 if(args.size() < 4) {
17 std::cout << "Usage: " << args[0]
18 << " <config file> <shard ID> <node ID>" << std::endl;
19 return 0;
20 }
21
22 auto cfg_or_err = cbdc::config::load_options(args[1]);
23 if(std::holds_alternative<std::string>(cfg_or_err)) {
24 std::cerr << "Error loading config file: "
25 << std::get<std::string>(cfg_or_err) << std::endl;
26 return -1;
27 }
28 auto cfg = std::get<cbdc::config::options>(cfg_or_err);
29 auto shard_id = std::stoull(args[2]);
30 auto node_id = std::stoull(args[3]);
31
32 if(cfg.m_locking_shard_endpoints.size() <= shard_id) {
33 std::cerr << "Shard ID not in config file" << std::endl;
34 return -1;
35 }
36
37 if(cfg.m_locking_shard_endpoints[shard_id].size() <= node_id) {
38 std::cerr << "Shard node ID not in config file" << std::endl;
39 return -1;
40 }
41
42 auto logger = std::make_shared<cbdc::logging::log>(
43 cfg.m_shard_loglevels[shard_id]);
44
45 std::string sha2_impl(SHA256AutoDetect());
46 logger->info("using sha2: ", sha2_impl);
47
48 auto ctl = cbdc::locking_shard::controller(shard_id, node_id, cfg, logger);
49 if(!ctl.init()) {
50 logger->error("Failed to initialize locking shard");
51 return -1;
52 }
53
54 static std::atomic_bool running{true};
55
56 // Wait for CTRL+C etc
57 std::signal(SIGINT, [](int /* sig */) {
58 running = false;
59 });
60
61 logger->info("Shard running...");
62
63 while(running) {
64 static constexpr auto running_check_delay
65 = std::chrono::milliseconds(1000);
66 std::this_thread::sleep_for(running_check_delay);
67 }
68
69 logger->info("Shutting down...");
70
71 return 0;
72}
73// LCOV_EXCL_STOP
Manages a replicated locking shard using Raft.
Tools for reading options from a configuration file and building application-specific parameter sets ...
auto main(int argc, char **argv) -> int
auto load_options(const std::string &config_file) -> std::variant< options, std::string >
Loads options from the given config file and check for invariants.
Definition config.cpp:668
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.
Definition config.cpp:751