-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig.rs
215 lines (196 loc) · 6.26 KB
/
config.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
use std::ops::Deref;
use std::str::FromStr;
use std::time::Duration;
use std::{collections::BTreeMap, fmt, path::PathBuf};
use alloy_primitives::{Address, U256};
use graph_subscriptions::subscription_tier::{SubscriptionTier, SubscriptionTiers};
use semver::Version;
use serde::Deserialize;
use serde_with::{serde_as, DisplayFromStr, FromInto};
use toolshed::url::Url;
use indexer_selection::SecretKey;
use prelude::USD;
use crate::chains::ethereum;
use crate::poi::ProofOfIndexingInfo;
#[serde_as]
#[derive(Debug, Deserialize)]
pub struct Config {
/// Respect the payment state of API keys (disable for testnets)
pub api_key_payment_required: bool,
pub attestations: AttestationConfig,
pub chains: Vec<Chain>,
/// Ethereum RPC provider, or fixed exchange rate for testing
pub exchange_rate_provider: ExchangeRateProvider,
/// GeoIP database path
pub geoip_database: Option<PathBuf>,
/// GeoIP blocked countries (ISO 3166-1 alpha-2 codes)
#[serde(default)]
pub geoip_blocked_countries: Vec<String>,
/// Graph network environment identifier, inserted into Kafka messages
pub graph_env_id: String,
/// Rounds of indexer selection and queries to attempt. Note that indexer queries have a 20s
/// timeout, so setting this to 5 for example would result in a 100s worst case response time
/// for a client query.
pub indexer_selection_retry_limit: usize,
/// IPFS endpoint with access to the subgraph files
#[serde_as(as = "DisplayFromStr")]
pub ipfs: Url,
/// IP rate limit in requests per second
pub ip_rate_limit: u16,
/// See https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md
#[serde(default)]
pub kafka: KafkaConfig,
/// Format log output as JSON
pub log_json: bool,
/// L2 gateway to forward client queries to
#[serde_as(as = "Option<DisplayFromStr>")]
pub l2_gateway: Option<Url>,
/// Minimum indexer software version that will receive queries
#[serde_as(as = "DisplayFromStr")]
pub min_indexer_version: Version,
/// Network subgraph query path
#[serde_as(as = "DisplayFromStr")]
pub network_subgraph: Url,
/// POI blocklist
#[serde(default)]
pub poi_blocklist: Vec<ProofOfIndexingInfo>,
/// POI blocklist update interval in minutes (default: 20 minutes)
pub poi_blocklist_update_interval: Option<u64>,
/// public API port
pub port_api: u16,
/// private metrics port
pub port_metrics: u16,
/// Target for indexer fees paid per query
pub query_fees_target: f64,
/// Scalar TAP config (receipt signing)
pub scalar: Scalar,
/// API keys that won't be blocked for non-payment
#[serde(default)]
pub special_api_keys: Vec<String>,
/// Subgraph studio admin auth token
pub studio_auth: String,
/// Subgraph studio admin url
#[serde_as(as = "Option<DisplayFromStr>")]
pub studio_url: Option<Url>,
/// Subscriptions configuration
pub subscriptions: Option<Subscriptions>,
}
#[derive(Debug, Deserialize)]
pub struct AttestationConfig {
pub chain_id: String,
pub dispute_manager: Address,
}
#[serde_as]
#[derive(Debug, Deserialize)]
pub struct Chain {
pub name: String,
#[serde_as(as = "DisplayFromStr")]
pub rpc: Url,
pub poll_hz: u16,
pub block_rate_hz: f64,
}
impl From<Chain> for ethereum::Provider {
fn from(chain: Chain) -> Self {
Self {
network: chain.name,
rpc: chain.rpc,
block_time: Duration::from_secs(chain.poll_hz as u64),
}
}
}
#[serde_as]
#[derive(Debug, Deserialize)]
#[serde(untagged)]
pub enum ExchangeRateProvider {
Rpc(#[serde_as(as = "DisplayFromStr")] Url),
Fixed(USD),
}
#[derive(Debug, Deserialize)]
pub struct KafkaConfig(BTreeMap<String, String>);
impl Default for KafkaConfig {
fn default() -> Self {
let settings = [
("bootstrap.servers", ""),
("group.id", "graph-gateway"),
("message.timeout.ms", "3000"),
("queue.buffering.max.ms", "1000"),
("queue.buffering.max.messages", "100000"),
];
Self(
settings
.into_iter()
.map(|(k, v)| (k.to_owned(), v.to_owned()))
.collect(),
)
}
}
impl From<KafkaConfig> for rdkafka::config::ClientConfig {
fn from(mut from: KafkaConfig) -> Self {
let mut settings = KafkaConfig::default().0;
settings.append(&mut from.0);
let mut config = rdkafka::config::ClientConfig::new();
for (k, v) in settings {
config.set(&k, &v);
}
config
}
}
#[serde_as]
#[derive(Debug, Deserialize)]
pub struct Scalar {
/// Scalar TAP verifier contract chain
pub chain_id: U256,
/// Mnemonic for legacy voucher signing
#[serde_as(as = "Option<DisplayFromStr>")]
pub legacy_signer: Option<Hidden<SecretKey>>,
/// Mnemonic for voucher signing
#[serde_as(as = "DisplayFromStr")]
pub signer: Hidden<SecretKey>,
/// Scalar TAP verifier contract address
pub verifier: Address,
}
#[serde_as]
#[derive(Debug, Deserialize)]
pub struct Subscriptions {
/// Subscriptions contract domains
pub domains: Vec<SubscriptionsDomain>,
/// Kafka topic to report subscription queries
pub kafka_topic: Option<String>,
/// Query key signers that don't require payment
pub special_signers: Vec<Address>,
/// Subscriptions subgraph URL
#[serde_as(as = "DisplayFromStr")]
pub subgraph: Url,
/// Subscriptions ticket for internal queries
pub ticket: Option<String>,
/// Subscription tiers
#[serde(default)]
#[serde_as(as = "FromInto<Vec<SubscriptionTier>>")]
pub tiers: SubscriptionTiers,
}
#[serde_as]
#[derive(Debug, Deserialize)]
pub struct SubscriptionsDomain {
pub chain_id: u64,
pub contract: Address,
}
#[derive(Deserialize)]
#[serde(transparent)]
pub struct Hidden<T>(pub T);
impl<T: fmt::Debug> fmt::Debug for Hidden<T> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "HIDDEN")
}
}
impl<T: FromStr> FromStr for Hidden<T> {
type Err = T::Err;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(s.parse()?))
}
}
impl<T> Deref for Hidden<T> {
type Target = T;
fn deref(&self) -> &Self::Target {
&self.0
}
}