From 6dafa6d38e0346e575396a4a9517fc7c87cc13a4 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 90727c748..4b1b15dfd 100644 --- a/src/new_index/schema.rs +++ b/src/new_index/schema.rs @@ -676,6 +676,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)) });