From ac7ba501cf0d9e14752df875f69a76c51b6b0ac2 Mon Sep 17 00:00:00 2001 From: Dagur Valberg Johannsson Date: Tue, 14 May 2019 15:42:59 +0200 Subject: [PATCH] [stats] Update index height when chain shortens This makes electrs_index_height report the right height after `invalidateblock` call in bitcoind --- src/index.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/index.rs b/src/index.rs index b7ac037..4a877d3 100644 --- a/src/index.rs +++ b/src/index.rs @@ -305,6 +305,10 @@ impl Stats { for tx in &block.txdata { self.vsize.inc_by(tx.get_weight() as i64 / 4); } + self.update_height(height); + } + + fn update_height(&self, height: usize) { self.height.set(height as i64); } @@ -422,6 +426,7 @@ impl Index { fetcher.join().expect("block fetcher failed"); self.headers.write().unwrap().apply(new_headers, tip); assert_eq!(tip, self.headers.read().unwrap().tip()); + self.stats.update_height(self.headers.read().unwrap().len() - 1); Ok(tip) } }