@@ -27,6 +27,7 @@ use libsigner::v0::messages::{
27
27
SignerMessage ,
28
28
} ;
29
29
use libsigner:: { BlockProposal , SignerSession , StackerDBSession , VERSION_STRING } ;
30
+ use serde:: Deserialize ;
30
31
use stacks:: address:: AddressHashMode ;
31
32
use stacks:: burnchains:: Txid ;
32
33
use stacks:: chainstate:: burn:: db:: sortdb:: SortitionDB ;
@@ -10816,6 +10817,31 @@ fn injected_signatures_are_ignored_across_boundaries() {
10816
10817
assert ! ( new_spawned_signer. stop( ) . is_none( ) ) ;
10817
10818
}
10818
10819
10820
+ #[ derive( Deserialize , Debug ) ]
10821
+ struct ObserverBlock {
10822
+ block_height : u64 ,
10823
+ #[ serde( deserialize_with = "strip_0x" ) ]
10824
+ block_hash : String ,
10825
+ #[ serde( deserialize_with = "strip_0x" ) ]
10826
+ parent_block_hash : String ,
10827
+ }
10828
+
10829
+ fn strip_0x < ' de , D > ( deserializer : D ) -> Result < String , D :: Error >
10830
+ where
10831
+ D : serde:: Deserializer < ' de > ,
10832
+ {
10833
+ let s: String = Deserialize :: deserialize ( deserializer) ?;
10834
+ Ok ( s. strip_prefix ( "0x" ) . unwrap_or ( & s) . to_string ( ) )
10835
+ }
10836
+
10837
+ fn get_last_observed_block ( ) -> ObserverBlock {
10838
+ let blocks = test_observer:: get_blocks ( ) ;
10839
+ let last_block_value = blocks. last ( ) . expect ( "No blocks mined" ) ;
10840
+ let last_block: ObserverBlock =
10841
+ serde_json:: from_value ( last_block_value. clone ( ) ) . expect ( "Failed to parse block" ) ;
10842
+ last_block
10843
+ }
10844
+
10819
10845
/// Test a scenario where:
10820
10846
/// Two miners boot to Nakamoto.
10821
10847
/// Sortition occurs. Miner 1 wins.
@@ -11033,26 +11059,24 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
11033
11059
. expect ( "Timed out waiting for Miner 1 to Mine Block N" ) ;
11034
11060
11035
11061
let blocks = test_observer:: get_mined_nakamoto_blocks ( ) ;
11036
- let block_n = blocks. last ( ) . unwrap ( ) . clone ( ) ;
11062
+ let block_n = blocks. last ( ) . expect ( "No blocks mined" ) ;
11037
11063
let block_n_height = block_n. stacks_height ;
11064
+ let block_n_hash = block_n. block_hash . clone ( ) ;
11038
11065
info ! ( "Block N: {block_n_height}" ) ;
11039
- let block_n_signature_hash = block_n. signer_signature_hash ;
11040
11066
11041
11067
let info_after = get_chain_info ( & conf) ;
11042
11068
assert_eq ! ( info_after. stacks_tip. to_string( ) , block_n. block_hash) ;
11043
- assert_eq ! ( block_n. signer_signature_hash, block_n_signature_hash) ;
11044
11069
assert_eq ! (
11045
11070
info_after. stacks_tip_height,
11046
11071
info_before. stacks_tip_height + 1
11047
11072
) ;
11073
+ assert_eq ! ( info_after. stacks_tip_height, block_n_height) ;
11048
11074
11049
11075
// assure we have a successful sortition that miner 1 won
11050
11076
let tip = SortitionDB :: get_canonical_burn_chain_tip ( sortdb. conn ( ) ) . unwrap ( ) ;
11051
11077
assert ! ( tip. sortition) ;
11052
11078
assert_eq ! ( tip. miner_pk_hash. unwrap( ) , mining_pkh_1) ;
11053
11079
11054
- debug ! ( "Miner 1 mined block N: {block_n_signature_hash}" ) ;
11055
-
11056
11080
info ! ( "------------------------- Miner 2 Submits a Block Commit -------------------------" ) ;
11057
11081
let rl2_commits_before = rl2_commits. load ( Ordering :: SeqCst ) ;
11058
11082
rl2_skip_commit_op. set ( false ) ;
@@ -11097,14 +11121,15 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
11097
11121
. nakamoto_test_skip_commit_op
11098
11122
. set ( true ) ;
11099
11123
11100
- info ! ( "------------------------- Miner 2 Mines Block N + 1 -------------------------" ) ;
11124
+ info ! ( "------------------------- Miner 2 Mines Block N+ 1 -------------------------" ) ;
11101
11125
let blocks_processed_before_2 = blocks_mined2. load ( Ordering :: SeqCst ) ;
11102
11126
let stacks_height_before = signer_test
11103
11127
. stacks_client
11104
11128
. get_peer_info ( )
11105
11129
. expect ( "Failed to get peer info" )
11106
11130
. stacks_tip_height ;
11107
11131
let info_before = get_chain_info ( & conf) ;
11132
+ let mined_before = test_observer:: get_blocks ( ) . len ( ) ;
11108
11133
11109
11134
TEST_MINE_STALL . lock ( ) . unwrap ( ) . replace ( false ) ;
11110
11135
@@ -11116,9 +11141,10 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
11116
11141
. stacks_tip_height
11117
11142
> stacks_height_before
11118
11143
&& blocks_mined2. load ( Ordering :: SeqCst ) > blocks_processed_before_2
11119
- && get_chain_info ( & conf) . stacks_tip_height > info_before. stacks_tip_height )
11144
+ && get_chain_info ( & conf) . stacks_tip_height > info_before. stacks_tip_height
11145
+ && test_observer:: get_blocks ( ) . len ( ) > mined_before)
11120
11146
} )
11121
- . expect ( "Timed out waiting for Miner 2 to Mine Block N + 1" ) ;
11147
+ . expect ( "Timed out waiting for Miner 2 to Mine Block N+ 1" ) ;
11122
11148
11123
11149
// assure we have a successful sortition that miner 2 won
11124
11150
let tip = SortitionDB :: get_canonical_burn_chain_tip ( sortdb. conn ( ) ) . unwrap ( ) ;
@@ -11127,6 +11153,9 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
11127
11153
11128
11154
assert_eq ! ( get_chain_info( & conf) . stacks_tip_height, block_n_height + 1 ) ;
11129
11155
11156
+ let last_block = get_last_observed_block ( ) ;
11157
+ assert_eq ! ( last_block. block_height, block_n_height + 1 ) ;
11158
+
11130
11159
info ! ( "------------------------- Miner 2 Mines N+2 and N+3 -------------------------" ) ;
11131
11160
let blocks_processed_before_2 = blocks_mined2. load ( Ordering :: SeqCst ) ;
11132
11161
let stacks_height_before = signer_test
@@ -11135,6 +11164,7 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
11135
11164
. expect ( "Failed to get peer info" )
11136
11165
. stacks_tip_height ;
11137
11166
let info_before = get_chain_info ( & conf) ;
11167
+ let mined_before = test_observer:: get_blocks ( ) . len ( ) ;
11138
11168
11139
11169
// submit a tx so that the miner will ATTEMPT to mine a stacks block N+2
11140
11170
let transfer_tx = make_stacks_transfer (
@@ -11157,17 +11187,22 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
11157
11187
. stacks_tip_height
11158
11188
> stacks_height_before
11159
11189
&& blocks_mined2. load ( Ordering :: SeqCst ) > blocks_processed_before_2
11160
- && get_chain_info ( & conf) . stacks_tip_height > info_before. stacks_tip_height )
11190
+ && get_chain_info ( & conf) . stacks_tip_height > info_before. stacks_tip_height
11191
+ && test_observer:: get_blocks ( ) . len ( ) > mined_before)
11161
11192
} )
11162
11193
. expect ( "Timed out waiting for Miner 2 to Mine Block N+2" ) ;
11163
11194
11195
+ let last_block = get_last_observed_block ( ) ;
11196
+ assert_eq ! ( last_block. block_height, block_n_height + 2 ) ;
11197
+
11164
11198
let blocks_processed_before_2 = blocks_mined2. load ( Ordering :: SeqCst ) ;
11165
11199
let stacks_height_before = signer_test
11166
11200
. stacks_client
11167
11201
. get_peer_info ( )
11168
11202
. expect ( "Failed to get peer info" )
11169
11203
. stacks_tip_height ;
11170
11204
let info_before = get_chain_info ( & conf) ;
11205
+ let mined_before = test_observer:: get_blocks ( ) . len ( ) ;
11171
11206
11172
11207
// submit a tx so that the miner will ATTEMPT to mine a stacks block N+3
11173
11208
let transfer_tx = make_stacks_transfer (
@@ -11190,32 +11225,38 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
11190
11225
. stacks_tip_height
11191
11226
> stacks_height_before
11192
11227
&& blocks_mined2. load ( Ordering :: SeqCst ) > blocks_processed_before_2
11193
- && get_chain_info ( & conf) . stacks_tip_height > info_before. stacks_tip_height )
11228
+ && get_chain_info ( & conf) . stacks_tip_height > info_before. stacks_tip_height
11229
+ && test_observer:: get_blocks ( ) . len ( ) > mined_before)
11194
11230
} )
11195
11231
. expect ( "Timed out waiting for Miner 2 to Mine Block N+3" ) ;
11196
11232
11197
11233
assert_eq ! ( get_chain_info( & conf) . stacks_tip_height, block_n_height + 3 ) ;
11198
11234
11235
+ let last_block = get_last_observed_block ( ) ;
11236
+ let block_n3_hash = last_block. block_hash . clone ( ) ;
11237
+ assert_eq ! ( last_block. block_height, block_n_height + 3 ) ;
11238
+
11199
11239
info ! ( "------------------------- Miner 1 Wins the Next Tenure, Mines N+1' -------------------------" ) ;
11200
11240
11201
11241
let blocks_processed_before_1 = blocks_mined1. load ( Ordering :: SeqCst ) ;
11202
- let mined_before = test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) ;
11242
+ let mined_before = test_observer:: get_blocks ( ) . len ( ) ;
11203
11243
11204
11244
next_block_and (
11205
11245
& mut signer_test. running_nodes . btc_regtest_controller ,
11206
11246
30 ,
11207
11247
|| {
11208
11248
Ok (
11209
11249
blocks_mined1. load ( Ordering :: SeqCst ) > blocks_processed_before_1
11210
- && test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) > mined_before,
11250
+ && test_observer:: get_blocks ( ) . len ( ) > mined_before,
11211
11251
)
11212
11252
} ,
11213
11253
)
11214
11254
. expect ( "Timed out waiting for Miner 1 to Mine Block N+1'" ) ;
11215
11255
11216
- let blocks = test_observer:: get_mined_nakamoto_blocks ( ) ;
11217
- let last_block = blocks. last ( ) . expect ( "No blocks mined" ) ;
11218
- assert_eq ! ( last_block. stacks_height, block_n_height + 1 ) ;
11256
+ let last_block = get_last_observed_block ( ) ;
11257
+ let block_n1_prime_hash = last_block. block_hash . clone ( ) ;
11258
+ assert_eq ! ( last_block. block_height, block_n_height + 1 ) ;
11259
+ assert_eq ! ( last_block. parent_block_hash, block_n_hash) ;
11219
11260
11220
11261
info ! ( "------------------------- Miner 1 Submits a Block Commit -------------------------" ) ;
11221
11262
@@ -11238,7 +11279,7 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
11238
11279
info ! ( "------------------------- Miner 1 Mines N+2' -------------------------" ) ;
11239
11280
11240
11281
let blocks_processed_before_1 = blocks_mined1. load ( Ordering :: SeqCst ) ;
11241
- let mined_before = test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) ;
11282
+ let mined_before = test_observer:: get_blocks ( ) . len ( ) ;
11242
11283
11243
11284
// submit a tx so that the miner will ATTEMPT to mine a stacks block N+2
11244
11285
let transfer_tx = make_stacks_transfer (
@@ -11255,27 +11296,46 @@ fn allow_reorg_within_first_proposal_burn_block_timing_secs() {
11255
11296
wait_for ( 30 , || {
11256
11297
Ok (
11257
11298
blocks_mined1. load ( Ordering :: SeqCst ) > blocks_processed_before_1
11258
- && test_observer:: get_mined_nakamoto_blocks ( ) . len ( ) > mined_before,
11299
+ && test_observer:: get_blocks ( ) . len ( ) > mined_before,
11259
11300
)
11260
11301
} )
11261
11302
. expect ( "Timed out waiting for Miner 1 to Mine Block N+2'" ) ;
11262
11303
11263
- let blocks = test_observer :: get_mined_nakamoto_blocks ( ) ;
11264
- let last_block = blocks . last ( ) . expect ( "No blocks mined" ) ;
11265
- assert_eq ! ( last_block. stacks_height , block_n_height + 2 ) ;
11304
+ let last_block = get_last_observed_block ( ) ;
11305
+ assert_eq ! ( last_block. block_height , block_n_height + 2 ) ;
11306
+ assert_eq ! ( last_block. parent_block_hash , block_n1_prime_hash ) ;
11266
11307
11267
11308
info ! ( "------------------------- Miner 1 Mines N+4 in Next Tenure -------------------------" ) ;
11268
11309
11269
- next_block_and_process_new_stacks_block (
11310
+ let blocks_processed_before_1 = blocks_mined1. load ( Ordering :: SeqCst ) ;
11311
+ let stacks_height_before = signer_test
11312
+ . stacks_client
11313
+ . get_peer_info ( )
11314
+ . expect ( "Failed to get peer info" )
11315
+ . stacks_tip_height ;
11316
+ let info_before = get_chain_info ( & conf) ;
11317
+ let mined_before = test_observer:: get_blocks ( ) . len ( ) ;
11318
+
11319
+ next_block_and (
11270
11320
& mut signer_test. running_nodes . btc_regtest_controller ,
11271
11321
30 ,
11272
- & signer_test. running_nodes . coord_channel ,
11322
+ || {
11323
+ Ok ( signer_test
11324
+ . stacks_client
11325
+ . get_peer_info ( )
11326
+ . expect ( "Failed to get peer info" )
11327
+ . stacks_tip_height
11328
+ > stacks_height_before
11329
+ && blocks_mined1. load ( Ordering :: SeqCst ) > blocks_processed_before_1
11330
+ && get_chain_info ( & conf) . stacks_tip_height > info_before. stacks_tip_height
11331
+ && test_observer:: get_blocks ( ) . len ( ) > mined_before)
11332
+ } ,
11273
11333
)
11274
11334
. expect ( "Timed out waiting for Miner 1 to Mine Block N+4" ) ;
11275
11335
11276
- let blocks = test_observer :: get_mined_nakamoto_blocks ( ) ;
11277
- let last_block = blocks . last ( ) . expect ( "No blocks mined" ) ;
11278
- assert_eq ! ( last_block. stacks_height , block_n_height + 4 ) ;
11336
+ let last_block = get_last_observed_block ( ) ;
11337
+ assert_eq ! ( last_block. block_height , block_n_height + 4 ) ;
11338
+ assert_eq ! ( last_block. parent_block_hash , block_n3_hash ) ;
11279
11339
11280
11340
info ! ( "------------------------- Shutdown -------------------------" ) ;
11281
11341
rl2_coord_channels
0 commit comments