nomos types needed for client

This commit is contained in:
Petar Radovic 2025-04-23 18:50:38 +02:00 committed by Giacomo Pasini
parent 7615b43488
commit 361833e4ac
No known key found for this signature in database
GPG Key ID: FC08489D2D895D4B
5 changed files with 42 additions and 80 deletions

View File

@ -11,4 +11,7 @@ tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
executor-http-client = { git = "https://github.com/logos-co/nomos", branch = "master" }
tokio = { version = "1", features = ["full"] }
kzgrs-backend = { git = "https://github.com/logos-co/nomos.git", branch = "master", package = "kzgrs-backend" }
crypto-bigint = { version = "0.5.5", features = ["serde"] }
risc0-zkvm = { version = "2" }
indexmap = { version = "1.9.3" }
url = { version = "2" }

View File

@ -1,60 +1,36 @@
use std::ops::Range;
use executor_http_client::{BasicAuthCredentials, ExecutorHttpClient};
use kzgrs_backend::common::share::DaShare;
use nomos::CryptarchiaInfo;
use reqwest::Url;
use serde::{Deserialize, Serialize};
use tracing::{error, error_span, info};
pub const DA_GET_RANGE: &str = "/da/get-range";
pub const CRYPTARCHIA_INFO: &str = "/cryptarchia/info";
pub const STORAGE_BLOCK: &str = "/storage/block";
pub struct NomosDa {
url: Url,
client: ExecutorHttpClient,
mod nomos;
pub struct NomosClient {
base_url: Url,
reqwest_client: reqwest::Client,
}
impl NomosDa {
pub fn new(basic_auth: BasicAuthCredentials, url: Url) -> Self {
impl NomosClient {
pub fn new(base_url: Url) -> Self {
Self {
client: ExecutorHttpClient::new(Some(basic_auth)),
url,
base_url,
reqwest_client: reqwest::Client::new(),
}
}
pub async fn get_indexer_range(
pub async fn get_cryptarchia_info(
&self,
app_id: [u8; 32],
range: Range<[u8; 8]>,
) -> Vec<([u8; 8], Vec<DaShare>)> {
let endpoint = self
.url
.join(DA_GET_RANGE)
.expect("Failed to construct valid URL");
match self
.reqwest_client
.post(endpoint)
.header("Content-Type", "application/json")
.body(serde_json::to_string(&GetRangeReq { app_id, range }).unwrap())
.send()
.await
.unwrap()
.json::<Vec<([u8; 8], Vec<DaShare>)>>()
.await
{
Ok(data) => data,
Err(e) => {
error!("Failed to get indexer range: {e}");
vec![]
}
}
base_url: Url,
) -> Result<CryptarchiaInfo, reqwest::Error> {
let url = base_url.join(CRYPTARCHIA_INFO).expect("Invalid URL");
let response = self.reqwest_client.get(url).send().await?;
let info = response.json::<CryptarchiaInfo>().await?;
Ok(info)
}
}
#[derive(Serialize, Deserialize)]
struct GetRangeReq {
pub app_id: [u8; 32],
pub range: Range<[u8; 8]>,
}

View File

@ -1,7 +1,7 @@
use clap::Parser;
use evm_lightnode::NomosDa;
use executor_http_client::BasicAuthCredentials;
use reqwest::Url;
use evm_lightnode::NomosClient;
use url::Url;
use std::error;
use tracing_subscriber::{EnvFilter, fmt};
@ -10,14 +10,6 @@ const TESTNET_EXECUTOR: &str = "https://testnet.nomos.tech/node/3/";
#[derive(Parser, Debug)]
#[clap(author, version, about = "Ethereum Proof Generation Tool")]
struct Args {
// #[clap(long, required = true)]
// block: u64,
// #[clap(long, required = true)]
// proof_file_path: String,
// #[clap(long)]
// zeth_binary_dir: Option<String>,
#[clap(long, default_value = "info")]
log_level: String,
}
@ -26,28 +18,14 @@ struct Args {
async fn main() -> Result<(), Box<dyn error::Error>> {
let args = Args::parse();
let url = std::env::var("NOMOS_EXECUTOR").unwrap_or(TESTNET_EXECUTOR.to_string());
let filter =
EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new(&args.log_level));
fmt::fmt().with_env_filter(filter).with_target(false).init();
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 da = NomosDa::new(
BasicAuthCredentials::new(user, Some(password)),
Url::parse(&url).unwrap(),
);
let from = 0u64.to_be_bytes();
let to = 1u64.to_be_bytes();
da.get_indexer_range([0; 32], from..to)
.await
.iter()
.for_each(|(key, value)| {
println!("Key: {:?}, Value: {:?}", key, value);
});
let consensus = NomosClient::new(Url::parse(&url).unwrap());
Ok(())
}

View File

@ -8,4 +8,4 @@ executor-http-client = { git = "https://github.com/logos-co/nomos", branch = "ma
reqwest = "0.11"
kzgrs-backend = { git = "https://github.com/logos-co/nomos", branch = "master" }
bincode = "1"
reth-tracing = { workspace = true }
reth-tracing = { workspace = true }

View File

@ -1,4 +1,4 @@
use evm_processor::{Processor, NomosDa, BasicAuthCredentials};
use evm_processor::{BasicAuthCredentials, NomosDa, Processor};
use futures::TryStreamExt as _;
use reth::{
api::{FullNodeTypes, NodePrimitives, NodeTypes},
@ -25,13 +25,15 @@ where
continue;
};
info!(committed_chain = ?new.range(), "Received commit");
processor.process_blocks(
new.inner()
.0
.clone()
.into_blocks()
.map(reth_ethereum::primitives::RecoveredBlock::into_block),
).await;
processor
.process_blocks(
new.inner()
.0
.clone()
.into_blocks()
.map(reth_ethereum::primitives::RecoveredBlock::into_block),
)
.await;
ctx.events
.send(ExExEvent::FinishedHeight(new.tip().num_hash()))
@ -57,7 +59,10 @@ fn main() -> eyre::Result<()> {
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 da = NomosDa::new( BasicAuthCredentials::new(user, Some(password)), url::Url::parse(&url).unwrap());
let da = NomosDa::new(
BasicAuthCredentials::new(user, Some(password)),
url::Url::parse(&url).unwrap(),
);
let processor = Processor::new(da);
let handle = Box::pin(
builder