OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
watchtower.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
10#ifndef OPENCBDC_TX_SRC_WATCHTOWER_WATCHTOWER_H_
11#define OPENCBDC_TX_SRC_WATCHTOWER_WATCHTOWER_H_
12
13#include "block_cache.hpp"
14#include "error_cache.hpp"
15#include "messages.hpp"
16#include "status_update.hpp"
17
18namespace cbdc::watchtower {
21 auto operator==(const best_block_height_request& /* unused */) const
22 -> bool;
23
25
29 };
30
34 public:
35 friend auto cbdc::operator<<(
36 cbdc::serializer& packet,
39 friend auto
43
44 auto operator==(const best_block_height_response& rhs) const -> bool;
45
47
50 explicit best_block_height_response(uint64_t height);
51
55
59 [[nodiscard]] auto height() const -> uint64_t;
60
61 private:
62 uint64_t m_height{};
63 };
64
66 class request {
67 public:
71
72 auto operator==(const request& rhs) const -> bool;
73
74 request() = delete;
75
77 = std::variant<status_update_request, best_block_height_request>;
78
81 explicit request(request_t req);
82
85 explicit request(cbdc::serializer& pkt);
86
89 [[nodiscard]] auto payload() const -> const request_t&;
90
91 private:
92 request_t m_req;
93 };
94
96 class response {
97 public:
101
102 auto operator==(const response& rhs) const -> bool;
103
104 response() = delete;
105
108
111 explicit response(response_t resp);
112
115 explicit response(cbdc::serializer& pkt);
116
119 [[nodiscard]] auto payload() const -> const response_t&;
120
121 private:
122 response_t m_resp;
123 };
124
128 public:
129 watchtower() = delete;
130
135 watchtower(size_t block_cache_size, size_t error_cache_size);
136
141 void add_block(cbdc::atomizer::block&& blk);
142
146 void add_errors(std::vector<tx_error>&& errs);
147
163 auto handle_status_update_request(const status_update_request& req)
164 -> std::unique_ptr<response>;
165
169 auto
170 handle_best_block_height_request(const best_block_height_request& req)
171 -> std::unique_ptr<response>;
172
173 private:
174 block_cache m_bc;
175 std::shared_mutex m_bc_mut;
176 error_cache m_ec;
177 std::shared_mutex m_ec_mut;
178
179 auto check_uhs_id_statuses(const std::vector<hash_t>& uhs_ids,
180 const hash_t& tx_id,
181 bool internal_err,
182 bool tx_err,
183 uint64_t best_height)
184 -> std::vector<status_update_state>;
185 };
186}
187
188#endif // OPENCBDC_TX_SRC_WATCHTOWER_WATCHTOWER_H_
Interface for serializing objects into and out of raw bytes representations.
Contains the watchtower's known best block height.
auto height() const -> uint64_t
Returns the states of a set of UHS IDs, following the order of the UHS IDs in the containing StatusUp...
auto operator==(const best_block_height_response &rhs) const -> bool
Stores a set of blocks in memory and maintains an index of the UHS IDs contained therein.
Stores a set of internal transaction errors in memory, indexed by Tx ID and UHS ID.
RPC request message to the watchtower external endpoint.
auto payload() const -> const request_t &
Return the request payload.
auto operator==(const request &rhs) const -> bool
std::variant< status_update_request, best_block_height_request > request_t
RPC response message from the watchtower external endpoint.
std::variant< status_request_check_success, best_block_height_response > response_t
Indicates a successful check request, sent with a StatusUpdateResponse.
Network request to interact with the Watchtower's status update service.
Service to answer client requests for processing status updates on submitted transactions.
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
auto operator>>(serializer &deser, parsec::agent::rpc::request &req) -> serializer &
auto operator<<(serializer &ser, const parsec::agent::rpc::request &req) -> serializer &
Batch of compact transactions settled by the atomizer.
Definition block.hpp:19
Request the watchtower's known best block height.
auto operator==(const best_block_height_request &) const -> bool
Messages clients can use to communicate with the Watchtower.