Skip to content

Commit

Permalink
Enable WASM compilation for utils and shutdown mods.
Browse files Browse the repository at this point in the history
  • Loading branch information
aterentic-ethernal committed Nov 25, 2024
1 parent 7edf50a commit 8dfbe55
Show file tree
Hide file tree
Showing 16 changed files with 118 additions and 46 deletions.
44 changes: 31 additions & 13 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 @@ -28,14 +28,14 @@ clap = { version = "4.4.4", features = ["derive", "cargo"] }
color-eyre = "0.6.2"
confy = "0.5.1"
hex = "0.4.3"
rand = "0.8.4"
rand = { version = "0.8.5", default-features = false }
libp2p = { version = "0.54", features = ["kad", "identify", "ping", "mdns", "autonat", "relay", "dcutr", "upnp", "noise", "yamux", "dns", "metrics", "tokio", "macros", "tcp", "quic", "serde", "websocket"] }
libp2p-allow-block-list = "0.4"
libp2p-webrtc = { version = "=0.8.0-alpha", features = ["tokio"] }
multihash = { version = "0.14.0", default-features = false, features = ["blake3", "sha3"] }
semver = "1.0.23"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.35", features = ["full"] }
tokio = { version = "1.35", default-features = false, features = ["sync", "macros", "io-util", "rt", "time"] }
tokio-stream = { version = "0.1.15", features = ["sync"] }
tracing = "0.1.35"
tracing-subscriber = { version = "0.3.17", features = ["json", "env-filter"] }
Expand Down
32 changes: 24 additions & 8 deletions core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,35 @@ version = "1.0.5"
edition = "2021"
description = "Avail Light core driving library"

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
# Internal deps
avail-rust = { workspace = true }

# 3rd-party
better-panic = "0.3.0"
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full", "bit-vec"] }
color-eyre = { workspace = true }
derive_more = { version = "1", features = ["from"] }
futures = { workspace = true }
getrandom = { version = "0.2.15", features = ["js"] }
strip-ansi-escapes = "0.2.0"
tokio = { workspace = true }
tracing = { workspace = true }
tracing-subscriber = { workspace = true }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
# Internal deps
avail-rust = { workspace = true }
dusk-plonk = { workspace = true }

# 3rd-party
async-std = { workspace = true }
async-stream = "0.3.5"
async-trait = { workspace = true }
base64 = "0.21.0"
better-panic = "0.3.0"
chrono = "0.4.19"
codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "full", "bit-vec"] }
color-eyre = { workspace = true }
confy = { workspace = true }
convert_case = "0.6.0"
derive_more = { version = "1", features = ["from"] }
Expand All @@ -37,7 +50,7 @@ multihash = { workspace = true }
num = "0.4.0"
num_cpus = "1.13.0"
pcap = "1.1.0"
rand = "0.8.4"
rand = { workspace = true, default-features = true }
rand_chacha = "0.3"
rocksdb = { version = "0.21.0", features = ["snappy", "multi-threaded-cf"], optional = true }
semver = { workspace = true }
Expand All @@ -48,7 +61,6 @@ strip-ansi-escapes = "0.2.0"
sysinfo = "0.30.12"
thiserror = "1.0.64"
threadpool = "1.8.1"
tokio = { workspace = true }
tokio-retry = "0.3"
tokio-stream = { workspace = true }
tokio-util = "0.7.10"
Expand All @@ -63,10 +75,14 @@ opentelemetry = { workspace = true }
opentelemetry-otlp = { workspace = true }
opentelemetry_sdk = { workspace = true }
strum = { version = "0.26.3", features = ["derive"] }
tracing-subscriber = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
blake2b_simd = "1.0.2"
rand = { workspace = true, features = ["std_rng"] }
tokio_with_wasm = { version = "0.7.1", default-features = false, features = ["sync", "macros", "rt", "time"] }

[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies]
hex-literal = "0.4.0"
hex-literal = "0.4.1"
proptest = "1.0.0"
test-case = "3.2.1"

Expand Down
3 changes: 1 addition & 2 deletions core/src/api/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use avail_rust::{
},
avail_core::kate::COMMITMENT_SIZE,
kate_recovery::{com::AppData, commitments},
sp_core::blake2_256,
subxt::config::substrate::{Digest as ApiDigest, DigestItem as ApiDigestItem},
AvailHeader, H256,
};
Expand Down Expand Up @@ -36,7 +35,7 @@ use crate::{
},
network::rpc::OutputEvent as RpcEvent,
types::{self, Base64, BlockVerified},
utils::{decode_app_data, OptionalExtension},
utils::{blake2_256, decode_app_data, OptionalExtension},
};

#[derive(Debug)]
Expand Down
3 changes: 1 addition & 2 deletions core/src/fat_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ use avail_rust::{
data::{self, Cell},
matrix::{Dimensions, Partition, Position, RowIndex},
},
sp_core::blake2_256,
AvailHeader, H256,
};
use codec::Encode;
Expand All @@ -35,7 +34,7 @@ use crate::{
},
shutdown::Controller,
types::{block_matrix_partition_format, BlockVerified, ClientChannels, Delay},
utils::extract_kate,
utils::{blake2_256, extract_kate},
};

#[async_trait]
Expand Down
6 changes: 4 additions & 2 deletions core/src/finality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use std::collections::HashMap;

