Skip to content

Commit e201a75

Browse files
committed
node, chain: Use features pattern for RPC compression configuration
Replace the separate `compression = "gzip"` field on Web3Provider with `features = ["compression/gzip"]`, aligning with the pattern established by firehose providers. This keeps extensibility open for future compression methods (e.g. "compression/brotli") without schema changes.
1 parent f891ec6 commit e201a75

File tree

5 files changed

+39
-74
lines changed

5 files changed

+39
-74
lines changed

chain/ethereum/src/network.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ mod tests {
314314
use graph::components::network_provider::ProviderManager;
315315
use graph::components::network_provider::ProviderName;
316316
use graph::data::value::Word;
317-
use graph::endpoint::Compression;
317+
318318
use graph::http::HeaderMap;
319319
use graph::{
320320
endpoint::EndpointMetrics,
@@ -395,7 +395,7 @@ mod tests {
395395
HeaderMap::new(),
396396
metrics.clone(),
397397
"",
398-
Compression::None,
398+
false,
399399
);
400400
let provider_metrics = Arc::new(ProviderEthRpcMetrics::new(mock_registry.clone()));
401401

@@ -499,7 +499,7 @@ mod tests {
499499
HeaderMap::new(),
500500
metrics.clone(),
501501
"",
502-
Compression::None,
502+
false,
503503
);
504504
let provider_metrics = Arc::new(ProviderEthRpcMetrics::new(mock_registry.clone()));
505505

@@ -571,7 +571,7 @@ mod tests {
571571
HeaderMap::new(),
572572
metrics.clone(),
573573
"",
574-
Compression::None,
574+
false,
575575
);
576576
let provider_metrics = Arc::new(ProviderEthRpcMetrics::new(mock_registry.clone()));
577577

@@ -636,7 +636,7 @@ mod tests {
636636
HeaderMap::new(),
637637
metrics.clone(),
638638
"",
639-
Compression::None,
639+
false,
640640
);
641641
let provider_metrics = Arc::new(ProviderEthRpcMetrics::new(mock_registry.clone()));
642642

@@ -924,7 +924,7 @@ mod tests {
924924
HeaderMap::new(),
925925
endpoint_metrics.clone(),
926926
"",
927-
Compression::None,
927+
false,
928928
);
929929

930930
Arc::new(

graph/src/endpoint.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use std::{
77
};
88

99
use prometheus::IntCounterVec;
10-
use serde::{Deserialize, Serialize};
1110
use slog::{warn, Logger};
1211

1312
use crate::components::network_provider::ProviderName;
@@ -18,26 +17,6 @@ use crate::{components::metrics::MetricsRegistry, data::value::Word};
1817
/// avoid locking since we don't need to modify the entire struture.
1918
type ProviderCount = Arc<HashMap<ProviderName, AtomicU64>>;
2019

21-
/// Compression methods for RPC transports
22-
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)]
23-
pub enum Compression {
24-
#[serde(rename = "none")]
25-
None,
26-
#[serde(rename = "gzip")]
27-
Gzip,
28-
// Future compression methods can be added here:
29-
// #[serde(rename = "brotli")]
30-
// Brotli,
31-
// #[serde(rename = "deflate")]
32-
// Deflate,
33-
}
34-
35-
impl Default for Compression {
36-
fn default() -> Self {
37-
Compression::None
38-
}
39-
}
40-
4120
/// This struct represents all the current labels except for the result
4221
/// which is added separately. If any new labels are necessary they should
4322
/// remain in the same order as added in [`EndpointMetrics::new`]

node/resources/tests/full_config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ shard = "primary"
4848
provider = [
4949
{ label = "mainnet-0", url = "http://rpc.mainnet.io", features = ["archive", "traces"] },
5050
{ label = "mainnet-1", details = { type = "web3call", url = "http://rpc.mainnet.io", features = ["archive", "traces"] }},
51-
{ label = "mainnet-2", details = { type = "web3", url = "http://rpc.mainnet.io", features = ["archive"], compression = "gzip" }},
51+
{ label = "mainnet-2", details = { type = "web3", url = "http://rpc.mainnet.io", features = ["archive", "compression/gzip"] }},
5252
{ label = "firehose", details = { type = "firehose", url = "http://localhost:9000", features = [] }},
5353
]
5454

node/src/chain.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,12 +206,13 @@ pub async fn create_ethereum_networks_for_chain(
206206
}
207207

208208
let logger = logger.new(o!("provider" => provider.label.clone()));
209+
let gzip = web3.gzip_compression_enabled();
209210
info!(
210211
logger,
211212
"Creating transport";
212213
"url" => &web3.url,
213214
"capabilities" => capabilities,
214-
"compression" => ?web3.compression
215+
"gzip" => gzip
215216
);
216217

217218
use crate::config::Transport::*;
@@ -222,7 +223,7 @@ pub async fn create_ethereum_networks_for_chain(
222223
web3.headers.clone(),
223224
endpoint_metrics.cheap_clone(),
224225
&provider.label,
225-
web3.compression,
226+
gzip,
226227
),
227228
Ipc => Transport::new_ipc(&web3.url).await,
228229
Ws => Transport::new_ws(&web3.url).await,

node/src/config.rs

Lines changed: 29 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use graph::{
22
anyhow::Error,
33
blockchain::BlockchainKind,
44
components::network_provider::ChainName,
5-
endpoint::Compression,
65
env::ENV_VARS,
76
firehose::{SubgraphLimit, SUBGRAPHS_PER_CONN},
87
itertools::Itertools,
@@ -517,7 +516,6 @@ impl ChainSection {
517516
features,
518517
headers: Default::default(),
519518
rules: vec![],
520-
compression: Compression::None,
521519
}),
522520
};
523521
let entry = chains.entry(name.to_string()).or_insert_with(|| Chain {
@@ -696,10 +694,6 @@ pub struct Web3Provider {
696694

697695
#[serde(default, rename = "match")]
698696
rules: Vec<Web3Rule>,
699-
700-
/// Compression method for RPC requests and responses
701-
#[serde(default)]
702-
pub compression: Compression,
703697
}
704698

705699
impl Web3Provider {
@@ -710,12 +704,16 @@ impl Web3Provider {
710704
}
711705
}
712706

707+
pub fn gzip_compression_enabled(&self) -> bool {
708+
self.features.contains("compression/gzip")
709+
}
710+
713711
pub fn limit_for(&self, node: &NodeId) -> SubgraphLimit {
714712
self.rules.limit_for(node)
715713
}
716714
}
717715

718-
const PROVIDER_FEATURES: [&str; 3] = ["traces", "archive", "no_eip1898"];
716+
const PROVIDER_FEATURES: [&str; 4] = ["traces", "archive", "no_eip1898", "compression/gzip"];
719717
const DEFAULT_PROVIDER_FEATURES: [&str; 2] = ["traces", "archive"];
720718

721719
impl Provider {
@@ -891,7 +889,6 @@ impl<'de> Deserialize<'de> for Provider {
891889
.ok_or_else(|| serde::de::Error::missing_field("features"))?,
892890
headers: headers.unwrap_or_else(HeaderMap::new),
893891
rules: nodes,
894-
compression: Compression::None,
895892
}),
896893
};
897894

