|
| 1 | +# Plan: Implement Extensible Compression for RPC Requests |
| 2 | + |
| 3 | +## Overview |
| 4 | +Add extensible compression support for Graph Node's outgoing RPC requests to upstream providers, configurable on a per-provider basis with future compression methods in mind. |
| 5 | + |
| 6 | +## Implementation Steps (COMPLETED) |
| 7 | + |
| 8 | +### 1. ✅ Create Compression Enum (`node/src/config.rs`) |
| 9 | +- Added `Compression` enum with `None` and `Gzip` variants |
| 10 | +- Commented placeholders for future compression methods (Brotli, Deflate) |
| 11 | +- Default implementation returns `Compression::None` |
| 12 | + |
| 13 | +### 2. ✅ Update Configuration Structure (`node/src/config.rs`) |
| 14 | +- Replaced `compression_enabled: bool` with `compression: Compression` field in `Web3Provider` struct |
| 15 | +- Updated all existing code to use new enum |
| 16 | +- Added unit tests for both "gzip" and "none" compression options |
| 17 | + |
| 18 | +### 3. ✅ Modify HTTP Transport (`chain/ethereum/src/transport.rs`) |
| 19 | +- Updated `Transport::new_rpc()` to accept `Compression` enum parameter |
| 20 | +- Implemented match statement for different compression types |
| 21 | +- Added comments showing where future compression methods can be added |
| 22 | +- Uses reqwest's `.gzip(true)` for automatic compression/decompression |
| 23 | + |
| 24 | +### 4. ✅ Update Transport Creation (`node/src/chain.rs`) |
| 25 | +- Pass compression enum from config to transport |
| 26 | +- Updated logging to show compression method using debug format |
| 27 | + |
| 28 | +### 5. ✅ Update Dependencies (`graph/Cargo.toml`) |
| 29 | +- Added "gzip" feature to reqwest dependency |
| 30 | + |
| 31 | +### 6. ✅ Update Test Configuration |
| 32 | +- Updated `full_config.toml` example to use new enum format |
| 33 | +- Added comprehensive unit tests for compression parsing |
| 34 | + |
| 35 | +## Configuration Examples |
| 36 | + |
| 37 | +### Gzip Compression |
| 38 | +```toml |
| 39 | +[chains.mainnet] |
| 40 | +provider = [ |
| 41 | + { |
| 42 | + label = "mainnet-rpc", |
| 43 | + details = { |
| 44 | + type = "web3", |
| 45 | + url = "http://rpc.example.com", |
| 46 | + features = ["archive"], |
| 47 | + compression = "gzip" |
| 48 | + } |
| 49 | + } |
| 50 | +] |
| 51 | +``` |
| 52 | + |
| 53 | +### No Compression (Default) |
| 54 | +```toml |
| 55 | +[chains.mainnet] |
| 56 | +provider = [ |
| 57 | + { |
| 58 | + label = "mainnet-rpc", |
| 59 | + details = { |
| 60 | + type = "web3", |
| 61 | + url = "http://rpc.example.com", |
| 62 | + features = ["archive"], |
| 63 | + compression = "none" # or omit entirely |
| 64 | + } |
| 65 | + } |
| 66 | +] |
| 67 | +``` |
| 68 | + |
| 69 | +### Future Extension Example |
| 70 | +```rust |
| 71 | +// Future compression methods can be easily added: |
| 72 | +#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq)] |
| 73 | +pub enum Compression { |
| 74 | + #[serde(rename = "none")] |
| 75 | + None, |
| 76 | + #[serde(rename = "gzip")] |
| 77 | + Gzip, |
| 78 | + #[serde(rename = "brotli")] |
| 79 | + Brotli, |
| 80 | + #[serde(rename = "deflate")] |
| 81 | + Deflate, |
| 82 | +} |
| 83 | + |
| 84 | +// And handled in transport: |
| 85 | +match compression { |
| 86 | + Compression::Gzip => client_builder = client_builder.gzip(true), |
| 87 | + Compression::Brotli => client_builder = client_builder.brotli(true), |
| 88 | + Compression::Deflate => client_builder = client_builder.deflate(true), |
| 89 | + Compression::None => {} // No compression |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +## Benefits of This Implementation |
| 94 | +- **Extensible**: Easy to add new compression methods without breaking changes |
| 95 | +- **Backward Compatible**: Defaults to no compression, existing configs work unchanged |
| 96 | +- **Type Safe**: Enum prevents invalid compression method strings |
| 97 | +- **Future Proof**: Clear pattern for adding Brotli, Deflate, etc. |
| 98 | +- **Per-Provider**: Each RPC provider can have different compression settings |
0 commit comments