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

Atomizer implementation. More...

#include <atomizer.hpp>

Public Member Functions

 atomizer (uint64_t best_height, size_t stxo_cache_depth)
 Constructor.
 
 ~atomizer ()=default
 
 atomizer ()=delete
 
 atomizer (const atomizer &)=delete
 
auto operator= (const atomizer &) -> atomizer &=delete
 
 atomizer (atomizer &&)=delete
 
auto operator= (atomizer &&) -> atomizer &=delete
 
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 specified block height.
 
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 inclusion in the next block.
 
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 transmission to subscribers.
 
auto pending_transactions () const -> size_t
 Returns the number of complete transactions waiting to be included in the next block.
 
auto height () const -> uint64_t
 Returns the height of the most recent block.
 
auto serialize () -> buffer
 Serializes the internal state of the atomizer into a buffer.
 
void deserialize (serializer &buf)
 Replaces the state of this atomizer instance with the provided serialized state data.
 
auto operator== (const atomizer &other) const -> bool
 

Detailed Description

Atomizer implementation.

Aggregates transaction notifications and input attestations. Accepts transactions with a full set of attestations, and provides block construction functionality. Keeps track of recently spent UHS IDs and the block height at which they were spent to enable input attestations that are not valid as of the most recent block height to still be used. This works because inputs covered by attestations with a block height lower than the most recent block will be in the spent cache if they are unspendable. Otherwise, the atomizer can be certain the inputs not have been spent.

Warning
Not thread-safe. Does not persist the atomizer internal state.

Definition at line 32 of file atomizer.hpp.

Constructor & Destructor Documentation

◆ atomizer() [1/4]

cbdc::atomizer::atomizer::atomizer ( uint64_t best_height,
size_t stxo_cache_depth )

Constructor.

Parameters
best_heightstarting block height.
stxo_cache_depthmaximum number of recent blocks over which to maintain the spent UHS IDs cache.

Definition at line 166 of file atomizer.cpp.

◆ ~atomizer()

cbdc::atomizer::atomizer::~atomizer ( )
default

◆ atomizer() [2/4]

cbdc::atomizer::atomizer::atomizer ( )
delete

◆ atomizer() [3/4]

cbdc::atomizer::atomizer::atomizer ( const atomizer & )
delete

◆ atomizer() [4/4]

cbdc::atomizer::atomizer::atomizer ( atomizer && )
delete

Member Function Documentation

◆ deserialize()

void cbdc::atomizer::atomizer::deserialize ( cbdc::serializer & buf)

Replaces the state of this atomizer instance with the provided serialized state data.

Parameters
bufserialized atomizer state produced with serialize.

Definition at line 184 of file atomizer.cpp.

◆ height()

auto cbdc::atomizer::atomizer::height ( ) const -> uint64_t
nodiscard

Returns the height of the most recent block.

Returns
block height.

Definition at line 162 of file atomizer.cpp.

◆ insert()

auto cbdc::atomizer::atomizer::insert ( uint64_t block_height,
transaction::compact_tx tx,
std::unordered_set< uint32_t > attestations ) -> std::optional<watchtower::tx_error>
nodiscard

Attempts to add the specified shard attestations for a specified transaction at or later than the specified block height.

Creates a new pending transaction if necessary. If the provided transaction is already pending, merges the new attestations. Returns an error to forward to the watchtower if:

  • The block height is below the lower limit of the STXO cache.
  • The STXO cache contains one of the transaction's inputs (double spend).
    Parameters
    block_heightthe block height at which the shard provided the attestations.
    txthe complete transaction.
    attestationsa set of the input indices to which the shard attested the validity.
    Returns
    an error to forward to the watchtower, if necessary.

Definition at line 44 of file atomizer.cpp.

◆ insert_complete()

auto cbdc::atomizer::atomizer::insert_complete ( uint64_t oldest_attestation,
transaction::compact_tx && tx ) -> std::optional<watchtower::tx_error>
nodiscard

Attempts to add the given compact transaction to the list of complete transactions pending for inclusion in the next block.

If the block height of the oldest attestation in the transaction precedes the height of the earliest block in the spent UHS ID cache, discards the transaction and returns a watchtower error. If the compact transaction attempts to spend a UHS ID matching one in the spent UHS ID cache, discards the compact TX and returns a watchtower error.

Parameters
oldest_attestationblock height of the oldest shard attestation in the notification.
txcompact transaction to insert in the next block.
Returns
std::nullopt if the operation successfully inserted the transaction into the next block, or the relevant watchtower error on failure.

Definition at line 134 of file atomizer.cpp.

◆ make_block()

auto cbdc::atomizer::atomizer::make_block ( ) -> std::pair<cbdc::atomizer::block, std::vector<watchtower::tx_error>>
nodiscard

Adds the current set of complete transactions to a new block and returns it for storage and transmission to subscribers.

Rotates the STXO cache, evicting the oldest set of transactions. Generates and returns a set of errors containing an error for each incomplete transaction in the set of evicted transactions, or an empty vector if there are no such errors.

Returns
a pair containing the resultant block and errors to forward to the watchtower if necessary.

Definition at line 14 of file atomizer.cpp.

References cbdc::atomizer::block::m_height, and cbdc::atomizer::block::m_transactions.

◆ operator=() [1/2]

auto cbdc::atomizer::atomizer::operator= ( atomizer && ) -> atomizer &=delete
delete

◆ operator=() [2/2]

auto cbdc::atomizer::atomizer::operator= ( const atomizer & ) -> atomizer &=delete
delete

◆ operator==()

auto cbdc::atomizer::atomizer::operator== ( const atomizer & other) const -> bool

Definition at line 195 of file atomizer.cpp.

◆ pending_transactions()

auto cbdc::atomizer::atomizer::pending_transactions ( ) const -> size_t
nodiscard

Returns the number of complete transactions waiting to be included in the next block.

Returns
number of transactions.

Definition at line 158 of file atomizer.cpp.

◆ serialize()

auto cbdc::atomizer::atomizer::serialize ( ) -> buffer
nodiscard

Serializes the internal state of the atomizer into a buffer.

Returns
serialized atomizer state.

Definition at line 174 of file atomizer.cpp.

References cbdc::buffer.


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