@@ -11237,3 +11237,145 @@ fn reload_miner_config() {
11237
11237
11238
11238
run_loop_thread. join ( ) . unwrap ( ) ;
11239
11239
}
11240
+
11241
+ /// Test that a new block commit is issued when the miner spend or config changes.
11242
+ ///
11243
+ /// The test boots into Nakamoto. Then, it waits for a block commit on the most recent
11244
+ /// tip. The config is updated, and then the test ensures that a new commit was submitted after that
11245
+ /// config change.
11246
+ #[ test]
11247
+ #[ ignore]
11248
+ fn rbf_on_config_change ( ) {
11249
+ if env:: var ( "BITCOIND_TEST" ) != Ok ( "1" . into ( ) ) {
11250
+ return ;
11251
+ }
11252
+
11253
+ let ( mut conf, _miner_account) = naka_neon_integration_conf ( None ) ;
11254
+ let password = "12345" . to_string ( ) ;
11255
+ let _http_origin = format ! ( "http://{}" , & conf. node. rpc_bind) ;
11256
+ conf. connection_options . auth_token = Some ( password. clone ( ) ) ;
11257
+ conf. miner . wait_on_interim_blocks = Duration :: from_secs ( 1 ) ;
11258
+ conf. node . next_initiative_delay = 500 ;
11259
+ let stacker_sk = setup_stacker ( & mut conf) ;
11260
+ let signer_sk = Secp256k1PrivateKey :: random ( ) ;
11261
+ let signer_addr = tests:: to_addr ( & signer_sk) ;
11262
+ let sender_sk = Secp256k1PrivateKey :: random ( ) ;
11263
+ let recipient_sk = Secp256k1PrivateKey :: random ( ) ;
11264
+ let _recipient_addr = tests:: to_addr ( & recipient_sk) ;
11265
+ // setup sender + recipient for some test stx transfers
11266
+ // these are necessary for the interim blocks to get mined at all
11267
+ let sender_addr = tests:: to_addr ( & sender_sk) ;
11268
+ let old_burn_fee_cap: u64 = 100000 ;
11269
+ conf. burnchain . burn_fee_cap = old_burn_fee_cap;
11270
+ conf. add_initial_balance ( PrincipalData :: from ( sender_addr) . to_string ( ) , 1000000 ) ;
11271
+ conf. add_initial_balance ( PrincipalData :: from ( signer_addr) . to_string ( ) , 100000 ) ;
11272
+
11273
+ test_observer:: spawn ( ) ;
11274
+ test_observer:: register ( & mut conf, & [ EventKeyType :: AnyEvent ] ) ;
11275
+
11276
+ let mut btcd_controller = BitcoinCoreController :: new ( conf. clone ( ) ) ;
11277
+ btcd_controller
11278
+ . start_bitcoind ( )
11279
+ . expect ( "Failed starting bitcoind" ) ;
11280
+ let mut btc_regtest_controller = BitcoinRegtestController :: new ( conf. clone ( ) , None ) ;
11281
+ btc_regtest_controller. bootstrap_chain ( 201 ) ;
11282
+
11283
+ let conf_path =
11284
+ std:: env:: temp_dir ( ) . join ( format ! ( "miner-config-test-{}.toml" , rand:: random:: <u64 >( ) ) ) ;
11285
+ conf. config_path = Some ( conf_path. clone ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ) ;
11286
+
11287
+ // Make a minimum-viable config file
11288
+ let update_config = |burn_fee_cap : u64 , sats_vbyte : u64 | {
11289
+ use std:: io:: Write ;
11290
+
11291
+ let new_config = format ! (
11292
+ r#"
11293
+ [burnchain]
11294
+ burn_fee_cap = {}
11295
+ satoshis_per_byte = {}
11296
+ "# ,
11297
+ burn_fee_cap, sats_vbyte,
11298
+ ) ;
11299
+ // Write to a file
11300
+ let mut file = File :: create ( & conf_path) . unwrap ( ) ;
11301
+ file. write_all ( new_config. as_bytes ( ) ) . unwrap ( ) ;
11302
+ } ;
11303
+
11304
+ let mut run_loop = boot_nakamoto:: BootRunLoop :: new ( conf. clone ( ) ) . unwrap ( ) ;
11305
+ let run_loop_stopper = run_loop. get_termination_switch ( ) ;
11306
+ let counters = run_loop. counters ( ) ;
11307
+ let Counters {
11308
+ blocks_processed,
11309
+ naka_submitted_commits : commits_submitted,
11310
+ ..
11311
+ } = run_loop. counters ( ) ;
11312
+
11313
+ let coord_channel = run_loop. coordinator_channels ( ) ;
11314
+
11315
+ let run_loop_thread = thread:: spawn ( move || run_loop. start ( None , 0 ) ) ;
11316
+ let mut signers = TestSigners :: new ( vec ! [ signer_sk] ) ;
11317
+ wait_for_runloop ( & blocks_processed) ;
11318
+ boot_to_epoch_3 (
11319
+ & conf,
11320
+ & blocks_processed,
11321
+ & [ stacker_sk] ,
11322
+ & [ signer_sk] ,
11323
+ & mut Some ( & mut signers) ,
11324
+ & mut btc_regtest_controller,
11325
+ ) ;
11326
+
11327
+ info ! ( "------------------------- Reached Epoch 3.0 -------------------------" ) ;
11328
+
11329
+ blind_signer ( & conf, & signers, & counters) ;
11330
+
11331
+ wait_for_first_naka_block_commit ( 60 , & commits_submitted) ;
11332
+
11333
+ next_block_and_mine_commit ( & mut btc_regtest_controller, 60 , & conf, & counters) . unwrap ( ) ;
11334
+
11335
+ let burnchain = conf. get_burnchain ( ) ;
11336
+ let sortdb = burnchain. open_sortition_db ( true ) . unwrap ( ) ;
11337
+
11338
+ let tip = SortitionDB :: get_canonical_burn_chain_tip ( sortdb. conn ( ) ) . unwrap ( ) ;
11339
+ let stacks_height = tip. stacks_block_height ;
11340
+
11341
+ let mut last_log = Instant :: now ( ) ;
11342
+ last_log -= Duration :: from_secs ( 5 ) ;
11343
+ wait_for ( 30 , || {
11344
+ let last_commit = & counters. naka_submitted_commit_last_stacks_tip . get ( ) ;
11345
+ if last_log. elapsed ( ) >= Duration :: from_secs ( 5 ) {
11346
+ info ! (
11347
+ "---- last_commit: {:?} stacks_height: {:?} ---- " ,
11348
+ last_commit, stacks_height
11349
+ ) ;
11350
+ last_log = Instant :: now ( ) ;
11351
+ }
11352
+ Ok ( * last_commit >= stacks_height)
11353
+ } )
11354
+ . expect ( "Failed to wait for last commit" ) ;
11355
+
11356
+ let commits_before = counters. naka_submitted_commits . get ( ) ;
11357
+
11358
+ let commit_amount_before = counters. naka_submitted_commit_last_commit_amount . get ( ) ;
11359
+
11360
+ info ! ( "---- Updating config ----" ) ;
11361
+
11362
+ update_config ( 155000 , 57 ) ;
11363
+
11364
+ wait_for ( 30 , || {
11365
+ let commit_count = & counters. naka_submitted_commits . get ( ) ;
11366
+ Ok ( * commit_count > commits_before)
11367
+ } )
11368
+ . expect ( "Expected new commit after config change" ) ;
11369
+
11370
+ let commit_amount_after = counters. naka_submitted_commit_last_commit_amount . get ( ) ;
11371
+ assert_eq ! ( commit_amount_after, 155000 ) ;
11372
+ assert_ne ! ( commit_amount_after, commit_amount_before) ;
11373
+
11374
+ coord_channel
11375
+ . lock ( )
11376
+ . expect ( "Mutex poisoned" )
11377
+ . stop_chains_coordinator ( ) ;
11378
+ run_loop_stopper. store ( false , Ordering :: SeqCst ) ;
11379
+
11380
+ run_loop_thread. join ( ) . unwrap ( ) ;
11381
+ }
0 commit comments