⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion chain/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ mod transport;
pub use self::capabilities::NodeCapabilities;
pub use self::ethereum_adapter::EthereumAdapter;
pub use self::runtime::RuntimeAdapter;
pub use self::transport::Transport;
pub use self::transport::{Compression, Transport};
pub use env::ENV_VARS;

pub use buffered_call_cache::BufferedCallCache;
Expand Down
10 changes: 9 additions & 1 deletion chain/ethereum/src/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ mod tests {
use graph::components::network_provider::ProviderManager;
use graph::components::network_provider::ProviderName;
use graph::data::value::Word;

use graph::http::HeaderMap;
use graph::{
endpoint::EndpointMetrics,
Expand All @@ -324,7 +325,9 @@ mod tests {
};
use std::sync::Arc;

use crate::{EthereumAdapter, EthereumAdapterTrait, ProviderEthRpcMetrics, Transport};
use crate::{
Compression, EthereumAdapter, EthereumAdapterTrait, ProviderEthRpcMetrics, Transport,
};

use super::{EthereumNetworkAdapter, EthereumNetworkAdapters, NodeCapabilities};

Expand Down Expand Up @@ -394,6 +397,7 @@ mod tests {
HeaderMap::new(),
metrics.clone(),
"",
Compression::None,
);
let provider_metrics = Arc::new(ProviderEthRpcMetrics::new(mock_registry.clone()));

Expand Down Expand Up @@ -497,6 +501,7 @@ mod tests {
HeaderMap::new(),
metrics.clone(),
"",
Compression::None,
);
let provider_metrics = Arc::new(ProviderEthRpcMetrics::new(mock_registry.clone()));

Expand Down Expand Up @@ -568,6 +573,7 @@ mod tests {
HeaderMap::new(),
metrics.clone(),
"",
Compression::None,
);
let provider_metrics = Arc::new(ProviderEthRpcMetrics::new(mock_registry.clone()));

Expand Down Expand Up @@ -632,6 +638,7 @@ mod tests {
HeaderMap::new(),
metrics.clone(),
"",
Compression::None,
);
let provider_metrics = Arc::new(ProviderEthRpcMetrics::new(mock_registry.clone()));

Expand Down Expand Up @@ -919,6 +926,7 @@ mod tests {
HeaderMap::new(),
endpoint_metrics.clone(),
"",
Compression::None,
);

Arc::new(
Expand Down
42 changes: 38 additions & 4 deletions chain/ethereum/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,27 @@ use alloy::transports::{TransportError, TransportFut};

use graph::prelude::alloy::transports::{http::Http, ipc::IpcConnect, ws::WsConnect};

/// Compression method for RPC requests.
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub enum Compression {
#[default]
None,
Gzip,
Brotli,
Deflate,
}

impl std::fmt::Display for Compression {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Compression::None => write!(f, "none"),
Compression::Gzip => write!(f, "gzip"),
Compression::Brotli => write!(f, "brotli"),
Compression::Deflate => write!(f, "deflate"),
}
}
}

/// Abstraction over different transport types for Alloy providers.
#[derive(Clone, Debug)]
pub enum Transport {
Expand Down Expand Up @@ -46,11 +67,24 @@ impl Transport {
headers: graph::http::HeaderMap,
metrics: Arc<EndpointMetrics>,
provider: impl AsRef<str>,
compression: Compression,
) -> Self {
let client = reqwest::Client::builder()
.default_headers(headers)
.build()
.expect("Failed to build HTTP client");
let mut client_builder = reqwest::Client::builder().default_headers(headers);

match compression {
Compression::None => {}
Compression::Gzip => {
client_builder = client_builder.gzip(true);
}
Compression::Brotli => {
client_builder = client_builder.brotli(true);
}
Compression::Deflate => {
client_builder = client_builder.deflate(true);
}
}

let client = client_builder.build().expect("Failed to build HTTP client");

let http_transport = Http::with_client(client, rpc);
let metrics_transport = MetricsHttp::new(http_transport, metrics, provider.as_ref().into());
Expand Down
2 changes: 1 addition & 1 deletion graph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ chrono = "0.4.43"
envconfig = { workspace = true }
Inflector = "0.11.3"
atty = "0.2"
reqwest = { version = "0.12.23", features = ["json", "stream", "multipart"] }
reqwest = { version = "0.12.23", features = ["json", "stream", "multipart", "gzip", "brotli", "deflate"] }
ethabi = "17.2"
hex = "0.4.3"
http0 = { version = "0", package = "http" }
Expand Down
4 changes: 2 additions & 2 deletions graph/src/components/link_resolver/arweave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl Default for ArweaveClient {

Self {
base_url: "https://arweave.net".parse().unwrap(),
client: Client::default(),
client: Client::builder().gzip(false).build().unwrap(),
logger: Logger::root(slog::Discard, o!()),
}
}
Expand All @@ -53,7 +53,7 @@ impl ArweaveClient {
Self {
base_url,
logger,
client: Client::default(),
client: Client::builder().gzip(false).build().unwrap(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions node/resources/tests/full_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ shard = "primary"
provider = [
{ label = "mainnet-0", url = "http://rpc.mainnet.io", features = ["archive", "traces"] },
{ label = "mainnet-1", details = { type = "web3call", url = "http://rpc.mainnet.io", features = ["archive", "traces"] }},
{ label = "mainnet-2", details = { type = "web3", url = "http://rpc.mainnet.io", features = ["archive", "compression/gzip"] }},
{ label = "firehose", details = { type = "firehose", url = "http://localhost:9000", features = [] }},
]

Expand Down
5 changes: 4 additions & 1 deletion node/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,11 +206,13 @@ pub async fn create_ethereum_networks_for_chain(
}

let logger = logger.new(o!("provider" => provider.label.clone()));
let compression = web3.compression();
info!(
logger,
"Creating transport";
"url" => &web3.url,
"capabilities" => capabilities
"capabilities" => capabilities,
"compression" => compression.to_string()
);

use crate::config::Transport::*;
Expand All @@ -221,6 +223,7 @@ pub async fn create_ethereum_networks_for_chain(
web3.headers.clone(),
endpoint_metrics.cheap_clone(),
&provider.label,
compression,
),
Ipc => Transport::new_ipc(&web3.url).await,
Ws => Transport::new_ws(&web3.url).await,
Expand Down
Loading