diff --git a/mistral/lightnode/src/main.rs b/mistral/lightnode/src/main.rs index 257c661..eb3f4a4 100644 --- a/mistral/lightnode/src/main.rs +++ b/mistral/lightnode/src/main.rs @@ -1,7 +1,9 @@ use clap::Parser; -use evm_lightnode::proofcheck; +use evm_lightnode::{Credentials, NomosClient, nomos::HeaderId, proofcheck}; +use futures::StreamExt; use std::error; use std::path::PathBuf; +use tracing::info; use tracing_subscriber::{EnvFilter, fmt}; use url::Url; @@ -27,6 +29,8 @@ struct Args { zeth_binary_dir: Option, } +const TESTNET_EXECUTOR: &str = "https://testnet.nomos.tech/node/3/"; + #[tokio::main] async fn main() -> Result<(), Box> { let args = Args::parse(); @@ -48,5 +52,69 @@ async fn main() -> Result<(), Box> { ) .await?; + //todo: use check_da_periodically to check for new blocks from da + Ok(()) } + +#[allow(dead_code)] +async fn check_da_periodically() -> Result<(), Box> { + let url = std::env::var("NOMOS_EXECUTOR").unwrap_or(TESTNET_EXECUTOR.to_string()); + let user = std::env::var("NOMOS_USER").unwrap_or_default(); + let password = std::env::var("NOMOS_PASSWORD").unwrap_or_default(); + let basic_auth = Credentials { + username: user, + password: Some(password), + }; + + let nomos_client = NomosClient::new(Url::parse(&url).unwrap(), basic_auth); + + let mut current_tip = HeaderId::default(); + + loop { + let info = nomos_client.get_cryptarchia_info().await?; + + if info.tip != current_tip { + current_tip = info.tip; + info!("New tip: {:?}", current_tip); + let block = nomos_client.get_block(info.tip).await?; + info!("Block: {:?}", block); + + let blobs = block.get("bl_blobs"); + + if blobs.is_none() { + info!("Parsing error"); + continue; + }; + + let blobs = blobs.unwrap().as_array().unwrap(); + if blobs.is_empty() { + info!("No blobs found in block"); + continue; + } + for blob in blobs { + let id_array = blob.get("id").unwrap().as_array().unwrap(); + + let mut blob_id = [0u8; 32]; + for (i, num) in id_array.iter().enumerate() { + if i < 32 { + blob_id[i] = num.as_u64().unwrap() as u8; + } + } + + info!("fetching stream"); + let shares_stream = nomos_client.get_shares(blob_id).await?; + + let shares = shares_stream.collect::>().await; + + info!("Shares for blob_id {:?}: {:?}", blob_id, shares); + + // todo: verify proof + } + } else { + info!("No new tip, sleeping..."); + } + + tokio::time::sleep(tokio::time::Duration::from_millis(500)).await; + } +} diff --git a/mistral/lightnode/src/nomos.rs b/mistral/lightnode/src/nomos.rs index 14cdcd1..325a4b5 100644 --- a/mistral/lightnode/src/nomos.rs +++ b/mistral/lightnode/src/nomos.rs @@ -2,10 +2,6 @@ use serde::{Deserialize, Deserializer, Serialize}; use hex::FromHex; -// tip "4f573735fb987453f7467688ea4e034b9161e3ca200526faf5c8ce6db09da180" -// slot 5085 -// height 1245 - #[derive(Serialize, Deserialize, Debug)] pub struct CryptarchiaInfo { pub tip: HeaderId, diff --git a/mistral/processor/src/lib.rs b/mistral/processor/src/lib.rs index 3cba4b5..602a351 100644 --- a/mistral/processor/src/lib.rs +++ b/mistral/processor/src/lib.rs @@ -46,7 +46,7 @@ impl NomosDa { } } - pub async fn disperse(&self, data: Vec, metadata: Metadata) -> Result<(), Error> { + pub async fn disperse(&self, data: Vec, metadata: Metadata) -> Result<[u8; 32], Error> { self.client .publish_blob(self.url.clone(), data, metadata) .await