1
- use crate :: signer:: { LocalOrAws , SignerError } ;
1
+ use crate :: {
2
+ constants,
3
+ signer:: { LocalOrAws , SignerError } ,
4
+ } ;
2
5
use alloy:: {
3
6
network:: { Ethereum , EthereumWallet } ,
4
7
primitives:: Address ,
@@ -9,10 +12,12 @@ use alloy::{
9
12
WalletFiller ,
10
13
} ,
11
14
} ,
12
- transports:: BoxTransport ,
13
15
} ;
16
+ use eyre:: Result ;
17
+ use oauth2:: url;
18
+ use signet_types:: config:: { HostConfig , PredeployTokens , RollupConfig , SignetSystemConstants } ;
19
+ use signet_zenith:: Zenith ;
14
20
use std:: { borrow:: Cow , env, num, str:: FromStr } ;
15
- use zenith_types:: Zenith ;
16
21
17
22
// Keys for .env variables that need to be set to configure the builder.
18
23
const HOST_CHAIN_ID : & str = "HOST_CHAIN_ID" ;
@@ -38,6 +43,8 @@ const OAUTH_CLIENT_ID: &str = "OAUTH_CLIENT_ID";
38
43
const OAUTH_CLIENT_SECRET : & str = "OAUTH_CLIENT_SECRET" ;
39
44
const OAUTH_AUTHENTICATE_URL : & str = "OAUTH_AUTHENTICATE_URL" ;
40
45
const OAUTH_TOKEN_URL : & str = "OAUTH_TOKEN_URL" ;
46
+ const CONCURRENCY_LIMIT : & str = "CONCURRENCY_LIMIT" ;
47
+ const START_TIMESTAMP : & str = "START_TIMESTAMP" ;
41
48
42
49
/// Configuration for a builder running a specific rollup on a specific host
43
50
/// chain.
@@ -93,6 +100,10 @@ pub struct BuilderConfig {
93
100
pub oauth_token_url : String ,
94
101
/// The oauth token refresh interval in seconds.
95
102
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 ,
96
107
}
97
108
98
109
/// Error loading the configuration.
@@ -116,6 +127,9 @@ pub enum ConfigError {
116
127
/// Error connecting to the signer
117
128
#[ error( "failed to connect to signer: {0}" ) ]
118
129
Signer ( #[ from] SignerError ) ,
130
+ /// I/O error
131
+ #[ error( "I/O error: {0}" ) ]
132
+ Io ( #[ from] std:: io:: Error ) ,
119
133
}
120
134
121
135
impl ConfigError {
@@ -125,35 +139,24 @@ impl ConfigError {
125
139
}
126
140
}
127
141
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 <
130
144
JoinFill <
131
145
JoinFill <
132
146
Identity ,
133
147
JoinFill < GasFiller , JoinFill < BlobGasFiller , JoinFill < NonceFiller , ChainIdFiller > > > ,
134
148
> ,
135
149
WalletFiller < EthereumWallet > ,
136
150
> ,
137
- RootProvider < BoxTransport > ,
138
- BoxTransport ,
151
+ RootProvider ,
139
152
Ethereum ,
140
153
> ;
141
154
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 > ;
152
157
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 > ;
157
160
158
161
impl BuilderConfig {
159
162
/// Load the builder configuration from environment variables.
@@ -189,6 +192,8 @@ impl BuilderConfig {
189
192
oauth_authenticate_url : load_string ( OAUTH_AUTHENTICATE_URL ) ?,
190
193
oauth_token_url : load_string ( OAUTH_TOKEN_URL ) ?,
191
194
oauth_token_refresh_interval : load_u64 ( AUTH_TOKEN_REFRESH_INTERVAL ) ?,
195
+ concurrency_limit : load_concurrency_limit ( ) ?,
196
+ start_timestamp : load_u64 ( START_TIMESTAMP ) ?,
192
197
} )
193
198
}
194
199
@@ -209,42 +214,67 @@ impl BuilderConfig {
209
214
}
210
215
211
216
/// 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)
218
221
}
219
222
220
223
/// 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 > {
222
225
let builder_signer = self . connect_builder_signer ( ) . await ?;
223
- ProviderBuilder :: new ( )
224
- . with_recommended_fillers ( )
226
+ let provider = ProviderBuilder :: new ( )
225
227
. wallet ( EthereumWallet :: from ( builder_signer) )
226
- . on_builtin ( & self . host_rpc_url )
228
+ . connect ( & self . host_rpc_url )
227
229
. await
228
- . map_err ( Into :: into)
230
+ . map_err ( ConfigError :: Provider ) ?;
231
+
232
+ Ok ( provider)
229
233
}
230
234
231
235
/// 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) ;
239
242
providers. push ( provider) ;
240
243
}
244
+
241
245
Ok ( providers)
242
246
}
243
247
244
248
/// 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 {
246
250
Zenith :: new ( self . zenith_address , provider)
247
251
}
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
+ }
248
278
}
249
279
250
280
/// Load a string from an environment variable.
@@ -278,5 +308,18 @@ pub fn load_url(key: &str) -> Result<Cow<'static, str>, ConfigError> {
278
308
/// Load an address from an environment variable.
279
309
pub fn load_address ( key : & str ) -> Result < Address , ConfigError > {
280
310
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
+ }
282
325
}
0 commit comments