From a269dd82029a51086bab66e63357bef3a2d0d000 Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Mon, 11 Nov 2024 23:58:39 +0100 Subject: limit reserve expiration query to reserves that actually had an incoming wire transfer, as purely purse-filled reserves cannot be closed (fixes #9209) --- src/exchangedb/pg_get_expired_reserves.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/exchangedb/pg_get_expired_reserves.c b/src/exchangedb/pg_get_expired_reserves.c index df069d4d4..2bb4da5fc 100644 --- a/src/exchangedb/pg_get_expired_reserves.c +++ b/src/exchangedb/pg_get_expired_reserves.c @@ -135,27 +135,26 @@ TEH_PG_get_expired_reserves ( PREPARE (pg, "get_expired_reserves", "WITH ed AS MATERIALIZED ( " - " SELECT * " - " FROM reserves " + " SELECT expiration_date" + " ,wire_source_h_payto" + " ,current_balance" + " ,r.reserve_pub" + " FROM reserves r" + " JOIN reserves_in" + " USING (reserve_pub)" " WHERE expiration_date <= $1 " " AND ((current_balance).val != 0 OR (current_balance).frac != 0) " " ORDER BY expiration_date ASC " " LIMIT 1 " ") " - "SELECT " - " ed.expiration_date " - " ,payto_uri AS account_details " - " ,ed.reserve_pub " - " ,current_balance " - "FROM ( " - " SELECT " - " * " - " FROM reserves_in " - " WHERE reserve_pub = ( " - " SELECT reserve_pub FROM ed) " - " ) ri " - "JOIN wire_targets wt ON (ri.wire_source_h_payto = wt.wire_target_h_payto) " - "JOIN ed ON (ri.reserve_pub = ed.reserve_pub);"); + "SELECT" + " wt.payto_uri AS account_details" + " ,ed.expiration_date" + " ,ed.reserve_pub" + " ,ed.current_balance" + " FROM wire_targets wt" + " JOIN ed" + " ON (ed.wire_source_h_payto=wt.wire_target_h_payto);"); qs = GNUNET_PQ_eval_prepared_multi_select (pg->conn, "get_expired_reserves", params, -- cgit v1.2.3