@@ -81,6 +81,9 @@ pub enum MinerDirective {
81
81
/// This is the block ID of the first block in the parent tenure
82
82
parent_tenure_start : StacksBlockId ,
83
83
/// This is the snapshot that this miner won, and will produce a tenure for
84
+ election_block : BlockSnapshot ,
85
+ /// This is the snapshot that caused the relayer to initiate this event (may be different
86
+ /// than the election block in the case where the miner is trying to mine a late block).
84
87
burnchain_tip : BlockSnapshot ,
85
88
/// This is `true` if the snapshot above is known not to be the the latest burnchain tip,
86
89
/// but an ancestor of it (for example, the burnchain tip could be an empty flash block, but the
@@ -170,7 +173,7 @@ pub struct BlockMinerThread {
170
173
burn_election_block : BlockSnapshot ,
171
174
/// Current burnchain tip as of the last TenureChange
172
175
/// * if the last tenure-change was a BlockFound, then this is the same as the
173
- /// `burn_election_block`.
176
+ /// `burn_election_block` (and it is also the `burn_view`)
174
177
/// * otherwise, if the last tenure-change is an Extend, then this is the sortition of the burn
175
178
/// view consensus hash in the TenureChange
176
179
burn_block : BlockSnapshot ,
@@ -185,6 +188,12 @@ pub struct BlockMinerThread {
185
188
signer_set_cache : Option < RewardSet > ,
186
189
/// The time at which tenure change/extend was attempted
187
190
tenure_change_time : Instant ,
191
+ /// The current tip when this miner thread was started.
192
+ /// This *should not* be passed into any block building code, as it
193
+ /// is not necessarily the burn view for the block being constructed.
194
+ /// Rather, this burn block is used to determine whether or not a new
195
+ /// burn block has arrived since this thread started.
196
+ burn_tip_at_start : ConsensusHash ,
188
197
}
189
198
190
199
impl BlockMinerThread {
@@ -195,6 +204,7 @@ impl BlockMinerThread {
195
204
burn_election_block : BlockSnapshot ,
196
205
burn_block : BlockSnapshot ,
197
206
parent_tenure_id : StacksBlockId ,
207
+ burn_tip_at_start : & ConsensusHash ,
198
208
reason : MinerReason ,
199
209
) -> BlockMinerThread {
200
210
BlockMinerThread {
@@ -212,6 +222,7 @@ impl BlockMinerThread {
212
222
reason,
213
223
p2p_handle : rt. get_p2p_handle ( ) ,
214
224
signer_set_cache : None ,
225
+ burn_tip_at_start : burn_tip_at_start. clone ( ) ,
215
226
tenure_change_time : Instant :: now ( ) ,
216
227
}
217
228
}
@@ -357,10 +368,11 @@ impl BlockMinerThread {
357
368
self . event_dispatcher . stackerdb_channel . clone ( ) ,
358
369
self . globals . should_keep_running . clone ( ) ,
359
370
& reward_set,
360
- & burn_tip ,
371
+ & self . burn_election_block ,
361
372
& self . burnchain ,
362
373
miner_privkey,
363
374
& self . config ,
375
+ & self . burn_tip_at_start ,
364
376
)
365
377
. map_err ( |e| {
366
378
NakamotoNodeError :: SigningCoordinatorFailure ( format ! (
@@ -433,7 +445,7 @@ impl BlockMinerThread {
433
445
let mut burn_db =
434
446
SortitionDB :: open ( & burn_db_path, true , self . burnchain . pox_constants . clone ( ) )
435
447
. expect ( "FATAL: could not open sortition DB" ) ;
436
- let burn_tip_changed = self . check_burn_tip_changed ( & burn_db, & mut chain_state ) ;
448
+ let burn_tip_changed = self . check_burn_tip_changed ( & burn_db) ;
437
449
match burn_tip_changed
438
450
. and_then ( |_| self . load_block_parent_info ( & mut burn_db, & mut chain_state) )
439
451
{
@@ -571,10 +583,7 @@ impl BlockMinerThread {
571
583
let wait_start = Instant :: now ( ) ;
572
584
while wait_start. elapsed ( ) < self . config . miner . wait_on_interim_blocks {
573
585
thread:: sleep ( Duration :: from_millis ( ABORT_TRY_AGAIN_MS ) ) ;
574
- if self
575
- . check_burn_tip_changed ( & sort_db, & mut chain_state)
576
- . is_err ( )
577
- {
586
+ if self . check_burn_tip_changed ( & sort_db) . is_err ( ) {
578
587
return Err ( NakamotoNodeError :: BurnchainTipChanged ) ;
579
588
}
580
589
}
@@ -602,13 +611,12 @@ impl BlockMinerThread {
602
611
} ) ?;
603
612
coordinator. propose_block (
604
613
new_block,
605
- & self . burn_block ,
606
614
& self . burnchain ,
607
615
sortdb,
608
616
& mut chain_state,
609
617
stackerdbs,
610
618
& self . globals . counters ,
611
- & self . burn_election_block . consensus_hash ,
619
+ & self . burn_election_block ,
612
620
)
613
621
}
614
622
@@ -1116,7 +1124,7 @@ impl BlockMinerThread {
1116
1124
let mut chain_state = neon_node:: open_chainstate_with_faults ( & self . config )
1117
1125
. expect ( "FATAL: could not open chainstate DB" ) ;
1118
1126
1119
- self . check_burn_tip_changed ( & burn_db, & mut chain_state ) ?;
1127
+ self . check_burn_tip_changed ( & burn_db) ?;
1120
1128
neon_node:: fault_injection_long_tenure ( ) ;
1121
1129
1122
1130
let mut mem_pool = self
@@ -1220,7 +1228,7 @@ impl BlockMinerThread {
1220
1228
// last chance -- confirm that the stacks tip is unchanged (since it could have taken long
1221
1229
// enough to build this block that another block could have arrived), and confirm that all
1222
1230
// Stacks blocks with heights higher than the canonical tip are processed.
1223
- self . check_burn_tip_changed ( & burn_db, & mut chain_state ) ?;
1231
+ self . check_burn_tip_changed ( & burn_db) ?;
1224
1232
Ok ( block)
1225
1233
}
1226
1234
@@ -1359,26 +1367,14 @@ impl BlockMinerThread {
1359
1367
/// Check if the tenure needs to change -- if so, return a BurnchainTipChanged error
1360
1368
/// The tenure should change if there is a new burnchain tip with a valid sortition,
1361
1369
/// or if the stacks chain state's burn view has advanced beyond our burn view.
1362
- fn check_burn_tip_changed (
1363
- & self ,
1364
- sortdb : & SortitionDB ,
1365
- _chain_state : & mut StacksChainState ,
1366
- ) -> Result < ( ) , NakamotoNodeError > {
1367
- if let MinerReason :: BlockFound { late } = & self . reason {
1368
- if * late && self . last_block_mined . is_none ( ) {
1369
- // this is a late BlockFound tenure change that ought to be appended to the Stacks
1370
- // chain tip, and we haven't submitted it yet.
1371
- return Ok ( ( ) ) ;
1372
- }
1373
- }
1374
-
1370
+ fn check_burn_tip_changed ( & self , sortdb : & SortitionDB ) -> Result < ( ) , NakamotoNodeError > {
1375
1371
let cur_burn_chain_tip = SortitionDB :: get_canonical_burn_chain_tip ( sortdb. conn ( ) )
1376
1372
. expect ( "FATAL: failed to query sortition DB for canonical burn chain tip" ) ;
1377
1373
1378
- if cur_burn_chain_tip. consensus_hash != self . burn_block . consensus_hash {
1374
+ if cur_burn_chain_tip. consensus_hash != self . burn_tip_at_start {
1379
1375
info ! ( "Miner: Cancel block assembly; burnchain tip has changed" ;
1380
1376
"new_tip" => %cur_burn_chain_tip. consensus_hash,
1381
- "local_tip" => %self . burn_block . consensus_hash ) ;
1377
+ "local_tip" => %self . burn_tip_at_start ) ;
1382
1378
self . globals . counters . bump_missed_tenures ( ) ;
1383
1379
Err ( NakamotoNodeError :: BurnchainTipChanged )
1384
1380
} else {
0 commit comments