1- use  crate :: { quincey:: Quincey ,  tasks:: block:: cfg:: SignetCfgEnv } ; 
1+ use  crate :: { 
2+     quincey:: Quincey , 
3+     tasks:: { 
4+         block:: { cfg:: SignetCfgEnv ,  sim:: SimResult } , 
5+         submit:: { BuilderHelperTask ,  FlashbotsTask } , 
6+     } , 
7+ } ; 
28use  alloy:: { 
39    network:: { Ethereum ,  EthereumWallet } , 
4-     primitives:: Address , 
10+     primitives:: { Address ,   TxHash } , 
511    providers:: { 
612        Identity ,  ProviderBuilder ,  RootProvider , 
713        fillers:: { 
@@ -24,7 +30,7 @@ use init4_bin_base::{
2430use  signet_constants:: SignetSystemConstants ; 
2531use  signet_zenith:: Zenith ; 
2632use  std:: borrow:: Cow ; 
27- use  tokio:: join; 
33+ use  tokio:: { join,  sync :: mpsc :: UnboundedSender ,  task :: JoinHandle } ; 
2834
2935/// Type alias for the provider used to simulate against rollup state. 
3036pub  type  RuProvider  = RootProvider < Ethereum > ; 
@@ -168,7 +174,13 @@ pub struct BuilderConfig {
168174impl  BuilderConfig  { 
169175    /// Connect to the Builder signer. 
170176     pub  async  fn  connect_builder_signer ( & self )  -> Result < LocalOrAws ,  SignerError >  { 
171-         LocalOrAws :: load ( & self . builder_key ,  Some ( self . host_chain_id ) ) . await 
177+         static  ONCE :  tokio:: sync:: OnceCell < LocalOrAws >  = tokio:: sync:: OnceCell :: const_new ( ) ; 
178+ 
179+         ONCE . get_or_try_init ( || async  { 
180+             LocalOrAws :: load ( & self . builder_key ,  Some ( self . host_chain_id ) ) . await 
181+         } ) 
182+         . await 
183+         . cloned ( ) 
172184    } 
173185
174186    /// Connect to the Sequencer signer. 
@@ -282,4 +294,28 @@ impl BuilderConfig {
282294            . build ( self . connect_builder_signer ( ) . await ?) 
283295            . ok_or_else ( || eyre:: eyre!( "Flashbots is not configured" ) ) 
284296    } 
297+ 
298+     /// Spawn a submit task, either Flashbots or BuilderHelper depending on 
299+      /// configuration. 
300+      pub  async  fn  spawn_submit_task ( 
301+         & self , 
302+         tx_channel :  UnboundedSender < TxHash > , 
303+     )  -> eyre:: Result < ( UnboundedSender < SimResult > ,  JoinHandle < ( ) > ) >  { 
304+         // If we have a flashbots endpoint, use that 
305+         if  self . flashbots . flashbots_endpoint . is_some ( )  { 
306+             // Make a Flashbots submission task 
307+             let  submit = FlashbotsTask :: new ( self . clone ( ) ,  tx_channel) . await ?; 
308+ 
309+             // Set up flashbots submission 
310+             let  ( submit_channel,  submit_jh)  = submit. spawn ( ) ; 
311+             return  Ok ( ( submit_channel,  submit_jh) ) ; 
312+         } 
313+ 
314+         // Make a Tx submission task 
315+         let  submit = BuilderHelperTask :: new ( self . clone ( ) ,  tx_channel) . await ?; 
316+ 
317+         // Set up tx submission 
318+         let  ( submit_channel,  submit_jh)  = submit. spawn ( ) ; 
319+         Ok ( ( submit_channel,  submit_jh) ) 
320+     } 
285321} 
0 commit comments