use avail_rust::{
sp_core::{
blake2_256,
ed25519::{self, Public},
Pair,
},
Expand All @@ -13,7 +12,10 @@ use itertools::Itertools;
use serde::{Deserialize, Serialize};
use tracing::{info, warn};

use crate::types::{GrandpaJustification, SignerMessage};
use crate::{
types::{GrandpaJustification, SignerMessage},
utils::blake2_256,
};
use color_eyre::{eyre::eyre, Result};

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down
2 changes: 0 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ pub mod maintenance;
pub mod network;
#[cfg(not(target_arch = "wasm32"))]
pub mod proof;
#[cfg(not(target_arch = "wasm32"))]
pub mod shutdown;
#[cfg(not(target_arch = "wasm32"))]
pub mod sync_client;
Expand All @@ -30,5 +29,4 @@ pub mod sync_finality;
pub mod telemetry;
#[cfg(not(target_arch = "wasm32"))]
pub mod types;
#[cfg(not(target_arch = "wasm32"))]
pub mod utils;
3 changes: 1 addition & 2 deletions core/src/light_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use avail_rust::{
kate_recovery::{commitments, matrix::Dimensions},
sp_core::blake2_256,
AvailHeader, H256,
};
use codec::Encode;
Expand All @@ -36,7 +35,7 @@ use crate::{
},
shutdown::Controller,
types::{self, BlockRange, ClientChannels, Delay},
utils::{calculate_confidence, extract_kate},
utils::{blake2_256, calculate_confidence, extract_kate},
};

pub enum OutputEvent {
Expand Down
3 changes: 2 additions & 1 deletion core/src/network/p2p/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use crate::{
network::p2p::{is_multiaddr_global, AgentVersion},
shutdown::Controller,
types::TimeToLive,
utils,
};

// RelayState keeps track of all things relay related
Expand All @@ -59,7 +60,7 @@ impl RelayState {

fn select_random(&mut self) {
// choose relay by random
if let Some(relay) = self.nodes.choose(&mut rand::thread_rng()) {
if let Some(relay) = self.nodes.choose(&mut utils::rng()) {
let (id, addr) = relay.clone();
// appoint this relay as our chosen one
self.id = id;
Expand Down
7 changes: 2 additions & 5 deletions core/src/network/rpc/subscriptions.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use avail_rust::{
primitives::block::grandpa::AuthorityId,
sp_core::{
blake2_256,
ed25519::{self, Public},
},
sp_core::ed25519::{self, Public},
AvailHeader,
};
use codec::Encode;
Expand All @@ -21,7 +18,7 @@ use crate::{
},
finality::{check_finality, ValidatorSet},
types::{BlockRange, GrandpaJustification},
utils::filter_auth_set_changes,
utils::{blake2_256, filter_auth_set_changes},
};

struct BlockData {
Expand Down
3 changes: 3 additions & 0 deletions core/src/shutdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::{
sync::{Arc, Mutex},
task::Waker,
};
#[cfg(not(target_arch = "wasm32"))]
use utils::user_signal;

mod completed;
Expand Down Expand Up @@ -162,6 +163,7 @@ impl<T: Clone> Controller<T> {
}
}

#[cfg(not(target_arch = "wasm32"))]
/// Triggers a shutdown when each of the default termination signals is received.
///
/// On Unix-based systems, these signals are Ctrl-C (SIGINT) or SIGTERM,
Expand Down Expand Up @@ -372,6 +374,7 @@ impl<T> std::fmt::Display for ShutdownHasCompleted<T> {
}
}

#[cfg(not(target_arch = "wasm32"))]
#[cfg(test)]
mod tests {
use std::{
Expand Down
1 change: 1 addition & 0 deletions core/src/shutdown/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(not(target_arch = "wasm32"))]
/// This utility function returns a [`Future`] that completes upon
/// receiving each of the default termination signals.
///
Expand Down
3 changes: 1 addition & 2 deletions core/src/sync_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ use crate::{
rpc::{self, Client as RpcClient},
},
types::{BlockRange, BlockVerified, SyncClientConfig},
utils::{calculate_confidence, extract_kate},
utils::{blake2_256, calculate_confidence, extract_kate},
};

use async_trait::async_trait;
use avail_rust::{
kate_recovery::{commitments, matrix::Dimensions},
sp_core::blake2_256,
AvailHeader, H256,
};
use codec::Encode;
Expand Down
4 changes: 2 additions & 2 deletions core/src/sync_finality.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use async_trait::async_trait;
use avail_rust::{
sp_core::{blake2_256, ed25519, twox_128},
sp_core::{ed25519, twox_128},
subxt::{backend::legacy::rpc_methods::StorageKey, utils::AccountId32},
AvailHeader, H256,
};
Expand All @@ -21,7 +21,7 @@ use crate::{
finality::{check_finality, ValidatorSet},
network::rpc::{self, WrappedProof},
shutdown::Controller,
utils::filter_auth_set_changes,
utils::{blake2_256, filter_auth_set_changes},
};

#[async_trait]
Expand Down
4 changes: 2 additions & 2 deletions core/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//! Shared light client structs and enums.
use crate::network::rpc::OutputEvent;
use crate::utils::{extract_app_lookup, extract_kate};
use crate::utils::{blake2_256, extract_app_lookup, extract_kate};
use avail_rust::{
avail::runtime_types::bounded_collections::bounded_vec::BoundedVec,
avail_core::DataLookup,
kate_recovery::{commitments, matrix::Dimensions},
sp_core::{
crypto::{self, Ss58Codec},
{blake2_256, bytes, ed25519},
{bytes, ed25519},
},
subxt_signer::{
bip39::{Language, Mnemonic},
Expand Down
Loading

0 comments on commit 8dfbe55

Please sign in to comment.