diff options
Diffstat (limited to 'src/exchange/taler-exchange-closer.c')
-rw-r--r-- | src/exchange/taler-exchange-closer.c | 55 |
1 files changed, 14 insertions, 41 deletions
diff --git a/src/exchange/taler-exchange-closer.c b/src/exchange/taler-exchange-closer.c index 89e439998..926c93554 100644 --- a/src/exchange/taler-exchange-closer.c +++ b/src/exchange/taler-exchange-closer.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of TALER | 2 | This file is part of TALER |
3 | Copyright (C) 2016-2020 Taler Systems SA | 3 | Copyright (C) 2016-2021 Taler Systems SA |
4 | 4 | ||
5 | TALER is free software; you can redistribute it and/or modify it under the | 5 | TALER is free software; you can redistribute it and/or modify it under the |
6 | terms of the GNU Affero General Public License as published by the Free Software | 6 | terms of the GNU Affero General Public License as published by the Free Software |
@@ -174,16 +174,14 @@ parse_wirewatch_config (void) | |||
174 | /** | 174 | /** |
175 | * Perform a database commit. If it fails, print a warning. | 175 | * Perform a database commit. If it fails, print a warning. |
176 | * | 176 | * |
177 | * @param session session to perform the commit for. | ||
178 | * @return status of commit | 177 | * @return status of commit |
179 | */ | 178 | */ |
180 | static enum GNUNET_DB_QueryStatus | 179 | static enum GNUNET_DB_QueryStatus |
181 | commit_or_warn (struct TALER_EXCHANGEDB_Session *session) | 180 | commit_or_warn (void) |
182 | { | 181 | { |
183 | enum GNUNET_DB_QueryStatus qs; | 182 | enum GNUNET_DB_QueryStatus qs; |
184 | 183 | ||
185 | qs = db_plugin->commit (db_plugin->cls, | 184 | qs = db_plugin->commit (db_plugin->cls); |
186 | session); | ||
187 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) | 185 | if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) |
188 | return qs; | 186 | return qs; |
189 | GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs) | 187 | GNUNET_log ((GNUNET_DB_STATUS_SOFT_ERROR == qs) |
@@ -195,26 +193,12 @@ commit_or_warn (struct TALER_EXCHANGEDB_Session *session) | |||
195 | 193 | ||
196 | 194 | ||
197 | /** | 195 | /** |
198 | * Closure for #expired_reserve_cb(). | ||
199 | */ | ||
200 | struct ExpiredReserveContext | ||
201 | { | ||
202 | |||
203 | /** | ||
204 | * Database session we are using. | ||
205 | */ | ||
206 | struct TALER_EXCHANGEDB_Session *session; | ||
207 | |||
208 | }; | ||
209 | |||
210 | |||
211 | /** | ||
212 | * Function called with details about expired reserves. | 196 | * Function called with details about expired reserves. |
213 | * We trigger the reserve closure by inserting the respective | 197 | * We trigger the reserve closure by inserting the respective |
214 | * closing record and prewire instructions into the respective | 198 | * closing record and prewire instructions into the respective |
215 | * tables. | 199 | * tables. |
216 | * | 200 | * |
217 | * @param cls a `struct ExpiredReserveContext *` | 201 | * @param cls NULL |
218 | * @param reserve_pub public key of the reserve | 202 | * @param reserve_pub public key of the reserve |
219 | * @param left amount left in the reserve | 203 | * @param left amount left in the reserve |
220 | * @param account_payto_uri information about the bank account that initially | 204 | * @param account_payto_uri information about the bank account that initially |
@@ -229,8 +213,6 @@ expired_reserve_cb (void *cls, | |||
229 | const char *account_payto_uri, | 213 | const char *account_payto_uri, |
230 | struct GNUNET_TIME_Absolute expiration_date) | 214 | struct GNUNET_TIME_Absolute expiration_date) |
231 | { | 215 | { |
232 | struct ExpiredReserveContext *erc = cls; | ||
233 | struct TALER_EXCHANGEDB_Session *session = erc->session; | ||
234 | struct GNUNET_TIME_Absolute now; | 216 | struct GNUNET_TIME_Absolute now; |
235 | struct TALER_WireTransferIdentifierRawP wtid; | 217 | struct TALER_WireTransferIdentifierRawP wtid; |
236 | struct TALER_Amount amount_without_fee; | 218 | struct TALER_Amount amount_without_fee; |
@@ -239,6 +221,7 @@ expired_reserve_cb (void *cls, | |||
239 | enum GNUNET_DB_QueryStatus qs; | 221 | enum GNUNET_DB_QueryStatus qs; |
240 | const struct TALER_EXCHANGEDB_AccountInfo *wa; | 222 | const struct TALER_EXCHANGEDB_AccountInfo *wa; |
241 | 223 | ||
224 | (void) cls; | ||
242 | /* NOTE: potential optimization: use custom SQL API to not | 225 | /* NOTE: potential optimization: use custom SQL API to not |
243 | fetch this: */ | 226 | fetch this: */ |
244 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 227 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
@@ -269,7 +252,6 @@ expired_reserve_cb (void *cls, | |||
269 | enum GNUNET_DB_QueryStatus qs; | 252 | enum GNUNET_DB_QueryStatus qs; |
270 | 253 | ||
271 | qs = db_plugin->get_wire_fee (db_plugin->cls, | 254 | qs = db_plugin->get_wire_fee (db_plugin->cls, |
272 | session, | ||
273 | wa->method, | 255 | wa->method, |
274 | expiration_date, | 256 | expiration_date, |
275 | &start_date, | 257 | &start_date, |
@@ -326,7 +308,6 @@ expired_reserve_cb (void *cls, | |||
326 | sizeof (*reserve_pub))); | 308 | sizeof (*reserve_pub))); |
327 | if (GNUNET_SYSERR != ret) | 309 | if (GNUNET_SYSERR != ret) |
328 | qs = db_plugin->insert_reserve_closed (db_plugin->cls, | 310 | qs = db_plugin->insert_reserve_closed (db_plugin->cls, |
329 | session, | ||
330 | reserve_pub, | 311 | reserve_pub, |
331 | now, | 312 | now, |
332 | account_payto_uri, | 313 | account_payto_uri, |
@@ -356,7 +337,7 @@ expired_reserve_cb (void *cls, | |||
356 | /* Reserve balance was almost zero OR soft error */ | 337 | /* Reserve balance was almost zero OR soft error */ |
357 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 338 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
358 | "Reserve was virtually empty, moving on\n"); | 339 | "Reserve was virtually empty, moving on\n"); |
359 | (void) commit_or_warn (session); | 340 | (void) commit_or_warn (); |
360 | return qs; | 341 | return qs; |
361 | } | 342 | } |
362 | 343 | ||
@@ -373,7 +354,6 @@ expired_reserve_cb (void *cls, | |||
373 | &buf_size); | 354 | &buf_size); |
374 | /* Commit our intention to execute the wire transfer! */ | 355 | /* Commit our intention to execute the wire transfer! */ |
375 | qs = db_plugin->wire_prepare_data_insert (db_plugin->cls, | 356 | qs = db_plugin->wire_prepare_data_insert (db_plugin->cls, |
376 | session, | ||
377 | wa->method, | 357 | wa->method, |
378 | buf, | 358 | buf, |
379 | buf_size); | 359 | buf_size); |
@@ -404,17 +384,16 @@ expired_reserve_cb (void *cls, | |||
404 | static void | 384 | static void |
405 | run_reserve_closures (void *cls) | 385 | run_reserve_closures (void *cls) |
406 | { | 386 | { |
407 | struct TALER_EXCHANGEDB_Session *session; | ||
408 | enum GNUNET_DB_QueryStatus qs; | 387 | enum GNUNET_DB_QueryStatus qs; |
409 | struct ExpiredReserveContext erc; | ||
410 | struct GNUNET_TIME_Absolute now; | 388 | struct GNUNET_TIME_Absolute now; |
411 | 389 | ||
412 | (void) cls; | 390 | (void) cls; |
413 | task = NULL; | 391 | task = NULL; |
414 | if (NULL == (session = db_plugin->get_session (db_plugin->cls))) | 392 | if (GNUNET_SYSERR == |
393 | db_plugin->preflight (db_plugin->cls)) | ||
415 | { | 394 | { |
416 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 395 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
417 | "Failed to obtain database session!\n"); | 396 | "Failed to obtain database connection!\n"); |
418 | global_ret = EXIT_FAILURE; | 397 | global_ret = EXIT_FAILURE; |
419 | GNUNET_SCHEDULER_shutdown (); | 398 | GNUNET_SCHEDULER_shutdown (); |
420 | return; | 399 | return; |
@@ -422,7 +401,6 @@ run_reserve_closures (void *cls) | |||
422 | 401 | ||
423 | if (GNUNET_OK != | 402 | if (GNUNET_OK != |
424 | db_plugin->start (db_plugin->cls, | 403 | db_plugin->start (db_plugin->cls, |
425 | session, | ||
426 | "aggregator reserve closures")) | 404 | "aggregator reserve closures")) |
427 | { | 405 | { |
428 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 406 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
@@ -431,30 +409,26 @@ run_reserve_closures (void *cls) | |||
431 | GNUNET_SCHEDULER_shutdown (); | 409 | GNUNET_SCHEDULER_shutdown (); |
432 | return; | 410 | return; |
433 | } | 411 | } |
434 | erc.session = session; | ||
435 | now = GNUNET_TIME_absolute_get (); | 412 | now = GNUNET_TIME_absolute_get (); |
436 | (void) GNUNET_TIME_round_abs (&now); | 413 | (void) GNUNET_TIME_round_abs (&now); |
437 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 414 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
438 | "Checking for reserves to close by date %s\n", | 415 | "Checking for reserves to close by date %s\n", |
439 | GNUNET_STRINGS_absolute_time_to_string (now)); | 416 | GNUNET_STRINGS_absolute_time_to_string (now)); |
440 | qs = db_plugin->get_expired_reserves (db_plugin->cls, | 417 | qs = db_plugin->get_expired_reserves (db_plugin->cls, |
441 | session, | ||
442 | now, | 418 | now, |
443 | &expired_reserve_cb, | 419 | &expired_reserve_cb, |
444 | &erc); | 420 | NULL); |
445 | GNUNET_assert (1 >= qs); | 421 | GNUNET_assert (1 >= qs); |
446 | switch (qs) | 422 | switch (qs) |
447 | { | 423 | { |
448 | case GNUNET_DB_STATUS_HARD_ERROR: | 424 | case GNUNET_DB_STATUS_HARD_ERROR: |
449 | GNUNET_break (0); | 425 | GNUNET_break (0); |
450 | db_plugin->rollback (db_plugin->cls, | 426 | db_plugin->rollback (db_plugin->cls); |
451 | session); | ||
452 | global_ret = EXIT_FAILURE; | 427 | global_ret = EXIT_FAILURE; |
453 | GNUNET_SCHEDULER_shutdown (); | 428 | GNUNET_SCHEDULER_shutdown (); |
454 | return; | 429 | return; |
455 | case GNUNET_DB_STATUS_SOFT_ERROR: | 430 | case GNUNET_DB_STATUS_SOFT_ERROR: |
456 | db_plugin->rollback (db_plugin->cls, | 431 | db_plugin->rollback (db_plugin->cls); |
457 | session); | ||
458 | GNUNET_assert (NULL == task); | 432 | GNUNET_assert (NULL == task); |
459 | task = GNUNET_SCHEDULER_add_now (&run_reserve_closures, | 433 | task = GNUNET_SCHEDULER_add_now (&run_reserve_closures, |
460 | NULL); | 434 | NULL); |
@@ -462,8 +436,7 @@ run_reserve_closures (void *cls) | |||
462 | case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: | 436 | case GNUNET_DB_STATUS_SUCCESS_NO_RESULTS: |
463 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 437 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
464 | "No more idle reserves to close, going to sleep.\n"); | 438 | "No more idle reserves to close, going to sleep.\n"); |
465 | db_plugin->rollback (db_plugin->cls, | 439 | db_plugin->rollback (db_plugin->cls); |
466 | session); | ||
467 | GNUNET_assert (NULL == task); | 440 | GNUNET_assert (NULL == task); |
468 | if (GNUNET_YES == test_mode) | 441 | if (GNUNET_YES == test_mode) |
469 | { | 442 | { |
@@ -477,7 +450,7 @@ run_reserve_closures (void *cls) | |||
477 | } | 450 | } |
478 | return; | 451 | return; |
479 | case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: | 452 | case GNUNET_DB_STATUS_SUCCESS_ONE_RESULT: |
480 | (void) commit_or_warn (session); | 453 | (void) commit_or_warn (); |
481 | GNUNET_assert (NULL == task); | 454 | GNUNET_assert (NULL == task); |
482 | task = GNUNET_SCHEDULER_add_now (&run_reserve_closures, | 455 | task = GNUNET_SCHEDULER_add_now (&run_reserve_closures, |
483 | NULL); | 456 | NULL); |