@@ -21,7 +21,7 @@ use std::time::{Duration, SystemTime};
21
21
use blockstack_lib:: chainstate:: nakamoto:: NakamotoBlock ;
22
22
use blockstack_lib:: chainstate:: stacks:: TransactionPayload ;
23
23
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,
25
25
Error as DBError ,
26
26
} ;
27
27
#[ cfg( any( test, feature = "testing" ) ) ]
@@ -831,9 +831,13 @@ impl SignerDb {
831
831
& self ,
832
832
tenure : & ConsensusHash ,
833
833
) -> 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" ;
835
835
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
+ }
837
841
}
838
842
839
843
/// Return the last accepted block in a tenure (identified by its consensus hash).
0 commit comments