OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
error_cache.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_ERROR_CACHE_H_
11#define OPENCBDC_TX_SRC_WATCHTOWER_ERROR_CACHE_H_
12
13#include "tx_error_messages.hpp"
15
16#include <memory>
17#include <mutex>
18#include <queue>
19#include <shared_mutex>
20#include <unordered_map>
21
22namespace cbdc::watchtower {
23
27 public:
28 error_cache() = delete;
29
32 explicit error_cache(size_t k);
33
37 void push_errors(std::vector<tx_error>&& errs);
38
42 auto check_tx_id(const hash_t& tx_id) const -> std::optional<tx_error>;
43
47 auto check_uhs_id(const hash_t& uhs_id) const
48 -> std::optional<tx_error>;
49
50 private:
51 size_t m_k_errs;
52 std::queue<std::shared_ptr<tx_error>> m_errs;
53 std::unordered_map<hash_t,
54 std::shared_ptr<tx_error>,
56 m_uhs_errs;
57 std::unordered_map<hash_t,
58 std::shared_ptr<tx_error>,
60 m_tx_id_errs;
61 };
62}
63
64#endif // OPENCBDC_TX_SRC_WATCHTOWER_ERROR_CACHE_H_
Stores a set of internal transaction errors in memory, indexed by Tx ID and UHS ID.
auto check_tx_id(const hash_t &tx_id) const -> std::optional< tx_error >
Checks the cache for an error associated with the given Tx ID.
void push_errors(std::vector< tx_error > &&errs)
Moves an error into the error cache, evicting the oldest error if the cache has reached its maximum s...
auto check_uhs_id(const hash_t &uhs_id) const -> std::optional< tx_error >
Checks the cache for an error associated with the given UHS ID.
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
SipHash function to generate STL data structure hash keys for system IDs.
Definition hashmap.hpp:27
Messages atomizers and shards can use to transmit errors to the watchtower, and which the watchtower ...