1- use crate :: signer:: { LocalOrAws , SignerError } ;
1+ use crate :: {
2+ constants,
3+ signer:: { LocalOrAws , SignerError } ,
4+ } ;
25use alloy:: {
36 network:: { Ethereum , EthereumWallet } ,
47 primitives:: Address ,
@@ -9,10 +12,12 @@ use alloy::{
912 WalletFiller ,
1013 } ,
1114 } ,
12- transports:: BoxTransport ,
1315} ;
16+ use eyre:: Result ;
17+ use oauth2:: url;
18+ use signet_types:: config:: { HostConfig , PredeployTokens , RollupConfig , SignetSystemConstants } ;
19+ use signet_zenith:: Zenith ;
1420use std:: { borrow:: Cow , env, num, str:: FromStr } ;
15- use zenith_types:: Zenith ;
1621
1722// Keys for .env variables that need to be set to configure the builder.
1823const HOST_CHAIN_ID : & str = "HOST_CHAIN_ID" ;
@@ -38,6 +43,8 @@ const OAUTH_CLIENT_ID: &str = "OAUTH_CLIENT_ID";
3843const OAUTH_CLIENT_SECRET : & str = "OAUTH_CLIENT_SECRET" ;
3944const OAUTH_AUTHENTICATE_URL : & str = "OAUTH_AUTHENTICATE_URL" ;
4045const OAUTH_TOKEN_URL : & str = "OAUTH_TOKEN_URL" ;
46+ const CONCURRENCY_LIMIT : & str = "CONCURRENCY_LIMIT" ;
47+ const START_TIMESTAMP : & str = "START_TIMESTAMP" ;
4148
4249/// Configuration for a builder running a specific rollup on a specific host
4350/// chain.
@@ -93,6 +100,10 @@ pub struct BuilderConfig {
93100 pub oauth_token_url : String ,
94101 /// The oauth token refresh interval in seconds.
95102 pub oauth_token_refresh_interval : u64 ,
103+ /// The max number of simultaneous block simulations to run.
104+ pub concurrency_limit : usize ,
105+ /// The anchor for slot time and number calculations before adjusting for chain offset.
106+ pub start_timestamp : u64 ,
96107}
97108
98109/// Error loading the configuration.
@@ -116,6 +127,9 @@ pub enum ConfigError {
116127 /// Error connecting to the signer
117128 #[ error( "failed to connect to signer: {0}" ) ]
118129 Signer ( #[ from] SignerError ) ,
130+ /// I/O error
131+ #[ error( "I/O error: {0}" ) ]
132+ Io ( #[ from] std:: io:: Error ) ,
119133}
120134
121135impl ConfigError {
@@ -125,35 +139,24 @@ impl ConfigError {
125139 }
126140}
127141
128- /// Provider type used to read & write .
129- pub type Provider = FillProvider <
142+ /// Type alias for the provider used to build and submit blocks to the host .
143+ pub type HostProvider = FillProvider <
130144 JoinFill <
131145 JoinFill <
132146 Identity ,
133147 JoinFill < GasFiller , JoinFill < BlobGasFiller , JoinFill < NonceFiller , ChainIdFiller > > > ,
134148 > ,
135149 WalletFiller < EthereumWallet > ,
136150 > ,
137- RootProvider < BoxTransport > ,
138- BoxTransport ,
151+ RootProvider ,
139152 Ethereum ,
140153> ;
141154
142- /// Provider type used to read-only.
143- pub type WalletlessProvider = FillProvider <
144- JoinFill <
145- Identity ,
146- JoinFill < GasFiller , JoinFill < BlobGasFiller , JoinFill < NonceFiller , ChainIdFiller > > > ,
147- > ,
148- RootProvider < BoxTransport > ,
149- BoxTransport ,
150- Ethereum ,
151- > ;
155+ /// Type alias for the provider used to simulate against rollup state.
156+ pub type RuProvider = RootProvider < Ethereum > ;
152157
153- /// A Zenith contract instance, using some provider `P` (defaults to
154- /// [`Provider`]).
155- pub type ZenithInstance < P = Provider > =
156- Zenith :: ZenithInstance < BoxTransport , P , alloy:: network:: Ethereum > ;
158+ /// A [`Zenith`] contract instance using [`Provider`] as the provider.
159+ pub type ZenithInstance < P = HostProvider > = Zenith :: ZenithInstance < ( ) , P , alloy:: network:: Ethereum > ;
157160
158161impl BuilderConfig {
159162 /// Load the builder configuration from environment variables.
@@ -189,6 +192,8 @@ impl BuilderConfig {
189192 oauth_authenticate_url : load_string ( OAUTH_AUTHENTICATE_URL ) ?,
190193 oauth_token_url : load_string ( OAUTH_TOKEN_URL ) ?,
191194 oauth_token_refresh_interval : load_u64 ( AUTH_TOKEN_REFRESH_INTERVAL ) ?,
195+ concurrency_limit : load_concurrency_limit ( ) ?,
196+ start_timestamp : load_u64 ( START_TIMESTAMP ) ?,
192197 } )
193198 }
194199
@@ -209,42 +214,67 @@ impl BuilderConfig {
209214 }
210215
211216 /// Connect to the Rollup rpc provider.
212- pub async fn connect_ru_provider ( & self ) -> Result < WalletlessProvider , ConfigError > {
213- ProviderBuilder :: new ( )
214- . with_recommended_fillers ( )
215- . on_builtin ( & self . ru_rpc_url )
216- . await
217- . map_err ( Into :: into)
217+ pub async fn connect_ru_provider ( & self ) -> Result < RootProvider < Ethereum > , ConfigError > {
218+ let url = url:: Url :: parse ( & self . ru_rpc_url ) . expect ( "failed to parse URL" ) ;
219+ let provider = RootProvider :: < Ethereum > :: new_http ( url) ;
220+ Ok ( provider)
218221 }
219222
220223 /// Connect to the Host rpc provider.
221- pub async fn connect_host_provider ( & self ) -> Result < Provider , ConfigError > {
224+ pub async fn connect_host_provider ( & self ) -> Result < HostProvider , ConfigError > {
222225 let builder_signer = self . connect_builder_signer ( ) . await ?;
223- ProviderBuilder :: new ( )
224- . with_recommended_fillers ( )
226+ let provider = ProviderBuilder :: new ( )
225227 . wallet ( EthereumWallet :: from ( builder_signer) )
226- . on_builtin ( & self . host_rpc_url )
228+ . connect ( & self . host_rpc_url )
227229 . await
228- . map_err ( Into :: into)
230+ . map_err ( ConfigError :: Provider ) ?;
231+
232+ Ok ( provider)
229233 }
230234
231235 /// Connect additional broadcast providers.
232- pub async fn connect_additional_broadcast (
233- & self ,
234- ) -> Result < Vec < RootProvider < BoxTransport > > , ConfigError > {
235- let mut providers = Vec :: with_capacity ( self . tx_broadcast_urls . len ( ) ) ;
236- for url in self . tx_broadcast_urls . iter ( ) {
237- let provider =
238- ProviderBuilder :: new ( ) . on_builtin ( url) . await . map_err ( Into :: < ConfigError > :: into) ?;
236+ pub async fn connect_additional_broadcast ( & self ) -> Result < Vec < RootProvider > , ConfigError > {
237+ let mut providers: Vec < RootProvider > = Vec :: with_capacity ( self . tx_broadcast_urls . len ( ) ) ;
238+
239+ for url_str in self . tx_broadcast_urls . iter ( ) {
240+ let url = url:: Url :: parse ( url_str) . expect ( "failed to parse URL" ) ;
241+ let provider = RootProvider :: new_http ( url) ;
239242 providers. push ( provider) ;
240243 }
244+
241245 Ok ( providers)
242246 }
243247
244248 /// Connect to the Zenith instance, using the specified provider.
245- pub const fn connect_zenith ( & self , provider : Provider ) -> ZenithInstance {
249+ pub const fn connect_zenith ( & self , provider : HostProvider ) -> ZenithInstance {
246250 Zenith :: new ( self . zenith_address , provider)
247251 }
252+
253+ /// Loads the Signet system constants for Pecorino.
254+ pub const fn load_pecorino_constants ( & self ) -> SignetSystemConstants {
255+ let host = HostConfig :: new (
256+ self . host_chain_id ,
257+ constants:: PECORINO_DEPLOY_HEIGHT ,
258+ self . zenith_address ,
259+ constants:: HOST_ORDERS ,
260+ constants:: HOST_PASSAGE ,
261+ constants:: HOST_TRANSACTOR ,
262+ PredeployTokens :: new ( constants:: HOST_USDC , constants:: HOST_USDT , constants:: HOST_WBTC ) ,
263+ ) ;
264+ let rollup = RollupConfig :: new (
265+ self . ru_chain_id ,
266+ constants:: ROLLUP_ORDERS ,
267+ constants:: ROLLUP_PASSAGE ,
268+ constants:: BASE_FEE_RECIPIENT ,
269+ PredeployTokens :: new (
270+ constants:: ROLLUP_USDC ,
271+ constants:: ROLLUP_USDT ,
272+ constants:: ROLLUP_WBTC ,
273+ ) ,
274+ ) ;
275+
276+ SignetSystemConstants :: new ( host, rollup)
277+ }
248278}
249279
250280/// Load a string from an environment variable.
@@ -278,5 +308,18 @@ pub fn load_url(key: &str) -> Result<Cow<'static, str>, ConfigError> {
278308/// Load an address from an environment variable.
279309pub fn load_address ( key : & str ) -> Result < Address , ConfigError > {
280310 let address = load_string ( key) ?;
281- Address :: from_str ( & address) . map_err ( Into :: into)
311+ Address :: from_str ( & address)
312+ . map_err ( |_| ConfigError :: Var ( format ! ( "Invalid address format for {}" , key) ) )
313+ }
314+
315+ /// Checks the configured concurrency parameter and, if none is set, checks the available
316+ /// system concurrency with `std::thread::available_parallelism` and returns that.
317+ pub fn load_concurrency_limit ( ) -> Result < usize , ConfigError > {
318+ match load_u16 ( CONCURRENCY_LIMIT ) {
319+ Ok ( env) => Ok ( env as usize ) ,
320+ Err ( _) => {
321+ let limit = std:: thread:: available_parallelism ( ) ?. get ( ) ;
322+ Ok ( limit)
323+ }
324+ }
282325}
0 commit comments