@@ -23,7 +23,7 @@ use stacks_common::types::chainstate::StacksPrivateKey;
23
23
24
24
use crate :: config:: InitialBalance ;
25
25
use crate :: tests:: bitcoin_regtest:: BitcoinCoreController ;
26
- use crate :: tests:: nakamoto_integrations:: wait_for;
26
+ use crate :: tests:: nakamoto_integrations:: { next_block_and , wait_for} ;
27
27
use crate :: tests:: neon_integrations:: {
28
28
get_account, get_chain_info, neon_integration_test_conf, next_block_and_wait, submit_tx,
29
29
test_observer, wait_for_runloop,
@@ -162,6 +162,9 @@ fn microblocks_disabled() {
162
162
// push us to block 205
163
163
next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
164
164
165
+ // Ensure we start off with 0 microblocks
166
+ assert ! ( test_observer:: get_microblocks( ) . is_empty( ) ) ;
167
+
165
168
let tx = make_stacks_transfer_mblock_only (
166
169
& spender_1_sk,
167
170
0 ,
@@ -172,7 +175,11 @@ fn microblocks_disabled() {
172
175
) ;
173
176
submit_tx ( & http_origin, & tx) ;
174
177
175
- // wait until just before epoch 2.5
178
+ // Wait for a microblock to be assembled
179
+ wait_for ( 60 , || Ok ( test_observer:: get_microblocks ( ) . len ( ) == 1 ) )
180
+ . expect ( "Failed to wait for microblocks to be assembled" ) ;
181
+
182
+ // mine Bitcoin blocks up until just before epoch 2.5
176
183
wait_for ( 120 , || {
177
184
let tip_info = get_chain_info ( & conf) ;
178
185
if tip_info. burn_block_height >= epoch_2_5 - 2 {
@@ -183,6 +190,14 @@ fn microblocks_disabled() {
183
190
} )
184
191
. expect ( "Failed to wait until just before epoch 2.5" ) ;
185
192
193
+ // Verify that the microblock was processed
194
+ let account = get_account ( & http_origin, & spender_1_addr) ;
195
+ assert_eq ! (
196
+ u64 :: try_from( account. balance) . unwrap( ) ,
197
+ spender_1_bal - 1_000
198
+ ) ;
199
+ assert_eq ! ( account. nonce, 1 ) ;
200
+
186
201
let old_tip_info = get_chain_info ( & conf) ;
187
202
next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
188
203
next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
@@ -194,13 +209,8 @@ fn microblocks_disabled() {
194
209
. expect ( "Failed to process block" ) ;
195
210
196
211
info ! ( "Test passed processing 2.5" ) ;
197
- let account = get_account ( & http_origin, & spender_1_addr) ;
198
- assert_eq ! (
199
- u64 :: try_from( account. balance) . unwrap( ) ,
200
- spender_1_bal - 1_000
201
- ) ;
202
- assert_eq ! ( account. nonce, 1 ) ;
203
212
213
+ // Submit another microblock only transaction
204
214
let tx = make_stacks_transfer_mblock_only (
205
215
& spender_1_sk,
206
216
1 ,
@@ -211,19 +221,12 @@ fn microblocks_disabled() {
211
221
) ;
212
222
submit_tx ( & http_origin, & tx) ;
213
223
214
- let mut last_block_height = get_chain_info ( & conf) . burn_block_height ;
215
- for _i in 0 ..5 {
216
- next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
217
- wait_for ( 30 , || {
218
- let tip_info = get_chain_info ( & conf) ;
219
- if tip_info. burn_block_height > last_block_height {
220
- last_block_height = tip_info. burn_block_height ;
221
- return Ok ( true ) ;
222
- }
223
- Ok ( false )
224
- } )
225
- . expect ( "Failed to mine" ) ;
226
- }
224
+ // Wait for a microblock to be assembled, but expect none to be assembled
225
+ wait_for ( 30 , || Ok ( test_observer:: get_microblocks ( ) . len ( ) > 1 ) )
226
+ . expect_err ( "Microblocks should not have been assembled" ) ;
227
+
228
+ // Mine a block to see if the microblock gets processed
229
+ next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
227
230
228
231
// second transaction should not have been processed!
229
232
let account = get_account ( & http_origin, & spender_1_addr) ;
@@ -233,31 +236,18 @@ fn microblocks_disabled() {
233
236
) ;
234
237
assert_eq ! ( account. nonce, 1 ) ;
235
238
236
- let microblocks_assembled = test_observer:: get_microblocks ( ) . len ( ) ;
237
- info ! ( "Microblocks assembled: {microblocks_assembled}" , ) ;
238
- assert ! (
239
- microblocks_assembled > 0 ,
240
- "There should be at least 1 microblock assembled"
241
- ) ;
242
-
243
239
let miner_nonce_before_microblock_assembly = get_account ( & http_origin, & miner_account) . nonce ;
244
240
245
241
// Now, lets tell the miner to try to mine microblocks, but don't try to confirm them!
242
+ info ! ( "Setting STACKS_TEST_FORCE_MICROBLOCKS_POST_25" ) ;
246
243
env:: set_var ( "STACKS_TEST_FORCE_MICROBLOCKS_POST_25" , "1" ) ;
247
244
248
- let mut last_block_height = get_chain_info ( & conf) . burn_block_height ;
249
- for _i in 0 ..2 {
250
- next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
251
- wait_for ( 30 , || {
252
- let tip_info = get_chain_info ( & conf) ;
253
- if tip_info. burn_block_height > last_block_height {
254
- last_block_height = tip_info. burn_block_height ;
255
- return Ok ( true ) ;
256
- }
257
- Ok ( false )
258
- } )
259
- . expect ( "Failed to mine" ) ;
260
- }
245
+ // Wait for a second microblock to be assembled
246
+ wait_for ( 60 , || Ok ( test_observer:: get_microblocks ( ) . len ( ) == 2 ) )
247
+ . expect ( "Failed to wait for microblocks to be assembled" ) ;
248
+
249
+ // Mine a block to see if the microblock gets processed
250
+ next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
261
251
262
252
let miner_nonce_after_microblock_assembly = get_account ( & http_origin, & miner_account) . nonce ;
263
253
@@ -270,44 +260,35 @@ fn microblocks_disabled() {
270
260
) ;
271
261
assert_eq ! ( account. nonce, 1 ) ;
272
262
273
- // but we should have assembled and announced at least 1 more block to the observer
274
- assert ! ( test_observer:: get_microblocks( ) . len( ) > microblocks_assembled) ;
275
263
info ! (
276
264
"Microblocks assembled: {}" ,
277
265
test_observer:: get_microblocks( ) . len( )
278
266
) ;
279
267
280
268
// and our miner should have gotten some blocks accepted
281
- assert ! (
282
- miner_nonce_after_microblock_assembly > miner_nonce_before_microblock_assembly,
269
+ assert_eq ! (
270
+ miner_nonce_after_microblock_assembly, miner_nonce_before_microblock_assembly + 1 ,
283
271
"Mined before started microblock assembly: {miner_nonce_before_microblock_assembly}, Mined after started microblock assembly: {miner_nonce_after_microblock_assembly}"
284
272
) ;
285
273
286
274
// Now, tell the miner to try to confirm microblocks as well.
287
275
// This should test that the block gets rejected by append block
276
+ info ! ( "Setting STACKS_TEST_CONFIRM_MICROBLOCKS_POST_25" ) ;
288
277
env:: set_var ( "STACKS_TEST_CONFIRM_MICROBLOCKS_POST_25" , "1" ) ;
289
278
290
- let mut last_block_height = get_chain_info ( & conf) . burn_block_height ;
291
- for _i in 0 ..2 {
292
- next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
293
- wait_for ( 30 , || {
294
- let tip_info = get_chain_info ( & conf) ;
295
- if tip_info. burn_block_height > last_block_height {
296
- last_block_height = tip_info. burn_block_height ;
297
- return Ok ( true ) ;
298
- }
299
- Ok ( false )
300
- } )
301
- . expect ( "Failed to mine" ) ;
302
- }
279
+ // Wait for a third microblock to be assembled
280
+ wait_for ( 60 , || Ok ( test_observer:: get_microblocks ( ) . len ( ) == 3 ) )
281
+ . expect ( "Failed to wait for microblocks to be assembled" ) ;
282
+
283
+ // Mine a block to see if the microblock gets processed
284
+ next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
303
285
304
286
let miner_nonce_after_microblock_confirmation = get_account ( & http_origin, & miner_account) . nonce ;
305
287
306
- // and our miner should have gotten at most one more block accepted
307
- // (because they may have had 1 block confirmation in the bitcoin mempool which didn't confirm a microblock
308
- // before we flipped the flag)
309
- assert ! (
310
- miner_nonce_after_microblock_confirmation <= miner_nonce_after_microblock_assembly + 1 ,
288
+ // our miner should not have gotten any more blocks accepted
289
+ assert_eq ! (
290
+ miner_nonce_after_microblock_confirmation,
291
+ miner_nonce_after_microblock_assembly + 1 ,
311
292
"Mined after started microblock confimration: {miner_nonce_after_microblock_confirmation}" ,
312
293
) ;
313
294
0 commit comments