From 74e93dfcc30b3e7ff47ea2cee6183c2de4753064 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 f5afd1fb3..4c276a32f 100644 --- a/src/new_index/schema.rs +++ b/src/new_index/schema.rs @@ -675,6 +675,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)) });