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

ignore unconfirmed spent input #198

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions src/locks/tokio/atomic_rw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use futures::future::BoxFuture;
use tokio::sync::RwLock;
use tokio::sync::RwLockReadGuard;
use tokio::sync::RwLockWriteGuard;
use tokio::sync::TryLockError;

use super::LockAcquisition;
use super::LockCallbackFn;
Expand Down Expand Up @@ -240,6 +241,15 @@ impl<T> AtomicRw<T> {
AtomicRwWriteGuard::new(guard, &self.lock_callback_info)
}

/// Attempt to acquire write lock immediately.
///
/// If the lock cannot be acquired without waiting, an error is returned.
pub fn try_lock_guard_mut(&mut self) -> Result<AtomicRwWriteGuard<T>, TryLockError> {
self.try_acquire_write_cb();
let guard = self.inner.try_write()?;
Ok(AtomicRwWriteGuard::new(guard, &self.lock_callback_info))
}

/// Immutably access the data of type `T` in a closure and possibly return a result of type `R`
///
/// # Examples
Expand Down
12 changes: 7 additions & 5 deletions src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,8 +528,8 @@ impl MainLoopHandler {

// Insert into mempool
global_state_mut
.mempool
.insert(&pt2m_transaction.transaction);
.mempool_insert(pt2m_transaction.transaction.to_owned())
.await?;

// send notification to peers
let transaction_notification: TransactionNotification =
Expand Down Expand Up @@ -970,7 +970,7 @@ impl MainLoopHandler {
// Handle mempool cleanup, i.e. removing stale/too old txs from mempool
_ = &mut mempool_cleanup_timer => {
debug!("Timer: mempool-cleaner job");
self.global_state_lock.lock_mut(|s| s.mempool.prune_stale_transactions()).await;
self.global_state_lock.lock_guard_mut().await.mempool_prune_stale_transactions().await?;

// Reset the timer to run this branch again in P seconds
mempool_cleanup_timer.as_mut().reset(tokio::time::Instant::now() + mempool_cleanup_timer_interval);
Expand Down Expand Up @@ -1026,8 +1026,10 @@ impl MainLoopHandler {

// insert transaction into mempool
self.global_state_lock
.lock_mut(|s| s.mempool.insert(&transaction))
.await;
.lock_guard_mut()
.await
.mempool_insert(*transaction)
.await?;

// do not shut down
Ok(false)
Expand Down
8 changes: 4 additions & 4 deletions src/mine_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ use crate::util_types::mutator_set::mutator_set_accumulator::MutatorSetAccumulat
const MOCK_MAX_BLOCK_SIZE: u32 = 1_000_000;

/// Prepare a Block for mining
fn make_block_template(
pub(crate) fn make_block_template(
previous_block: &Block,
transaction: Transaction,
mut block_timestamp: Timestamp,
Expand Down Expand Up @@ -299,7 +299,7 @@ fn make_coinbase_transaction(
/// Create the transaction that goes into the block template. The transaction is
/// built from the mempool and from the coinbase transaction. Also returns the
/// "sender randomness" used in the coinbase transaction.
fn create_block_transaction(
pub(crate) fn create_block_transaction(
latest_block: &Block,
global_state: &GlobalState,
timestamp: Timestamp,
Expand Down Expand Up @@ -603,8 +603,8 @@ mod mine_loop_tests {
.await?;

premine_receiver_global_state
.mempool
.insert(&tx_by_preminer);
.mempool_insert(tx_by_preminer)
.await?;
assert_eq!(1, premine_receiver_global_state.mempool.len());

// Build transaction
Expand Down
Loading
Loading