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

Add locking on all mempool functions #107

Merged
merged 2 commits into from
Jan 6, 2025
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
11 changes: 11 additions & 0 deletions src/koinos/mempool/mempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -747,17 +747,20 @@ mempool::~mempool() = default;
bool mempool::has_pending_transaction( const transaction_id_type& id,
std::optional< crypto::multihash > block_id ) const
{
std::lock_guard< std::mutex > lock( _mutex );
return _my->has_pending_transaction( id, block_id );
}

std::vector< rpc::mempool::pending_transaction >
mempool::get_pending_transactions( uint64_t limit, std::optional< crypto::multihash > block_id )
{
std::lock_guard< std::mutex > lock( _mutex );
return _my->get_pending_transactions( limit, block_id );
}

uint64_t mempool::get_reserved_account_rc( const account_type& account ) const
{
std::lock_guard< std::mutex > lock( _mutex );
return _my->get_reserved_account_rc( account );
}

Expand All @@ -766,18 +769,21 @@ bool mempool::check_pending_account_resources( const account_type& payer,
uint64_t trx_resource_limit,
std::optional< crypto::multihash > block_id ) const
{
std::lock_guard< std::mutex > lock( _mutex );
return _my->check_pending_account_resources( payer, max_payer_resources, trx_resource_limit, block_id );
}

bool mempool::check_account_nonce( const account_type& payee,
const std::string& nonce,
std::optional< crypto::multihash > block_id ) const
{
std::lock_guard< std::mutex > lock( _mutex );
return _my->check_account_nonce( payee, nonce, block_id );
}

std::string mempool::get_pending_nonce( const std::string& account, std::optional< crypto::multihash > block_id ) const
{
std::lock_guard< std::mutex > lock( _mutex );
return _my->get_pending_nonce( account, block_id );
}

Expand All @@ -788,6 +794,7 @@ uint64_t mempool::add_pending_transaction( const protocol::transaction& transact
uint64_t network_bandwidth_used,
uint64_t compute_bandwidth_used )
{
std::lock_guard< std::mutex > lock( _mutex );
return _my->add_pending_transaction( transaction,
time,
max_payer_rc,
Expand All @@ -798,21 +805,25 @@ uint64_t mempool::add_pending_transaction( const protocol::transaction& transact

uint64_t mempool::remove_pending_transactions( const std::vector< transaction_id_type >& ids )
{
std::lock_guard< std::mutex > lock( _mutex );
return _my->remove_pending_transactions( ids );
}

uint64_t mempool::prune( std::chrono::seconds expiration, std::chrono::system_clock::time_point now )
{
std::lock_guard< std::mutex > lock( _mutex );
return _my->prune( expiration, now );
}

bool mempool::handle_block( const koinos::broadcast::block_accepted& bam )
{
std::lock_guard< std::mutex > lock( _mutex );
return _my->handle_block( bam );
}

void mempool::handle_irreversibility( const koinos::broadcast::block_irreversible& bi )
{
std::lock_guard< std::mutex > lock( _mutex );
_my->handle_irreversibility( bi );
}

Expand Down
1 change: 1 addition & 0 deletions src/koinos/mempool/mempool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class mempool final
{
private:
std::unique_ptr< detail::mempool_impl > _my;
mutable std::mutex _mutex;

public:
mempool( state_db::fork_resolution_algorithm algo = state_db::fork_resolution_algorithm::fifo );
Expand Down