Skip to content

Commit

Permalink
chore: Update wasm-bindgen, remove cfg_attr wasm-bindgen workaround (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fl0rek authored Jan 14, 2025
1 parent 4c2187c commit 29df1e4
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 112 deletions.
51 changes: 24 additions & 27 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ nmt-rs = "0.2.1"
prost = "0.13.3"
prost-build = "0.13.3"
prost-types = "0.13.3"
wasm-bindgen = "0.2.99"
wasm-bindgen = "0.2.100"
wasm-bindgen-test = "0.3.49"

[patch.crates-io]
Expand Down
42 changes: 6 additions & 36 deletions node/src/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,57 +35,27 @@ mod redb_store;

pub(crate) mod utils;

// TODO: once https://github.com/rustwasm/wasm-bindgen/pull/4351 is merged,
// this can be replaced with a single common type definition
/// Sampling metadata for a block.
///
/// This struct persists DAS-ing information in a header store for future reference.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[cfg(not(all(feature = "wasm-bindgen", target_arch = "wasm32")))]
#[cfg_attr(all(feature = "wasm-bindgen", target_arch = "wasm32"), wasm_bindgen)]
pub struct SamplingMetadata {
/// Indicates whether this node was able to successfuly sample the block
pub status: SamplingStatus,

/// List of CIDs used while sampling. Can be used to remove associated data
/// from Blockstore, when cleaning up the old ExtendedHeaders
#[cfg_attr(
all(feature = "wasm-bindgen", target_arch = "wasm32"),
wasm_bindgen(skip)
)]
pub cids: Vec<Cid>,
}

/// Sampling metadata for a block.
///
/// This struct persists DAS-ing information in a header store for future reference.
#[derive(Debug, Default, Clone, Serialize, Deserialize)]
#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))]
#[wasm_bindgen]
pub struct SamplingMetadata {
/// Indicates whether this node was able to successfuly sample the block
pub status: SamplingStatus,

/// List of CIDs used while sampling. Can be used to remove associated data
/// from Blockstore, when cleaning up the old ExtendedHeaders
#[wasm_bindgen(skip)]
pub cids: Vec<Cid>,
}

// TODO: once https://github.com/rustwasm/wasm-bindgen/pull/4351 is merged,
// this can be replaced with a single common type definition
/// Sampling status for a block.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg(not(all(feature = "wasm-bindgen", target_arch = "wasm32")))]
pub enum SamplingStatus {
/// Sampling is not done.
#[default]
Unknown,
/// Sampling is done and block is accepted.
Accepted,
/// Sampling is done and block is rejected.
Rejected,
}

/// Sampling status for a block.
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))]
#[wasm_bindgen]
#[cfg_attr(all(feature = "wasm-bindgen", target_arch = "wasm32"), wasm_bindgen)]
pub enum SamplingStatus {
/// Sampling is not done.
#[default]
Expand Down
68 changes: 20 additions & 48 deletions types/src/extended_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ pub type ValidatorSet = validator::Set;
))]
const VERIFY_CLOCK_DRIFT: Duration = Duration::from_secs(10);

// TODO: once https://github.com/rustwasm/wasm-bindgen/pull/4351 is merged,
// this can be replaced with a single common type definition
/// Block header together with the relevant Data Availability metadata.
///
/// [`ExtendedHeader`]s are used to announce and describe the blocks
Expand Down Expand Up @@ -67,60 +65,34 @@ const VERIFY_CLOCK_DRIFT: Duration = Duration::from_secs(10);
/// genesis_header.verify(&fetched_header).expect("Malicious header received");
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg(not(all(feature = "wasm-bindgen", target_arch = "wasm32")))]
#[cfg_attr(
all(feature = "wasm-bindgen", target_arch = "wasm32"),
wasm_bindgen(inspectable)
)]
pub struct ExtendedHeader {
/// Tendermint block header.
#[cfg_attr(
all(feature = "wasm-bindgen", target_arch = "wasm32"),
wasm_bindgen(skip)
)]
pub header: Header,
/// Commit metadata and signatures from validators committing the block.
#[cfg_attr(
all(feature = "wasm-bindgen", target_arch = "wasm32"),
wasm_bindgen(skip)
)]
pub commit: Commit,
/// Information about the set of validators commiting the block.
#[cfg_attr(
all(feature = "wasm-bindgen", target_arch = "wasm32"),
wasm_bindgen(skip)
)]
pub validator_set: ValidatorSet,
/// Header of the block data availability.
pub dah: DataAvailabilityHeader,
}

/// Block header together with the relevant Data Availability metadata.
///
/// [`ExtendedHeader`]s are used to announce and describe the blocks
/// in the Celestia network.
///
/// Before being used, each header should be validated and verified with a header you trust.
///
/// # Example
///
/// ```
/// # use celestia_types::ExtendedHeader;
/// # fn trusted_genesis_header() -> ExtendedHeader {
/// # let s = include_str!("../test_data/chain1/extended_header_block_1.json");
/// # serde_json::from_str(s).unwrap()
/// # }
/// # fn some_untrusted_header() -> ExtendedHeader {
/// # let s = include_str!("../test_data/chain1/extended_header_block_27.json");
/// # serde_json::from_str(s).unwrap()
/// # }
/// let genesis_header = trusted_genesis_header();
///
/// // fetch new header
/// let fetched_header = some_untrusted_header();
///
/// fetched_header.validate().expect("Invalid block header");
/// genesis_header.verify(&fetched_header).expect("Malicious header received");
/// ```
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg(all(feature = "wasm-bindgen", target_arch = "wasm32"))]
#[wasm_bindgen(inspectable)]
pub struct ExtendedHeader {
/// Tendermint block header.
#[wasm_bindgen(skip)]
pub header: Header,
/// Commit metadata and signatures from validators committing the block.
#[wasm_bindgen(skip)]
pub commit: Commit,
/// Information about the set of validators commiting the block.
#[wasm_bindgen(skip)]
pub validator_set: ValidatorSet,
/// Header of the block data availability.
#[wasm_bindgen(getter_with_clone)]
#[cfg_attr(
all(feature = "wasm-bindgen", target_arch = "wasm32"),
wasm_bindgen(getter_with_clone)
)]
pub dah: DataAvailabilityHeader,
}

Expand Down

0 comments on commit 29df1e4

Please sign in to comment.