Skip to content

Commit

Permalink
feat: deploy to berachain (#5375)
Browse files Browse the repository at this point in the history
### Description

feat: deploy to berachain

### Drive-by changes

- includes rust changes to support custom headers with RPC requests
#5379
- update lumia route id, copied from
#5377

### Related issues

hyperlane-xyz/hyperlane-registry#553

### Backward compatibility

<!--
Are these changes backward compatible? Are there any infrastructure
implications, e.g. changes that would prohibit deploying older commits
using this infra tooling?

Yes/No
-->

### Testing

manual

---------

Co-authored-by: Trevor Porter <[email protected]>
  • Loading branch information
paulbalaji and tkporter authored Feb 5, 2025
1 parent 6013dd6 commit 276d7ce
Show file tree
Hide file tree
Showing 15 changed files with 440 additions and 131 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-garlics-hunt.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperlane-xyz/sdk': minor
---

Deploy to berachain.
2 changes: 1 addition & 1 deletion .registryrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
15c0acaff965e3bd4042482d2db9041b74de6191
78895565b7f4a57e94d1b6a8f069d670f8ed98c7
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::{Debug, Write};
use std::str::FromStr;
use std::sync::Arc;
use std::time::Duration;

Expand All @@ -14,6 +15,7 @@ use ethers::prelude::{
use ethers::types::Address;
use ethers_signers::Signer;
use hyperlane_core::rpc_clients::FallbackProvider;
use reqwest::header::{HeaderName, HeaderValue};
use reqwest::{Client, Url};
use thiserror::Error;

Expand Down Expand Up @@ -73,12 +75,8 @@ pub trait BuildableWithProvider {
Ok(match &conn.rpc_connection {
RpcConnectionConf::HttpQuorum { urls } => {
let mut builder = QuorumProvider::builder().quorum(Quorum::Majority);
let http_client = Client::builder()
.timeout(HTTP_CLIENT_TIMEOUT)
.build()
.map_err(EthereumProviderConnectionError::from)?;
for url in urls {
let http_provider = Http::new_with_client(url.clone(), http_client.clone());
let http_provider = build_http_provider(url.clone())?;
// Wrap the inner providers as RetryingProviders rather than the QuorumProvider.
// We've observed issues where the QuorumProvider will first get the latest
// block number and then submit an RPC at that block height,
Expand All @@ -104,12 +102,8 @@ pub trait BuildableWithProvider {
}
RpcConnectionConf::HttpFallback { urls } => {
let mut builder = FallbackProvider::builder();
let http_client = Client::builder()
.timeout(HTTP_CLIENT_TIMEOUT)
.build()
.map_err(EthereumProviderConnectionError::from)?;
for url in urls {
let http_provider = Http::new_with_client(url.clone(), http_client.clone());
let http_provider = build_http_provider(url.clone())?;
let metrics_provider = self.wrap_rpc_with_metrics(
http_provider,
url.clone(),
Expand All @@ -127,11 +121,7 @@ pub trait BuildableWithProvider {
.await?
}
RpcConnectionConf::Http { url } => {
let http_client = Client::builder()
.timeout(HTTP_CLIENT_TIMEOUT)
.build()
.map_err(EthereumProviderConnectionError::from)?;
let http_provider = Http::new_with_client(url.clone(), http_client);
let http_provider = build_http_provider(url.clone())?;
let metrics_provider = self.wrap_rpc_with_metrics(
http_provider,
url.clone(),
Expand Down Expand Up @@ -312,3 +302,42 @@ where
const FREQUENCY: Frequency = Frequency::Duration(Duration::from_secs(12).as_millis() as _);
GasEscalatorMiddleware::new(provider, escalator, FREQUENCY)
}

fn build_http_provider(url: Url) -> ChainResult<Http> {
let mut queries_to_keep = vec![];
let mut headers = reqwest::header::HeaderMap::new();

// A hack to pass custom headers to the provider without
// requiring a bunch of changes to our configuration surface area.
// Any `custom_rpc_header` query parameter is expected to have the value
// format: `header_name:header_value`, will be added to the headers
// of the HTTP client, and removed from the URL params.
let mut updated_url = url.clone();
for (key, value) in url.query_pairs() {
if key != "custom_rpc_header" {
queries_to_keep.push((key.clone(), value.clone()));
continue;
}
if let Some((header_name, header_value)) = value.split_once(':') {
let header_name =
HeaderName::from_str(header_name).map_err(ChainCommunicationError::from_other)?;
let mut header_value =
HeaderValue::from_str(header_value).map_err(ChainCommunicationError::from_other)?;
header_value.set_sensitive(true);
headers.insert(header_name, header_value);
}
}

updated_url
.query_pairs_mut()
.clear()
.extend_pairs(queries_to_keep);

let http_client = Client::builder()
.timeout(HTTP_CLIENT_TIMEOUT)
.default_headers(headers)
.build()
.map_err(EthereumProviderConnectionError::from)?;

Ok(Http::new_with_client(url, http_client))
}
Loading

0 comments on commit 276d7ce

Please sign in to comment.