@@ -1204,7 +1201,6 @@ mod tests {
12041201
Chain, Config, FirehoseProvider, Provider, ProviderDetails, Shard, Transport, Web3Provider,
12051202
};
12061203
use graph::blockchain::BlockchainKind;
1207-
use graph::endpoint::Compression;
12081204
use graph::firehose::SubgraphLimit;
12091205
use graph::http::{HeaderMap, HeaderValue};
12101206
use graph::prelude::regex::Regex;
@@ -1293,7 +1289,6 @@ mod tests {
12931289
features: BTreeSet::new(),
12941290
headers: HeaderMap::new(),
12951291
rules: Vec::new(),
1296-
compression: Compression::None,
12971292
}),
12981293
},
12991294
actual
@@ -1320,7 +1315,6 @@ mod tests {
13201315
features: BTreeSet::new(),
13211316
headers: HeaderMap::new(),
13221317
rules: Vec::new(),
1323-
compression: Compression::None,
13241318
}),
13251319
},
13261320
actual
@@ -1382,7 +1376,6 @@ mod tests {
13821376
features,
13831377
headers,
13841378
rules: Vec::new(),
1385-
compression: Compression::None,
13861379
}),
13871380
},
13881381
actual
@@ -1408,7 +1401,6 @@ mod tests {
14081401
features: BTreeSet::new(),
14091402
headers: HeaderMap::new(),
14101403
rules: Vec::new(),
1411-
compression: Compression::None,
14121404
}),
14131405
},
14141406
actual
@@ -1619,7 +1611,6 @@ mod tests {
16191611
features: BTreeSet::new(),
16201612
headers: HeaderMap::new(),
16211613
rules: Vec::new(),
1622-
compression: Compression::None,
16231614
}),
16241615
},
16251616
actual
@@ -1633,63 +1624,57 @@ mod tests {
16331624
}
16341625

