Skip to content

Commit 3c97623

Browse files
authored
fix(avail-client): add GasRelay timeout and Referer header (#4588)
## What ❔ Fixes some of the Avail issues that occurred recently. The only issue that remains unresolved by this PR is when the Avail Bridge API returns inclusion data for a certain blob, but the L1AvailBridge doesn't have the state root containing this blob. In theory, this shouldn't happen, but Avail services had this type of race condition before. The proper fix would require fetching L1 DA validator from the DiamondProxy, then fetching the bridge address from the L1DAValidator, and making sure that the underlying call to the bridge would succeed. The upcoming upgrade that switches to enum of L1 DA validators makes the process more comples, so I decided to not include it to limit the amout of effort spent here. ## Why ❔ To handle some corner cases with Avail client. ## Is this a breaking change? - [ ] Yes - [x] No ## Operational changes <!-- Any config changes? Any new flags? Any changes to any scripts? --> <!-- Please add anything that non-Matter Labs entities running their own ZK Chain may need to know --> ## Checklist <!-- Check your PR fulfills the following items. --> <!-- For draft PRs check the boxes as you complete them. --> - [ ] PR title corresponds to the body of PR (we generate changelog entries from PRs). - [ ] Tests for the changes have been added / updated. - [ ] Documentation comments have been added / updated. - [ ] Code has been formatted via `zkstack dev fmt` and `zkstack dev lint`.
1 parent 5baffd7 commit 3c97623

File tree

4 files changed

+32
-0
lines changed

4 files changed

+32
-0
lines changed

core/lib/config/src/configs/da_client/avail.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ pub struct AvailGasRelayConfig {
3838
pub gas_relay_api_url: String,
3939
#[config(default_t = 5)]
4040
pub max_retries: usize,
41+
#[config(default_t = "zksync".to_string())]
42+
pub referer_header: String,
43+
#[config(default_t = 3 * TimeUnit::Minutes)]
44+
pub dispatch_timeout: Duration,
4145
}
4246

4347
#[derive(Clone, Debug, DescribeConfig, DeserializeConfig)]

core/lib/config/src/configs/da_client/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ mod tests {
156156
avail_client_type: GasRelay
157157
gas_relay_api_url: https://lens-turbo-api.availproject.org
158158
max_retries: 4
159+
referer_header: zksync
160+
dispatch_timeout: 2s
159161
"#;
160162
let yaml = Yaml::new("test.yml", serde_yaml::from_str(yaml).unwrap()).unwrap();
161163

@@ -177,6 +179,8 @@ mod tests {
177179
"https://lens-turbo-api.availproject.org"
178180
);
179181
assert_eq!(client.max_retries, 4);
182+
assert_eq!(client.referer_header, "zksync");
183+
assert_eq!(client.dispatch_timeout, Duration::from_secs(2));
180184
}
181185

182186
#[test]
@@ -188,6 +192,8 @@ mod tests {
188192
gas_relay:
189193
gas_relay_api_url: https://lens-turbo-api.availproject.org
190194
max_retries: 4
195+
referer_header: zksync
196+
dispatch_timeout: 2s
191197
"#;
192198
let yaml = Yaml::new("test.yml", serde_yaml::from_str(yaml).unwrap()).unwrap();
193199

core/node/da_clients/src/avail/client.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl AvailClient {
139139
&conf.gas_relay_api_url,
140140
gas_relay_api_key.0.expose_secret(),
141141
conf.max_retries,
142+
&conf.referer_header,
142143
Arc::clone(&api_client),
143144
)
144145
.await?;
@@ -254,6 +255,23 @@ impl DataAvailabilityClient for AvailClient {
254255
})
255256
}
256257
AvailClientMode::GasRelay(client) => {
258+
let config = match &self.config.config {
259+
AvailClientConfig::GasRelay(conf) => conf,
260+
_ => unreachable!(), // validated in protobuf config
261+
};
262+
263+
if Utc::now()
264+
.signed_duration_since(dispatched_at)
265+
.to_std()
266+
.map_err(to_retriable_da_error)?
267+
> config.dispatch_timeout
268+
{
269+
return Err(DAError {
270+
error: anyhow!("Dispatch timeout exceeded"),
271+
is_retriable: false,
272+
});
273+
}
274+
257275
let Some((block_hash, extrinsic_index)) = client
258276
.check_finality(dispatch_request_id)
259277
.await

core/node/da_clients/src/avail/sdk.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ pub(crate) struct GasRelayClient {
453453
api_url: String,
454454
api_key: String,
455455
max_retries: usize,
456+
referer_header: String,
456457
api_client: Arc<reqwest::Client>,
457458
}
458459

@@ -478,12 +479,14 @@ impl GasRelayClient {
478479
api_url: &str,
479480
api_key: &str,
480481
max_retries: usize,
482+
referer_header: &str,
481483
api_client: Arc<reqwest::Client>,
482484
) -> anyhow::Result<Self> {
483485
Ok(Self {
484486
api_url: api_url.to_owned(),
485487
api_key: api_key.to_owned(),
486488
max_retries,
489+
referer_header: referer_header.to_owned(),
487490
api_client,
488491
})
489492
}
@@ -496,6 +499,7 @@ impl GasRelayClient {
496499
.post(&submit_url)
497500
.body(Bytes::from(data))
498501
.header("Content-Type", "application/octet-stream")
502+
.header("Referer", &self.referer_header)
499503
.header("x-api-key", &self.api_key)
500504
.send()
501505
.await

0 commit comments

Comments
 (0)