@@ -2340,17 +2340,12 @@ impl BlockMinerThread {
2340
2340
}
2341
2341
2342
2342
/// Read any mock signatures from stackerdb and respond to them
2343
- pub fn send_mock_miner_messages ( & mut self ) -> Result < ( ) , ChainstateError > {
2344
- let miner_config = self . config . get_miner_config ( ) ;
2345
- if !miner_config. pre_nakamoto_mock_signing {
2346
- debug ! ( "Pre-Nakamoto mock signing is disabled" ) ;
2347
- return Ok ( ( ) ) ;
2348
- }
2349
-
2343
+ pub fn send_mock_miner_messages ( & mut self ) -> Result < ( ) , String > {
2350
2344
let burn_db_path = self . config . get_burn_db_file_path ( ) ;
2351
2345
let burn_db = SortitionDB :: open ( & burn_db_path, false , self . burnchain . pox_constants . clone ( ) )
2352
2346
. expect ( "FATAL: could not open sortition DB" ) ;
2353
- let epoch_id = SortitionDB :: get_stacks_epoch ( burn_db. conn ( ) , self . burn_block . block_height ) ?
2347
+ let epoch_id = SortitionDB :: get_stacks_epoch ( burn_db. conn ( ) , self . burn_block . block_height )
2348
+ . map_err ( |e| e. to_string ( ) ) ?
2354
2349
. expect ( "FATAL: no epoch defined" )
2355
2350
. epoch_id ;
2356
2351
if epoch_id != StacksEpochId :: Epoch25 {
@@ -2360,6 +2355,12 @@ impl BlockMinerThread {
2360
2355
return Ok ( ( ) ) ;
2361
2356
}
2362
2357
2358
+ let miner_config = self . config . get_miner_config ( ) ;
2359
+ if !miner_config. pre_nakamoto_mock_signing {
2360
+ debug ! ( "Pre-Nakamoto mock signing is disabled" ) ;
2361
+ return Ok ( ( ) ) ;
2362
+ }
2363
+
2363
2364
let mining_key = miner_config
2364
2365
. mining_key
2365
2366
. expect ( "Cannot mock sign without mining key" ) ;
@@ -2374,25 +2375,31 @@ impl BlockMinerThread {
2374
2375
}
2375
2376
2376
2377
// find out which slot we're in. If we are not the latest sortition winner, we should not be sending anymore messages anyway
2377
- let stackerdbs = StackerDBs :: connect ( & self . config . get_stacker_db_file_path ( ) , false ) ? ;
2378
- let ( _ , miners_info ) =
2379
- NakamotoChainState :: make_miners_stackerdb_config ( & burn_db , & self . burn_block ) ? ;
2380
- let idx = miners_info . get_latest_winner_index ( ) ;
2381
- let sortitions = miners_info . get_sortitions ( ) ;
2382
- let election_sortition = * sortitions
2383
- . get ( idx as usize )
2384
- . expect ( "FATAL: latest winner index out of bounds" ) ;
2385
-
2386
- let miner_contract_id = boot_code_id ( MINERS_NAME , self . config . is_mainnet ( ) ) ;
2387
- let mut miners_stackerdb =
2388
- StackerDBSession :: new ( & self . config . node . rpc_bind , miner_contract_id ) ;
2389
-
2378
+ let ih = burn_db . index_handle ( & self . burn_block . sortition_id ) ;
2379
+ let last_winner_snapshot = ih
2380
+ . get_last_snapshot_with_sortition ( self . burn_block . block_height )
2381
+ . map_err ( |e| e . to_string ( ) ) ? ;
2382
+
2383
+ if last_winner_snapshot . miner_pk_hash
2384
+ != Some ( Hash160 :: from_node_public_key (
2385
+ & StacksPublicKey :: from_private ( & mining_key ) ,
2386
+ ) )
2387
+ {
2388
+ return Ok ( ( ) ) ;
2389
+ }
2390
+ let election_sortition = last_winner_snapshot . consensus_hash ;
2390
2391
let mock_proposal =
2391
2392
MockProposal :: new ( peer_info, self . config . burnchain . chain_id , & mining_key) ;
2392
2393
2393
2394
info ! ( "Sending mock proposal to stackerdb: {mock_proposal:?}" ) ;
2394
2395
2395
- if let Err ( e) = SignCoordinator :: send_miners_message (
2396
+ let stackerdbs = StackerDBs :: connect ( & self . config . get_stacker_db_file_path ( ) , false )
2397
+ . map_err ( |e| e. to_string ( ) ) ?;
2398
+ let miner_contract_id = boot_code_id ( MINERS_NAME , self . config . is_mainnet ( ) ) ;
2399
+ let mut miners_stackerdb =
2400
+ StackerDBSession :: new ( & self . config . node . rpc_bind , miner_contract_id) ;
2401
+
2402
+ SignCoordinator :: send_miners_message (
2396
2403
& mining_key,
2397
2404
& burn_db,
2398
2405
& self . burn_block ,
@@ -2402,24 +2409,26 @@ impl BlockMinerThread {
2402
2409
self . config . is_mainnet ( ) ,
2403
2410
& mut miners_stackerdb,
2404
2411
& election_sortition,
2405
- ) {
2406
- warn ! ( "Failed to send mock proposal to stackerdb: {:?}" , & e) ;
2407
- return Ok ( ( ) ) ;
2408
- }
2412
+ )
2413
+ . map_err ( |e| {
2414
+ warn ! ( "Failed to write mock proposal to stackerdb." ) ;
2415
+ e
2416
+ } ) ?;
2409
2417
2410
2418
// Retrieve any MockSignatures from stackerdb
2411
2419
info ! ( "Waiting for mock signatures..." ) ;
2412
- let mock_signatures =
2413
- self . wait_for_mock_signatures ( & mock_proposal, & stackerdbs, Duration :: from_secs ( 10 ) ) ?;
2420
+ let mock_signatures = self
2421
+ . wait_for_mock_signatures ( & mock_proposal, & stackerdbs, Duration :: from_secs ( 10 ) )
2422
+ . map_err ( |e| e. to_string ( ) ) ?;
2414
2423
2415
2424
let mock_block = MockBlock {
2416
2425
mock_proposal,
2417
2426
mock_signatures,
2418
2427
} ;
2419
2428
2420
2429
info ! ( "Sending mock block to stackerdb: {mock_block:?}" ) ;
2421
- if let Err ( e ) = SignCoordinator :: send_miners_message (
2422
- & miner_config . mining_key . expect ( "BUG: no mining key" ) ,
2430
+ SignCoordinator :: send_miners_message (
2431
+ & mining_key,
2423
2432
& burn_db,
2424
2433
& self . burn_block ,
2425
2434
& stackerdbs,
@@ -2428,9 +2437,11 @@ impl BlockMinerThread {
2428
2437
self . config . is_mainnet ( ) ,
2429
2438
& mut miners_stackerdb,
2430
2439
& election_sortition,
2431
- ) {
2432
- warn ! ( "Failed to send mock block to stackerdb: {:?}" , & e) ;
2433
- }
2440
+ )
2441
+ . map_err ( |e| {
2442
+ warn ! ( "Failed to write mock block to stackerdb." ) ;
2443
+ e
2444
+ } ) ?;
2434
2445
Ok ( ( ) )
2435
2446
}
2436
2447
@@ -3795,7 +3806,7 @@ impl RelayerThread {
3795
3806
}
3796
3807
3797
3808
let Some ( mut miner_thread_state) =
3798
- self . create_block_miner ( registered_key, last_burn_block, issue_timestamp_ms)
3809
+ self . create_block_miner ( registered_key, last_burn_block. clone ( ) , issue_timestamp_ms)
3799
3810
else {
3800
3811
return false ;
3801
3812
} ;
0 commit comments