Skip to content

Commit

Permalink
Merge pull request #86 from koinos/79-fork-awareness
Browse files Browse the repository at this point in the history
Upgrades `mempool` to become fork aware
  • Loading branch information
mvandeberg authored Dec 15, 2022
2 parents 54d52da + 2ab2f5b commit b0e3c2d
Show file tree
Hide file tree
Showing 12 changed files with 743 additions and 427 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@
[submodule "libraries/proto"]
path = libraries/proto
url = https://github.com/koinos/koinos-proto-cpp.git
[submodule "libraries/state_db"]
path = libraries/state_db
url = https://github.com/koinos/koinos-state-db-cpp.git
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ hunter_add_package(OpenSSL)
hunter_add_package(Protobuf)
hunter_add_package(rabbitmq-c)
hunter_add_package(yaml-cpp)
hunter_add_package(rocksdb)

hunter_add_package(koinos_log)
hunter_add_package(koinos_util)
hunter_add_package(koinos_proto)
hunter_add_package(koinos_exception)
hunter_add_package(koinos_crypto)
hunter_add_package(koinos_mq)
hunter_add_package(koinos_state_db)

find_package(Boost CONFIG REQUIRED COMPONENTS system log log_setup thread date_time filesystem chrono program_options)
find_package(ethash CONFIG REQUIRED)
Expand All @@ -115,13 +117,15 @@ find_package(Protobuf CONFIG REQUIRED)
find_package(OpenSSL REQUIRED)
find_package(rabbitmq-c CONFIG REQUIRED)
find_package(yaml-cpp CONFIG REQUIRED)
find_package(RocksDB CONFIG REQUIRED)

find_package(koinos_crypto CONFIG REQUIRED)
find_package(koinos_exception CONFIG REQUIRED)
find_package(koinos_log CONFIG REQUIRED)
find_package(koinos_mq CONFIG REQUIRED)
find_package(koinos_proto CONFIG REQUIRED)
find_package(koinos_util CONFIG REQUIRED)
find_package(koinos_state_db CONFIG REQUIRED)

add_subdirectory(programs)
add_subdirectory(libraries)
Expand Down
24 changes: 24 additions & 0 deletions cmake/Hunter/config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,23 @@ hunter_config(Boost
Boost_NO_BOOST_CMAKE=ON
)

hunter_config(rocksdb
URL "https://github.com/facebook/rocksdb/archive/v6.15.2.tar.gz"
SHA1 "daf7ef3946fd39c910acaaa57789af8515b39251"
CMAKE_ARGS
WITH_TESTS=OFF
WITH_TOOLS=OFF
WITH_JNI=OFF
WITH_BENCHMARK_TOOLS=OFF
WITH_CORE_TOOLS=OFF
WITH_GFLAGS=OFF
PORTABLE=ON
FAIL_ON_WARNINGS=OFF
ROCKSDB_BUILD_SHARED=OFF
CMAKE_CXX_FLAGS=-fvisibility=hidden
CMAKE_C_FLAGS=-fvisibility=hidden
)

