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

perf: remove reduandent checking deposits expired #703

Merged
merged 2 commits into from
May 26, 2022
Merged
Changes from all 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
40 changes: 19 additions & 21 deletions crates/mem-pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use gw_store::{
};
use gw_traits::CodeStore;
use gw_types::{
offchain::{CellStatus, DepositInfo},
offchain::{CellStatus, CellWithStatus, DepositInfo},
packed::{
AccountMerkleState, BlockInfo, L2Block, L2Transaction, Script, TxReceipt,
WithdrawalRequest, WithdrawalRequestExtra,
Expand Down Expand Up @@ -783,34 +783,39 @@ impl MemPool {

// check expire
let mut force_expired = false;
let mut tasks = Vec::with_capacity(self.pending_deposits.len());
for deposit in &self.pending_deposits {
// check is handled by current block
if processed_deposit_requests.contains(&deposit.request) {
force_expired = true;
break;
}

// query deposit live cell
tasks.push(self.provider.get_cell(deposit.cell.out_point.clone()));
}

// check cell is available
for task in tasks {
match task.await? {
Some(cell_with_status) => {
if cell_with_status.status != CellStatus::Live {
// check whether the deposited cells are live
if !force_expired {
for deposit in &self.pending_deposits {
match self
.provider
.get_cell(deposit.cell.out_point.clone())
.await?
{
Some(CellWithStatus {
status: CellStatus::Live,
..
}) => {}
_ => {
force_expired = true;
break;
}
}
None => {
force_expired = true;
break;
}
}
}

if force_expired {
log::debug!("[mem-pool] forced clear pending deposits");
self.pending_deposits.clear();
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note for reviewers, when force_expired is true, we should clear self.pending_deposits before making the safe_expired prediction. Otherwise safe_expired will always be false when force_expired is equal to true.


// refresh
let snap = self.mem_pool_state.load();
let state = snap.state()?;
Expand Down Expand Up @@ -847,13 +852,6 @@ impl MemPool {
"[mem-pool] refreshed deposits: {}",
self.pending_deposits.len()
);
} else if force_expired {
log::debug!(
"[mem-pool] forced clear pending deposits, mem_account_count: {}, tip_account_count: {}",
mem_account_count,
tip_account_count
);
self.pending_deposits.clear();
} else {
log::debug!(
"[mem-pool] skip pending deposits, pending deposits: {}, mem_account_count: {}, tip_account_count: {}",
Expand Down