OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
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"
8
9#include <cassert>
10#include <csignal>
11#include <iostream>
12#include <memory>
13#include <thread>
14
15// LCOV_EXCL_START
16auto main(int argc, char** argv) -> int {
17 auto args = cbdc::config::get_args(argc, argv);
18 if(args.size() < 3) {
19 std::cerr << "Usage: " << args[0] << " <config file> <shard id>"
20 << std::endl;
21 return 0;
22 }
23
24 const auto shard_id = std::stoull(args[2]);
25
26 auto cfg_or_err = cbdc::config::load_options(args[1]);
27 if(std::holds_alternative<std::string>(cfg_or_err)) {
28 std::cerr << "Error loading config file: "
29 << std::get<std::string>(cfg_or_err) << std::endl;
30 return -1;
31 }
32 auto opts = std::get<cbdc::config::options>(cfg_or_err);
33
34 if(opts.m_shard_endpoints.size() <= shard_id) {
35 std::cerr << "Shard ID not in config file" << std::endl;
36 return -1;
37 }
38
39 auto logger = std::make_shared<cbdc::logging::log>(
40 opts.m_shard_loglevels[shard_id]);
41
42 auto ctl = cbdc::shard::controller{static_cast<uint32_t>(shard_id),
43 opts,
44 logger};
45 if(!ctl.init()) {
46 return -1;
47 }
48
49 // Wait for CTRL+C etc
50 static std::atomic_bool running{true};
51
52 std::signal(SIGINT, [](int /* signal */) {
53 running = false;
54 });
55
56 while(running) {
57 std::this_thread::sleep_for(std::chrono::seconds(1));
58 };
59
60 logger->info("Shutting down...");
61
62 return 0;
63}
64// LCOV_EXCL_STOP
Wrapper for the shard executable implementation.
Tools for reading options from a configuration file and building application-specific parameter sets ...
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
auto main(int argc, char **argv) -> int
Definition shardd.cpp:16