Skip to content

Commit

Permalink
Add locking on all mempool functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mvandeberg committed Dec 20, 2024
1 parent 7ad908a commit ec2d77a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit ec2d77a

Please sign in to comment.