Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Make sure we run clippy for wasm and fix wasm build/lints #115

Merged
merged 19 commits into from
Nov 17, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,18 @@ jobs:
version: "23.3"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Run clippy
- name: Install wasm Rust
uses: ATiltedTree/setup-rust@v1
zvolin marked this conversation as resolved.
Show resolved Hide resolved
with:
rust-version: stable
components: clippy
targets: wasm32-unknown-unknown

- name: Run clippy for native
run: cargo clippy --all --all-targets -- -D warnings

- name: Run clippy for wasm32
run: cargo clippy --all --all-targets --target=wasm32-unknown-unknown -- -D warnings

fmt:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -57,17 +66,20 @@ jobs:
uses: nanasess/setup-chromedriver@v2

- name: Build (wasm32-unknown-unknown)
run: cargo build --all --target=wasm32-unknown-unknown
run: cargo build --all --target=wasm32-unknown-unknown --features=wasm-bindgen

- name: Test proto crate
run: wasm-pack test --node proto

- name: Test types crate
run: wasm-pack test --node types
run: wasm-pack test --node types --features=wasm-bindgen

- name: Test node crate
run: wasm-pack test --headless --chrome node

- name: Test node-wasm crate
run: wasm-pack test --headless --chrome node-wasm

- name: Build and pack node-wasm
run: wasm-pack build --release --target web node-wasm && wasm-pack pack node-wasm

Expand Down
4 changes: 2 additions & 2 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ celestia-rpc = { version = "0.1.0", path = "rpc", default-features = false }
celestia-types = { version = "0.1.0", path = "types", default-features = false }
libp2p = "0.53.1"
nmt-rs = { git = "https://github.com/Sovereign-Labs/nmt-rs.git", rev = "d821332" }
tendermint = { git = "https://github.com/eigerco/celestia-tendermint-rs.git", rev = "ef58b85", default-features = false }
tendermint-proto = { git = "https://github.com/eigerco/celestia-tendermint-rs.git", rev = "ef58b85" }
tendermint = { git = "https://github.com/eigerco/celestia-tendermint-rs.git", rev = "bbe7de8", default-features = false }
tendermint-proto = { git = "https://github.com/eigerco/celestia-tendermint-rs.git", rev = "bbe7de8" }

[patch.'https://github.com/eigerco/celestia-tendermint-rs.git']
# Uncomment to apply local changes
Expand Down
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ libp2p = { workspace = true, features = [

[target.'cfg(target_arch = "wasm32")'.dependencies]
backoff = { version = "0.4.0", features = ["wasm-bindgen"] }
celestia-types = { workspace = true, features = ["wasm-bindgen"] }
getrandom = { version = "0.2.10", features = ["js"] }
gloo-timers = { version = "0.3.0", features = ["futures"] }
libp2p = { workspace = true, features = ["wasm-bindgen", "webtransport-websys"] }
Expand Down
1 change: 1 addition & 0 deletions rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ tracing = "0.1.37"
[features]
default = ["p2p"]
p2p = ["celestia-types/p2p"]
wasm-bindgen = ["celestia-types/wasm-bindgen"]
2 changes: 2 additions & 0 deletions rpc/tests/blob.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(target_arch = "wasm32"))]

use std::time::Duration;

use celestia_rpc::prelude::*;
Expand Down
2 changes: 2 additions & 0 deletions rpc/tests/header.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(target_arch = "wasm32"))]

use celestia_rpc::prelude::*;

pub mod utils;
Expand Down
2 changes: 1 addition & 1 deletion rpc/tests/p2p.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg(feature = "p2p")]
#![cfg(all(not(target_arch = "wasm32"), feature = "p2p"))]
use crate::utils::client::{new_test_client, AuthLevel};
use celestia_rpc::prelude::*;
use celestia_types::p2p;
Expand Down
2 changes: 2 additions & 0 deletions rpc/tests/share.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(target_arch = "wasm32"))]

use celestia_rpc::prelude::*;
use celestia_types::consts::appconsts::{
CONTINUATION_SPARSE_SHARE_CONTENT_SIZE, FIRST_SPARSE_SHARE_CONTENT_SIZE, SEQUENCE_LEN_BYTES,
Expand Down
2 changes: 2 additions & 0 deletions rpc/tests/state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(target_arch = "wasm32"))]

use celestia_rpc::prelude::*;

pub mod utils;
Expand Down
2 changes: 2 additions & 0 deletions rpc/tests/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![cfg(not(target_arch = "wasm32"))]

use celestia_types::nmt::{Namespace, NS_ID_V0_SIZE};
use rand::{Rng, RngCore};

Expand Down
10 changes: 5 additions & 5 deletions types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ tendermint = { workspace = true, features = ["std", "rust-crypto"] }
tendermint-proto = { workspace = true }
thiserror = "1.0.40"

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { version = "0.2.10", features = ["js"] }
tendermint = { workspace = true, features = ["wasm-bindgen"] }
wasm-bindgen-test = "0.3"

[dev-dependencies]
ed25519-consensus = "2.1.0"
proptest = { version = "1.2.0", default-features = false, features = ["std"] }
rand = "0.8.5"
serde_json = "1.0.97"

[target.'cfg(target_arch = "wasm32")'.dev-dependencies]
getrandom = { version = "0.2.10", features = ["js"] }
wasm-bindgen-test = "0.3"

[features]
default = ["p2p"]
p2p = ["dep:libp2p-identity", "dep:multiaddr", "dep:serde_repr"]
test-utils = ["dep:ed25519-consensus", "dep:rand"]
wasm-bindgen = ["tendermint/wasm-bindgen"]
23 changes: 14 additions & 9 deletions types/src/extended_header.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::fmt::{Display, Formatter};
#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-bindgen"))]
use std::time::Duration;

use celestia_proto::header::pb::ExtendedHeader as RawExtendedHeader;
Expand All @@ -18,6 +19,7 @@ use crate::{
pub type Validator = validator::Info;
pub type ValidatorSet = validator::Set;

#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-bindgen"))]
const VERIFY_CLOCK_DRIFT: Duration = Duration::from_secs(10);

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
Expand Down Expand Up @@ -144,16 +146,19 @@ impl ExtendedHeader {
);
}

let now = Time::now();
let valid_until = now.checked_add(VERIFY_CLOCK_DRIFT).unwrap();
#[cfg(any(not(target_arch = "wasm32"), feature = "wasm-bindgen"))]
{
let now = Time::now();
let valid_until = now.checked_add(VERIFY_CLOCK_DRIFT).unwrap();

if !untrusted.time().before(valid_until) {
bail_verification!(
"new untrusted header has a time from the future {} (now: {}, clock_drift: {:?})",
untrusted.time(),
now,
VERIFY_CLOCK_DRIFT
);
if !untrusted.time().before(valid_until) {
bail_verification!(
"new untrusted header has a time from the future {} (now: {}, clock_drift: {:?})",
untrusted.time(),
now,
VERIFY_CLOCK_DRIFT
);
}
}

// Optimization: If we are verifying an adjacent header we can avoid
Expand Down
Loading