OpenCBDC Transaction Processor
|
In-memory implementation of interface and status_interface. More...
#include <locking_shard.hpp>
Public Member Functions | |
locking_shard (const std::pair< uint8_t, uint8_t > &output_range, std::shared_ptr< logging::log > logger, size_t completed_txs_cache_size, const std::string &preseed_file, config::options opts) | |
Constructor. | |
locking_shard ()=delete | |
auto | lock_outputs (std::vector< tx > &&txs, const hash_t &dtx_id) -> std::optional< std::vector< bool > > final |
Attempts to lock the input hashes for the given batch of transactions. | |
auto | apply_outputs (std::vector< bool > &&complete_txs, const hash_t &dtx_id) -> bool final |
Selectively applies the transactions from a previous lock operation. | |
auto | discard_dtx (const hash_t &dtx_id) -> bool final |
Discards any cached information about a given distributed transaction. | |
void | stop () final |
Stops the locking shard from processing further commands. | |
auto | check_unspent (const hash_t &uhs_id) -> std::optional< bool > final |
Queries whether the shard's UHS contains the given UHS ID. | |
auto | check_tx_id (const hash_t &tx_id) -> std::optional< bool > final |
Queries whether the given TX ID is confirmed in the cache of recently confirmed TX IDs. | |
![]() | |
interface (std::pair< uint8_t, uint8_t > output_range) | |
Constructor. | |
virtual | ~interface ()=default |
interface ()=delete | |
interface (const interface &)=delete | |
auto | operator= (const interface &) -> interface &=delete |
interface (interface &&)=delete | |
auto | operator= (interface &&) -> interface &=delete |
virtual auto | hash_in_shard_range (const hash_t &h) const -> bool |
Returns whether a given hash is within the shard's range. | |
![]() | |
status_interface ()=default | |
virtual | ~status_interface ()=default |
status_interface (const status_interface &)=default | |
auto | operator= (const status_interface &) -> status_interface &=default |
status_interface (status_interface &&)=default | |
auto | operator= (status_interface &&) -> status_interface &=default |
In-memory implementation of interface and status_interface.
Definition at line 44 of file locking_shard.hpp.
cbdc::locking_shard::locking_shard::locking_shard | ( | const std::pair< uint8_t, uint8_t > & | output_range, |
std::shared_ptr< logging::log > | logger, | ||
size_t | completed_txs_cache_size, | ||
const std::string & | preseed_file, | ||
config::options | opts ) |
Constructor.
output_range | inclusive range of hash prefixes this shard is responsible for. |
logger | log instance. |
completed_txs_cache_size | number of confirmed TX IDs to keep before evicting the oldest TX ID. |
preseed_file | path to file containing shard pre-seeding data or empty string to disable pre-seeding. |
opts | configuration options. |
Definition at line 24 of file locking_shard.cpp.
|
delete |
|
finalvirtual |
Selectively applies the transactions from a previous lock operation.
Follows confirmation from other shards via the coordinator. Completes a previous lock operation by deleting the input hashes and adding the output hashes of confirmed transactions, and unlocking the input hashes of aborted transactions. Preceded by a lock operation with the same dtx_id.
complete_txs | vector of truth values indicating which txs from the previous lock operation the shard should apply (true ), and which it should cancel (false ). Must have the same size and order as txs from lock. |
dtx_id | distributed transaction ID of the previous lock operation. |
Implements cbdc::locking_shard::interface.
Definition at line 135 of file locking_shard.cpp.
References cbdc::transaction::compact_tx::m_id, cbdc::transaction::compact_tx::m_inputs, cbdc::locking_shard::tx::m_tx, cbdc::transaction::compact_tx::m_uhs_outputs, and cbdc::to_string().
|
nodiscardfinalvirtual |
Queries whether the given TX ID is confirmed in the cache of recently confirmed TX IDs.
tx_id | TX ID to query. |
Implements cbdc::locking_shard::status_interface.
Definition at line 195 of file locking_shard.cpp.
|
nodiscardfinalvirtual |
Queries whether the shard's UHS contains the given UHS ID.
uhs_id | UHS ID to query. |
Implements cbdc::locking_shard::status_interface.
Definition at line 188 of file locking_shard.cpp.
|
finalvirtual |
Discards any cached information about a given distributed transaction.
Called as the final step of a distributed transaction once all other participating shards have finished processing apply_outputs.
dtx_id | distributed transaction ID of a previous apply command. |
Implements cbdc::locking_shard::interface.
Definition at line 15 of file locking_shard.cpp.
|
finalvirtual |
Attempts to lock the input hashes for the given batch of transactions.
Only considers input hashes within this shard's range. The batch of transactions is a single distributed transaction, or 'dtx'. The coordinator that communicates with instances of this class provides a globally unique dtx ID along for each dtx. The provided vector of transactions may be a subset of the overall batch only including transactions relevant to this shard.
txs | list of txs to attempt to lock. |
dtx_id | distributed tx ID for lock operation. |
Implements cbdc::locking_shard::interface.
Definition at line 78 of file locking_shard.cpp.
|
finalvirtual |
Stops the locking shard from processing further commands.
Any future calls to methods of this class will return a failure result.
Implements cbdc::locking_shard::interface.
Definition at line 184 of file locking_shard.cpp.