16351626
#[test]
1636-
fn it_parses_web3_provider_with_compression() {
1637-
let actual = toml::from_str(
1627+
fn it_parses_web3_provider_with_gzip_compression_feature() {
1628+
let actual: Provider = toml::from_str(
16381629
r#"
16391630
label = "compressed"
1640-
details = { type = "web3", url = "http://localhost:8545", features = ["archive"], compression = "gzip" }
1631+
details = { type = "web3", url = "http://localhost:8545", features = ["archive", "compression/gzip"] }
16411632
"#,
16421633
)
16431634
.unwrap();
16441635

1636+
let mut features = BTreeSet::new();
1637+
features.insert("archive".to_string());
1638+
features.insert("compression/gzip".to_string());
1639+
16451640
assert_eq!(
16461641
Provider {
16471642
label: "compressed".to_owned(),
16481643
details: ProviderDetails::Web3(Web3Provider {
16491644
transport: Transport::Rpc,
16501645
url: "http://localhost:8545".to_owned(),
1651-
features: {
1652-
let mut features = BTreeSet::new();
1653-
features.insert("archive".to_string());
1654-
features
1655-
},
1646+
features,
16561647
headers: HeaderMap::new(),
16571648
rules: Vec::new(),
1658-
compression: Compression::Gzip,
16591649
}),
16601650
},
16611651
actual
16621652
);
1653+
1654+
match actual.details {
1655+
ProviderDetails::Web3(ref web3) => {
1656+
assert!(web3.gzip_compression_enabled());
1657+
}
1658+
_ => panic!("expected Web3 provider"),
1659+
}
16631660
}
16641661

16651662
#[test]
1666-
fn it_parses_web3_provider_with_no_compression() {
1667-
let actual = toml::from_str(
1663+
fn it_parses_web3_provider_without_compression_feature() {
1664+
let actual: Provider = toml::from_str(
16681665
r#"
16691666
label = "uncompressed"
1670-
details = { type = "web3", url = "http://localhost:8545", features = ["archive"], compression = "none" }
1667+
details = { type = "web3", url = "http://localhost:8545", features = ["archive"] }
16711668
"#,
16721669
)
16731670
.unwrap();
16741671

1675-
assert_eq!(
1676-
Provider {
1677-
label: "uncompressed".to_owned(),
1678-
details: ProviderDetails::Web3(Web3Provider {
1679-
transport: Transport::Rpc,
1680-
url: "http://localhost:8545".to_owned(),
1681-
features: {
1682-
let mut features = BTreeSet::new();
1683-
features.insert("archive".to_string());
1684-
features
1685-
},
1686-
headers: HeaderMap::new(),
1687-
rules: Vec::new(),
1688-
compression: Compression::None,
1689-
}),
1690-
},
1691-
actual
1692-
);
1672+
match actual.details {
1673+
ProviderDetails::Web3(ref web3) => {
1674+
assert!(!web3.gzip_compression_enabled());
1675+
}
1676+
_ => panic!("expected Web3 provider"),
1677+
}
16931678
}
16941679

16951680
#[test]

0 commit comments

Comments
 (0)