OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
uhs/atomizer/archiver/controller.hpp
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#ifndef OPENCBDC_TX_SRC_ARCHIVER_CONTROLLER_H_
7#define OPENCBDC_TX_SRC_ARCHIVER_CONTROLLER_H_
8
9#include "client.hpp"
13
14#include <leveldb/db.h>
15
16namespace cbdc::archiver {
17
22 struct leveldbWriteOptions : public leveldb::WriteOptions {
23 explicit leveldbWriteOptions(bool do_sync);
24 };
25
30 class controller {
31 public:
32 controller() = delete;
33 controller(const controller&) = delete;
34 auto operator=(const controller&) -> controller& = delete;
36 auto operator=(controller&&) -> controller& = delete;
37
43 controller(uint32_t archiver_id,
44 config::options opts,
45 std::shared_ptr<logging::log> log,
46 size_t max_samples);
47
49
52 auto init() -> bool;
53
56 auto init_leveldb() -> bool;
57
60 auto init_best_block() -> bool;
61
64 auto init_sample_collection() -> bool;
65
68 auto init_atomizer_connection() -> bool;
69
72 auto init_archiver_server() -> bool;
73
76 [[nodiscard]] auto best_block_height() const -> uint64_t;
77
82 auto server_handler(cbdc::network::message_t&& pkt)
83 -> std::optional<cbdc::buffer>;
84
90 auto atomizer_handler(cbdc::network::message_t&& pkt)
91 -> std::optional<cbdc::buffer>;
92
104 void digest_block(const cbdc::atomizer::block& blk);
105
111 auto get_block(uint64_t height)
112 -> std::optional<cbdc::atomizer::block>;
113
120 [[nodiscard]] auto running() const -> bool;
121
122 private:
123 uint32_t m_archiver_id;
124 cbdc::config::options m_opts;
125 std::shared_ptr<logging::log> m_logger;
126
127 std::unique_ptr<leveldb::DB> m_db;
128 uint64_t m_best_height{0};
132 std::map<uint64_t, cbdc::atomizer::block> m_deferred;
133 std::ofstream m_tp_sample_file;
134 std::chrono::high_resolution_clock::time_point m_last_block_time;
135 size_t m_max_samples{};
136 size_t m_samples{};
137
138 cbdc::network::connection_manager m_atomizer_network;
139 cbdc::network::connection_manager m_archiver_network;
140
141 bool m_sample_collection_active{false};
142
143 std::thread m_atomizer_handler_thread;
144 std::thread m_archiver_server;
145
146 std::atomic_bool m_running{true};
147
148 const std::string m_bestblock_key = "bestblock";
149 static constexpr const leveldb::ReadOptions m_read_options{};
150 static const leveldbWriteOptions m_write_options;
151
152 void request_block(uint64_t height);
153 void request_prune(uint64_t height);
154 };
155}
156
157#endif // OPENCBDC_TX_SRC_ARCHIVER_CONTROLLER_H_
Wrapper for the archiver executable implementation.
auto get_block(uint64_t height) -> std::optional< cbdc::atomizer::block >
Queries the archiver database for the block at the specified height.
auto init() -> bool
Initializes the controller with all its dependencies.
auto running() const -> bool
Returns true if this archiver is receiving blocks from the atomizer.
auto init_sample_collection() -> bool
Initializes the sample collection.
auto atomizer_handler(cbdc::network::message_t &&pkt) -> std::optional< cbdc::buffer >
Receives a serialized block from the atomizer and digests it.
void digest_block(const cbdc::atomizer::block &blk)
Adds a block to the archiver database.
auto init_leveldb() -> bool
Initializes the LevelDB database.
auto best_block_height() const -> uint64_t
Returns the archiver's best block height.
controller(controller &&)=delete
auto operator=(controller &&) -> controller &=delete
auto init_archiver_server() -> bool
Initializes the archiver server.
auto server_handler(cbdc::network::message_t &&pkt) -> std::optional< cbdc::buffer >
Receives a request for an archived block and returns the block.
controller(const controller &)=delete
auto operator=(const controller &) -> controller &=delete
auto init_best_block() -> bool
Initializes the best block value.
auto init_atomizer_connection() -> bool
Initializes the connection to the atomizer.
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
Tools for reading options from a configuration file and building application-specific parameter sets ...
Wrapper for leveldb::WriteOptions to provide a constructor to set base class member "sync".
Project-wide configuration options.
Definition config.hpp:132