Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
AllFi committed Sep 9, 2024
1 parent 9c5a90e commit c88d14a
Show file tree
Hide file tree
Showing 11 changed files with 148 additions and 27 deletions.
115 changes: 108 additions & 7 deletions da-indexer/Cargo.lock

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

1 change: 1 addition & 0 deletions da-indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ l2_api_url = "http://localhost:3001"
l2_blockscout_url = "http://arbitrum.blockscout.com"
l1_chain_id = 456 # optional
request_timeout = 30 # optional
request_retries = 2 # optional
```

## Dev
Expand Down
2 changes: 2 additions & 0 deletions da-indexer/da-indexer-logic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ ethers = { version = "2.0.11", features = ["ws"] }
reqwest = { version = "0.12.5", features = ["json"] }
chrono = "0.4"
toml = "0.8.14"
reqwest-middleware = "0.3.3"
reqwest-retry = "0.6.1"

[dev-dependencies]
blockscout-service-launcher = { version = "0.9.0", features = ["test-database", "database-0_12"] }
Expand Down
13 changes: 6 additions & 7 deletions da-indexer/da-indexer-logic/src/celestia/l2_router/arbitrum.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
use super::types::{L2BatchMetadata, L2Config};
use super::{
new_client,
types::{L2BatchMetadata, L2Config},
};
use anyhow::Result;
use blockscout_display_bytes::Bytes;
use chrono::DateTime;
use reqwest::{Client, StatusCode, Url};
use reqwest::{StatusCode, Url};
use serde::Deserialize;

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -31,11 +34,7 @@ pub async fn get_l2_batch(
config.l2_api_url, height, commitment,
);

let response = Client::new()
.get(&query)
.timeout(config.request_timeout)
.send()
.await?;
let response = new_client(config)?.get(&query).send().await?;

if response.status() == StatusCode::NOT_FOUND {
tracing::debug!(
Expand Down
17 changes: 15 additions & 2 deletions da-indexer/da-indexer-logic/src/celestia/l2_router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ pub mod settings;
pub mod types;

use anyhow::Result;
use blockscout_display_bytes::Bytes;
use blockscout_display_bytes::ToHex;
use reqwest_middleware::{ClientBuilder, ClientWithMiddleware};
use reqwest_retry::{policies::ExponentialBackoff, RetryTransientMiddleware};
use serde::{Deserialize, Serialize};
use settings::L2RouterSettings;
use std::{collections::HashMap, fs};
Expand Down Expand Up @@ -41,7 +43,7 @@ impl L2Router {
namespace: &[u8],
commitment: &[u8],
) -> Result<Option<L2BatchMetadata>> {
let namespace = blockscout_display_bytes::ToHex::to_hex(namespace);
let namespace = ToHex::to_hex(&namespace);
let config = match self.routes.get(&namespace) {
Some(config) => config,
None => {
Expand All @@ -56,3 +58,14 @@ impl L2Router {
}
}
}

pub fn new_client(config: &L2Config) -> Result<ClientWithMiddleware> {
let retry_policy = ExponentialBackoff::builder().build_with_max_retries(config.request_retries);
Ok(ClientBuilder::new(
reqwest::Client::builder()
.timeout(config.request_timeout)
.build()?,
)
.with(RetryTransientMiddleware::new_with_policy(retry_policy))
.build())
}
10 changes: 3 additions & 7 deletions da-indexer/da-indexer-logic/src/celestia/l2_router/optimism.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use super::{types::L2BatchMetadata, L2Config};
use super::{new_client, types::L2BatchMetadata, L2Config};
use anyhow::{anyhow, Result};
use blockscout_display_bytes::Bytes;
use chrono::DateTime;
use reqwest::{Client, StatusCode, Url};
use reqwest::{StatusCode, Url};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -37,11 +37,7 @@ pub async fn get_l2_batch(
config.l2_api_url, height, commitment,
);

let response = Client::new()
.get(&query)
.timeout(config.request_timeout)
.send()
.await?;
let response = new_client(config)?.get(&query).send().await?;

if response.status() == StatusCode::NOT_FOUND {
tracing::debug!(
Expand Down
6 changes: 6 additions & 0 deletions da-indexer/da-indexer-logic/src/celestia/l2_router/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,18 @@ pub struct L2Config {
#[serde(default = "default_request_timeout")]
#[serde_as(as = "serde_with::DurationSeconds<u64>")]
pub request_timeout: time::Duration,
#[serde(default = "default_request_retries")]
pub request_retries: u32,
}

fn default_request_timeout() -> time::Duration {
time::Duration::from_secs(5)
}

fn default_request_retries() -> u32 {
1
}

pub struct CelestiaBlobId {
pub namespace: String,
pub height: u64,
Expand Down
2 changes: 2 additions & 0 deletions da-indexer/da-indexer-logic/src/celestia/tests/l2_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ async fn create_test_router() -> L2Router {
l2_blockscout_url: "http://raspberry.blockscout.com".to_string(),
l1_chain_id: None,
request_timeout: time::Duration::from_secs(5),
request_retries: 1,
},
);
routes.insert(
Expand All @@ -105,6 +106,7 @@ async fn create_test_router() -> L2Router {
l2_blockscout_url: "http://arbitrum.blockscout.com".to_string(),
l1_chain_id: Some(12),
request_timeout: time::Duration::from_secs(5),
request_retries: 1,
},
);

Expand Down
3 changes: 2 additions & 1 deletion da-indexer/da-indexer-server/config/celestia_routes.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ l2_chain_type = "Optimism"
l2_chain_id = 123420111
l2_api_url = "https://opcelestia-raspberry.gelatoscout.com/"
l2_blockscout_url = "https://opcelestia-raspberry.gelatoscout.com/"
request_timeout = 30
request_timeout = 30
request_retries = 1
4 changes: 2 additions & 2 deletions da-indexer/da-indexer-server/src/services/celestia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Celestia for CelestiaService {
let db = self
.db
.as_ref()
.ok_or(Status::internal("database not configured"))?;
.ok_or(Status::unimplemented("database is not configured"))?;
let inner = request.into_inner();

let height = inner.height;
Expand Down Expand Up @@ -64,7 +64,7 @@ impl Celestia for CelestiaService {
let l2_router = self
.l2_router
.as_ref()
.ok_or(Status::internal("l2 router not configured"))?;
.ok_or(Status::unimplemented("l2 router is not configured"))?;
let inner = request.into_inner();

let height = inner.height;
Expand Down
2 changes: 1 addition & 1 deletion da-indexer/da-indexer-server/src/services/eigenda.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl EigenDa for EigenDaService {
let db = self
.db
.as_ref()
.ok_or(Status::internal("database not configured"))?;
.ok_or(Status::unimplemented("database is not configured"))?;
let inner = request.into_inner();

let blob_index = inner.blob_index;
Expand Down

0 comments on commit c88d14a

Please sign in to comment.