OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
uhs/twophase/sentinel_2pc/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_2PC_CONTROLLER_H_
7#define OPENCBDC_TX_SRC_SENTINEL_2PC_CONTROLLER_H_
8
9#include "crypto/sha256.h"
10#include "server.hpp"
19
20#include <random>
21
22namespace cbdc::sentinel_2pc {
25 public:
26 controller() = delete;
27 controller(const controller&) = delete;
28 auto operator=(const controller&) -> controller& = delete;
30 auto operator=(controller&&) -> controller& = delete;
31
36 controller(uint32_t sentinel_id,
37 const config::options& opts,
38 std::shared_ptr<logging::log> logger);
39
40 ~controller() override = default;
41
45 auto init() -> bool;
46
55 execute_result_callback_type result_callback)
56 -> bool override;
57
64 auto
66 validate_result_callback_type result_callback)
67 -> bool override;
68
69 private:
70 static void result_handler(std::optional<bool> res,
71 const execute_result_callback_type& res_cb);
72
73 void
74 validate_result_handler(validate_result v_res,
75 const transaction::full_tx& tx,
76 execute_result_callback_type result_callback,
78 std::unordered_set<size_t> requested);
79
80 void gather_attestations(const transaction::full_tx& tx,
81 execute_result_callback_type result_callback,
82 const transaction::compact_tx& ctx,
83 std::unordered_set<size_t> requested);
84
85 void send_compact_tx(const transaction::compact_tx& ctx,
86 execute_result_callback_type result_callback);
87
88 uint32_t m_sentinel_id;
90 std::shared_ptr<logging::log> m_logger;
91
92 std::unique_ptr<cbdc::sentinel::rpc::async_server> m_rpc_server;
93
94 std::unique_ptr<secp256k1_context,
95 decltype(&secp256k1_context_destroy)>
96 m_secp{secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
97 &secp256k1_context_destroy};
98
99 coordinator::rpc::client m_coordinator_client;
100
101 std::vector<std::unique_ptr<sentinel::rpc::client>>
102 m_sentinel_clients{};
103
104 std::random_device m_r{};
105 std::default_random_engine m_rand{m_r()};
106 std::uniform_int_distribution<size_t> m_dist{};
107
108 privkey_t m_privkey{};
109 };
110}
111
112#endif // OPENCBDC_TX_SRC_SENTINEL_2PC_CONTROLLER_H_
Interface for an asynchronous sentinel.
std::optional< cbdc::sentinel::validate_response > validate_result
Result of a validation operation.
std::function< void( std::optional< cbdc::sentinel::execute_response >)> execute_result_callback_type
Callback function for transaction execution result.
std::function< void(validate_result)> validate_result_callback_type
Callback function for providing a transaction validation result.
Manages a sentinel server for the two-phase commit architecture.
auto execute_transaction(transaction::full_tx tx, execute_result_callback_type result_callback) -> bool override
Statically validates a transaction, submits it the shard coordinator network, and returns the result ...
controller(const controller &)=delete
auto init() -> bool
Initializes the controller.
~controller() override=default
controller(controller &&)=delete
auto validate_transaction(transaction::full_tx tx, validate_result_callback_type result_callback) -> bool override
Statically validates a transaction and generates a sentinel attestation if the transaction is valid.
auto operator=(controller &&) -> controller &=delete
auto operator=(const controller &) -> controller &=delete
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 condensed, hash-only transaction representation.
A complete transaction.