exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

commit 6e3bef787b9990ab5eb4f976e7e49ab4b668a3cb
parent eb45f57e80211b3bd3f4467d7ddb7249cb149dea
Author: Christian Grothoff <christian@grothoff.org>
Date:   Sat, 11 Jan 2025 12:11:08 +0100

fix #9418

Diffstat:
Msrc/auditor/taler-helper-auditor-wire-debit.c | 42++++++++++++++++++++++++++++++++++++++----
Msrc/auditordb/Makefile.am | 1+
Asrc/auditordb/pg_delete_auditor_closure_lag.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/auditordb/pg_delete_auditor_closure_lag.h | 46++++++++++++++++++++++++++++++++++++++++++++++
Msrc/auditordb/plugin_auditordb_postgres.c | 3+++
Msrc/auditordb/test_auditordb.c | 29+++++++++++++++++++++++++++++
Msrc/include/taler_auditordb_plugin.h | 18++++++++++++++++++
7 files changed, 190 insertions(+), 4 deletions(-)

diff --git a/src/auditor/taler-helper-auditor-wire-debit.c b/src/auditor/taler-helper-auditor-wire-debit.c @@ -458,7 +458,6 @@ check_pending_rc (void *cls, }; enum GNUNET_DB_QueryStatus qs; - /* FIXME-#9418: where do we *undo* this if the wire transfer is found later? */ qs = TALER_ARL_adb->insert_auditor_closure_lags ( TALER_ARL_adb->cls, &cl); @@ -468,8 +467,6 @@ check_pending_rc (void *cls, GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); return GNUNET_SYSERR; } - /* FIXME-#9418: where do we *undo* this if the wire transfer is - found later? */ TALER_ARL_amount_add (&TALER_ARL_USE_AB (total_closure_amount_lag), &TALER_ARL_USE_AB (total_closure_amount_lag), &rc->amount); @@ -976,6 +973,41 @@ check_profit_drain (struct ReserveOutInfo *roi) /** + * Check whether the given transfer was justified because it was + * actually previously reported as missing. + * + * @param roi the reserve out operation to check + * @return #GNUNET_OK on success, #GNUNET_NO if there was no + * matching lag, #GNUNET_SYSERR on database trouble + */ +static enum GNUNET_GenericReturnValue +check_closure_lag (const struct ReserveOutInfo *roi) +{ + enum GNUNET_DB_QueryStatus qs; + + qs = TALER_ARL_adb->delete_auditor_closure_lag ( + TALER_ARL_adb->cls, + &roi->details.amount, + &roi->details.wtid, + roi->details.credit_account_uri); + if (qs < 0) + { + global_qs = qs; + GNUNET_break (GNUNET_DB_STATUS_SOFT_ERROR == qs); + return GNUNET_SYSERR; + } + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + return GNUNET_NO; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Cleared closure lag: found justification\n"); + TALER_ARL_amount_subtract (&TALER_ARL_USE_AB (total_closure_amount_lag), + &TALER_ARL_USE_AB (total_closure_amount_lag), + &roi->details.amount); + return GNUNET_YES; /* found! */ +} + + +/** * Check whether the given transfer was justified by a reserve closure or * profit drain. If not, complain that we failed to match an entry from * #out_map. This means a wire transfer was made without proper @@ -1021,7 +1053,9 @@ complain_out_not_found (void *cls, ret = check_profit_drain (roi); if (GNUNET_NO != ret) return ret; - + ret = check_closure_lag (roi); + if (GNUNET_NO != ret) + return ret; { struct TALER_AUDITORDB_WireOutInconsistency woi = { diff --git a/src/auditordb/Makefile.am b/src/auditordb/Makefile.am @@ -59,6 +59,7 @@ endif libtaler_plugin_auditordb_postgres_la_SOURCES = \ pg_del_denomination_balance.h pg_del_denomination_balance.c \ pg_del_reserve_info.c pg_del_reserve_info.h \ + pg_delete_auditor_closure_lag.h pg_delete_auditor_closure_lag.c \ pg_delete_early_aggregation.h pg_delete_early_aggregation.c \ pg_delete_generic.c pg_delete_generic.h \ pg_delete_pending_deposit.c pg_delete_pending_deposit.h \ diff --git a/src/auditordb/pg_delete_auditor_closure_lag.c b/src/auditordb/pg_delete_auditor_closure_lag.c @@ -0,0 +1,55 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file auditordb/pg_delete_auditor_closure_lag.c + * @brief Implementation of the delete_auditor_closure_lag function for Postgres + * @author Christian Grothoff + */ +#include "platform.h" +#include "taler_error_codes.h" +#include "taler_dbevents.h" +#include "taler_pq_lib.h" +#include "pg_delete_auditor_closure_lag.h" +#include "pg_helper.h" + + +enum GNUNET_DB_QueryStatus +TAH_PG_delete_auditor_closure_lag ( + void *cls, + const struct TALER_Amount *amount, + const struct TALER_WireTransferIdentifierRawP *wtid, + struct TALER_FullPayto credit_account_uri) +{ + struct PostgresClosure *pg = cls; + struct GNUNET_PQ_QueryParam params[] = { + TALER_PQ_query_param_amount (pg->conn, + amount), + GNUNET_PQ_query_param_auto_from_type (wtid), + GNUNET_PQ_query_param_string (credit_account_uri.full_payto), + GNUNET_PQ_query_param_end + }; + + PREPARE (pg, + "delete_auditor_closure_lag", + "DELETE FROM auditor_closure_lags " + " WHERE (amount).frac=($1::taler_amount).frac" + " AND (amount).val=($1::taler_amount).val" + " AND wtid=$2" + " AND account=$3;"); + return GNUNET_PQ_eval_prepared_non_select (pg->conn, + "delete_auditor_closure_lag", + params); +} diff --git a/src/auditordb/pg_delete_auditor_closure_lag.h b/src/auditordb/pg_delete_auditor_closure_lag.h @@ -0,0 +1,46 @@ +/* + This file is part of TALER + Copyright (C) 2025 Taler Systems SA + + TALER is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + TALER is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ +/** + * @file auditordb/pg_delete_auditor_closure_lag.h + * @brief implementation of the delete_auditor_closure_lag function for Postgres + * @author Christian Grothoff + */ +#ifndef PG_DELETE_AUDITOR_CLOSURE_LAG_H +#define PG_DELETE_AUDITOR_CLOSURE_LAG_H + +#include "taler_util.h" +#include "taler_json_lib.h" +#include "taler_auditordb_plugin.h" + +/** + * A previously missing wire transfer may have been found. Remove an alert + * (if we raised one). + * + * @param cls plugin closure + * @param amount wire transfer amount + * @param wtid wire transfer subject + * @param credit_account_uri destination account + * @return #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no matching alert was + * found + */ +enum GNUNET_DB_QueryStatus +TAH_PG_delete_auditor_closure_lag ( + void *cls, + const struct TALER_Amount *amount, + const struct TALER_WireTransferIdentifierRawP *wtid, + struct TALER_FullPayto credit_account_uri); + +#endif diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c @@ -23,6 +23,7 @@ #include "taler_pq_lib.h" #include <pthread.h> #include <libpq-fe.h> +#include "pg_delete_auditor_closure_lag.h" #include "pg_delete_early_aggregation.h" #include "pg_delete_generic.h" #include "pg_delete_pending_deposit.h" @@ -555,6 +556,8 @@ libtaler_plugin_auditordb_postgres_init (void *cls) plugin->delete_wire_out_inconsistency_if_matching = &TAH_PG_delete_wire_out_inconsistency_if_matching; + plugin->delete_auditor_closure_lag + = &TAH_PG_delete_auditor_closure_lag; plugin->update_auditor_progress = &TAH_PG_update_auditor_progress; diff --git a/src/auditordb/test_auditordb.c b/src/auditordb/test_auditordb.c @@ -348,6 +348,35 @@ run (void *cls) } { + struct TALER_AUDITORDB_ClosureLags cl = { + .problem_row_id = 42 + }; + + GNUNET_assert (GNUNET_OK == + TALER_string_to_amount (CURRENCY ":12.345678", + &cl.amount)); + cl.account.full_payto + = (char *) "payto://unspec/foo?receiver-name=bar"; + memset (&cl.wtid, + 42, + sizeof (cl.wtid)); + cl.deadline = GNUNET_TIME_absolute_get (); + FAILIF (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS != + plugin->delete_auditor_closure_lag (plugin->cls, + &cl.amount, + &cl.wtid, + cl.account)); + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->insert_auditor_closure_lags (plugin->cls, + &cl)); + FAILIF (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT != + plugin->delete_auditor_closure_lag (plugin->cls, + &cl.amount, + &cl.wtid, + cl.account)); + } + + { struct TALER_AUDITORDB_DenominationCirculationData dcd; struct TALER_AUDITORDB_DenominationCirculationData dcd2; diff --git a/src/include/taler_auditordb_plugin.h b/src/include/taler_auditordb_plugin.h @@ -1366,6 +1366,24 @@ struct TALER_AUDITORDB_Plugin TALER_AUDITORDB_ClosureLagsCallback cb, void *cb_cls); + /** + * A previously missing wire transfer may have been found. Remove an alert + * (if we raised one). + * + * @param cls plugin closure + * @param amount wire transfer amount + * @param wtid wire transfer subject + * @param credit_account_uri destination account + * @return #GNUNET_DB_STATUS_SUCCESS_NO_RESULTS if no matching alert was + * found + */ + enum GNUNET_DB_QueryStatus + (*delete_auditor_closure_lag)( + void *cls, + const struct TALER_Amount *amount, + const struct TALER_WireTransferIdentifierRawP *wtid, + struct TALER_FullPayto credit_account_uri); + enum GNUNET_DB_QueryStatus (*get_refreshes_hanging)( void *cls,