OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
uhs/atomizer/sentinel/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_SENTINEL_CONTROLLER_H_
7#define OPENCBDC_TX_SRC_SENTINEL_CONTROLLER_H_
8
9#include "server.hpp"
15
16#include <memory>
17#include <random>
18
19namespace cbdc::sentinel {
21 class controller : public interface {
22 public:
23 controller() = delete;
24 controller(const controller&) = delete;
25 auto operator=(const controller&) -> controller& = delete;
27 auto operator=(controller&&) -> controller& = delete;
28
33 controller(uint32_t sentinel_id,
34 config::options opts,
35 std::shared_ptr<logging::log> logger);
36
37 ~controller() override = default;
38
41 auto init() -> bool;
42
49 -> std::optional<cbdc::sentinel::execute_response> override;
50
57 -> std::optional<validate_response> override;
58
59 private:
60 uint32_t m_sentinel_id;
62 std::shared_ptr<logging::log> m_logger;
63
64 std::vector<shard_info> m_shard_data;
65
67
68 std::unique_ptr<rpc::server> m_rpc_server;
69
70 std::unique_ptr<secp256k1_context,
71 decltype(&secp256k1_context_destroy)>
72 m_secp{secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
73 &secp256k1_context_destroy};
74
75 std::vector<std::unique_ptr<sentinel::rpc::client>>
76 m_sentinel_clients{};
77
78 std::random_device m_r{};
79 std::default_random_engine m_rand{m_r()};
80 std::uniform_int_distribution<size_t> m_dist{};
81 std::uniform_int_distribution<size_t> m_shard_dist{};
82 std::mutex m_rand_mut;
83
84 privkey_t m_privkey{};
85
86 void send_transaction(const transaction::full_tx& tx);
87
88 void validate_result_handler(async_interface::validate_result v_res,
89 const transaction::full_tx& tx,
90 transaction::compact_tx ctx,
91 std::unordered_set<size_t> requested);
92
93 void gather_attestations(const transaction::full_tx& tx,
94 const transaction::compact_tx& ctx,
95 std::unordered_set<size_t> requested);
96
97 void send_compact_tx(const transaction::compact_tx& ctx);
98 };
99}
100
101#endif // OPENCBDC_TX_SRC_SENTINEL_CONTROLLER_H_
std::optional< cbdc::sentinel::validate_response > validate_result
Result of a validation operation.
controller(const controller &)=delete
auto operator=(const controller &) -> controller &=delete
controller(controller &&)=delete
auto operator=(controller &&) -> controller &=delete
~controller() override=default
auto validate_transaction(transaction::full_tx tx) -> std::optional< validate_response > override
Validate transaction and generate a sentinel attestation if the transaction is valid.
auto init() -> bool
Initializes the controller.
auto execute_transaction(transaction::full_tx tx) -> std::optional< cbdc::sentinel::execute_response > override
Validate transaction, forward it to shards for processing, and return the validation result to send b...
Interface for a sentinel.
Tools for reading options from a configuration file and building application-specific parameter sets ...
struct secp256k1_context_struct secp256k1_context
Definition keys.hpp:14
std::array< unsigned char, pubkey_len > privkey_t
A private key of a public/private keypair.
Definition keys.hpp:23
Project-wide configuration options.
Definition config.hpp:132
A complete transaction.