@@ -826,10 +826,14 @@ impl SignerDb {
826
826
try_deserialize ( result)
827
827
}
828
828
829
- /// Return the count of signed blocks in a tenure (identified by its consensus hash)
830
- pub fn get_signed_block_count_in_tenure ( & self , tenure : & ConsensusHash ) -> Result < i64 , DBError > {
831
- let query = "SELECT COUNT(*) FROM blocks WHERE consensus_hash = ? AND signed_over = 1" ;
832
- query_count ( & self . db , query, [ tenure] )
829
+ /// Return the count of globally signed blocks in a tenure (identified by its consensus hash)
830
+ pub fn get_globally_signed_block_count_in_tenure (
831
+ & self ,
832
+ tenure : & ConsensusHash ,
833
+ ) -> Result < i64 , DBError > {
834
+ let query = "SELECT COUNT(*) FROM blocks WHERE consensus_hash = ?1 AND state = ?2 AND signed_over = 1" ;
835
+ let args = params ! [ tenure, & BlockState :: GloballyAccepted . to_string( ) ] ;
836
+ query_count ( & self . db , query, args)
833
837
}
834
838
835
839
/// Return the last accepted block in a tenure (identified by its consensus hash).
@@ -1994,7 +1998,7 @@ mod tests {
1994
1998
}
1995
1999
1996
2000
#[ test]
1997
- fn check_signed_block_count ( ) {
2001
+ fn check_globally_signed_block_count ( ) {
1998
2002
let db_path = tmp_db_path ( ) ;
1999
2003
let consensus_hash_1 = ConsensusHash ( [ 0x01 ; 20 ] ) ;
2000
2004
let mut db = SignerDb :: new ( db_path) . expect ( "Failed to create signer db" ) ;
@@ -2003,42 +2007,58 @@ mod tests {
2003
2007
} ) ;
2004
2008
2005
2009
assert_eq ! (
2006
- db. get_signed_block_count_in_tenure ( & consensus_hash_1)
2010
+ db. get_globally_signed_block_count_in_tenure ( & consensus_hash_1)
2007
2011
. unwrap( ) ,
2008
2012
0
2009
2013
) ;
2010
2014
2011
2015
block_info. signed_over = true ;
2016
+ block_info. state = BlockState :: GloballyAccepted ;
2012
2017
block_info. block . header . chain_length = 1 ;
2013
2018
db. insert_block ( & block_info) . unwrap ( ) ;
2014
2019
2015
2020
assert_eq ! (
2016
- db. get_signed_block_count_in_tenure ( & consensus_hash_1)
2021
+ db. get_globally_signed_block_count_in_tenure ( & consensus_hash_1)
2017
2022
. unwrap( ) ,
2018
2023
1
2019
2024
) ;
2020
2025
2021
2026
block_info. signed_over = true ;
2027
+ block_info. state = BlockState :: GloballyAccepted ;
2022
2028
block_info. block . header . chain_length = 2 ;
2023
2029
db. insert_block ( & block_info) . unwrap ( ) ;
2024
2030
2025
2031
block_info. signed_over = true ;
2032
+ block_info. state = BlockState :: GloballyAccepted ;
2026
2033
block_info. block . header . chain_length = 3 ;
2027
2034
db. insert_block ( & block_info) . unwrap ( ) ;
2028
2035
2029
2036
assert_eq ! (
2030
- db. get_signed_block_count_in_tenure ( & consensus_hash_1)
2037
+ db. get_globally_signed_block_count_in_tenure ( & consensus_hash_1)
2031
2038
. unwrap( ) ,
2032
2039
3
2033
2040
) ;
2034
2041
2035
2042
// add an unsigned block
2036
2043
block_info. signed_over = false ;
2044
+ block_info. state = BlockState :: GloballyAccepted ;
2037
2045
block_info. block . header . chain_length = 4 ;
2038
2046
db. insert_block ( & block_info) . unwrap ( ) ;
2039
2047
2040
2048
assert_eq ! (
2041
- db. get_signed_block_count_in_tenure( & consensus_hash_1)
2049
+ db. get_globally_signed_block_count_in_tenure( & consensus_hash_1)
2050
+ . unwrap( ) ,
2051
+ 3
2052
+ ) ;
2053
+
2054
+ // add a locally signed block
2055
+ block_info. signed_over = true ;
2056
+ block_info. state = BlockState :: LocallyAccepted ;
2057
+ block_info. block . header . chain_length = 5 ;
2058
+ db. insert_block ( & block_info) . unwrap ( ) ;
2059
+
2060
+ assert_eq ! (
2061
+ db. get_globally_signed_block_count_in_tenure( & consensus_hash_1)
2042
2062
. unwrap( ) ,
2043
2063
3
2044
2064
) ;
0 commit comments