OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
atomizer_raft.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_ATOMIZER_ATOMIZER_RAFT_H_
7#define OPENCBDC_TX_SRC_ATOMIZER_ATOMIZER_RAFT_H_
8
9#include "messages.hpp"
10#include "state_machine.hpp"
12#include "util/raft/node.hpp"
14
15namespace cbdc::atomizer {
22 public:
30 atomizer_raft(uint32_t atomizer_id,
31 std::vector<network::endpoint_t> raft_endpoints,
32 size_t stxo_cache_depth,
33 std::shared_ptr<logging::log> logger,
34 config::options opts,
35 nuraft::cb_func::func_type raft_callback);
36
45 const raft::callback_type& result_fn) -> bool;
46
49 [[nodiscard]] auto get_sm() -> state_machine*;
50
54 [[nodiscard]] auto tx_notify_count() -> uint64_t;
55
62 void tx_notify(tx_notify_request&& notif);
63
69 [[nodiscard]] auto
70 send_complete_txs(const raft::callback_type& result_fn) -> bool;
71
72 private:
73 static constexpr const auto m_node_type = "atomizer";
74
75 using attestation = std::pair<uint64_t, uint64_t>;
76
77 struct attestation_hash {
78 auto operator()(const attestation& pair) const -> size_t;
79 };
80
81 struct attestation_cmp {
82 auto operator()(const attestation& a, const attestation& b) const
83 -> bool;
84 };
85
86 using attestation_set = std::
87 unordered_set<attestation, attestation_hash, attestation_cmp>;
88
89 std::unordered_map<transaction::compact_tx,
90 attestation_set,
92 m_txs;
93 std::mutex m_complete_mut;
94 std::vector<aggregate_tx_notification> m_complete_txs;
95 std::shared_ptr<logging::log> m_log;
96 config::options m_opts;
97
98 std::mutex m_txs_mut;
99 };
100}
101
102#endif // OPENCBDC_TX_SRC_ATOMIZER_ATOMIZER_RAFT_H_
Manager for an atomizer raft node.
void tx_notify(tx_notify_request &&notif)
Add the given transaction notification to the set of pending notifications.
auto send_complete_txs(const raft::callback_type &result_fn) -> bool
Replicate a transaction notification command in the state machine containing the current set of compl...
auto get_sm() -> state_machine *
Return a pointer to the state machine replicated by this raft node.
atomizer_raft(uint32_t atomizer_id, std::vector< network::endpoint_t > raft_endpoints, size_t stxo_cache_depth, std::shared_ptr< logging::log > logger, config::options opts, nuraft::cb_func::func_type raft_callback)
Constructor.
auto make_request(const state_machine::request &r, const raft::callback_type &result_fn) -> bool
Serialize and replicate the given request in the atomizer raft cluster.
auto tx_notify_count() -> uint64_t
Return the number of transaction notifications handled by the state machine.
Raft state machine for managing a replicated atomizer.
std::variant< aggregate_tx_notify_request, make_block_request, get_block_request, prune_request > request
Atomizer state machine request.
A node in a raft cluster.
Definition node.hpp:31
std::function< void(result_type &r, nuraft::ptr< std::exception > &err)> callback_type
Function type for raft state machine execution result callbacks.
Definition node.hpp:21
Project-wide configuration options.
Definition config.hpp:132
A condensed, hash-only transaction representation.