Skip to content

Commit

Permalink
polls mempool svc from tx verifier when a mempool tx that creates tra…
Browse files Browse the repository at this point in the history
…nsparent outputs has been verified.

adds a TODO for adding a `pending_outputs` field to the mempool Storage
  • Loading branch information
arya2 committed Sep 7, 2024
1 parent d0b2d41 commit 0a72b41
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
17 changes: 12 additions & 5 deletions zebra-consensus/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::{
pin::Pin,
sync::Arc,
task::{Context, Poll},
time::Duration,
};

use chrono::{DateTime, Utc};
Expand Down Expand Up @@ -421,7 +422,7 @@ where
// Load spent UTXOs from state.
// The UTXOs are required for almost all the async checks.
let load_spent_utxos_fut =
Self::spent_utxos(tx.clone(), req.known_utxos(), req.is_mempool(), state.clone(), mempool);
Self::spent_utxos(tx.clone(), req.known_utxos(), req.is_mempool(), state.clone(), mempool.clone());
let (spent_utxos, spent_outputs, spent_mempool_outpoints) = load_spent_utxos_fut.await?;

// WONTFIX: Return an error for Request::Block as well to replace this check in
Expand Down Expand Up @@ -517,17 +518,23 @@ where
legacy_sigop_count,
},
Request::Mempool { transaction, .. } => {
// TODO: If the mempool transaction has any transparent outputs, poll the mempool so
// it sees the new verified result promptly / nearly-immediately
// (to solve concurrency issue with dependency chains of orphaned transactions)

let transaction = VerifiedUnminedTx::new(
transaction,
miner_fee.expect(
"unexpected mempool coinbase transaction: should have already rejected",
),
legacy_sigop_count,
)?;

if let Some(mut mempool) = mempool {
if !transaction.transaction.transaction.outputs().is_empty() {
tokio::spawn(async move {
tokio::time::sleep(Duration::from_millis(50)).await;
mempool.ready().await.expect("mempool poll_ready() method should not return an error");
});
}
}

Response::Mempool { transaction, spent_mempool_outpoints }
},
};
Expand Down
3 changes: 3 additions & 0 deletions zebrad/src/components/mempool/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ pub enum RejectionError {
}

/// Hold mempool verified and rejected mempool transactions.
//
// Add a `pending_outputs` field similar to the `pending_utxos` field in the state service
// for queuing outpoint queries.
pub struct Storage {
/// The set of verified transactions in the mempool.
verified: VerifiedSet,
Expand Down

0 comments on commit 0a72b41

Please sign in to comment.