mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-18 23:31:04 +00:00
Replace async-std with tokio in PVF subsystem (#6419)
* Replace async-std with tokio in PVF subsystem * Rework workers to use `select!` instead of a mutex The improvement in code readability is more important than the thread overhead. * Remove unnecessary `fuse` * Add explanation for `expect()` * Update node/core/pvf/src/worker_common.rs Co-authored-by: Bastian Köcher <info@kchr.de> * Update node/core/pvf/src/worker_common.rs Co-authored-by: Bastian Köcher <info@kchr.de> * Address some review comments * Shutdown tokio runtime * Run cargo fmt * Add a small note about retries * Fix up merge * Rework `cpu_time_monitor_loop` to return when other thread finishes * Add error string to PrepareError::IoErr variant * Log when artifacts fail to prepare * Fix `cpu_time_monitor_loop`; fix test * Fix text * Fix a couple of potential minor data races. First data race was due to logging in the CPU monitor thread even if the job (other thread) finished. It can technically finish before or after the log. Maybe best would be to move this log to the `select!`s, where we are guaranteed to have chosen the timed-out branch, although there would be a bit of duplication. Also, it was possible for this thread to complete before we executed `finished_tx.send` in the other thread, which would trigger an error as the receiver has already been dropped. And right now, such a spurious error from `send` would be returned even if the job otherwise succeeded. * Update Cargo.lock Co-authored-by: Bastian Köcher <info@kchr.de>
This commit is contained in:
@@ -16,10 +16,10 @@
|
||||
|
||||
use crate::{error::PrepareError, host::PrepareResultSender};
|
||||
use always_assert::always;
|
||||
use async_std::path::{Path, PathBuf};
|
||||
use polkadot_parachain::primitives::ValidationCodeHash;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
path::{Path, PathBuf},
|
||||
time::{Duration, SystemTime},
|
||||
};
|
||||
|
||||
@@ -136,8 +136,8 @@ impl Artifacts {
|
||||
pub async fn new(cache_path: &Path) -> Self {
|
||||
// Make sure that the cache path directory and all its parents are created.
|
||||
// First delete the entire cache. Nodes are long-running so this should populate shortly.
|
||||
let _ = async_std::fs::remove_dir_all(cache_path).await;
|
||||
let _ = async_std::fs::create_dir_all(cache_path).await;
|
||||
let _ = tokio::fs::remove_dir_all(cache_path).await;
|
||||
let _ = tokio::fs::create_dir_all(cache_path).await;
|
||||
|
||||
Self { artifacts: HashMap::new() }
|
||||
}
|
||||
@@ -214,9 +214,8 @@ impl Artifacts {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{ArtifactId, Artifacts};
|
||||
use async_std::path::Path;
|
||||
use sp_core::H256;
|
||||
use std::str::FromStr;
|
||||
use std::{path::Path, str::FromStr};
|
||||
|
||||
#[test]
|
||||
fn from_file_name() {
|
||||
@@ -252,11 +251,9 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn artifacts_removes_cache_on_startup() {
|
||||
let fake_cache_path = async_std::task::block_on(async move {
|
||||
crate::worker_common::tmpfile("test-cache").await.unwrap()
|
||||
});
|
||||
#[tokio::test]
|
||||
async fn artifacts_removes_cache_on_startup() {
|
||||
let fake_cache_path = crate::worker_common::tmpfile("test-cache").await.unwrap();
|
||||
let fake_artifact_path = {
|
||||
let mut p = fake_cache_path.clone();
|
||||
p.push("wasmtime_0x1234567890123456789012345678901234567890123456789012345678901234");
|
||||
@@ -271,7 +268,7 @@ mod tests {
|
||||
// this should remove it and re-create.
|
||||
|
||||
let p = &fake_cache_path;
|
||||
async_std::task::block_on(async { Artifacts::new(p).await });
|
||||
Artifacts::new(p).await;
|
||||
|
||||
assert_eq!(std::fs::read_dir(&fake_cache_path).unwrap().count(), 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user