@@ -111,19 +111,23 @@ namespace cbdc::sentinel_2pc {
111
111
return true ;
112
112
}
113
113
114
+ controller::~controller () {
115
+ stop ();
116
+ }
117
+
114
118
void controller::validation_worker () {
115
119
while (m_running) {
116
120
auto v = queued_validation ();
117
121
if (m_validation_queue.pop (v)) {
118
122
auto [tx, cb] = v;
119
- cb (std::move (tx) , transaction::validation::check_tx (tx));
123
+ cb (tx , transaction::validation::check_tx (tx));
120
124
}
121
125
}
122
126
}
123
127
124
128
auto controller::validate_tx (const transaction::full_tx& tx,
125
129
validation_callback cb) -> bool {
126
- m_validation_queue.push ({std::move (tx) , std::move (cb)});
130
+ m_validation_queue.push ({tx , std::move (cb)});
127
131
return true ;
128
132
}
129
133
@@ -133,22 +137,22 @@ namespace cbdc::sentinel_2pc {
133
137
if (m_attestation_queue.pop (v)) {
134
138
auto [tx, cb] = v;
135
139
auto compact_tx = cbdc::transaction::compact_tx (tx);
136
- cb (std::move (tx) , compact_tx.sign (m_secp.get (), m_privkey));
140
+ cb (tx , compact_tx.sign (m_secp.get (), m_privkey));
137
141
}
138
142
}
139
143
}
140
144
141
145
auto controller::attest_tx (const transaction::full_tx& tx,
142
146
attestation_callback cb) -> bool {
143
- m_attestation_queue.push ({std::move (tx) , std::move (cb)});
147
+ m_attestation_queue.push ({tx , std::move (cb)});
144
148
return true ;
145
149
}
146
150
147
151
auto controller::execute_transaction (
148
152
transaction::full_tx tx,
149
153
execute_result_callback_type result_callback) -> bool {
150
154
return controller::validate_tx (
151
- std::move (tx) ,
155
+ tx ,
152
156
[&, result_callback](
153
157
const transaction::full_tx& tx2,
154
158
std::optional<cbdc::transaction::validation::tx_error> err) {
@@ -166,10 +170,7 @@ namespace cbdc::sentinel_2pc {
166
170
}
167
171
168
172
auto compact_tx = cbdc::transaction::compact_tx (tx2);
169
- gather_attestations (std::move (tx2),
170
- std::move (result_callback),
171
- compact_tx,
172
- {});
173
+ gather_attestations (tx2, result_callback, compact_tx, {});
173
174
return ;
174
175
});
175
176
}
@@ -194,7 +195,7 @@ namespace cbdc::sentinel_2pc {
194
195
transaction::full_tx tx,
195
196
validate_result_callback_type result_callback) -> bool {
196
197
return controller::validate_tx (
197
- std::move (tx) ,
198
+ tx ,
198
199
[&, result_callback](
199
200
const transaction::full_tx& tx2,
200
201
std::optional<cbdc::transaction::validation::tx_error> err) {
@@ -203,7 +204,7 @@ namespace cbdc::sentinel_2pc {
203
204
return ;
204
205
}
205
206
controller::attest_tx (
206
- std::move ( tx2) ,
207
+ tx2,
207
208
[&, result_callback](
208
209
const transaction::full_tx& /* tx3 */ ,
209
210
std::optional<cbdc::sentinel::validate_response> res) {
@@ -233,17 +234,24 @@ namespace cbdc::sentinel_2pc {
233
234
234
235
void controller::stop () {
235
236
m_running = false ;
237
+ m_rpc_server.reset ();
238
+
239
+ m_validation_queue.clear ();
240
+ m_attestation_queue.clear ();
241
+
236
242
for (auto & t : m_validation_threads) {
237
243
if (t.joinable ()) {
238
244
t.join ();
239
245
}
240
246
}
247
+ m_validation_threads.clear ();
241
248
242
249
for (auto & t : m_attestation_threads) {
243
250
if (t.joinable ()) {
244
251
t.join ();
245
252
}
246
253
}
254
+ m_attestation_threads.clear ();
247
255
}
248
256
249
257
void controller::gather_attestations (
@@ -252,10 +260,10 @@ namespace cbdc::sentinel_2pc {
252
260
const transaction::compact_tx& ctx,
253
261
std::unordered_set<size_t > requested) {
254
262
if (ctx.m_attestations .size () < m_opts.m_attestation_threshold ) {
255
- if (ctx.m_attestations .size () == 0 ) {
263
+ if (ctx.m_attestations .empty () ) {
256
264
// Self-attest first
257
265
controller::attest_tx (
258
- std::move (tx) ,
266
+ tx ,
259
267
[&, ctx, result_callback](const transaction::full_tx& tx2,
260
268
validate_result res) {
261
269
validate_result_handler (res,
@@ -297,7 +305,7 @@ namespace cbdc::sentinel_2pc {
297
305
void
298
306
controller::send_compact_tx (const transaction::compact_tx& ctx,
299
307
execute_result_callback_type result_callback) {
300
- auto cb = [&, this , ctx, res_cb = std::move (result_callback)](
308
+ auto cb = [&, ctx, res_cb = std::move (result_callback)](
301
309
std::optional<bool > res) {
302
310
result_handler (res, res_cb);
303
311
};
0 commit comments