OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
atomizer_client.cpp
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#include "atomizer_client.hpp"
7
10
11namespace cbdc {
13 const cbdc::config::options& opts,
14 const std::shared_ptr<logging::log>& logger,
15 const std::string& wallet_file,
16 const std::string& client_file)
17 : client(opts, logger, wallet_file, client_file),
18 m_wc(opts.m_watchtower_client_endpoints[0]),
19 m_logger(logger),
20 m_opts(opts) {}
21
23 m_atomizer_network.close();
24 }
25
27 m_atomizer_network.cluster_connect(m_opts.m_atomizer_endpoints);
28 if(!m_atomizer_network.connected_to_one()) {
29 m_logger->warn("Failed to connect to any atomizers");
30 }
31
32 if(!m_wc.init()) {
33 m_logger->warn("Failed to initialize watchtower client");
34 }
35
36 return true;
37 }
38
39 auto atomizer_client::sync() -> bool {
41 for(const auto& [tx_id, tx] : pending_txs()) {
42 auto ctx = transaction::compact_tx(tx);
43 auto [it, success] = tus.insert({ctx.m_id, {}});
44 assert(success);
45 it->second.insert(it->second.end(),
46 ctx.m_inputs.begin(),
47 ctx.m_inputs.end());
48 it->second.insert(it->second.end(),
49 ctx.m_uhs_outputs.begin(),
50 ctx.m_uhs_outputs.end());
51 }
52
53 for(const auto& [tx_id, in] : pending_inputs()) {
54 tus.insert({tx_id, {in.hash()}});
55 }
56
58
59 m_logger->debug("Checking watchtower state...");
60
61 auto res = m_wc.request_status_update(req);
62
63 bool success{true};
64 for(const auto& [tx_id, uhs_states] : res->states()) {
65 for(const auto& s : uhs_states) {
67 && (s.status() != cbdc::watchtower::search_status::spent)) {
68 m_logger->warn("Tx ID:",
69 to_string(tx_id),
70 ", UHS ID:",
71 to_string(s.uhs_id()),
72 ", status:",
73 static_cast<uint32_t>(s.status()));
74 success = false;
75 continue;
76 }
77 break;
78 }
79 if(!success) {
80 continue;
81 }
82 success = confirm_transaction(tx_id);
83 }
84
85 return success;
86 }
87
89 -> bool {
91 auto ctx = transaction::compact_tx(mint_tx);
92 for(size_t i = 0; i < m_opts.m_attestation_threshold; i++) {
93 auto att
94 = ctx.sign(m_secp.get(), m_opts.m_sentinel_private_keys[i]);
95 ctx.m_attestations.insert(att);
96 }
97 msg.m_tx = std::move(ctx);
98 msg.m_block_height = m_wc.request_best_block_height()->height();
99 return m_atomizer_network.send_to_one(atomizer::request{msg});
100 }
101}
auto init_derived() -> bool override
Initializes the atomizer client.
auto sync() -> bool override
Update the client with the latest state from the watchtower.
auto send_mint_tx(const transaction::full_tx &mint_tx) -> bool override
Sends the given transaction directly to the atomizer cluster.
External client for sending new transactions to the system.
void close()
Shuts down the network listener and all existing peer connections.
Network request to interact with the Watchtower's status update service.
std::variant< tx_notify_request, prune_request, get_block_request > request
Atomizer RPC request.
@ spent
The STXO set contains the requested UHS ID.
@ unspent
The UTXO set contains the requested UHS ID.
std::unordered_map< hash_t, std::vector< hash_t >, hashing::const_sip_hash< hash_t > > tx_id_uhs_ids
Set of UHS IDs to query, keyed by Tx IDs.
auto to_string(const hash_t &val) -> std::string
Converts a hash to a hexadecimal string.
transaction::compact_tx m_tx
Compact transaction associated with the notification.
uint64_t m_block_height
Block height at which the given input attestations are valid.
Project-wide configuration options.
Definition config.hpp:132
A condensed, hash-only transaction representation.
A complete transaction.
Watchtower core functionality.