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

fix(mem-pool): remove re-injected failed txs in mem pool #831

Merged
Merged
Show file tree
Hide file tree
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
26 changes: 26 additions & 0 deletions crates/mem-pool/src/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ impl MemPool {
cycles_pool,
};
mem_pool.restore_pending_withdrawals().await?;
mem_pool.remove_reinjected_failed_txs()?;

// update mem block info
let snap = mem_pool.mem_pool_state().load();
Expand Down Expand Up @@ -1192,6 +1193,31 @@ impl MemPool {
Ok(())
}

// Remove re-injected failed txs in mem pool db before bug fix.
// These txs depend on auto create tx to create sender accounts. Because we package
// new deposits during mem block reset, make these txs' from id invalid and re-injected failed.
fn remove_reinjected_failed_txs(&mut self) -> Result<()> {
let db = self.store.begin_transaction();
let txs_iter = db.get_mem_pool_transaction_iter();

for (tx_hash, _) in txs_iter {
if self.mem_block.txs_set().contains(&tx_hash)
|| self.pending_restored_tx_hashes.contains(&tx_hash)
{
continue;
}

log::info!(
"[mem-pool] remove re-injected failed tx {:x}",
tx_hash.pack()
);
db.remove_mem_pool_transaction(&tx_hash)?;
}

db.commit()?;
Ok(())
}

// Only **ReadOnly** node needs this.
// Refresh mem block with those params.
// Always expects next block number equals with current_tip_block_number + 1.
Expand Down
12 changes: 12 additions & 0 deletions crates/store/src/transaction/store_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -744,6 +744,18 @@ impl StoreTransaction {
)
})
}

pub fn get_mem_pool_transaction_iter(
&self,
) -> impl Iterator<Item = (H256, packed::L2Transaction)> + '_ {
self.get_iter(COLUMN_MEM_POOL_TRANSACTION, IteratorMode::End)
.map(|(key, val)| {
(
packed::Byte32Reader::from_slice_should_be_ok(key.as_ref()).unpack(),
from_box_should_be_ok!(packed::L2TransactionReader, val),
)
})
}
}

impl ChainStore for StoreTransaction {}