@@ -300,6 +300,13 @@ pub trait StacksDBIndexed {
300
300
fn get ( & mut self , tip : & StacksBlockId , key : & str ) -> Result < Option < String > , DBError > ;
301
301
fn sqlite ( & self ) -> & Connection ;
302
302
303
+ /// Get the ancestor block hash given a height
304
+ fn get_ancestor_block_id (
305
+ & mut self ,
306
+ coinbase_height : u64 ,
307
+ tip_index_hash : & StacksBlockId ,
308
+ ) -> Result < Option < StacksBlockId > , DBError > ;
309
+
303
310
/// Get the block ID for a specific coinbase height in the fork identified by `tip`
304
311
fn get_nakamoto_block_id_at_coinbase_height (
305
312
& mut self ,
@@ -452,6 +459,14 @@ impl StacksDBIndexed for StacksDBConn<'_> {
452
459
fn sqlite ( & self ) -> & Connection {
453
460
self . conn ( )
454
461
}
462
+
463
+ fn get_ancestor_block_id (
464
+ & mut self ,
465
+ coinbase_height : u64 ,
466
+ tip_index_hash : & StacksBlockId ,
467
+ ) -> Result < Option < StacksBlockId > , DBError > {
468
+ self . get_ancestor_block_hash ( coinbase_height, tip_index_hash)
469
+ }
455
470
}
456
471
457
472
impl StacksDBIndexed for StacksDBTx < ' _ > {
@@ -462,6 +477,14 @@ impl StacksDBIndexed for StacksDBTx<'_> {
462
477
fn sqlite ( & self ) -> & Connection {
463
478
self . tx ( ) . deref ( )
464
479
}
480
+
481
+ fn get_ancestor_block_id (
482
+ & mut self ,
483
+ coinbase_height : u64 ,
484
+ tip_index_hash : & StacksBlockId ,
485
+ ) -> Result < Option < StacksBlockId > , DBError > {
486
+ self . get_ancestor_block_hash ( coinbase_height, tip_index_hash)
487
+ }
465
488
}
466
489
467
490
impl < ' a > ChainstateTx < ' a > {
@@ -2406,22 +2429,22 @@ impl NakamotoChainState {
2406
2429
/// Return a Nakamoto StacksHeaderInfo at a given coinbase height in the fork identified by `tip_index_hash`.
2407
2430
/// * For Stacks 2.x, this is the Stacks block's header
2408
2431
/// * For Stacks 3.x (Nakamoto), this is the first block in the miner's tenure.
2409
- pub fn get_header_by_coinbase_height (
2410
- tx : & mut StacksDBTx ,
2432
+ pub fn get_header_by_coinbase_height < SDBI : StacksDBIndexed > (
2433
+ conn : & mut SDBI ,
2411
2434
tip_index_hash : & StacksBlockId ,
2412
2435
coinbase_height : u64 ,
2413
2436
) -> Result < Option < StacksHeaderInfo > , ChainstateError > {
2414
2437
// nakamoto block?
2415
2438
if let Some ( block_id) =
2416
- tx . get_nakamoto_block_id_at_coinbase_height ( tip_index_hash, coinbase_height) ?
2439
+ conn . get_nakamoto_block_id_at_coinbase_height ( tip_index_hash, coinbase_height) ?
2417
2440
{
2418
- return Self :: get_block_header_nakamoto ( tx . sqlite ( ) , & block_id) ;
2441
+ return Self :: get_block_header_nakamoto ( conn . sqlite ( ) , & block_id) ;
2419
2442
}
2420
2443
2421
2444
// epcoh2 block?
2422
- let Some ( ancestor_at_height) = tx
2423
- . get_ancestor_block_hash ( coinbase_height, tip_index_hash) ?
2424
- . map ( |ancestor| Self :: get_block_header ( tx . tx ( ) , & ancestor) )
2445
+ let Some ( ancestor_at_height) = conn
2446
+ . get_ancestor_block_id ( coinbase_height, tip_index_hash) ?
2447
+ . map ( |ancestor| Self :: get_block_header ( conn . sqlite ( ) , & ancestor) )
2425
2448
. transpose ( ) ?
2426
2449
. flatten ( )
2427
2450
else {
0 commit comments