From 05be1c506e61df91e46981e256ab84af46db9e7a Mon Sep 17 00:00:00 2001 From: Nadav Ivgi Date: Tue, 5 Sep 2023 22:41:28 +0300 Subject: [PATCH] Fix address stats with re-orged history entries There might be history entries where the txid ended up confirming at a different block height following a re-org. Before this fix, these entries would get counted twice, once with the initial re-orged confirmation height, then again with the final confirmation height. See https://github.com/mempool/electrs/pull/12. --- src/new_index/schema.rs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/new_index/schema.rs b/src/new_index/schema.rs index 35e49f8de..8fc35f29a 100644 --- a/src/new_index/schema.rs +++ b/src/new_index/schema.rs @@ -669,6 +669,9 @@ impl ChainQuery { .map(TxHistoryRow::from_row) .filter_map(|history| { self.tx_confirming_block(&history.get_txid()) + // drop history entries that were previously confirmed in a re-orged block and later + // confirmed again at a different height + .filter(|blockid| blockid.height == history.key.confirmed_height as usize) .map(|blockid| (history, blockid)) });