@@ -619,7 +619,7 @@ impl PeerHostExtensions for PeerHost {
619
619
}
620
620
621
621
/// Runtime arguments to an RPC handler
622
- #[ derive( Default ) ]
622
+ #[ derive( Default , Clone ) ]
623
623
pub struct RPCHandlerArgs < ' a > {
624
624
/// What height at which this node will terminate (testnet only)
625
625
pub exit_at_block_height : Option < u64 > ,
@@ -2222,7 +2222,7 @@ pub mod test {
2222
2222
use std:: net:: * ;
2223
2223
use std:: ops:: { Deref , DerefMut } ;
2224
2224
use std:: sync:: mpsc:: sync_channel;
2225
- use std:: sync:: Mutex ;
2225
+ use std:: sync:: { Arc , Mutex } ;
2226
2226
use std:: { fs, io, thread} ;
2227
2227
2228
2228
use clarity:: boot_util:: boot_code_id;
@@ -2277,6 +2277,9 @@ pub mod test {
2277
2277
use crate :: chainstate:: * ;
2278
2278
use crate :: clarity:: vm:: clarity:: TransactionConnection ;
2279
2279
use crate :: core:: { EpochList , StacksEpoch , StacksEpochExtension , NETWORK_P2P_PORT } ;
2280
+ use crate :: cost_estimates:: metrics:: UnitMetric ;
2281
+ use crate :: cost_estimates:: tests:: fee_rate_fuzzer:: ConstantFeeEstimator ;
2282
+ use crate :: cost_estimates:: UnitEstimator ;
2280
2283
use crate :: net:: asn:: * ;
2281
2284
use crate :: net:: atlas:: * ;
2282
2285
use crate :: net:: chat:: * ;
@@ -2287,7 +2290,7 @@ pub mod test {
2287
2290
use crate :: net:: p2p:: * ;
2288
2291
use crate :: net:: poll:: * ;
2289
2292
use crate :: net:: relay:: * ;
2290
- use crate :: net:: Error as net_error;
2293
+ use crate :: net:: { Error as net_error, ProtocolFamily , TipRequest } ;
2291
2294
use crate :: util_lib:: boot:: boot_code_test_addr;
2292
2295
use crate :: util_lib:: strings:: * ;
2293
2296
@@ -2552,6 +2555,75 @@ pub mod test {
2552
2555
}
2553
2556
}
2554
2557
2558
+ const DEFAULT_RPC_HANDLER_ARGS : RPCHandlerArgs < ' static > = RPCHandlerArgs {
2559
+ exit_at_block_height : None ,
2560
+ genesis_chainstate_hash : Sha256Sum ( [ 0x00 ; 32 ] ) ,
2561
+ event_observer : None ,
2562
+ cost_estimator : None ,
2563
+ fee_estimator : None ,
2564
+ cost_metric : None ,
2565
+ coord_comms : None ,
2566
+ } ;
2567
+
2568
+ const NULL_COST_ESTIMATOR : ( ) = ( ) ;
2569
+ const NULL_FEE_ESTIMATOR : ( ) = ( ) ;
2570
+ const NULL_COST_METRIC : UnitMetric = UnitMetric { } ;
2571
+ const NULL_RPC_HANDLER_ARGS : RPCHandlerArgs < ' static > = RPCHandlerArgs {
2572
+ exit_at_block_height : None ,
2573
+ genesis_chainstate_hash : Sha256Sum ( [ 0x00 ; 32 ] ) ,
2574
+ event_observer : None ,
2575
+ cost_estimator : Some ( & NULL_COST_ESTIMATOR ) ,
2576
+ fee_estimator : Some ( & NULL_FEE_ESTIMATOR ) ,
2577
+ cost_metric : Some ( & NULL_COST_METRIC ) ,
2578
+ coord_comms : None ,
2579
+ } ;
2580
+
2581
+ const UNIT_COST_ESTIMATOR : UnitEstimator = UnitEstimator { } ;
2582
+ const CONSTANT_FEE_ESTIMATOR : ConstantFeeEstimator = ConstantFeeEstimator { } ;
2583
+ const UNIT_COST_METRIC : UnitMetric = UnitMetric { } ;
2584
+ const UNIT_RPC_HANDLER_ARGS : RPCHandlerArgs < ' static > = RPCHandlerArgs {
2585
+ exit_at_block_height : None ,
2586
+ genesis_chainstate_hash : Sha256Sum ( [ 0x00 ; 32 ] ) ,
2587
+ event_observer : None ,
2588
+ cost_estimator : Some ( & UNIT_COST_ESTIMATOR ) ,
2589
+ fee_estimator : Some ( & CONSTANT_FEE_ESTIMATOR ) ,
2590
+ cost_metric : Some ( & UNIT_COST_METRIC ) ,
2591
+ coord_comms : None ,
2592
+ } ;
2593
+
2594
+ /// Templates for RPC Handler Args (which must be owned by the TestPeer, and cannot be a bare
2595
+ /// RPCHandlerArgs since references to the inner members cannot be made thread-safe).
2596
+ #[ derive( Clone , Debug , PartialEq ) ]
2597
+ pub enum RPCHandlerArgsType {
2598
+ Default ,
2599
+ Null ,
2600
+ Unit ,
2601
+ }
2602
+
2603
+ impl RPCHandlerArgsType {
2604
+ pub fn instantiate ( & self ) -> RPCHandlerArgs < ' static > {
2605
+ match self {
2606
+ Self :: Default => {
2607
+ debug ! ( "Default RPC Handler Args" ) ;
2608
+ DEFAULT_RPC_HANDLER_ARGS . clone ( )
2609
+ }
2610
+ Self :: Null => {
2611
+ debug ! ( "Null RPC Handler Args" ) ;
2612
+ NULL_RPC_HANDLER_ARGS . clone ( )
2613
+ }
2614
+ Self :: Unit => {
2615
+ debug ! ( "Unit RPC Handler Args" ) ;
2616
+ UNIT_RPC_HANDLER_ARGS . clone ( )
2617
+ }
2618
+ }
2619
+ }
2620
+
2621
+ pub fn make_default ( ) -> RPCHandlerArgs < ' static > {
2622
+ debug ! ( "Default RPC Handler Args" ) ;
2623
+ DEFAULT_RPC_HANDLER_ARGS . clone ( )
2624
+ }
2625
+ }
2626
+
2555
2627
// describes a peer's initial configuration
2556
2628
#[ derive( Debug , Clone ) ]
2557
2629
pub struct TestPeerConfig {
@@ -2771,6 +2843,8 @@ pub mod test {
2771
2843
/// tenure-start block of tenure to mine on.
2772
2844
/// gets consumed on the call to begin_nakamoto_tenure
2773
2845
pub nakamoto_parent_tenure_opt : Option < Vec < NakamotoBlock > > ,
2846
+ /// RPC handler args to use
2847
+ pub rpc_handler_args : Option < RPCHandlerArgsType > ,
2774
2848
}
2775
2849
2776
2850
impl < ' a > TestPeer < ' a > {
@@ -3190,6 +3264,7 @@ pub mod test {
3190
3264
malleablized_blocks : vec ! [ ] ,
3191
3265
mine_malleablized_blocks : true ,
3192
3266
nakamoto_parent_tenure_opt : None ,
3267
+ rpc_handler_args : None ,
3193
3268
}
3194
3269
}
3195
3270
@@ -3301,6 +3376,11 @@ pub mod test {
3301
3376
let mut stacks_node = self . stacks_node . take ( ) . unwrap ( ) ;
3302
3377
let mut mempool = self . mempool . take ( ) . unwrap ( ) ;
3303
3378
let indexer = self . indexer . take ( ) . unwrap ( ) ;
3379
+ let rpc_handler_args = self
3380
+ . rpc_handler_args
3381
+ . as_ref ( )
3382
+ . map ( |args_type| args_type. instantiate ( ) )
3383
+ . unwrap_or ( RPCHandlerArgsType :: make_default ( ) ) ;
3304
3384
3305
3385
let old_tip = self . network . stacks_tip . clone ( ) ;
3306
3386
@@ -3313,14 +3393,13 @@ pub mod test {
3313
3393
false ,
3314
3394
ibd,
3315
3395
100 ,
3316
- & RPCHandlerArgs :: default ( ) ,
3396
+ & rpc_handler_args ,
3317
3397
) ;
3318
3398
3319
3399
self . sortdb = Some ( sortdb) ;
3320
3400
self . stacks_node = Some ( stacks_node) ;
3321
3401
self . mempool = Some ( mempool) ;
3322
3402
self . indexer = Some ( indexer) ;
3323
-
3324
3403
ret
3325
3404
}
3326
3405
@@ -3381,7 +3460,11 @@ pub mod test {
3381
3460
burn_tip_height,
3382
3461
) ;
3383
3462
let indexer = BitcoinIndexer :: new_unit_test ( & self . config . burnchain . working_dir ) ;
3384
-
3463
+ let rpc_handler_args = self
3464
+ . rpc_handler_args
3465
+ . as_ref ( )
3466
+ . map ( |args_type| args_type. instantiate ( ) )
3467
+ . unwrap_or ( RPCHandlerArgsType :: make_default ( ) ) ;
3385
3468
let old_tip = self . network . stacks_tip . clone ( ) ;
3386
3469
3387
3470
let ret = self . network . run (
@@ -3393,7 +3476,7 @@ pub mod test {
3393
3476
false ,
3394
3477
ibd,
3395
3478
100 ,
3396
- & RPCHandlerArgs :: default ( ) ,
3479
+ & rpc_handler_args ,
3397
3480
) ;
3398
3481
3399
3482
self . sortdb = Some ( sortdb) ;
0 commit comments