Skip to content

Commit

Permalink
polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
oblique committed Nov 12, 2024
1 parent b58c4f0 commit 1a0b9be
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 13 deletions.
11 changes: 3 additions & 8 deletions types/src/extended_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::fmt::{Display, Formatter};
use std::time::Duration;

use celestia_proto::header::pb::ExtendedHeader as RawExtendedHeader;
use serde::de::Error as _;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use tendermint::block::header::Header;
use tendermint::block::{Commit, Height};
Expand Down Expand Up @@ -163,16 +162,12 @@ impl ExtendedHeader {
)
}

let Some(data_hash) = self.header.data_hash else {
bail_validation!("header dah hash is missing")
};

// ensure data root from raw header matches computed root
if self.dah.hash() != data_hash {
if self.dah.hash() != self.header.data_hash.unwrap_or_default() {
bail_validation!(
"dah hash ({}) != header dah hash ({})",
self.dah.hash(),
data_hash,
self.header.data_hash.unwrap_or_default(),
)
}

Expand Down Expand Up @@ -519,7 +514,7 @@ impl<'de> Deserialize<'de> for ExtendedHeader {
{
let custom_de = custom_serde::SerdeExtendedHeader::deserialize(deserializer)?;
let pb: RawExtendedHeader = custom_de.into();
ExtendedHeader::try_from(pb).map_err(|e| D::Error::custom(e.to_string()))
ExtendedHeader::try_from(pb).map_err(serde::de::Error::custom)
}
}

Expand Down
3 changes: 0 additions & 3 deletions types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ mod tx_config;
mod validate;
mod validator_set;

pub use tendermint;
pub use tendermint_proto;

pub use crate::blob::{Blob, Commitment};
pub use crate::block::*;
pub use crate::consts::appconsts::AppVersion;
Expand Down
3 changes: 1 addition & 2 deletions types/src/serializers/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use std::str::FromStr;

use serde::de::Error as _;
use serde::{Deserialize, Deserializer, Serialize, Serializer};
use tendermint::hash::Hash;

Expand All @@ -12,7 +11,7 @@ where
D: Deserializer<'de>,
{
let hex = Option::<String>::deserialize(deserializer)?.unwrap_or_default();
Hash::from_str(&hex).map_err(|e| D::Error::custom(e.to_string()))
Hash::from_str(&hex).map_err(serde::de::Error::custom)
}

/// Serialize [`tendermint::hash::Hash`].
Expand Down

0 comments on commit 1a0b9be

Please sign in to comment.