1- use std:: net:: { IpAddr , Ipv4Addr } ;
2-
1+ use crate :: fork:: ForkDetails ;
32use crate :: { observability, system_contracts} ;
3+ use anyhow:: anyhow;
4+ use std:: net:: { IpAddr , Ipv4Addr } ;
45
56use crate :: config:: {
67 cache:: { CacheConfig , CacheType } ,
@@ -414,6 +415,12 @@ impl TestNodeConfig {
414415 self . chain_id . unwrap_or ( TEST_NODE_NETWORK_ID )
415416 }
416417
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+
417424 /// Set the system contracts configuration option
418425 #[ must_use]
419426 pub fn with_system_contracts ( mut self , option : Option < system_contracts:: Options > ) -> Self {
@@ -470,6 +477,12 @@ impl TestNodeConfig {
470477 self . l1_gas_price . unwrap_or ( DEFAULT_L1_GAS_PRICE )
471478 }
472479
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+
473486 /// Set the L2 gas price
474487 #[ must_use]
475488 pub fn with_l2_gas_price ( mut self , price : Option < u64 > ) -> Self {
@@ -484,6 +497,12 @@ impl TestNodeConfig {
484497 self . l2_gas_price . unwrap_or ( DEFAULT_L2_GAS_PRICE )
485498 }
486499
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+
487506 /// Set the L1 pubdata price
488507 #[ must_use]
489508 pub fn with_l1_pubdata_price ( mut self , price : Option < u64 > ) -> Self {
@@ -496,6 +515,12 @@ impl TestNodeConfig {
496515 self . l1_pubdata_price . unwrap_or ( DEFAULT_FAIR_PUBDATA_PRICE )
497516 }
498517
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+
499524 /// Set the log level
500525 #[ must_use]
501526 pub fn with_log_level ( mut self , level : Option < LogLevel > ) -> Self {
@@ -581,6 +606,12 @@ impl TestNodeConfig {
581606 . unwrap_or ( DEFAULT_ESTIMATE_GAS_SCALE_FACTOR )
582607 }
583608
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+
584615 /// Set the price scale factor
585616 #[ must_use]
586617 pub fn with_price_scale ( mut self , scale : Option < f64 > ) -> Self {
@@ -596,6 +627,12 @@ impl TestNodeConfig {
596627 . unwrap_or ( DEFAULT_ESTIMATE_GAS_PRICE_SCALE_FACTOR )
597628 }
598629
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+
599636 /// Set the detail level of VM execution logs
600637 #[ must_use]
601638 pub fn with_vm_log_detail ( mut self , detail : Option < ShowVMDetails > ) -> Self {
@@ -686,6 +723,28 @@ impl TestNodeConfig {
686723 self . health_check_endpoint
687724 }
688725
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+
689748 /// Set the block time
690749 #[ must_use]
691750 pub fn with_block_time ( mut self , block_time : Option < Duration > ) -> Self {
0 commit comments