Skip to content

Commit

Permalink
Build Breakage with Avail and Celestia Feature Flags (Madara PR keep…
Browse files Browse the repository at this point in the history
…-starknet-strange#1481) (keep-starknet-strange#1487)

Co-authored-by: apoorvsadana <95699312+apoorvsadana@users.noreply.github.com>
Co-authored-by: 0xevolve <Artevolve@yahoo.com>
Co-authored-by: Timothée Delabrouille <34384633+tdelabro@users.noreply.github.com>
Co-authored-by: anondev1993 <114292591+anondev1993@users.noreply.github.com>
  • Loading branch information
5 people authored and hhamud committed Mar 29, 2024
1 parent 8585252 commit 157e33f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

## v0.7.0

- fix: fixing build breakage for celestia/avail
- chore: release v0.7.0
- refacto: remove abusive `TryInto` impl
- dev: optimize tx trace creation
Expand Down
11 changes: 7 additions & 4 deletions crates/client/data-availability/src/avail/config.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use std::fs::File;
use std::path::PathBuf;

use serde::Deserialize;

use crate::{DaError, DaLayer, DaMode};
use crate::{DaError, DaMode};

const DEFAULT_AVAIL_WS: &str = "ws://127.0.0.1:9945";
const DEFAULT_APP_ID: u32 = 0;
Expand All @@ -22,10 +25,10 @@ pub struct AvailConfig {
}

impl TryFrom<&PathBuf> for AvailConfig {
type Error = DaErr;
type Error = DaError;
fn try_from(path: &PathBuf) -> Result<Self, Self::Error> {
let file = File::open(path).map_err(|e| DaError::FailedOpeningConfig(e))?;
serde_json::from_reader(file).map_err(|e| DaError::FailedParsingConfig(e))
let file = File::open(path).map_err(DaError::FailedOpeningConfig)?;
serde_json::from_reader(file).map_err(DaError::FailedParsingConfig)
}
}

Expand Down
10 changes: 5 additions & 5 deletions crates/client/data-availability/src/avail/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use subxt::ext::sp_core::sr25519::Pair;
use subxt::OnlineClient;

use crate::utils::get_bytes_from_state_diff;
use crate::{DaClient, DaError, DaLayer, DaMode};
use crate::{DaClient, DaError, DaMode};

type AvailPairSigner = subxt::tx::PairSigner<AvailConfig, Pair>;

Expand Down Expand Up @@ -44,7 +44,7 @@ impl SubxtClient {
pub async fn restart(&mut self) -> Result<(), DaError> {
self.client = match build_client(self.config.ws_provider.as_str(), self.config.validate_codegen).await {
Ok(i) => i,
Err(e) => return DaError::FailedBuildingClient(e.into()),
Err(e) => return Err(DaError::FailedBuildingClient(e.into())),
};

Ok(())
Expand All @@ -65,7 +65,7 @@ impl TryFrom<config::AvailConfig> for SubxtClient {

#[async_trait]
impl DaClient for AvailClient {
async fn publish_state_diff(&self, state_diff: Vec<U256>) -> Result<(), DaError> {
async fn publish_state_diff(&self, state_diff: Vec<U256>) -> Result<(), anyhow::Error> {
let bytes = get_bytes_from_state_diff(&state_diff);
let bytes = BoundedVec(bytes);
self.publish_data(&bytes).await?;
Expand All @@ -75,7 +75,7 @@ impl DaClient for AvailClient {

// state diff can be published w/o verification of last state for the time being
// may change in subsequent DaMode implementations
async fn last_published_state(&self) -> Result<I256> {
async fn last_published_state(&self) -> Result<I256, anyhow::Error> {
Ok(I256::from(1))
}

Expand All @@ -102,7 +102,7 @@ impl AvailClient {
let _ = ws_client.restart().await;
}

return DaError::FailedBuildingClient(e.into());
return Err(DaError::FailedBuildingClient(e.into()));
}
};

Expand Down
3 changes: 3 additions & 0 deletions crates/client/data-availability/src/celestia/config.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::fs::File;
use std::path::PathBuf;

use serde::Deserialize;

use crate::{DaError, DaMode};
Expand Down
9 changes: 6 additions & 3 deletions crates/client/data-availability/src/celestia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct CelestiaClient {

#[async_trait]
impl DaClient for CelestiaClient {
async fn publish_state_diff(&self, state_diff: Vec<U256>) -> Result<(), DaError> {
async fn publish_state_diff(&self, state_diff: Vec<U256>) -> Result<(), anyhow::Error> {
let blob = self.get_blob_from_state_diff(state_diff).map_err(|e| DaError::FailedDataFetching(e.into()))?;

let submitted_height = self.publish_data(&blob).await.map_err(|e| DaError::FailedDataSubmission(e.into()))?;
Expand All @@ -39,7 +39,7 @@ impl DaClient for CelestiaClient {
Ok(())
}

async fn last_published_state(&self) -> Result<I256> {
async fn last_published_state(&self) -> Result<I256, anyhow::Error> {
Ok(I256::from(1))
}

Expand Down Expand Up @@ -93,7 +93,10 @@ impl TryFrom<config::CelestiaConfig> for CelestiaClient {
// 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))?;
let val = match HeaderValue::from_str(&format!("Bearer {}", auth_token)) {
Ok(value) => value,
Err(e) => return Err(DaError::FailedConversion(e.into())),
};
headers.insert(header::AUTHORIZATION, val);
}

Expand Down

0 comments on commit 157e33f

Please sign in to comment.