OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
cbdc::shard::shard Class Reference

Database shard representing a fraction of the UTXO set. More...

#include <shard.hpp>

Public Member Functions

 shard (config::shard_range_t prefix_range)
 Constructor.
 
auto open_db (const std::string &db_dir) -> std::optional< std::string >
 Creates or restores this shard's UTXO database.
 
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 forward to the atomizer or a transaction error to forward to the watchtower.
 
auto digest_block (const cbdc::atomizer::block &blk) -> bool
 Updates records to reflect changes from a new, contiguous transaction block from the atomizer.
 
auto best_block_height () const -> uint64_t
 Returns the height of the most recently digested block.
 

Detailed Description

Database shard representing a fraction of the UTXO set.

Receives transactions from sentinels, and generates transaction input validity attestations to forward to the atomizer. Receives confirmed transaction blocks from the atomizer to update its internal state.

Definition at line 36 of file shard.hpp.

Constructor & Destructor Documentation

◆ shard()

cbdc::shard::shard::shard ( config::shard_range_t prefix_range)
explicit

Constructor.

Call open_db() before using.

Parameters
prefix_rangethe inclusive UHS ID prefix range which this shard should track.

Definition at line 11 of file shard.cpp.

Member Function Documentation

◆ best_block_height()

auto cbdc::shard::shard::best_block_height ( ) const -> uint64_t
nodiscard

Returns the height of the most recently digested block.

Returns
the best block height.

Definition at line 169 of file shard.cpp.

◆ digest_block()

auto cbdc::shard::shard::digest_block ( const cbdc::atomizer::block & blk) -> bool

Updates records to reflect changes from a new, contiguous transaction block from the atomizer.

Deletes spent UTXOs and adds new ones. Increments the best block height. Accepts only blocks whose block height is one greater than the previous best block height; rejects non-contiguous blocks.

Parameters
blkthe block to digest.
Returns
true if the shard successfully digested the block. False if the block height is not contiguous.

Definition at line 57 of file shard.cpp.

◆ digest_transaction()

auto cbdc::shard::shard::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 forward to the atomizer or a transaction error to forward to the watchtower.

Parameters
txthe transaction to digest.
Returns
result message to forward.

Definition at line 105 of file shard.cpp.

References cbdc::atomizer::tx_notify_request::m_attestations, cbdc::atomizer::tx_notify_request::m_block_height, and cbdc::atomizer::tx_notify_request::m_tx.

◆ open_db()

auto cbdc::shard::shard::open_db ( const std::string & db_dir) -> std::optional<std::string>

Creates or restores this shard's UTXO database.

Parameters
db_dirrelative path to the directory to create or read this shard's database files.
Returns
nullopt if the shard successfully opened the database. Otherwise, returns the error message.

Definition at line 14 of file shard.cpp.


The documentation for this class was generated from the following files: