Skip to content

Commit

Permalink
Add optional l1_chain_id, update bs urls
Browse files Browse the repository at this point in the history
  • Loading branch information
AllFi committed Jul 31, 2024
1 parent b731fd7 commit 582e422
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 38 deletions.
9 changes: 5 additions & 4 deletions da-indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ The EigenDA indexer runs on top of the EigenDA disperser. It is worth mentioning
To fetch L2 batch metadata, the service must be aware of the L2s that use Celestia as a DA layer and the namespaces they utilize. This information is configured in a separate file, with its path specified in the `DA_INDEXER__L2_ROUTER__ROUTES_PATH` environment variable. Indexer and database configuration are optional if the `DA_INDEXER__L2_ROUTER__ROUTES_PATH` environment variable is set. An example of the routes config is shown below:
```toml
[routes.0x00000000000000000000000000000000000000000008e5f679bf7116cb]
chain_type = "Optimism"
chain_id = 123420111
l2_chain_type = "Optimism"
l2_chain_id = 123420111
l2_api_url = "https://opcelestia-raspberry.gelatoscout.com/"
l2_blockscout_url = "https://opcelestia-raspberry.gelatoscout.com/"

[routes.0x00000000000000000000000000000000000000ca1de12a1f4dbe943b6b]
chain_type = "Arbitrum"
chain_id = 123
l2_chain_type = "Arbitrum"
l2_chain_id = 123
l2_api_url = "http://localhost:3001"
l2_blockscout_url = "http://arbitrum.blockscout.com"
l1_chain_id = 456 # optional
```

## Dev
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::types::{L2BatchMetadata, L2Config};
use anyhow::Result;
use blockscout_display_bytes::Bytes;
use chrono::DateTime;
use reqwest::Client;
use reqwest::{Client, Url};
use serde::Deserialize;

#[derive(Deserialize, Debug)]
Expand Down Expand Up @@ -43,15 +43,18 @@ pub async fn get_l2_batch(

Ok(Some(L2BatchMetadata {
chain_type: super::types::L2Type::Arbitrum,
chain_id: config.chain_id,
l2_chain_id: config.l2_chain_id,
l2_batch_id: response.number.to_string(),
l2_start_block: response.start_block,
l2_end_block: response.end_block,
l2_batch_tx_count: response.transactions_count as u32,
l2_blockscout_url: config.l2_blockscout_url.clone(),
l2_blockscout_url: Url::parse(&config.l2_blockscout_url)?
.join(&format!("batches/{}", response.number))?
.to_string(),
l1_tx_hash: response.commitment_transaction.hash.clone(),
l1_tx_timestamp: DateTime::parse_from_rfc3339(&response.commitment_transaction.timestamp)?
.timestamp() as u64,
l1_chain_id: config.l1_chain_id,
related_blobs: vec![], // Arbitrum indexer doesn't support related blobs
}))
}
2 changes: 1 addition & 1 deletion da-indexer/da-indexer-logic/src/celestia/l2_router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ impl L2Router {
}
let config = config.unwrap();

