commit 82f940fca3a0ab83d238db04f629ea89102a303c
parent ca6048655a01d9c8124225c22133b5cb88c454d1
Author: Antoine A <>
Date: Tue, 10 Jun 2025 15:00:08 +0200
nexus: fails when manually setting status of an unknown batch or tx
Diffstat:
3 files changed, 25 insertions(+), 11 deletions(-)
diff --git a/database-versioning/libeufin-nexus-procedures.sql b/database-versioning/libeufin-nexus-procedures.sql
@@ -509,9 +509,9 @@ END $$;
CREATE FUNCTION batch_status_update(
IN in_message_id text,
IN in_status submission_state,
- IN in_status_msg text
+ IN in_status_msg text,
+ OUT out_ok BOOLEAN
)
-RETURNS void
LANGUAGE plpgsql AS $$
DECLARE
local_batch_id INT8;
@@ -520,6 +520,7 @@ BEGIN
SELECT initiated_outgoing_batch_id INTO local_batch_id
FROM initiated_outgoing_batches
WHERE message_id = in_message_id;
+ out_ok=FOUND;
IF FOUND THEN
-- Update unsettled batch status
UPDATE initiated_outgoing_batches
@@ -544,9 +545,9 @@ CREATE FUNCTION tx_status_update(
IN in_end_to_end_id text,
IN in_message_id text,
IN in_status submission_state,
- IN in_status_msg text
+ IN in_status_msg text,
+ OUT out_ok BOOLEAN
)
-RETURNS void
LANGUAGE plpgsql AS $$
DECLARE
local_status submission_state;
@@ -556,6 +557,7 @@ BEGIN
SELECT initiated_outgoing_transaction_id, status INTO local_tx_id, local_status
FROM initiated_outgoing_transactions
WHERE end_to_end_id = in_end_to_end_id;
+ out_ok=FOUND;
IF FOUND THEN
-- Update unsettled transaction status
IF in_status = 'permanent_failure' OR local_status NOT IN ('success', 'permanent_failure', 'late_failure') THEN
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/cli/Manual.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/cli/Manual.kt
@@ -1,6 +1,6 @@
/*
* This file is part of LibEuFin.
- * Copyright (C) 2024 Taler Systems S.A.
+ * Copyright (C) 2024-2025 Taler Systems S.A.
* LibEuFin is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
@@ -119,8 +119,16 @@ class StatusCmd: CliktCommand("status") {
override fun run() = cliCmd(logger, common.log) {
nexusConfig(common.config).withDb { db, cfg ->
when (kind) {
- Kind.batch -> db.initiated.batchStatusUpdate(id, status, msg)
- Kind.tx -> db.initiated.txStatusUpdate(id, null, status, msg)
+ Kind.batch -> if (db.initiated.batchStatusUpdate(id, status, msg)) {
+ logger.info("Updated batch '${id}' to ${status}")
+ } else {
+ throw Exception("Unknown batch '$id'")
+ }
+ Kind.tx -> if (db.initiated.txStatusUpdate(id, null, status, msg)) {
+ logger.info("Updated tx '${id}' to ${status}")
+ } else {
+ throw Exception("Unknown tx '$id'")
+ }
}
}
}
diff --git a/nexus/src/main/kotlin/tech/libeufin/nexus/db/InitiatedDAO.kt b/nexus/src/main/kotlin/tech/libeufin/nexus/db/InitiatedDAO.kt
@@ -251,23 +251,27 @@ class InitiatedDAO(private val db: Database) {
/** Register payment status [state] with [msg] for batch [msgId] */
suspend fun batchStatusUpdate(msgId: String, state: StatusUpdate, msg: String?) = db.serializable(
- "SELECT FROM batch_status_update(?,?::submission_state,?)"
+ "SELECT out_ok FROM batch_status_update(?,?::submission_state,?)"
) {
bind(msgId)
bind(state)
bind(msg)
- executeQuery()
+ one {
+ it.getBoolean(1)
+ }
}
/** Register payment status [state] with [msg] for transaction [endToEndId] in batch [msgId] */
suspend fun txStatusUpdate(endToEndId: String, msgId: String?, state: StatusUpdate, msg: String?) = db.serializable(
- "SELECT FROM tx_status_update(?,?,?::submission_state,?)"
+ "SELECT out_ok FROM tx_status_update(?,?,?::submission_state,?)"
) {
bind(endToEndId)
bind(msgId)
bind(state)
bind(msg)
- executeQuery()
+ one {
+ it.getBoolean(1)
+ }
}
/** Unsettled initiated payment in batch [msgId] */