OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
block_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_BLOCK_CACHE_H_
11#define OPENCBDC_TX_SRC_WATCHTOWER_BLOCK_CACHE_H_
12
15
16#include <forward_list>
17#include <memory>
18#include <mutex>
19#include <optional>
20#include <queue>
21#include <shared_mutex>
22#include <unordered_map>
23
24namespace cbdc::watchtower {
27 using block_cache_result = std::pair<size_t, hash_t>;
31 public:
32 block_cache() = delete;
33
36 explicit block_cache(size_t k);
37
42
47 auto check_unspent(const hash_t& uhs_id) const
48 -> std::optional<block_cache_result>;
49
54 auto check_spent(const hash_t& uhs_id) const
55 -> std::optional<block_cache_result>;
56
59 auto best_block_height() const -> uint64_t;
60
61 private:
62 size_t m_k_blks;
63 std::queue<cbdc::atomizer::block> m_blks;
64 uint64_t m_best_blk_height{0};
65 std::unordered_map<hash_t,
68 m_unspent_ids;
69 std::unordered_map<hash_t,
72 m_spent_ids;
73 };
74}
75
76#endif // OPENCBDC_TX_SRC_WATCHTOWER_BLOCK_CACHE_H_
Stores a set of blocks in memory and maintains an index of the UHS IDs contained therein.
void push_block(cbdc::atomizer::block &&blk)
Moves a block into the block cache, evicting the oldest block if the cache has reached its maximum si...
auto check_unspent(const hash_t &uhs_id) const -> std::optional< block_cache_result >
Checks to see if the given UHS ID is spendable according to the blocks in the cache.
auto best_block_height() const -> uint64_t
Returns the block height of the highest observed block.
auto check_spent(const hash_t &uhs_id) const -> std::optional< block_cache_result >
Checks to see if the given UHS ID has been spent according to the blocks in the cache.
std::pair< size_t, hash_t > block_cache_result
With respect to a particular UHS ID, block height + ID of containing transaction.
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
Batch of compact transactions settled by the atomizer.
Definition block.hpp:19
SipHash function to generate STL data structure hash keys for system IDs.
Definition hashmap.hpp:27