Skip to content

Commit

Permalink
Celestia bump (keep-starknet-strange#1342)
Browse files Browse the repository at this point in the history
  • Loading branch information
apoorvsadana authored Jan 3, 2024
1 parent 61a1c4c commit 3ecc442
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 40 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- chore: bump celestia rpc crate version
- fix(DA): run the proof first then the state update
- fix: `prove_current_block` is called after `update_state`
- ci: add foundry ci task to push workflow
Expand Down
92 changes: 58 additions & 34 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions crates/client/data-availability/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ sp-keyring = { workspace = true }
subxt = { workspace = true }

# Celestia
celestia-rpc = { git = "https://github.com/eigerco/celestia-node-rs", rev = "bd6394b66b11065c543ab3f19fd66000a72b6236" }
celestia-types = { git = "https://github.com/eigerco/celestia-node-rs", rev = "bd6394b66b11065c543ab3f19fd66000a72b6236" }
celestia-rpc = { git = "https://github.com/eigerco/lumina", rev = "ccc5b9bfeac632cccd32d35ecb7b7d51d71fbb87" }
celestia-types = { git = "https://github.com/eigerco/lumina", rev = "ccc5b9bfeac632cccd32d35ecb7b7d51d71fbb87" }

# Madara
mp-digest-log = { workspace = true, default-features = true }
Expand Down
24 changes: 20 additions & 4 deletions crates/client/data-availability/src/celestia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ pub mod config;

use anyhow::Result;
use async_trait::async_trait;
use celestia_rpc::client::new_http;
use celestia_rpc::{BlobClient, HeaderClient};
use celestia_types::blob::SubmitOptions;
use celestia_types::nmt::Namespace;
use celestia_types::{Blob, Result as CelestiaTypesResult};
use ethers::types::{I256, U256};
use jsonrpsee::http_client::HttpClient;
use jsonrpsee::http_client::{HeaderMap, HeaderValue, HttpClient, HttpClientBuilder};
use reqwest::header;

use crate::{DaClient, DaMode};

Expand All @@ -22,6 +23,7 @@ pub struct CelestiaClient {
impl DaClient for CelestiaClient {
async fn publish_state_diff(&self, state_diff: Vec<U256>) -> Result<()> {
let blob = self.get_blob_from_state_diff(state_diff).map_err(|e| anyhow::anyhow!("celestia error: {e}"))?;

let submitted_height = self.publish_data(&blob).await.map_err(|e| anyhow::anyhow!("celestia error: {e}"))?;

// blocking call, awaiting on server side (Celestia Node) that a block with our data is included
Expand All @@ -48,7 +50,10 @@ impl DaClient for CelestiaClient {

impl CelestiaClient {
async fn publish_data(&self, blob: &Blob) -> Result<u64> {
self.http_client.blob_submit(&[blob.clone()]).await.map_err(|e| anyhow::anyhow!("could not submit blob {e}"))
self.http_client
.blob_submit(&[blob.clone()], SubmitOptions::default())
.await
.map_err(|e| anyhow::anyhow!("could not submit blob {e}"))
}

fn get_blob_from_state_diff(&self, state_diff: Vec<U256>) -> CelestiaTypesResult<Blob> {
Expand All @@ -75,7 +80,18 @@ impl TryFrom<config::CelestiaConfig> for CelestiaClient {
type Error = anyhow::Error;

fn try_from(conf: config::CelestiaConfig) -> Result<Self, Self::Error> {
let http_client = new_http(conf.http_provider.as_str(), conf.auth_token.as_deref())
// Borrowed the below code from https://github.com/eigerco/lumina/blob/ccc5b9bfeac632cccd32d35ecb7b7d51d71fbb87/rpc/src/client.rs#L41.
// Directly calling the function wasn't possible as the function is async. Since
// we only need to initiate the http provider and not the ws provider, we don't need async
let mut headers = HeaderMap::new();
if let Some(auth_token) = conf.auth_token {
let val = HeaderValue::from_str(&format!("Bearer {}", auth_token))?;
headers.insert(header::AUTHORIZATION, val);
}

let http_client = HttpClientBuilder::default()
.set_headers(headers)
.build(conf.http_provider.as_str())
.map_err(|e| anyhow::anyhow!("could not init http client: {e}"))?;

// Convert the input string to bytes
Expand Down

0 comments on commit 3ecc442

Please sign in to comment.