OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
atomizer.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_H_
7#define OPENCBDC_TX_SRC_ATOMIZER_ATOMIZER_H_
8
9#include "block.hpp"
13
14#include <map>
15#include <mutex>
16#include <unordered_map>
17#include <unordered_set>
18
19namespace cbdc::atomizer {
32 class atomizer {
33 public:
38 atomizer(uint64_t best_height, size_t stxo_cache_depth);
39
40 ~atomizer() = default;
41
42 atomizer() = delete;
43 atomizer(const atomizer&) = delete;
44 auto operator=(const atomizer&) -> atomizer& = delete;
45 atomizer(atomizer&&) = delete;
46 auto operator=(atomizer&&) -> atomizer& = delete;
47
62 [[nodiscard]] auto insert(uint64_t block_height,
64 std::unordered_set<uint32_t> attestations)
65 -> std::optional<watchtower::tx_error>;
66
82 [[nodiscard]] auto insert_complete(uint64_t oldest_attestation,
84 -> std::optional<watchtower::tx_error>;
85
94 [[nodiscard]] auto make_block()
95 -> std::pair<cbdc::atomizer::block,
96 std::vector<watchtower::tx_error>>;
97
101 [[nodiscard]] auto pending_transactions() const -> size_t;
102
105 [[nodiscard]] auto height() const -> uint64_t;
106
109 [[nodiscard]] auto serialize() -> buffer;
110
114 void deserialize(serializer& buf);
115
116 auto operator==(const atomizer& other) const -> bool;
117
118 private:
119 std::vector<std::unordered_map<transaction::compact_tx,
120 std::unordered_set<uint32_t>,
121 transaction::compact_tx_hasher>>
122 m_txs;
123
124 // These maps should be keyed/salted for safety. For now they
125 // use input values directly as an optimization.
126 std::vector<transaction::compact_tx> m_complete_txs;
127
128 std::vector<std::unordered_set<hash_t, hashing::null>> m_spent;
129
130 uint64_t m_best_height{};
131 size_t m_spent_cache_depth;
132
133 [[nodiscard]] auto get_notification_offset(uint64_t block_height) const
134 -> uint64_t;
135
136 [[nodiscard]] auto
137 check_notification_offset(uint64_t height_offset,
138 const transaction::compact_tx& tx) const
139 -> std::optional<watchtower::tx_error>;
140
141 [[nodiscard]] auto check_stxo_cache(const transaction::compact_tx& tx,
142 uint64_t cache_check_range) const
143 -> std::optional<watchtower::tx_error>;
144
145 void add_tx_to_stxo_cache(const transaction::compact_tx& tx);
146 };
147}
148
149#endif // OPENCBDC_TX_SRC_ATOMIZER_ATOMIZER_H_
Atomizer implementation.
Definition atomizer.hpp:32
atomizer(atomizer &&)=delete
auto operator=(const atomizer &) -> atomizer &=delete
atomizer(const atomizer &)=delete
auto pending_transactions() const -> size_t
Returns the number of complete transactions waiting to be included in the next block.
Definition atomizer.cpp:158
auto insert(uint64_t block_height, transaction::compact_tx tx, std::unordered_set< uint32_t > attestations) -> std::optional< watchtower::tx_error >
Attempts to add the specified shard attestations for a specified transaction at or later than the spe...
Definition atomizer.cpp:44
auto height() const -> uint64_t
Returns the height of the most recent block.
Definition atomizer.cpp:162
auto operator=(atomizer &&) -> atomizer &=delete
auto serialize() -> buffer
Serializes the internal state of the atomizer into a buffer.
Definition atomizer.cpp:174
void deserialize(serializer &buf)
Replaces the state of this atomizer instance with the provided serialized state data.
Definition atomizer.cpp:184
auto make_block() -> std::pair< cbdc::atomizer::block, std::vector< watchtower::tx_error > >
Adds the current set of complete transactions to a new block and returns it for storage and transmiss...
Definition atomizer.cpp:14
auto insert_complete(uint64_t oldest_attestation, transaction::compact_tx &&tx) -> std::optional< watchtower::tx_error >
Attempts to add the given compact transaction to the list of complete transactions pending for inclus...
Definition atomizer.cpp:134
Buffer to store and retrieve byte data.
Definition buffer.hpp:15
Interface for serializing objects into and out of raw bytes representations.
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
Batch of compact transactions settled by the atomizer.
Definition block.hpp:19
A condensed, hash-only transaction representation.
Messages atomizers and shards can use to transmit errors to the watchtower, and which the watchtower ...