From 1f06c4d4dc4a6c611231c2e95a1e464e038b2570 Mon Sep 17 00:00:00 2001 From: Antoine Poinsot Date: Tue, 22 Nov 2022 18:30:54 +0100 Subject: [PATCH] db: fix the list_txids query We need to limit the number of *distinct* txids. Limiting the number of results in the inner queries at all could lead to incorrect results with regard to ordering too. See https://github.com/revault/liana/pull/99#discussion_r1029619579. --- src/database/sqlite/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/database/sqlite/mod.rs b/src/database/sqlite/mod.rs index b40df29e..d5233b69 100644 --- a/src/database/sqlite/mod.rs +++ b/src/database/sqlite/mod.rs @@ -500,14 +500,14 @@ impl SqliteConn { SELECT txid, blocktime AS date FROM coins \ WHERE blocktime >= (?1) \ AND blocktime <= (?2) \ - ORDER BY blocktime DESC LIMIT (?3) \ + ORDER BY blocktime \ ) \ UNION \ SELECT * FROM ( SELECT spend_txid AS txid, spend_block_time AS date FROM coins \ WHERE spend_block_time >= (?1) \ AND spend_block_time <= (?2) \ - ORDER BY spend_block_time DESC LIMIT (?3) \ + ORDER BY spend_block_time \ ) \ ORDER BY date DESC LIMIT (?3) \ )",