Skip to content

Commit 90d7101

Browse files
committed
added get_signed_block_count_in_tenure
1 parent 4dadde0 commit 90d7101

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

stacks-signer/src/chainstate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ impl SortitionsView {
440440
}
441441

442442
if tenure.first_block_mined.is_some() {
443+
// TODO: roberto -> get the amount of signed blocks
443444
let Some(local_block_info) =
444445
signer_db.get_first_signed_block_in_tenure(&tenure.consensus_hash)?
445446
else {

stacks-signer/src/signerdb.rs

Lines changed: 7 additions & 1 deletion
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_row, query_rows, sqlite_open, table_exists, tx_begin_immediate, u64_to_sql,
24+
query_count, 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"))]
@@ -792,6 +792,12 @@ impl SignerDb {
792792
try_deserialize(result)
793793
}
794794

795+
/// Return the count of signed blocks in a tenure (identified by its consensus hash)
796+
pub fn get_signed_block_count_in_tenure(&self, tenure: &ConsensusHash) -> Result<i64, DBError> {
797+
let query = "SELECT COUNT(*) FROM blocks WHERE consensus_hash = ? AND signed_over = 1";
798+
query_count(&self.db, query, [tenure])
799+
}
800+
795801
/// Return the last accepted block in a tenure (identified by its consensus hash).
796802
pub fn get_last_accepted_block(
797803
&self,

0 commit comments

Comments
 (0)