hunter_config(Protobuf
URL "https://github.com/koinos/protobuf/archive/e1b1477875a8b022903b548eb144f2c7bf4d9561.tar.gz"
SHA1 "5796707a98eec15ffb3ad86ff50e8eec5fa65e68"
Expand Down Expand Up @@ -79,3 +96,10 @@ hunter_config(koinos_mq
CMAKE_ARGS
BUILD_TESTS=OFF
)

hunter_config(koinos_state_db
GIT_SUBMODULE "libraries/state_db"
CMAKE_ARGS
BUILD_TESTS=OFF
)

3 changes: 2 additions & 1 deletion libraries/mempool/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
file(GLOB HEADERS "include/koinos/mempool/*.hpp")
add_library(koinos_mempool_lib
mempool.cpp
state.cpp
${HEADERS})
target_link_libraries(koinos_mempool_lib Koinos::exception Koinos::log Koinos::util)
target_link_libraries(koinos_mempool_lib Koinos::exception Koinos::log Koinos::util Koinos::state_db)
target_include_directories(koinos_mempool_lib PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include)
add_library(Koinos::mempool ALIAS koinos_mempool_lib)
38 changes: 27 additions & 11 deletions libraries/mempool/include/koinos/mempool/mempool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,16 @@

#include <koinos/crypto/multihash.hpp>
#include <koinos/exception.hpp>
#include <koinos/state_db/state_db.hpp>

#include <koinos/broadcast/broadcast.pb.h>
#include <koinos/protocol/protocol.pb.h>
#include <koinos/rpc/mempool/mempool_rpc.pb.h>

#define MAX_PENDING_TRANSACTION_REQUEST 2000

namespace koinos::mempool {

namespace constants { constexpr uint64_t max_request_limit = 2000; }

using transaction_id_type = std::string;
using account_type = std::string;
using nonce_type = uint64_t;
Expand All @@ -22,6 +25,8 @@ using block_height_type = uint64_t;
KOINOS_DECLARE_EXCEPTION( pending_transaction_insertion_failure );
KOINOS_DECLARE_EXCEPTION( pending_transaction_exceeds_resources );
KOINOS_DECLARE_EXCEPTION( pending_transaction_request_overflow );
KOINOS_DECLARE_EXCEPTION( pending_transaction_unlinkable_block );
KOINOS_DECLARE_EXCEPTION( pending_transaction_unknown_block );

namespace detail { class mempool_impl; }

Expand All @@ -31,13 +36,14 @@ class mempool final
std::unique_ptr< detail::mempool_impl > _my;

public:
mempool();
mempool( state_db::fork_resolution_algorithm algo = state_db::fork_resolution_algorithm::fifo );
virtual ~mempool();

bool check_pending_account_resources(
const account_type& payer,
uint64_t max_payer_rc,
uint64_t rc_limit )const;
uint64_t max_payer_resources,
uint64_t trx_resource_limit,
std::optional< crypto::multihash > block_id = {} ) const;

uint64_t add_pending_transaction(
const protocol::transaction& transaction,
Expand All @@ -47,12 +53,22 @@ class mempool final
uint64_t network_bandwidth_used,
uint64_t compute_bandwidth_used );

bool has_pending_transaction( const transaction_id_type& id )const;
std::vector< rpc::mempool::pending_transaction > get_pending_transactions( std::size_t limit = MAX_PENDING_TRANSACTION_REQUEST );
std::pair< uint64_t, uint64_t > remove_pending_transactions( const std::vector< transaction_id_type >& ids );
uint64_t prune( std::chrono::seconds expiration, std::chrono::system_clock::time_point now = std::chrono::system_clock::now() );
std::size_t payer_entries_size() const;
std::size_t pending_transaction_count() const;
bool has_pending_transaction(
const transaction_id_type& id,
std::optional< crypto::multihash > block_id = {} ) const;

std::vector< rpc::mempool::pending_transaction > get_pending_transactions(
uint64_t limit = constants::max_request_limit,
std::optional< crypto::multihash > block_id = {} );

uint64_t remove_pending_transactions( const std::vector< transaction_id_type >& ids );

uint64_t prune(
std::chrono::seconds expiration,
std::chrono::system_clock::time_point now = std::chrono::system_clock::now() );

void handle_block( const koinos::broadcast::block_accepted& bam );
void handle_irreversibility( const koinos::broadcast::block_irreversible& bi );
};

} // koinos::mempool
13 changes: 13 additions & 0 deletions libraries/mempool/include/koinos/mempool/state.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#pragma once

#include <koinos/chain/chain.pb.h>
#include <koinos/state_db/state_db_types.hpp>

namespace koinos::mempool::space {

const chain::object_space& mempool_metadata();
const chain::object_space& pending_transaction();
const chain::object_space& transaction_index();
const chain::object_space& address_resources();

} // koinos::mempool::space
Loading

0 comments on commit b0e3c2d

Please sign in to comment.