Skip to content

Commit 0e7ae1b

Browse files
committed
improved get_globally_accepted_block_count_in_tenure api
1 parent 5a25e3e commit 0e7ae1b

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

stacks-signer/src/signerdb.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -857,13 +857,19 @@ impl SignerDb {
857857
pub fn get_globally_accepted_block_count_in_tenure(
858858
&self,
859859
tenure: &ConsensusHash,
860-
) -> Result<i64, DBError> {
860+
) -> Result<u64, DBError> {
861861
let query = "SELECT COALESCE((MAX(stacks_height) - MIN(stacks_height) + 1), 0) AS block_count FROM blocks WHERE consensus_hash = ?1 AND state = ?2";
862862
let args = params![tenure, &BlockState::GloballyAccepted.to_string()];
863-
let block_count_opt: Option<i64> = query_row(&self.db, query, args)?;
863+
let block_count_opt: Option<u64> = query_row(&self.db, query, args)?;
864864
match block_count_opt {
865-
Some(block_count) => Ok(block_count),
866-
None => Ok(0),
865+
Some(block_count) => {
866+
if block_count > 0 {
867+
Ok(block_count)
868+
} else {
869+
Err(DBError::NotFoundError)
870+
}
871+
}
872+
None => Err(DBError::NotFoundError),
867873
}
868874
}
869875

0 commit comments

Comments
 (0)