exchange

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

commit ba48fdeace7641e3a3bb46484d7b5fc08de396c4
parent fee5dc76ce61aaec7c9f96e3f5581007fb3a0050
Author: Özgür Kesim <oec@codeblau.de>
Date:   Sat, 21 Nov 2026 18:42:19 +0100

exchangedb: rename sync_refresh to do_sync_refresh

Fixes the 004-db-naming CI job, failing since 0b87586b9.
No change in behaviour.

Diffstat:
Msrc/auditor/taler-auditor-sync.c | 10+++++-----
Asrc/exchangedb/do_sync_refresh.c | 128+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/exchangedb/meson.build | 2+-
Dsrc/exchangedb/sync_refresh.c | 128-------------------------------------------------------------------------------
Asrc/include/exchange-database/do_sync_refresh.h | 41+++++++++++++++++++++++++++++++++++++++++
Dsrc/include/exchange-database/sync_refresh.h | 41-----------------------------------------
6 files changed, 175 insertions(+), 175 deletions(-)

diff --git a/src/auditor/taler-auditor-sync.c b/src/auditor/taler-auditor-sync.c @@ -136,7 +136,7 @@ struct InsertContext; #include "exchange-database/iterate_records_by_table.h" #include "exchange-database/get_rules_by_access_token.h" #include "exchange-database/get_serial_by_table.h" -#include "exchange-database/sync_refresh.h" +#include "exchange-database/do_sync_refresh.h" #include "exchange-database/get_signkey.h" #include "exchange-database/get_signkey_revocation.h" #include "exchange-database/get_transfer_by_deposit.h" @@ -756,10 +756,10 @@ transact (void) do { enum GNUNET_DB_QueryStatus qs; - qs = TALER_EXCHANGEDB_sync_refresh (src, - dst, - GNUNET_MAX (1, transaction_size), - &after); + qs = TALER_EXCHANGEDB_do_sync_refresh (src, + dst, + GNUNET_MAX (1, transaction_size), + &after); if (qs < 0) { if (GNUNET_DB_STATUS_HARD_ERROR == qs) diff --git a/src/exchangedb/do_sync_refresh.c b/src/exchangedb/do_sync_refresh.c @@ -0,0 +1,128 @@ +/* + This file is part of TALER + Copyright (C) 2026 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 exchangedb/do_sync_refresh.c + * @brief reconcile previously copied melts with the exchange + */ +#include "helper.h" +#include "exchange-database/do_sync_refresh.h" + + +enum GNUNET_DB_QueryStatus +TALER_EXCHANGEDB_do_sync_refresh ( + struct TALER_EXCHANGEDB_PostgresContext *src, + struct TALER_EXCHANGEDB_PostgresContext *dst, + uint64_t limit, + uint64_t *after) +{ + char *candidates = NULL; + char *changes = NULL; + enum GNUNET_DB_QueryStatus qs; + + /* With 64 hex-encoded transfer keys per melt, 1024 rows serialize to + less than 5 MiB, below GNUnet's checked-allocation limit. */ + limit = GNUNET_MIN (limit, 1024); + + /* Old replicas omitted both transfer_pubs and revealed. Their migration + consequently classified these rows as v27, including pre-v45 melts + which had transfer keys on the source. A reveal can also happen after + the initial copy. An old sync process still running after migration + inserts rows with the new default version but without transfer keys. */ + PREPARE (dst, + "do_sync_refresh_candidates", + "SELECT max(refresh_id) AS last_id," + " jsonb_agg(jsonb_build_object('rc',rc,'rc_version',rc_version," + " 'missing_keys',missing_keys))::text AS batch" + " FROM (SELECT refresh_id,rc,rc_version,transfer_pubs IS NULL AS missing_keys" + " FROM refresh WHERE refresh_id > $1" + " AND (NOT revealed OR (rc_version <> 0 AND transfer_pubs IS NULL))" + " ORDER BY refresh_id LIMIT $2) pending" + " HAVING count(*) > 0"); + PREPARE (src, + "do_sync_refresh_changes", + "SELECT jsonb_agg(jsonb_build_object('rc',r.rc," + " 'revealed',r.revealed,'rc_version',r.rc_version," + " 'transfer_pubs',CASE WHEN r.rc_version <> q.rc_version" + " OR q.missing_keys THEN r.transfer_pubs END))::text AS batch" + " FROM jsonb_to_recordset($1::text::jsonb) q(rc bytea,rc_version int4,missing_keys bool)" + " JOIN refresh r USING (rc)" + " WHERE r.revealed OR r.rc_version <> q.rc_version" + " OR (q.missing_keys AND r.transfer_pubs IS NOT NULL)" + " HAVING count(*) > 0"); + PREPARE (dst, + "do_sync_refresh_apply", + "UPDATE refresh r SET revealed=(r.revealed OR s.revealed)," + " rc_version=s.rc_version," + " transfer_pubs=CASE WHEN r.rc_version <> s.rc_version" + " OR r.transfer_pubs IS NULL" + " THEN s.transfer_pubs ELSE r.transfer_pubs END" + " FROM jsonb_to_recordset($1::text::jsonb)" + " AS s(rc bytea,rc_version int4,transfer_pubs bytea[],revealed bool)" + " WHERE r.rc=s.rc AND (r.rc_version <> s.rc_version" + " OR (r.transfer_pubs IS NULL AND s.transfer_pubs IS NOT NULL)" + " OR (s.revealed AND NOT r.revealed))"); + { + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_uint64 (after), + GNUNET_PQ_query_param_uint64 (&limit), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_uint64 ("last_id", after), + GNUNET_PQ_result_spec_string ("batch", &candidates), + GNUNET_PQ_result_spec_end + }; + + qs = GNUNET_PQ_eval_prepared_singleton_select (dst->conn, + "do_sync_refresh_candidates", + params, + rs); + if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) + *after = 0; + if (qs <= 0) + return qs; + } + { + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (candidates), + GNUNET_PQ_query_param_end + }; + struct GNUNET_PQ_ResultSpec rs[] = { + GNUNET_PQ_result_spec_string ("batch", &changes), + GNUNET_PQ_result_spec_end + }; + + qs = GNUNET_PQ_eval_prepared_singleton_select (src->conn, + "do_sync_refresh_changes", + params, + rs); + GNUNET_free (candidates); + if (qs <= 0) + return qs; + } + { + struct GNUNET_PQ_QueryParam params[] = { + GNUNET_PQ_query_param_string (changes), + GNUNET_PQ_query_param_end + }; + + qs = GNUNET_PQ_eval_prepared_non_select (dst->conn, + "do_sync_refresh_apply", + params); + GNUNET_free (changes); + return qs; + } +} diff --git a/src/exchangedb/meson.build b/src/exchangedb/meson.build @@ -172,7 +172,7 @@ libtalerexchangedb = library( 'iterate_records_by_table.c', 'get_rules_by_access_token.c', 'get_serial_by_table.c', - 'sync_refresh.c', + 'do_sync_refresh.c', 'get_signkey.c', 'get_signkey_revocation.c', 'get_transfer_by_deposit.c', diff --git a/src/exchangedb/sync_refresh.c b/src/exchangedb/sync_refresh.c @@ -1,128 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2026 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 exchangedb/sync_refresh.c - * @brief reconcile previously copied melts with the exchange - */ -#include "helper.h" -#include "exchange-database/sync_refresh.h" - - -enum GNUNET_DB_QueryStatus -TALER_EXCHANGEDB_sync_refresh ( - struct TALER_EXCHANGEDB_PostgresContext *src, - struct TALER_EXCHANGEDB_PostgresContext *dst, - uint64_t limit, - uint64_t *after) -{ - char *candidates = NULL; - char *changes = NULL; - enum GNUNET_DB_QueryStatus qs; - - /* With 64 hex-encoded transfer keys per melt, 1024 rows serialize to - less than 5 MiB, below GNUnet's checked-allocation limit. */ - limit = GNUNET_MIN (limit, 1024); - - /* Old replicas omitted both transfer_pubs and revealed. Their migration - consequently classified these rows as v27, including pre-v45 melts - which had transfer keys on the source. A reveal can also happen after - the initial copy. An old sync process still running after migration - inserts rows with the new default version but without transfer keys. */ - PREPARE (dst, - "refresh_sync_candidates", - "SELECT max(refresh_id) AS last_id," - " jsonb_agg(jsonb_build_object('rc',rc,'rc_version',rc_version," - " 'missing_keys',missing_keys))::text AS batch" - " FROM (SELECT refresh_id,rc,rc_version,transfer_pubs IS NULL AS missing_keys" - " FROM refresh WHERE refresh_id > $1" - " AND (NOT revealed OR (rc_version <> 0 AND transfer_pubs IS NULL))" - " ORDER BY refresh_id LIMIT $2) pending" - " HAVING count(*) > 0"); - PREPARE (src, - "refresh_sync_changes", - "SELECT jsonb_agg(jsonb_build_object('rc',r.rc," - " 'revealed',r.revealed,'rc_version',r.rc_version," - " 'transfer_pubs',CASE WHEN r.rc_version <> q.rc_version" - " OR q.missing_keys THEN r.transfer_pubs END))::text AS batch" - " FROM jsonb_to_recordset($1::text::jsonb) q(rc bytea,rc_version int4,missing_keys bool)" - " JOIN refresh r USING (rc)" - " WHERE r.revealed OR r.rc_version <> q.rc_version" - " OR (q.missing_keys AND r.transfer_pubs IS NOT NULL)" - " HAVING count(*) > 0"); - PREPARE (dst, - "refresh_sync_apply", - "UPDATE refresh r SET revealed=(r.revealed OR s.revealed)," - " rc_version=s.rc_version," - " transfer_pubs=CASE WHEN r.rc_version <> s.rc_version" - " OR r.transfer_pubs IS NULL" - " THEN s.transfer_pubs ELSE r.transfer_pubs END" - " FROM jsonb_to_recordset($1::text::jsonb)" - " AS s(rc bytea,rc_version int4,transfer_pubs bytea[],revealed bool)" - " WHERE r.rc=s.rc AND (r.rc_version <> s.rc_version" - " OR (r.transfer_pubs IS NULL AND s.transfer_pubs IS NOT NULL)" - " OR (s.revealed AND NOT r.revealed))"); - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_uint64 (after), - GNUNET_PQ_query_param_uint64 (&limit), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_uint64 ("last_id", after), - GNUNET_PQ_result_spec_string ("batch", &candidates), - GNUNET_PQ_result_spec_end - }; - - qs = GNUNET_PQ_eval_prepared_singleton_select (dst->conn, - "refresh_sync_candidates", - params, - rs); - if (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS == qs) - *after = 0; - if (qs <= 0) - return qs; - } - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (candidates), - GNUNET_PQ_query_param_end - }; - struct GNUNET_PQ_ResultSpec rs[] = { - GNUNET_PQ_result_spec_string ("batch", &changes), - GNUNET_PQ_result_spec_end - }; - - qs = GNUNET_PQ_eval_prepared_singleton_select (src->conn, - "refresh_sync_changes", - params, - rs); - GNUNET_free (candidates); - if (qs <= 0) - return qs; - } - { - struct GNUNET_PQ_QueryParam params[] = { - GNUNET_PQ_query_param_string (changes), - GNUNET_PQ_query_param_end - }; - - qs = GNUNET_PQ_eval_prepared_non_select (dst->conn, - "refresh_sync_apply", - params); - GNUNET_free (changes); - return qs; - } -} diff --git a/src/include/exchange-database/do_sync_refresh.h b/src/include/exchange-database/do_sync_refresh.h @@ -0,0 +1,41 @@ +/* + This file is part of TALER + Copyright (C) 2026 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 exchange-database/do_sync_refresh.h + * @brief reconcile refresh data on an auditor replica + */ +#ifndef EXCHANGE_DATABASE_DO_SYNC_REFRESH_H +#define EXCHANGE_DATABASE_DO_SYNC_REFRESH_H + +#include "exchangedb_lib.h" + +/** + * Check up to @a limit previously copied melts against the source. + * + * @param src authoritative exchange database + * @param dst auditor replica + * @param limit maximum number of destination rows to check + * @param[in,out] after last refresh_id checked, initially zero; zero on exhaustion + * @return number of destination rows changed, or a database error + */ +enum GNUNET_DB_QueryStatus +TALER_EXCHANGEDB_do_sync_refresh ( + struct TALER_EXCHANGEDB_PostgresContext *src, + struct TALER_EXCHANGEDB_PostgresContext *dst, + uint64_t limit, + uint64_t *after); + +#endif diff --git a/src/include/exchange-database/sync_refresh.h b/src/include/exchange-database/sync_refresh.h @@ -1,41 +0,0 @@ -/* - This file is part of TALER - Copyright (C) 2026 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 exchange-database/sync_refresh.h - * @brief reconcile refresh data on an auditor replica - */ -#ifndef EXCHANGE_DATABASE_SYNC_REFRESH_H -#define EXCHANGE_DATABASE_SYNC_REFRESH_H - -#include "exchangedb_lib.h" - -/** - * Check up to @a limit previously copied melts against the source. - * - * @param src authoritative exchange database - * @param dst auditor replica - * @param limit maximum number of destination rows to check - * @param[in,out] after last refresh_id checked, initially zero; zero on exhaustion - * @return number of destination rows changed, or a database error - */ -enum GNUNET_DB_QueryStatus -TALER_EXCHANGEDB_sync_refresh ( - struct TALER_EXCHANGEDB_PostgresContext *src, - struct TALER_EXCHANGEDB_PostgresContext *dst, - uint64_t limit, - uint64_t *after); - -#endif