match config.chain_type {
match config.l2_chain_type {
L2Type::Optimism => optimism::get_l2_batch(config, height, commitment).await,
L2Type::Arbitrum => arbitrum::get_l2_batch(config, height, commitment).await,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use super::{types::L2BatchMetadata, L2Config};
use anyhow::Result;
use blockscout_display_bytes::Bytes;
use chrono::DateTime;
use reqwest::{Client, StatusCode};
use reqwest::{Client, StatusCode, Url};
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -63,14 +63,17 @@ pub async fn get_l2_batch(

Ok(Some(L2BatchMetadata {
chain_type: super::types::L2Type::Optimism,
chain_id: config.chain_id,
l2_chain_id: config.l2_chain_id,
l2_batch_id: response.internal_id.to_string(),
l2_start_block: response.l2_block_start,
l2_end_block: response.l2_block_end,
l2_batch_tx_count: response.tx_count as u32,
l2_blockscout_url: config.l2_blockscout_url.clone(),
l2_blockscout_url: Url::parse(&config.l2_blockscout_url)?
.join(&format!("batches/{}", response.internal_id))?
.to_string(),
l1_tx_hash: response.l1_tx_hashes[0].clone(),
l1_tx_timestamp: DateTime::parse_from_rfc3339(&response.l1_timestamp)?.timestamp() as u64,
l1_chain_id: config.l1_chain_id,
related_blobs,
}))
}
8 changes: 5 additions & 3 deletions da-indexer/da-indexer-logic/src/celestia/l2_router/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ pub enum L2Type {

#[derive(Serialize, Deserialize, Debug)]
pub struct L2Config {
pub chain_type: L2Type,
pub chain_id: u32,
pub l2_chain_type: L2Type,
pub l2_chain_id: u32,
pub l2_api_url: String,
pub l2_blockscout_url: String,
pub l1_chain_id: Option<u32>,
}

pub struct CelestiaBlobId {
Expand All @@ -22,13 +23,14 @@ pub struct CelestiaBlobId {

pub struct L2BatchMetadata {
pub chain_type: L2Type,
pub chain_id: u32,
pub l2_chain_id: u32,
pub l2_batch_id: String,
pub l2_start_block: u64,
pub l2_end_block: u64,
pub l2_batch_tx_count: u32,
pub l2_blockscout_url: String,
pub l1_tx_hash: String,
pub l1_tx_timestamp: u64,
pub l1_chain_id: Option<u32>,
pub related_blobs: Vec<CelestiaBlobId>,
}
20 changes: 12 additions & 8 deletions da-indexer/da-indexer-logic/src/celestia/tests/l2_router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,21 @@ async fn test_optimism_router() {
.unwrap();

assert_eq!(batch_metadata.chain_type, L2Type::Optimism);
assert_eq!(batch_metadata.chain_id, 123420111);
assert_eq!(batch_metadata.l2_chain_id, 123420111);
assert_eq!(batch_metadata.l2_batch_id, "5");
assert_eq!(batch_metadata.l2_start_block, 29996);
assert_eq!(batch_metadata.l2_end_block, 33082);
assert_eq!(batch_metadata.l2_batch_tx_count, 1);
assert_eq!(
batch_metadata.l2_blockscout_url,
"http://raspberry.blockscout.com",
"http://raspberry.blockscout.com/batches/5",
);
assert_eq!(
batch_metadata.l1_tx_hash,
"0xf41211e966ec23032dde713d1f775ae5cb07dc5e15951281e6844d74cc02a930",
);
assert_eq!(batch_metadata.l1_tx_timestamp, 1703067444);
assert_eq!(batch_metadata.l1_chain_id, None);
assert_eq!(batch_metadata.related_blobs.len(), 1);
}

Expand All @@ -63,20 +64,21 @@ async fn test_arbitrum_router() {
.unwrap()
.unwrap();
assert_eq!(batch_metadata.chain_type, L2Type::Arbitrum);
assert_eq!(batch_metadata.chain_id, 123);
assert_eq!(batch_metadata.l2_chain_id, 123);
assert_eq!(batch_metadata.l2_batch_id, "610699");
assert_eq!(batch_metadata.l2_start_block, 217961563);
assert_eq!(batch_metadata.l2_end_block, 217962052);
assert_eq!(batch_metadata.l2_batch_tx_count, 3061);
assert_eq!(
batch_metadata.l2_blockscout_url,
"http://arbitrum.blockscout.com",
"http://arbitrum.blockscout.com/batches/610699",
);
assert_eq!(
batch_metadata.l1_tx_hash,
"0x6090384cc3f60874ee6e4bcd213629f0b68ef7607fd012714905ebc28c28078e",
);
assert_eq!(batch_metadata.l1_tx_timestamp, 1717415255);
assert_eq!(batch_metadata.l1_chain_id, Some(12));
assert_eq!(batch_metadata.related_blobs.len(), 0);
}

Expand All @@ -86,19 +88,21 @@ async fn create_test_router() -> L2Router {
routes.insert(
"0x00000000000000000000000000000000000000000008e5f679bf7116cb".to_string(),
L2Config {
chain_type: L2Type::Optimism,
chain_id: 123420111,
l2_chain_type: L2Type::Optimism,
l2_chain_id: 123420111,
l2_api_url: mock_server.uri(),
l2_blockscout_url: "http://raspberry.blockscout.com".to_string(),
l1_chain_id: None,
},
);
routes.insert(
"0x00000000000000000000000000000000000000ca1de12a1f4dbe943b6b".to_string(),
L2Config {
chain_type: L2Type::Arbitrum,
chain_id: 123,
l2_chain_type: L2Type::Arbitrum,
l2_chain_id: 123,
l2_api_url: mock_server.uri(),
l2_blockscout_url: "http://arbitrum.blockscout.com".to_string(),
l1_chain_id: Some(12),
},
);

Expand Down
8 changes: 4 additions & 4 deletions da-indexer/da-indexer-proto/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ fn compile(
".blockscout.daIndexer.v1.HealthCheckRequest.service",
"#[serde(default)]"
)
// .field_attribute(
// ".blockscout.daIndexer.v1.<MessageName>.<DefaultFieldName>",
// "#[serde(default)]"
// )
.message_attribute(
".blockscout.daIndexer.v1.CelestiaL2BatchMetadata",
"#[serde_with::skip_serializing_none]"
)
;
config.compile_protos(protos, includes)?;
Ok(())
Expand Down
11 changes: 6 additions & 5 deletions da-indexer/da-indexer-proto/proto/v1/da-indexer.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,16 @@ message CelestiaBlobId {
}

message CelestiaL2BatchMetadata {
uint32 chain_id = 1;
uint32 l2_chain_id = 1;
string l2_batch_id = 2;
uint64 l2_start_block = 3;
uint64 l2_end_block = 4;
uint32 l2_batch_tx_count = 5;
string l2_blockscout_url = 8;
string l1_tx_hash = 6;
uint64 l1_tx_timestamp = 7;
repeated CelestiaBlobId related_blobs = 9;
string l2_blockscout_url = 6;
string l1_tx_hash = 7;
uint64 l1_tx_timestamp = 8;
optional uint32 l1_chain_id = 9;
repeated CelestiaBlobId related_blobs = 10;
}

message GetEigenDaBlobRequest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ definitions:
v1CelestiaL2BatchMetadata:
type: object
properties:
chainId:
l2ChainId:
type: integer
format: int64
l2BatchId:
Expand All @@ -198,6 +198,9 @@ definitions:
l1TxTimestamp:
type: string
format: uint64
l1ChainId:
type: integer
format: int64
relatedBlobs:
type: array
items:
Expand Down
8 changes: 4 additions & 4 deletions da-indexer/da-indexer-server/config/celestia_routes.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[routes.0x00000000000000000000000000000000000000ca1de12a1f4dbe943b6b]
chain_type = "Arbitrum"
chain_id = 123
l2_chain_type = "Arbitrum"
l2_chain_id = 123
l2_api_url = "http://localhost:3001"
l2_blockscout_url = "http://arbitrum.blockscout.com"

[routes.0x00000000000000000000000000000000000000000008e5f679bf7116cb]
chain_type = "Optimism"
chain_id = 123420111
l2_chain_type = "Optimism"
l2_chain_id = 123420111
l2_api_url = "https://opcelestia-raspberry.gelatoscout.com/"
l2_blockscout_url = "https://opcelestia-raspberry.gelatoscout.com/"
5 changes: 3 additions & 2 deletions da-indexer/da-indexer-server/src/services/celestia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,15 @@ impl Celestia for CelestiaService {
.collect();

Ok(Response::new(CelestiaL2BatchMetadata {
chain_id: l2_batch_metadata.chain_id,
l2_chain_id: l2_batch_metadata.l2_chain_id,
l2_batch_id: l2_batch_metadata.l2_batch_id,
l2_start_block: l2_batch_metadata.l2_start_block,
l2_end_block: l2_batch_metadata.l2_end_block,
l2_blockscout_url: l2_batch_metadata.l2_blockscout_url,
l2_batch_tx_count: l2_batch_metadata.l2_batch_tx_count,
l1_tx_hash: l2_batch_metadata.l1_tx_hash,
l1_tx_timestamp: l2_batch_metadata.l1_tx_timestamp,
l2_batch_tx_count: l2_batch_metadata.l2_batch_tx_count,
l1_chain_id: l2_batch_metadata.l1_chain_id,
related_blobs,
}))
}
Expand Down

0 comments on commit 582e422

Please sign in to comment.