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

Spawn VID with spawn_blocking #2369

Merged
merged 6 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
15 changes: 12 additions & 3 deletions crates/task-impls/src/vid.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::events::HotShotEvent;
use async_lock::RwLock;
#[cfg(async_executor_impl = "async-std")]
use async_std::task::spawn_blocking;
use hotshot_task::{
event_stream::ChannelStream,
global_registry::GlobalRegistry,
Expand All @@ -22,6 +24,8 @@ use hotshot_types::{
data::{test_srs, VidScheme, VidSchemeTrait},
traits::network::ConsensusIntentEvent,
};
#[cfg(async_executor_impl = "tokio")]
use tokio::task::spawn_blocking;

use hotshot_task::event_stream::EventStream;
use snafu::Snafu;
Expand Down Expand Up @@ -90,9 +94,14 @@ impl<TYPES: NodeType, I: NodeImplementation<TYPES>, A: ConsensusApi<TYPES, I> +
let chunk_size = 1 << num_quorum_committee.ilog2();

// calculate vid shares
let vid = VidScheme::new(chunk_size, num_quorum_committee, &srs).unwrap();
let vid_disperse = vid.disperse(encoded_transactions.clone()).unwrap();

let vid_disperse = spawn_blocking(move || {
let vid = VidScheme::new(chunk_size, num_quorum_committee, &srs).unwrap();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add the note below (copied from the PR description) as a comment here?

Note that the unwrap for the tokio version just passes on any panics that happen during the thread, so it is "safe", i.e it's not adding a new place we can panic.

vid.disperse(encoded_transactions.clone()).unwrap()
})
.await;

#[cfg(async_executor_impl = "tokio")]
let vid_disperse = vid_disperse.unwrap();
// send the commitment and metadata to consensus for block building
self.event_stream
.publish(HotShotEvent::SendPayloadCommitmentAndMetadata(
Expand Down
1 change: 1 addition & 0 deletions crates/testing/tests/network_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use std::{collections::HashMap, marker::PhantomData};
tokio::test(flavor = "multi_thread", worker_threads = 2)
)]
#[cfg_attr(async_executor_impl = "async-std", async_std::test)]
#[ignore]
async fn test_network_task() {
use hotshot_task_impls::harness::run_harness;
use hotshot_testing::task_helpers::build_system_handle;
Expand Down
26 changes: 13 additions & 13 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,54 @@ test_basic: test_success test_with_failures test_network_task test_consensus_tas

test_catchup:
echo Testing with async std executor
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_catchup -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_catchup -- --test-threads=1 --nocapture

test_crypto:
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast crypto_test -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast crypto_test -- --test-threads=1 --nocapture

test_success:
echo Testing success test
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_success -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_success -- --test-threads=1 --nocapture

test_timeout:
echo Testing timeout test
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_timeout -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_timeout -- --test-threads=1 --nocapture

test_combined_network:
echo Testing combined network
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_combined_network -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_combined_network -- --test-threads=1 --nocapture

test_web_server:
echo Testing web server
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast web_server_network -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast web_server_network -- --test-threads=1 --nocapture

test_with_failures:
echo Testing nodes leaving the network with async std executor
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_with_failures -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_with_failures -- --test-threads=1 --nocapture

test_network_task:
echo Testing the DA task with async std executor
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_network_task -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_network_task -- --test-threads=1 --nocapture

test_memory_network:
echo Testing the DA task with async std executor
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast memory_network -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast memory_network -- --test-threads=1 --nocapture

test_consensus_task:
echo Testing with async std executor
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_consensus -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_consensus -- --test-threads=1 --nocapture

test_da_task:
echo Testing the DA task with async std executor
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_da_task -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_da_task -- --test-threads=1 --nocapture

test_vid_task:
echo Testing the VID task with async std executor
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_vid_task -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_vid_task -- --test-threads=1 --nocapture

test_view_sync_task:
echo Testing the view sync task with async std executor
ASYNC_STD_THREAD_COUNT=1 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_view_sync_task -- --test-threads=1 --nocapture
ASYNC_STD_THREAD_COUNT=2 cargo test --lib --bins --tests --benches --workspace --no-fail-fast test_view_sync_task -- --test-threads=1 --nocapture

test_pkg := "hotshot"

Expand Down