Skip to content

Commit

Permalink
use tokio block_in_place in SchedulerDB
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomoto911 committed Jan 14, 2025
1 parent 8ba091d commit 500346e
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ where
fn load_cache_account(&mut self, address: Address) -> Result<&mut CacheAccount, DB::Error> {
match self.state.cache.accounts.entry(address) {
hash_map::Entry::Vacant(entry) => {
let info = self.database.basic_ref(address)?;
let info = tokio::task::block_in_place(|| self.database.basic_ref(address))?;
Ok(entry.insert(into_cache_account(info)))
}
hash_map::Entry::Occupied(entry) => Ok(entry.into_mut()),
Expand Down Expand Up @@ -355,7 +355,8 @@ where
let res = match self.state.cache.contracts.entry(code_hash) {
hash_map::Entry::Occupied(entry) => Ok(entry.get().clone()),
hash_map::Entry::Vacant(entry) => {
let code = self.database.code_by_hash_ref(code_hash)?;
let code =
tokio::task::block_in_place(|| self.database.code_by_hash_ref(code_hash))?;
entry.insert(code.clone());
Ok(code)
}
Expand All @@ -371,7 +372,8 @@ where
match self.state.block_hashes.entry(number) {
btree_map::Entry::Occupied(entry) => Ok(*entry.get()),
btree_map::Entry::Vacant(entry) => {
let ret = *entry.insert(self.database.block_hash_ref(number)?);
let ret = *entry
.insert(tokio::task::block_in_place(|| self.database.block_hash_ref(number))?);

// prune all hashes that are older than BLOCK_HASH_HISTORY
let last_block = number.saturating_sub(BLOCK_HASH_HISTORY);
Expand Down Expand Up @@ -478,9 +480,9 @@ impl<DB> PartitionDB<DB> {
read_account.account.as_ref().map_or(true, |read_account| {
new_contract_account =
has_code && read_account.info.is_empty_code_hash();
new_contract_account ||
read_account.info.nonce != account.info.nonce ||
read_account.info.balance != account.info.balance
new_contract_account
|| read_account.info.nonce != account.info.nonce
|| read_account.info.balance != account.info.balance
})
}
None => {
Expand Down Expand Up @@ -591,8 +593,8 @@ where
let mut wait_time_ms = 0;
let loop_wait_time = 10; // 10ms
let wait_time_out = 10_1000; // 10s
while accumulator.accumulate_counter.load(Ordering::Acquire) <
accumulator.accumulate_num
while accumulator.accumulate_counter.load(Ordering::Acquire)
< accumulator.accumulate_num
{
let notifier = accumulator.notifier.clone();
tokio::task::block_in_place(move || {
Expand Down

0 comments on commit 500346e

Please sign in to comment.