Skip to content
Prev Previous commit
Next Next commit
cleanup, cargo clippy
  • Loading branch information
Andrew Plaza committed Sep 19, 2020
commit 02a20a62474319dd8a1e78f8f750f261c2bd7ee9
12 changes: 2 additions & 10 deletions src/actors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,7 @@ where
workers: usize,
pg_url: &str,
) -> Result<Self> {
let context = ActorContext::new(
backend.clone(),
client_api.clone(),
workers,
pg_url.to_string(),
);
let context = ActorContext::new(backend, client_api.clone(), workers, pg_url.to_string());
let (start_tx, kill_tx, handle) = Self::start(context.clone(), client_api);

Ok(Self {
Expand Down Expand Up @@ -306,10 +301,7 @@ where
.iter()
.map(|b| b.block_num as u32)
.collect();
let difference: HashSet<u32> = missing_storage_nums
.difference(&blocks)
.map(|b| *b)
.collect();
let difference: HashSet<u32> = missing_storage_nums.difference(&blocks).copied().collect();
missing_storage_blocks.retain(|b| difference.contains(&(b.block_num as u32)));
let jobs: Vec<crate::tasks::execute_block::Job<B, R, C>> =
SqlBlockBuilder::with_vec(missing_storage_blocks)?
Expand Down
2 changes: 1 addition & 1 deletion src/actors/actor_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ where
// `Sync` Cell<bool>
let (mut tx, mut rx) = futures::channel::mpsc::channel(0);

let handle = smol::Task::spawn(async move { rx.next().await.map(|r: R| r).expect("One Shot") });
let handle = smol::Task::spawn(async move { rx.next().await.expect("One Shot") });
let fut = async move {
match fut.await {
Ok(v) => {
Expand Down
8 changes: 3 additions & 5 deletions src/actors/workers/blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ where
.do_send(ReIndex)
.expect("Actor cannot be disconnected; just started");

ctx.notify_interval(std::time::Duration::from_secs(5), || Crawl);
ctx.notify_interval(std::time::Duration::from_secs(10), || Crawl);
}
}

Expand All @@ -148,10 +148,8 @@ where
match self.crawl().await {
Err(e) => log::error!("{}", e.to_string()),
Ok(b) => {
if !b.is_empty() {
if let Err(_) = self.meta.send(BatchBlock::new(b)).await {
ctx.stop();
}
if !b.is_empty() && self.meta.send(BatchBlock::new(b)).await.is_err() {
ctx.stop();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/actors/workers/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl<B: BlockT> DatabaseActor<B> {
async fn batch_storage_handler(&self, storage: Vec<Storage<B>>) -> Result<()> {
let mut conn = self.db.conn().await?;
let mut block_nums: Vec<u32> = storage.iter().map(|s| s.block_num()).collect();
block_nums.sort();
block_nums.sort_unstable();
log::debug!(
"Inserting: {:#?}, {} .. {}",
block_nums.len(),
Expand Down
10 changes: 5 additions & 5 deletions src/backend/runtime_version_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,11 @@ impl<B: BlockT> RuntimeVersionCache<B> {
// remove some unnecessary host functions
let funs = sp_io::SubstrateHostFunctions::host_functions()
.into_iter()
.filter(|f| !(f.name().matches("wasm_tracing").count() > 0))
.filter(|f| !(f.name().matches("ext_offchain").count() > 0))
.filter(|f| !(f.name().matches("ext_storage").count() > 0))
.filter(|f| !(f.name().matches("ext_default_child_storage").count() > 0))
.filter(|f| !(f.name().matches("ext_logging").count() > 0))
.filter(|f| f.name().matches("wasm_tracing").count() == 0)
.filter(|f| f.name().matches("ext_offchain").count() == 0)
.filter(|f| f.name().matches("ext_storage").count() == 0)
.filter(|f| f.name().matches("ext_default_child_storage").count() == 0)
.filter(|f| f.name().matches("ext_logging").count() == 0)
.collect::<Vec<_>>();

let exec = WasmExecutor::new(WasmExecutionMethod::Interpreted, Some(128), funs, 1);
Expand Down
25 changes: 13 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,18 +79,18 @@ impl sp_core::traits::SpawnNamed for TaskExecutor {
_: &'static str,
fut: std::pin::Pin<Box<dyn futures::Future<Output = ()> + Send + 'static>>,
) {
smol::Task::spawn(async move { smol::unblock!(fut) }).detach();
smol::Task::spawn(async move { smol::unblock!(fut).await }).detach();
}
}

#[cfg(test)]
use test::{initialize, DATABASE_URL, PG_POOL, DUMMY_HASH, TestGuard};
use test::{initialize, TestGuard, DATABASE_URL, DUMMY_HASH, PG_POOL};

#[cfg(test)]
mod test {
use once_cell::sync::Lazy;
use std::sync::{Once, Mutex, MutexGuard};
use sqlx::prelude::*;
use std::sync::{Mutex, MutexGuard, Once};

pub static DATABASE_URL: Lazy<String> = Lazy::new(|| {
dotenv::var("DATABASE_URL").expect("TEST_DATABASE_URL must be set to run tests!")
Expand All @@ -99,14 +99,16 @@ mod test {
pub const DUMMY_HASH: [u8; 2] = [0x13, 0x37];

pub static PG_POOL: Lazy<sqlx::PgPool> = Lazy::new(|| {
smol::block_on(async {
let pool = sqlx::postgres::PgPoolOptions::new()
.min_connections(4)
.max_connections(8)
.idle_timeout(std::time::Duration::from_millis(3600))
.connect(&DATABASE_URL).await.expect("Couldn't initialize postgres pool for tests");
pool
})
smol::block_on(async {
let pool = sqlx::postgres::PgPoolOptions::new()
.min_connections(4)
.max_connections(8)
.idle_timeout(std::time::Duration::from_millis(3600))
.connect(&DATABASE_URL)
.await
.expect("Couldn't initialize postgres pool for tests");
pool
})
});

static INIT: Once = Once::new();
Expand Down Expand Up @@ -179,5 +181,4 @@ mod test {
});
}
}

}
2 changes: 1 addition & 1 deletion src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,6 @@ macro_rules! p_err {
fn format_opt(file: Option<String>) -> String {
match file {
None => "".to_string(),
Some(f) => f.to_string(),
Some(f) => f,
}
}