@@ -40,7 +40,6 @@ impl ExternalIdentifier {
4040
4141 let config = match config. get_etherscan_config_with_chain ( chain) {
4242 Ok ( Some ( config) ) => {
43- trace ! ( target: "traces::external" , chain=?config. chain, url=?config. api_url, "using etherscan identifier" ) ;
4443 chain = config. chain ;
4544 Some ( config)
4645 }
@@ -55,10 +54,18 @@ impl ExternalIdentifier {
5554 } ;
5655
5756 let mut fetchers = Vec :: < Arc < dyn ExternalFetcherT > > :: new ( ) ;
58- fetchers. push ( Arc :: new ( SourcifyFetcher :: new ( chain. unwrap_or_default ( ) ) ) ) ;
57+ if let Some ( chain) = chain {
58+ trace ! ( target: "traces::external" , ?chain, "using sourcify identifier" ) ;
59+ fetchers. push ( Arc :: new ( SourcifyFetcher :: new ( chain) ) ) ;
60+ }
5961 if let Some ( config) = config {
62+ trace ! ( target: "traces::external" , chain=?config. chain, url=?config. api_url, "using etherscan identifier" ) ;
6063 fetchers. push ( Arc :: new ( EtherscanFetcher :: new ( config. into_client ( ) ?) ) ) ;
6164 }
65+ if fetchers. is_empty ( ) {
66+ trace ! ( target: "traces::external" , "no fetchers enabled" ) ;
67+ return Ok ( None ) ;
68+ }
6269
6370 Ok ( Some ( Self { fetchers, contracts : Default :: default ( ) } ) )
6471 }
@@ -141,11 +148,10 @@ impl TraceIdentifier for ExternalIdentifier {
141148 if to_fetch. is_empty ( ) {
142149 return identities;
143150 }
151+ trace ! ( target: "evm::traces::external" , "fetching {} addresses" , to_fetch. len( ) ) ;
144152
145- let fetchers = self
146- . fetchers
147- . iter ( )
148- . map ( |fetcher| ExternalFetcher :: new ( fetcher. clone ( ) , Duration :: from_secs ( 1 ) , 5 ) ) ;
153+ let fetchers =
154+ self . fetchers . iter ( ) . map ( |fetcher| ExternalFetcher :: new ( fetcher. clone ( ) , & to_fetch) ) ;
149155 let fetched_identities = foundry_common:: block_on (
150156 futures:: stream:: select_all ( fetchers)
151157 . map ( |( address, value) | {
@@ -164,6 +170,7 @@ impl TraceIdentifier for ExternalIdentifier {
164170 } )
165171 . collect :: < Vec < IdentifiedAddress < ' _ > > > ( ) ,
166172 ) ;
173+ trace ! ( target: "traces::external" , "fetched {} addresses" , fetched_identities. len( ) ) ;
167174
168175 identities. extend ( fetched_identities) ;
169176 identities
@@ -192,13 +199,13 @@ struct ExternalFetcher {
192199}
193200
194201impl ExternalFetcher {
195- fn new ( fetcher : Arc < dyn ExternalFetcherT > , timeout : Duration , concurrency : usize ) -> Self {
202+ fn new ( fetcher : Arc < dyn ExternalFetcherT > , to_fetch : & [ Address ] ) -> Self {
196203 Self {
197- fetcher,
198- timeout,
204+ timeout : fetcher. timeout ( ) ,
199205 backoff : None ,
200- concurrency,
201- queue : Vec :: new ( ) ,
206+ concurrency : fetcher. concurrency ( ) ,
207+ fetcher,
208+ queue : to_fetch. to_vec ( ) ,
202209 in_progress : FuturesUnordered :: new ( ) ,
203210 }
204211 }
@@ -288,6 +295,8 @@ enum FetcherKind {
288295#[ async_trait:: async_trait]
289296trait ExternalFetcherT : Send + Sync {
290297 fn kind ( & self ) -> FetcherKind ;
298+ fn timeout ( & self ) -> Duration ;
299+ fn concurrency ( & self ) -> usize ;
291300 fn invalid_api_key ( & self ) -> & AtomicBool ;
292301 async fn fetch ( & self , address : Address ) -> Result < Option < Metadata > , EtherscanError > ;
293302}
@@ -309,6 +318,14 @@ impl ExternalFetcherT for EtherscanFetcher {
309318 FetcherKind :: Etherscan
310319 }
311320
321+ fn timeout ( & self ) -> Duration {
322+ Duration :: from_secs ( 1 )
323+ }
324+
325+ fn concurrency ( & self ) -> usize {
326+ 5
327+ }
328+
312329 fn invalid_api_key ( & self ) -> & AtomicBool {
313330 & self . invalid_api_key
314331 }
@@ -340,6 +357,14 @@ impl ExternalFetcherT for SourcifyFetcher {
340357 FetcherKind :: Sourcify
341358 }
342359
360+ fn timeout ( & self ) -> Duration {
361+ Duration :: from_secs ( 1 )
362+ }
363+
364+ fn concurrency ( & self ) -> usize {
365+ 5
366+ }
367+
343368 fn invalid_api_key ( & self ) -> & AtomicBool {
344369 & self . invalid_api_key
345370 }
@@ -349,14 +374,15 @@ impl ExternalFetcherT for SourcifyFetcher {
349374 let url = format ! ( "{url}/{address}?fields=abi,compilation,proxyResolution" , url = self . url) ;
350375 let response = self . client . get ( url) . send ( ) . await ?;
351376 let code = response. status ( ) ;
377+ let response: SourcifyResponse = response. json ( ) . await ?;
378+ trace ! ( target: "traces::external" , "Sourcify response: {response:#?}" ) ;
352379 match code. as_u16 ( ) {
353380 // Not verified.
354381 404 => return Ok ( None ) ,
355382 // Rate limited.
356383 429 => return Err ( EtherscanError :: RateLimitExceeded ) ,
357384 _ => { }
358385 }
359- let response: SourcifyResponse = response. json ( ) . await ?;
360386 match response {
361387 SourcifyResponse :: Success ( metadata) => Ok ( Some ( metadata. into ( ) ) ) ,
362388 SourcifyResponse :: Error ( error) => Err ( EtherscanError :: Unknown ( format ! ( "{error:#?}" ) ) ) ,
0 commit comments