OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
shard.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_SHARD_SHARD_H_
11#define OPENCBDC_TX_SRC_SHARD_SHARD_H_
12
22
23#include <atomic>
24#include <leveldb/db.h>
25#include <leveldb/write_batch.h>
26#include <memory>
27#include <mutex>
28#include <thread>
29#include <unordered_set>
30
31namespace cbdc::shard {
36 class shard {
37 public:
40 explicit shard(config::shard_range_t prefix_range);
41
45 auto open_db(const std::string& db_dir) -> std::optional<std::string>;
46
53 -> std::variant<atomizer::tx_notify_request, watchtower::tx_error>;
54
62 auto digest_block(const cbdc::atomizer::block& blk) -> bool;
63
66 [[nodiscard]] auto best_block_height() const -> uint64_t;
67
68 private:
69 [[nodiscard]] auto is_output_on_shard(const hash_t& uhs_hash) const
70 -> bool;
71
72 void update_snapshot();
73
74 std::unique_ptr<leveldb::DB> m_db;
75 leveldb::ReadOptions m_read_options;
76 leveldb::WriteOptions m_write_options;
77
78 uint64_t m_best_block_height{};
79
80 std::shared_ptr<const leveldb::Snapshot> m_snp;
81 uint64_t m_snp_height{};
82 std::shared_mutex m_snp_mut;
83
84 const std::string m_best_block_height_key = "bestBlockHeight";
85
86 std::pair<uint8_t, uint8_t> m_prefix_range;
87 };
88}
89
90#endif // OPENCBDC_TX_SRC_SHARD_SHARD_H_
Database shard representing a fraction of the UTXO set.
Definition shard.hpp:36
auto open_db(const std::string &db_dir) -> std::optional< std::string >
Creates or restores this shard's UTXO database.
Definition shard.cpp:14
auto best_block_height() const -> uint64_t
Returns the height of the most recently digested block.
Definition shard.cpp:169
auto digest_block(const cbdc::atomizer::block &blk) -> bool
Updates records to reflect changes from a new, contiguous transaction block from the atomizer.
Definition shard.cpp:57
auto digest_transaction(transaction::compact_tx tx) -> std::variant< atomizer::tx_notify_request, watchtower::tx_error >
Checks the validity of a provided transaction's inputs, and returns a transaction notification to for...
Definition shard.cpp:105
Tools for reading options from a configuration file and building application-specific parameter sets ...
std::pair< uint8_t, uint8_t > shard_range_t
[start, end] inclusive.
Definition config.hpp:129
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 ...