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:: {
@@ -15,14 +21,16 @@ use init4_bin_base::{
1521 perms:: { Authenticator , OAuthConfig , SharedToken } ,
1622 utils:: {
1723 calc:: SlotCalculator ,
24+ flashbots:: Flashbots ,
1825 from_env:: FromEnv ,
1926 provider:: { ProviderConfig , PubSubConfig } ,
2027 signer:: { LocalOrAws , SignerError } ,
2128 } ,
2229} ;
30+ use signet_constants:: SignetSystemConstants ;
2331use signet_zenith:: Zenith ;
2432use std:: borrow:: Cow ;
25- use tokio:: join;
33+ use tokio:: { join, sync :: mpsc :: UnboundedSender , task :: JoinHandle } ;
2634
2735/// Type alias for the provider used to simulate against rollup state.
2836pub type RuProvider = RootProvider < Ethereum > ;
@@ -89,13 +97,8 @@ pub struct BuilderConfig {
8997 ) ]
9098 pub tx_broadcast_urls : Vec < Cow < ' static , str > > ,
9199
92- /// Flashbots endpoint for privately submitting rollup blocks.
93- #[ from_env(
94- var = "FLASHBOTS_ENDPOINT" ,
95- desc = "Flashbots endpoint for privately submitting rollup blocks" ,
96- optional
97- ) ]
98- pub flashbots_endpoint : Option < url:: Url > ,
100+ /// Flashbots configuration for privately submitting rollup blocks.
101+ pub flashbots : init4_bin_base:: utils:: flashbots:: FlashbotsConfig ,
99102
100103 /// Address of the Zenith contract on Host.
101104 #[ from_env( var = "ZENITH_ADDRESS" , desc = "address of the Zenith contract on Host" ) ]
@@ -163,12 +166,21 @@ pub struct BuilderConfig {
163166
164167 /// The slot calculator for the builder.
165168 pub slot_calculator : SlotCalculator ,
169+
170+ /// The signet system constants.
171+ pub constants : SignetSystemConstants ,
166172}
167173
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.
@@ -275,4 +287,35 @@ impl BuilderConfig {
275287 . unwrap_or ( DEFAULT_CONCURRENCY_LIMIT )
276288 } )
277289 }
290+
291+ /// Connect to a Flashbots provider.
292+ pub async fn flashbots_provider ( & self ) -> eyre:: Result < Flashbots > {
293+ self . flashbots
294+ . build ( self . connect_builder_signer ( ) . await ?)
295+ . ok_or_else ( || eyre:: eyre!( "Flashbots is not configured" ) )
296+ }
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+ }
278321}
0 commit comments