1
- use std:: net:: { IpAddr , Ipv4Addr } ;
2
-
1
+ use crate :: fork:: ForkDetails ;
3
2
use crate :: { observability, system_contracts} ;
3
+ use anyhow:: anyhow;
4
+ use std:: net:: { IpAddr , Ipv4Addr } ;
4
5
5
6
use crate :: config:: {
6
7
cache:: { CacheConfig , CacheType } ,
@@ -414,6 +415,12 @@ impl TestNodeConfig {
414
415
self . chain_id . unwrap_or ( TEST_NODE_NETWORK_ID )
415
416
}
416
417
418
+ /// Update the chain ID
419
+ pub fn update_chain_id ( & mut self , chain_id : Option < u32 > ) -> & mut Self {
420
+ self . chain_id = chain_id;
421
+ self
422
+ }
423
+
417
424
/// Set the system contracts configuration option
418
425
#[ must_use]
419
426
pub fn with_system_contracts ( mut self , option : Option < system_contracts:: Options > ) -> Self {
@@ -470,6 +477,12 @@ impl TestNodeConfig {
470
477
self . l1_gas_price . unwrap_or ( DEFAULT_L1_GAS_PRICE )
471
478
}
472
479
480
+ /// Update the L1 gas price
481
+ pub fn update_l1_gas_price ( & mut self , price : Option < u64 > ) -> & mut Self {
482
+ self . l1_gas_price = price;
483
+ self
484
+ }
485
+
473
486
/// Set the L2 gas price
474
487
#[ must_use]
475
488
pub fn with_l2_gas_price ( mut self , price : Option < u64 > ) -> Self {
@@ -484,6 +497,12 @@ impl TestNodeConfig {
484
497
self . l2_gas_price . unwrap_or ( DEFAULT_L2_GAS_PRICE )
485
498
}
486
499
500
+ /// Update the L2 gas price
501
+ pub fn update_l2_gas_price ( & mut self , price : Option < u64 > ) -> & mut Self {
502
+ self . l2_gas_price = price;
503
+ self
504
+ }
505
+
487
506
/// Set the L1 pubdata price
488
507
#[ must_use]
489
508
pub fn with_l1_pubdata_price ( mut self , price : Option < u64 > ) -> Self {
@@ -496,6 +515,12 @@ impl TestNodeConfig {
496
515
self . l1_pubdata_price . unwrap_or ( DEFAULT_FAIR_PUBDATA_PRICE )
497
516
}
498
517
518
+ /// Update the L1 pubdata price
519
+ pub fn update_l1_pubdata_price ( & mut self , price : Option < u64 > ) -> & mut Self {
520
+ self . l1_pubdata_price = price;
521
+ self
522
+ }
523
+
499
524
/// Set the log level
500
525
#[ must_use]
501
526
pub fn with_log_level ( mut self , level : Option < LogLevel > ) -> Self {
@@ -581,6 +606,12 @@ impl TestNodeConfig {
581
606
. unwrap_or ( DEFAULT_ESTIMATE_GAS_SCALE_FACTOR )
582
607
}
583
608
609
+ /// Update the gas limit scale factor
610
+ pub fn update_gas_limit_scale ( & mut self , scale : Option < f32 > ) -> & mut Self {
611
+ self . limit_scale_factor = scale;
612
+ self
613
+ }
614
+
584
615
/// Set the price scale factor
585
616
#[ must_use]
586
617
pub fn with_price_scale ( mut self , scale : Option < f64 > ) -> Self {
@@ -596,6 +627,12 @@ impl TestNodeConfig {
596
627
. unwrap_or ( DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR )
597
628
}
598
629
630
+ /// Updates the price scale factor
631
+ pub fn update_price_scale ( & mut self , scale : Option < f64 > ) -> & mut Self {
632
+ self . price_scale_factor = scale;
633
+ self
634
+ }
635
+
599
636
/// Set the detail level of VM execution logs
600
637
#[ must_use]
601
638
pub fn with_vm_log_detail ( mut self , detail : Option < ShowVMDetails > ) -> Self {
@@ -686,6 +723,28 @@ impl TestNodeConfig {
686
723
self . health_check_endpoint
687
724
}
688
725
726
+ /// Updates the configuration from fork details.
727
+ pub async fn update_with_fork_details (
728
+ & mut self ,
729
+ fork_details_result : Result < ForkDetails , eyre:: Report > ,
730
+ ) -> Result < Option < ForkDetails > , anyhow:: Error > {
731
+ match fork_details_result {
732
+ Ok ( fd) => {
733
+ self . update_l1_gas_price ( Some ( fd. l1_gas_price ) )
734
+ . update_l2_gas_price ( Some ( fd. l2_fair_gas_price ) )
735
+ . update_l1_pubdata_price ( Some ( fd. fair_pubdata_price ) )
736
+ . update_price_scale ( Some ( fd. estimate_gas_price_scale_factor ) )
737
+ . update_gas_limit_scale ( Some ( fd. estimate_gas_scale_factor ) )
738
+ . update_chain_id ( Some ( fd. chain_id . as_u64 ( ) as u32 ) ) ;
739
+ Ok ( Some ( fd) )
740
+ }
741
+ Err ( error) => {
742
+ tracing:: error!( "Error while attempting to fork: {:?}" , error) ;
743
+ Err ( anyhow ! ( error) )
744
+ }
745
+ }
746
+ }
747
+
689
748
/// Set the block time
690
749
#[ must_use]
691
750
pub fn with_block_time ( mut self , block_time : Option < Duration > ) -> Self {
0 commit comments