Skip to content

Commit b9d4073

Browse files
committed
improved count of globally accepted blocks
1 parent 0dce36e commit b9d4073

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

stacks-signer/src/signerdb.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::time::{Duration, SystemTime};
2121
use blockstack_lib::chainstate::nakamoto::NakamotoBlock;
2222
use blockstack_lib::chainstate::stacks::TransactionPayload;
2323
use blockstack_lib::util_lib::db::{
24-
query_count, query_row, query_rows, sqlite_open, table_exists, tx_begin_immediate, u64_to_sql,
24+
query_row, query_rows, sqlite_open, table_exists, tx_begin_immediate, u64_to_sql,
2525
Error as DBError,
2626
};
2727
#[cfg(any(test, feature = "testing"))]
@@ -831,9 +831,13 @@ impl SignerDb {
831831
&self,
832832
tenure: &ConsensusHash,
833833
) -> Result<i64, DBError> {
834-
let query = "SELECT COUNT(*) FROM blocks WHERE consensus_hash = ?1 AND state = ?2";
834+
let query = "SELECT COALESCE((MAX(stacks_height) - MIN(stacks_height) + 1), 0) AS block_count FROM blocks WHERE consensus_hash = ?1 AND state = ?2";
835835
let args = params![tenure, &BlockState::GloballyAccepted.to_string()];
836-
query_count(&self.db, query, args)
836+
let block_count_opt: Option<i64> = query_row(&self.db, query, args)?;
837+
match block_count_opt {
838+
Some(block_count) => Ok(block_count),
839+
None => Ok(0),
840+
}
837841
}
838842

839843
/// Return the last accepted block in a tenure (identified by its consensus hash).

0 commit comments

Comments
 (0)