Skip to content

Commit

Permalink
Merge pull request #3209 from dusk-network/fix-mempool-stackof
Browse files Browse the repository at this point in the history
  • Loading branch information
herr-seppia authored Dec 17, 2024
2 parents ccc8bd4 + 341d70c commit c3e832e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
9 changes: 9 additions & 0 deletions node-data/src/ledger/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,15 @@ impl SpendingId {
}
}
}

pub fn next(&self) -> Option<SpendingId> {
match self {
SpendingId::Nullifier(_) => None,
SpendingId::AccountNonce(account, nonce) => {
Some(SpendingId::AccountNonce(*account, nonce + 1))
}
}
}
}

#[cfg(any(feature = "faker", test))]
Expand Down
23 changes: 16 additions & 7 deletions node/src/database/rocksdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,16 +894,25 @@ impl<'db, DB: DBAccess> Mempool for DBTransaction<'db, DB> {
deleted.push(h);

if cascade {
let mut dependants = vec![];
// Get the next spending id (aka next nonce tx)
// retrieve tx_id and delete it
if let Some(spending_id) = tx.next_spending_id() {
for tx_id in
self.mempool_txs_by_spendable_ids(&[spending_id])
{
let cascade_deleted =
self.delete_mempool_tx(tx_id, cascade)?;
deleted.extend(cascade_deleted);
let mut next_spending_id = tx.next_spending_id();
while let Some(spending_id) = next_spending_id {
next_spending_id = spending_id.next();
let next_txs =
self.mempool_txs_by_spendable_ids(&[spending_id]);
if next_txs.is_empty() {
break;
}
dependants.extend(next_txs);
}

// delete all dependants
for tx_id in dependants {
let cascade_deleted =
self.delete_mempool_tx(tx_id, false)?;
deleted.extend(cascade_deleted);
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions node/src/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,19 @@ impl<N: Network, DB: database::DB, VM: vm::VMExecution>

// Remove expired transactions from the mempool
db.read().await.update(|db| {
let expired_txs = db.mempool_expired_txs(expiration_time)?;
let expired_txs = db.mempool_expired_txs(expiration_time).unwrap_or_else(|e| {
error!("cannot get expired txs: {e}");
vec![]
});
for tx_id in expired_txs {
info!(event = "expired_tx", hash = hex::encode(tx_id));
for deleted_tx_id in db.delete_mempool_tx(tx_id, true)? {
let deleted_txs = db.delete_mempool_tx(tx_id, true).unwrap_or_else(|e| {
error!("cannot delete expired tx: {e}");
vec![]
});
for deleted_tx_id in deleted_txs{
let event = TransactionEvent::Removed(deleted_tx_id);
info!(event = "mempool_deleted", hash = hex::encode(deleted_tx_id));
if let Err(e) = self.event_sender.try_send(event.into()) {
warn!("cannot notify mempool removed transaction {e}")
};
Expand Down

0 comments on commit c3e832e

Please sign in to comment.