OpenCBDC Transaction Processor
Loading...
Searching...
No Matches
tx_error_messages.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
7
10
11namespace cbdc::watchtower {
13 pkt >> *this;
14 }
15
16 auto tx_error_sync::operator==(const tx_error_sync& /* rhs */) const
17 -> bool {
18 return true;
19 }
20
24
25 auto tx_error_inputs_dne::input_uhs_ids() const -> std::vector<hash_t> {
26 return m_input_uhs_ids;
27 }
28
29 tx_error_inputs_dne::tx_error_inputs_dne(std::vector<hash_t> input_uhs_ids)
30 : m_input_uhs_ids(std::move(input_uhs_ids)) {}
31
33 -> bool {
34 return m_input_uhs_ids == rhs.m_input_uhs_ids;
35 }
36
40
41 auto
43 -> bool {
44 return true;
45 }
46
50
51 auto
53 -> bool {
54 return true;
55 }
56
60
62 -> std::unordered_set<hash_t, hashing::null> {
63 return m_input_uhs_ids;
64 }
65
67 std::unordered_set<hash_t, hashing::null> input_uhs_ids)
68 : m_input_uhs_ids(std::move(input_uhs_ids)) {}
69
70 auto
72 -> bool {
73 return rhs.m_input_uhs_ids == m_input_uhs_ids;
74 }
75
77 pkt >> *this;
78 }
79
80 auto tx_error::tx_id() const -> hash_t {
81 return m_tx_id;
82 }
83
84 auto tx_error::info() const -> tx_error_info {
85 return *m_info;
86 }
87
88 auto tx_error::to_string() const -> std::string {
89 const auto* ret = "Unknown error";
90 std::visit(
92 [&](const tx_error_sync& /* v */) {
93 ret = "Shard is not synchronized with atomizer";
94 },
95 [&](const tx_error_inputs_dne& /* v */) {
96 ret = "Input(s) do not exist";
97 },
98 [&](const tx_error_stxo_range& /* v */) {
99 ret = "Transaction not in STXO Cache range";
100 },
101 [&](const tx_error_inputs_spent& /* v */) {
102 ret = "Input(s) are already spent";
103 },
104 [&](const tx_error_incomplete& /* v */) {
105 ret = "Did not receive attestations to all inputs before "
106 "STXO cache expired";
107 }},
108 *m_info);
109 return ret;
110 }
111
112 auto tx_error::operator==(const tx_error& rhs) const -> bool {
113 return rhs.m_tx_id == m_tx_id && *rhs.m_info == *m_info;
114 }
115
116 tx_error::tx_error(const hash_t& tx_id, const tx_error_sync& err)
117 : m_tx_id(tx_id),
118 m_info(std::make_shared<decltype(m_info)::element_type>(err)) {}
119
121 : m_tx_id(tx_id),
122 m_info(std::make_shared<decltype(m_info)::element_type>(err)) {}
123
125 : m_tx_id(tx_id),
126 m_info(std::make_shared<decltype(m_info)::element_type>(err)) {}
127
129 : m_tx_id(tx_id),
130 m_info(std::make_shared<decltype(m_info)::element_type>(err)) {}
131
134 : m_tx_id(tx_id),
135 m_info(std::make_shared<decltype(m_info)::element_type>(err)) {}
136}
137
138namespace cbdc {
141 -> cbdc::serializer& {
142 packet << err.m_input_uhs_ids;
143 return packet;
144 }
145
148 -> cbdc::serializer& {
149 packet >> err.m_input_uhs_ids;
150 return packet;
151 }
152
155 -> cbdc::serializer& {
156 packet << err.m_input_uhs_ids;
157 return packet;
158 }
159
162 -> cbdc::serializer& {
163 packet >> err.m_input_uhs_ids;
164 return packet;
165 }
166
169 -> cbdc::serializer& {
170 return packet << err.m_tx_id << *err.m_info;
171 }
172
174 -> cbdc::serializer& {
175 packet >> err.m_tx_id;
176 err.m_info = std::make_shared<decltype(err.m_info)::element_type>(
182 return packet;
183 }
184}
Interface for serializing objects into and out of raw bytes representations.
Indicates a shard that tried to process a given transaction could not locate one or more of the trans...
auto input_uhs_ids() const -> std::vector< hash_t >
Returns the UHS IDs of the inputs that caused this error.
auto operator==(const tx_error_inputs_dne &rhs) const -> bool
Indicates that the given transaction contains one or more inputs that have already been spent in othe...
auto input_uhs_ids() const -> std::unordered_set< hash_t, hashing::null >
Returns the UHS IDs of the inputs that caused this error.
auto operator==(const tx_error_inputs_spent &rhs) const -> bool
Wrapper for transaction errors.
auto to_string() const -> std::string
Returns a human-friendly description of the error.
auto tx_id() const -> hash_t
Returns the transaction ID to which this error pertains.
auto info() const -> tx_error_info
Returns the type and associated information about this error.
auto operator==(const tx_error &rhs) const -> bool
std::variant< tx_error_sync, tx_error_inputs_dne, tx_error_stxo_range, tx_error_incomplete, tx_error_inputs_spent > tx_error_info
auto get_variant(serializer &deser) -> std::variant< Ts... >
Deserializes a variant where the alternatives are all default constructible or all are not default co...
std::array< unsigned char, cbdc::hash_size > hash_t
SHA256 hash container.
auto operator>>(serializer &deser, parsec::agent::rpc::request &req) -> serializer &
auto operator<<(serializer &ser, const parsec::agent::rpc::request &req) -> serializer &
Variant handler template.
Indicates that the atomizer did not receive enough attestations for a particular transaction from sha...
auto operator==(const tx_error_incomplete &rhs) const -> bool
Indicates that a shard did not attest to this transaction recently enough for the atomizer to check i...
auto operator==(const tx_error_stxo_range &rhs) const -> bool
Indicates a shard that tried to process a given transaction was out of sync with the atomizer,...
auto operator==(const tx_error_sync &rhs) const -> bool
Messages atomizers and shards can use to transmit errors to the watchtower, and which the watchtower ...