Skip to content

Commit

Permalink
L1 client fixup (#2442)
Browse files Browse the repository at this point in the history
* Add new L1 env vars to public endpoint

* Don't expose L1 provider URL in metrics
  • Loading branch information
jbearer authored Jan 14, 2025
1 parent ed18183 commit ea5d100
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
4 changes: 4 additions & 0 deletions sequencer/api/public-env-vars.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,14 @@ variables = [
"ESPRESSO_SEQUENCER_HOTSHOT_EVENT_STREAMING_API_PORT",
"ESPRESSO_SEQUENCER_IS_DA",
"ESPRESSO_SEQUENCER_L1_BLOCKS_CACHE_SIZE",
"ESPRESSO_SEQUENCER_L1_CONSECUTIVE_FAILURE_TOLERANCE",
"ESPRESSO_SEQUENCER_L1_EVENTS_CHANNEL_CAPACITY",
"ESPRESSO_SEQUENCER_L1_EVENTS_MAX_BLOCK_RANGE",
"ESPRESSO_SEQUENCER_L1_FREQUENT_FAILURE_TOLERANCE",
"ESPRESSO_SEQUENCER_L1_POLLING_INTERVAL",
"ESPRESSO_SEQUENCER_L1_RATE_LIMIT_DELAY",
"ESPRESSO_SEQUENCER_L1_RETRY_DELAY",
"ESPRESSO_SEQUENCER_L1_SUBSCRIPTION_TIMEOUT",
"ESPRESSO_SEQUENCER_LIBP2P_ADVERTISE_ADDRESS",
"ESPRESSO_SEQUENCER_LIBP2P_BIND_ADDRESS",
"ESPRESSO_SEQUENCER_MAX_CONNECTIONS",
Expand Down
17 changes: 10 additions & 7 deletions types/src/v0/impls/l1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ impl L1ClientMetrics {
}

impl L1Provider {
fn new(url: Url, failures: &dyn CounterFamily) -> Self {
fn new(index: usize, url: Url, failures: &dyn CounterFamily) -> Self {
Self {
failures: failures.create(vec![url.to_string()]),
failures: failures.create(vec![index.to_string()]),
inner: Http::new(url),
}
}
Expand All @@ -157,7 +157,8 @@ impl MultiRpcClient {
clients: Arc::new(
clients
.into_iter()
.map(|url| L1Provider::new(url, &*failures))
.enumerate()
.map(|(i, url)| L1Provider::new(i, url, &*failures))
.collect(),
),
status: Default::default(),
Expand Down Expand Up @@ -226,12 +227,13 @@ impl JsonRpcClient for MultiRpcClient {

status.client
};
let client = &self.clients[current % self.clients.len()];
let provider = current % self.clients.len();
let client = &self.clients[provider];
match client.request(method, &params).await {
Ok(res) => Ok(res),
Err(err) => {
let t = Instant::now();
tracing::warn!(?t, method, ?params, "L1 client error: {err:#}");
tracing::warn!(?t, method, ?params, provider, "L1 client error: {err:#}");
client.failures.add(1);

// Keep track of failures, failing over to the next client if necessary.
Expand Down Expand Up @@ -344,11 +346,12 @@ impl L1Client {
Some(urls) => {
// Use a new WebSockets host each time we retry in case there is a
// problem with one of the hosts specifically.
let url = &urls[i % urls.len()];
let provider = i % urls.len();
let url = &urls[provider];
ws = match Provider::<Ws>::connect(url.clone()).await {
Ok(ws) => ws,
Err(err) => {
tracing::warn!(%url, "failed to connect WebSockets provider: {err:#}");
tracing::warn!(provider, "failed to connect WebSockets provider: {err:#}");
sleep(retry_delay).await;
continue;
}
Expand Down

0 comments on commit ea5d100

Please sign in to comment.