@@ -532,6 +532,15 @@ CREATE TABLE IF NOT EXISTS signer_state_machine_updates (
532
532
PRIMARY KEY (signer_addr, reward_cycle)
533
533
) STRICT;"# ;
534
534
535
+ static ADD_PARENT_BURN_BLOCK_HASH : & str = r#"
536
+ ALTER TABLE burn_blocks
537
+ ADD COLUMN parent_burn_block_hash TEXT;
538
+ "# ;
539
+
540
+ static ADD_PARENT_BURN_BLOCK_HASH_INDEX : & str = r#"
541
+ CREATE INDEX IF NOT EXISTS burn_blocks_parent_burn_block_hash_idx on burn_blocks (parent_burn_block_hash);
542
+ "# ;
543
+
535
544
static SCHEMA_1 : & [ & str ] = & [
536
545
DROP_SCHEMA_0 ,
537
546
CREATE_DB_CONFIG ,
@@ -613,9 +622,15 @@ static SCHEMA_11: &[&str] = &[
613
622
"INSERT INTO db_config (version) VALUES (11);" ,
614
623
] ;
615
624
625
+ static SCHEMA_12 : & [ & str ] = & [
626
+ ADD_PARENT_BURN_BLOCK_HASH ,
627
+ ADD_PARENT_BURN_BLOCK_HASH_INDEX ,
628
+ "INSERT INTO db_config (version) VALUES (12);" ,
629
+ ] ;
630
+
616
631
impl SignerDb {
617
632
/// The current schema version used in this build of the signer binary.
618
- pub const SCHEMA_VERSION : u32 = 11 ;
633
+ pub const SCHEMA_VERSION : u32 = 12 ;
619
634
620
635
/// Create a new `SignerState` instance.
621
636
/// This will create a new SQLite database at the given path
@@ -799,6 +814,20 @@ impl SignerDb {
799
814
Ok ( ( ) )
800
815
}
801
816
817
+ /// Migrate from schema 11 to schema 12
818
+ fn schema_12_migration ( tx : & Transaction ) -> Result < ( ) , DBError > {
819
+ if Self :: get_schema_version ( tx) ? >= 12 {
820
+ // no migration necessary
821
+ return Ok ( ( ) ) ;
822
+ }
823
+
824
+ for statement in SCHEMA_12 . iter ( ) {
825
+ tx. execute_batch ( statement) ?;
826
+ }
827
+
828
+ Ok ( ( ) )
829
+ }
830
+
802
831
/// Register custom scalar functions used by the database
803
832
fn register_scalar_functions ( & self ) -> Result < ( ) , DBError > {
804
833
// Register helper function for determining if a block is a tenure change transaction
@@ -843,7 +872,8 @@ impl SignerDb {
843
872
8 => Self :: schema_9_migration ( & sql_tx) ?,
844
873
9 => Self :: schema_10_migration ( & sql_tx) ?,
845
874
10 => Self :: schema_11_migration ( & sql_tx) ?,
846
- 11 => break ,
875
+ 11 => Self :: schema_12_migration ( & sql_tx) ?,
876
+ 12 => break ,
847
877
x => return Err ( DBError :: Other ( format ! (
848
878
"Database schema is newer than supported by this binary. Expected version = {}, Database version = {x}" ,
849
879
Self :: SCHEMA_VERSION ,
@@ -978,19 +1008,27 @@ impl SignerDb {
978
1008
consensus_hash : & ConsensusHash ,
979
1009
burn_height : u64 ,
980
1010
received_time : & SystemTime ,
1011
+ parent_burn_block_hash : & BurnchainHeaderHash ,
981
1012
) -> Result < ( ) , DBError > {
982
1013
let received_ts = received_time
983
1014
. duration_since ( std:: time:: UNIX_EPOCH )
984
1015
. map_err ( |e| DBError :: Other ( format ! ( "Bad system time: {e}" ) ) ) ?
985
1016
. as_secs ( ) ;
986
- debug ! ( "Inserting burn block info" ; "burn_block_height" => burn_height, "burn_hash" => %burn_hash, "received" => received_ts, "ch" => %consensus_hash) ;
1017
+ debug ! ( "Inserting burn block info" ;
1018
+ "burn_block_height" => burn_height,
1019
+ "burn_hash" => %burn_hash,
1020
+ "received" => received_ts,
1021
+ "ch" => %consensus_hash,
1022
+ "parent_burn_block_hash" => %parent_burn_block_hash
1023
+ ) ;
987
1024
self . db . execute (
988
- "INSERT OR REPLACE INTO burn_blocks (block_hash, consensus_hash, block_height, received_time) VALUES (?1, ?2, ?3, ?4)" ,
1025
+ "INSERT OR REPLACE INTO burn_blocks (block_hash, consensus_hash, block_height, received_time, parent_burn_block_hash ) VALUES (?1, ?2, ?3, ?4, ?5 )" ,
989
1026
params ! [
990
1027
burn_hash,
991
1028
consensus_hash,
992
1029
u64_to_sql( burn_height) ?,
993
1030
u64_to_sql( received_ts) ?,
1031
+ parent_burn_block_hash,
994
1032
] ,
995
1033
) ?;
996
1034
Ok ( ( ) )
@@ -1641,8 +1679,14 @@ pub mod tests {
1641
1679
. duration_since ( SystemTime :: UNIX_EPOCH )
1642
1680
. unwrap ( )
1643
1681
. as_secs ( ) ;
1644
- db. insert_burn_block ( & test_burn_hash, & test_consensus_hash, 10 , & stime)
1645
- . unwrap ( ) ;
1682
+ db. insert_burn_block (
1683
+ & test_burn_hash,
1684
+ & test_consensus_hash,
1685
+ 10 ,
1686
+ & stime,
1687
+ & test_burn_hash,
1688
+ )
1689
+ . unwrap ( ) ;
1646
1690
1647
1691
let stored_time = db
1648
1692
. get_burn_block_receive_time ( & test_burn_hash)
0 commit comments