140
140
use std:: cmp;
141
141
use std:: cmp:: Ordering as CmpOrdering ;
142
142
use std:: collections:: { BTreeMap , HashMap , HashSet , VecDeque } ;
143
- use std:: io:: { Read , Write } ;
143
+ use std:: io:: { ErrorKind , Read , Write } ;
144
144
use std:: net:: SocketAddr ;
145
145
use std:: sync:: mpsc:: { Receiver , TrySendError } ;
146
146
use std:: thread:: JoinHandle ;
@@ -1123,7 +1123,7 @@ impl BlockMinerThread {
1123
1123
) -> Vec < & AssembledAnchorBlock > {
1124
1124
let mut ret = vec ! [ ] ;
1125
1125
for ( _, ( assembled_block, _) ) in last_mined_blocks. iter ( ) {
1126
- if assembled_block. my_block_height >= burn_height {
1126
+ if assembled_block. burn_block_height >= burn_height {
1127
1127
ret. push ( assembled_block) ;
1128
1128
}
1129
1129
}
@@ -1633,7 +1633,7 @@ impl BlockMinerThread {
1633
1633
& prev_block. anchored_block. block_hash( ) ,
1634
1634
& prev_block. parent_consensus_hash,
1635
1635
& prev_block. anchored_block. header. parent_block,
1636
- & prev_block. my_burn_hash ,
1636
+ & prev_block. burn_hash ,
1637
1637
& prev_block. anchored_block. txs. len( )
1638
1638
) ;
1639
1639
max_txs = cmp:: max ( max_txs, prev_block. anchored_block . txs . len ( ) ) ;
@@ -1645,7 +1645,7 @@ impl BlockMinerThread {
1645
1645
continue ;
1646
1646
}
1647
1647
if prev_block. parent_consensus_hash == * parent_consensus_hash
1648
- && prev_block. my_burn_hash == self . burn_block . burn_header_hash
1648
+ && prev_block. burn_hash == self . burn_block . burn_header_hash
1649
1649
&& prev_block. anchored_block . header . parent_block
1650
1650
== stacks_parent_header. anchored_header . block_hash ( )
1651
1651
{
@@ -1677,7 +1677,7 @@ impl BlockMinerThread {
1677
1677
// already have.
1678
1678
info ! ( "Relayer: Stacks tip is unchanged since we last tried to mine a block off of {}/{} at height {} with {} txs, in {} at burn height {}, and no new microblocks ({} <= {} + 1)" ,
1679
1679
& prev_block. parent_consensus_hash, & prev_block. anchored_block. header. parent_block, prev_block. anchored_block. header. total_work. work,
1680
- prev_block. anchored_block. txs. len( ) , prev_block. my_burn_hash , parent_block_burn_height, stream. len( ) , prev_block. anchored_block. header. parent_microblock_sequence) ;
1680
+ prev_block. anchored_block. txs. len( ) , prev_block. burn_hash , parent_block_burn_height, stream. len( ) , prev_block. anchored_block. header. parent_microblock_sequence) ;
1681
1681
1682
1682
return None ;
1683
1683
}
@@ -1688,7 +1688,7 @@ impl BlockMinerThread {
1688
1688
// fee minus the old BTC fee
1689
1689
info ! ( "Relayer: Stacks tip is unchanged since we last tried to mine a block off of {}/{} at height {} with {} txs, in {} at burn height {}, but there are new microblocks ({} > {} + 1)" ,
1690
1690
& prev_block. parent_consensus_hash, & prev_block. anchored_block. header. parent_block, prev_block. anchored_block. header. total_work. work,
1691
- prev_block. anchored_block. txs. len( ) , prev_block. my_burn_hash , parent_block_burn_height, stream. len( ) , prev_block. anchored_block. header. parent_microblock_sequence) ;
1691
+ prev_block. anchored_block. txs. len( ) , prev_block. burn_hash , parent_block_burn_height, stream. len( ) , prev_block. anchored_block. header. parent_microblock_sequence) ;
1692
1692
1693
1693
best_attempt = cmp:: max ( best_attempt, prev_block. attempt ) ;
1694
1694
}
@@ -1697,20 +1697,20 @@ impl BlockMinerThread {
1697
1697
// no microblock stream to confirm, and the stacks tip hasn't changed
1698
1698
info ! ( "Relayer: Stacks tip is unchanged since we last tried to mine a block off of {}/{} at height {} with {} txs, in {} at burn height {}, and no microblocks present" ,
1699
1699
& prev_block. parent_consensus_hash, & prev_block. anchored_block. header. parent_block, prev_block. anchored_block. header. total_work. work,
1700
- prev_block. anchored_block. txs. len( ) , prev_block. my_burn_hash , parent_block_burn_height) ;
1700
+ prev_block. anchored_block. txs. len( ) , prev_block. burn_hash , parent_block_burn_height) ;
1701
1701
1702
1702
return None ;
1703
1703
}
1704
1704
}
1705
1705
} else {
1706
- if self . burn_block . burn_header_hash == prev_block. my_burn_hash {
1706
+ if self . burn_block . burn_header_hash == prev_block. burn_hash {
1707
1707
// only try and re-mine if there was no sortition since the last chain tip
1708
1708
info ! ( "Relayer: Stacks tip has changed to {}/{} since we last tried to mine a block in {} at burn height {}; attempt was {} (for Stacks tip {}/{})" ,
1709
- parent_consensus_hash, stacks_parent_header. anchored_header. block_hash( ) , prev_block. my_burn_hash , parent_block_burn_height, prev_block. attempt, & prev_block. parent_consensus_hash, & prev_block. anchored_block. header. parent_block) ;
1709
+ parent_consensus_hash, stacks_parent_header. anchored_header. block_hash( ) , prev_block. burn_hash , parent_block_burn_height, prev_block. attempt, & prev_block. parent_consensus_hash, & prev_block. anchored_block. header. parent_block) ;
1710
1710
best_attempt = cmp:: max ( best_attempt, prev_block. attempt ) ;
1711
1711
} else {
1712
1712
info ! ( "Relayer: Burn tip has changed to {} ({}) since we last tried to mine a block in {}" ,
1713
- & self . burn_block. burn_header_hash, self . burn_block. block_height, & prev_block. my_burn_hash ) ;
1713
+ & self . burn_block. burn_header_hash, self . burn_block. block_height, & prev_block. burn_hash ) ;
1714
1714
}
1715
1715
}
1716
1716
}
@@ -2554,34 +2554,48 @@ impl BlockMinerThread {
2554
2554
} = self . config . get_node_config ( false ) ;
2555
2555
2556
2556
let res = bitcoin_controller. submit_operation ( target_epoch_id, op, & mut op_signer, attempt) ;
2557
+ if res. is_none ( ) {
2558
+ self . failed_to_submit_last_attempt = true ;
2559
+ if !mock_mining {
2560
+ warn ! ( "Relayer: Failed to submit Bitcoin transaction" ) ;
2561
+ return None ;
2562
+ }
2563
+ debug ! ( "Relayer: Mock-mining enabled; not sending Bitcoin transaction" ) ;
2564
+ } else {
2565
+ self . failed_to_submit_last_attempt = false ;
2566
+ }
2567
+
2557
2568
let assembled_block = AssembledAnchorBlock {
2558
2569
parent_consensus_hash : parent_block_info. parent_consensus_hash ,
2559
2570
consensus_hash : cur_burn_chain_tip. consensus_hash ,
2560
- my_burn_hash : cur_burn_chain_tip. burn_header_hash ,
2561
- my_block_height : cur_burn_chain_tip. block_height ,
2571
+ burn_hash : cur_burn_chain_tip. burn_header_hash ,
2572
+ burn_block_height : cur_burn_chain_tip. block_height ,
2562
2573
orig_burn_hash : self . burn_block . burn_header_hash ,
2563
2574
anchored_block,
2564
2575
attempt,
2565
2576
tenure_begin,
2566
2577
} ;
2567
- if res. is_none ( ) {
2568
- self . failed_to_submit_last_attempt = true ;
2569
- if mock_mining {
2570
- debug ! ( "Relayer: Mock-mining enabled; not sending Bitcoin transaction" ) ;
2571
- if let Some ( dir) = mock_mining_output_dir {
2572
- let stacks_block_height = assembled_block. anchored_block . header . total_work . work ;
2573
- let filename = format ! ( "{stacks_block_height}.json" ) ;
2574
- let filepath = dir. join ( filename) ;
2575
- assembled_block
2576
- . serialize_to_file ( & filepath)
2577
- . unwrap_or_else ( |e| panic ! ( "Failed to write to file '{filepath:?}': {e}" ) ) ;
2578
- }
2579
- } else {
2580
- warn ! ( "Relayer: Failed to submit Bitcoin transaction" ) ;
2581
- return None ;
2578
+
2579
+ if mock_mining {
2580
+ let stacks_block_height = assembled_block. anchored_block . header . total_work . work ;
2581
+ info ! ( "Mock mined Stacks block {stacks_block_height}" ) ;
2582
+ if let Some ( dir) = mock_mining_output_dir {
2583
+ info ! ( "Writing mock mined Stacks block {stacks_block_height} to file" ) ;
2584
+ fs:: create_dir_all ( & dir) . unwrap_or_else ( |e| match e. kind ( ) {
2585
+ ErrorKind :: AlreadyExists => { /* This is fine */ }
2586
+ _ => error ! ( "Failed to create directory '{dir:?}': {e}" ) ,
2587
+ } ) ;
2588
+ let filename = format ! ( "{stacks_block_height}.json" ) ;
2589
+ let filepath = dir. join ( filename) ;
2590
+ assembled_block
2591
+ . serialize_to_file ( & filepath)
2592
+ . unwrap_or_else ( |e| match e. kind ( ) {
2593
+ ErrorKind :: AlreadyExists => {
2594
+ error ! ( "Failed to overwrite file '{filepath:?}'" )
2595
+ }
2596
+ _ => error ! ( "Failed to write to file '{filepath:?}': {e}" ) ,
2597
+ } ) ;
2582
2598
}
2583
- } else {
2584
- self . failed_to_submit_last_attempt = false ;
2585
2599
}
2586
2600
2587
2601
Some ( MinerThreadResult :: Block (
@@ -3010,7 +3024,7 @@ impl RelayerThread {
3010
3024
let AssembledAnchorBlock {
3011
3025
parent_consensus_hash,
3012
3026
anchored_block : mined_block,
3013
- my_burn_hash : mined_burn_hash,
3027
+ burn_hash : mined_burn_hash,
3014
3028
attempt : _,
3015
3029
..
3016
3030
} = last_mined_block_data;
@@ -3423,16 +3437,16 @@ impl RelayerThread {
3423
3437
fn clear_stale_mined_blocks ( burn_height : u64 , last_mined_blocks : MinedBlocks ) -> MinedBlocks {
3424
3438
let mut ret = HashMap :: new ( ) ;
3425
3439
for ( stacks_bhh, ( assembled_block, microblock_privkey) ) in last_mined_blocks. into_iter ( ) {
3426
- if assembled_block. my_block_height < burn_height {
3440
+ if assembled_block. burn_block_height < burn_height {
3427
3441
debug ! (
3428
3442
"Stale mined block: {} (as of {},{})" ,
3429
- & stacks_bhh, & assembled_block. my_burn_hash , assembled_block. my_block_height
3443
+ & stacks_bhh, & assembled_block. burn_hash , assembled_block. burn_block_height
3430
3444
) ;
3431
3445
continue ;
3432
3446
}
3433
3447
debug ! (
3434
3448
"Mined block in-flight: {} (as of {},{})" ,
3435
- & stacks_bhh, & assembled_block. my_burn_hash , assembled_block. my_block_height
3449
+ & stacks_bhh, & assembled_block. burn_hash , assembled_block. burn_block_height
3436
3450
) ;
3437
3451
ret. insert ( stacks_bhh, ( assembled_block, microblock_privkey) ) ;
3438
3452
}
@@ -3760,7 +3774,7 @@ impl RelayerThread {
3760
3774
) => {
3761
3775
// finished mining a block
3762
3776
if BlockMinerThread :: find_inflight_mined_blocks (
3763
- last_mined_block. my_block_height ,
3777
+ last_mined_block. burn_block_height ,
3764
3778
& self . last_mined_blocks ,
3765
3779
)
3766
3780
. len ( )
@@ -3769,7 +3783,7 @@ impl RelayerThread {
3769
3783
// first time we've mined a block in this burnchain block
3770
3784
debug ! (
3771
3785
"Bump block processed for burnchain block {}" ,
3772
- & last_mined_block. my_block_height
3786
+ & last_mined_block. burn_block_height
3773
3787
) ;
3774
3788
self . globals . counters . bump_blocks_processed ( ) ;
3775
3789
}
@@ -3779,7 +3793,7 @@ impl RelayerThread {
3779
3793
& last_mined_block. anchored_block. block_hash( )
3780
3794
) ;
3781
3795
3782
- let bhh = last_mined_block. my_burn_hash . clone ( ) ;
3796
+ let bhh = last_mined_block. burn_hash . clone ( ) ;
3783
3797
let orig_bhh = last_mined_block. orig_burn_hash . clone ( ) ;
3784
3798
let tenure_begin = last_mined_block. tenure_begin ;
3785
3799
0 commit comments