Use a convenient global instead of passing use_memory_pools explicitly (#2059)

This commit is contained in:
Wesley Shillingford 2019-06-04 11:49:52 +01:00 committed by GitHub
commit e68c6c5d78
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 93 additions and 88 deletions

View file

@ -54,12 +54,12 @@ size_t get_allocated_size ()
TEST (memory_pool, validate_cleanup) TEST (memory_pool, validate_cleanup)
{ {
nano::make_shared<nano::open_block> (true); nano::make_shared<nano::open_block> ();
nano::make_shared<nano::receive_block> (true); nano::make_shared<nano::receive_block> ();
nano::make_shared<nano::send_block> (true); nano::make_shared<nano::send_block> ();
nano::make_shared<nano::change_block> (true); nano::make_shared<nano::change_block> ();
nano::make_shared<nano::state_block> (true); nano::make_shared<nano::state_block> ();
nano::make_shared<nano::vote> (true); nano::make_shared<nano::vote> ();
ASSERT_TRUE (nano::purge_singleton_pool_memory<nano::open_block> ()); ASSERT_TRUE (nano::purge_singleton_pool_memory<nano::open_block> ());
ASSERT_TRUE (nano::purge_singleton_pool_memory<nano::receive_block> ()); ASSERT_TRUE (nano::purge_singleton_pool_memory<nano::receive_block> ());

View file

@ -79,7 +79,7 @@ TEST (message, confirm_ack_serialization)
nano::bufferstream stream2 (bytes.data (), bytes.size ()); nano::bufferstream stream2 (bytes.data (), bytes.size ());
bool error (false); bool error (false);
nano::message_header header (error, stream2); nano::message_header header (error, stream2);
nano::confirm_ack con2 (error, stream2, header, true); nano::confirm_ack con2 (error, stream2, header);
ASSERT_FALSE (error); ASSERT_FALSE (error);
ASSERT_EQ (con1, con2); ASSERT_EQ (con1, con2);
ASSERT_EQ (header.block_type (), nano::block_type::send); ASSERT_EQ (header.block_type (), nano::block_type::send);
@ -106,7 +106,7 @@ TEST (message, confirm_ack_hash_serialization)
nano::bufferstream stream2 (bytes.data (), bytes.size ()); nano::bufferstream stream2 (bytes.data (), bytes.size ());
bool error (false); bool error (false);
nano::message_header header (error, stream2); nano::message_header header (error, stream2);
nano::confirm_ack con2 (error, stream2, header, true); nano::confirm_ack con2 (error, stream2, header);
ASSERT_FALSE (error); ASSERT_FALSE (error);
ASSERT_EQ (con1, con2); ASSERT_EQ (con1, con2);
std::vector<nano::block_hash> vote_blocks; std::vector<nano::block_hash> vote_blocks;

View file

@ -707,7 +707,7 @@ TEST (node_config, v16_v17_upgrade)
ASSERT_FALSE (tree.get_optional_child ("tcp_incoming_connections_max")); ASSERT_FALSE (tree.get_optional_child ("tcp_incoming_connections_max"));
ASSERT_FALSE (tree.get_optional_child ("vote_generator_delay")); ASSERT_FALSE (tree.get_optional_child ("vote_generator_delay"));
ASSERT_FALSE (tree.get_optional_child ("diagnostics")); ASSERT_FALSE (tree.get_optional_child ("diagnostics"));
ASSERT_FALSE (tree.get_optional_child ("use_memory_pool")); ASSERT_FALSE (tree.get_optional_child ("use_memory_pools"));
ASSERT_FALSE (tree.get_optional_child ("confirmation_history_size")); ASSERT_FALSE (tree.get_optional_child ("confirmation_history_size"));
config.deserialize_json (upgraded, tree); config.deserialize_json (upgraded, tree);
@ -719,7 +719,7 @@ TEST (node_config, v16_v17_upgrade)
ASSERT_TRUE (!!tree.get_optional_child ("tcp_incoming_connections_max")); ASSERT_TRUE (!!tree.get_optional_child ("tcp_incoming_connections_max"));
ASSERT_TRUE (!!tree.get_optional_child ("vote_generator_delay")); ASSERT_TRUE (!!tree.get_optional_child ("vote_generator_delay"));
ASSERT_TRUE (!!tree.get_optional_child ("diagnostics")); ASSERT_TRUE (!!tree.get_optional_child ("diagnostics"));
ASSERT_TRUE (!!tree.get_optional_child ("use_memory_pool")); ASSERT_TRUE (!!tree.get_optional_child ("use_memory_pools"));
ASSERT_TRUE (!!tree.get_optional_child ("confirmation_history_size")); ASSERT_TRUE (!!tree.get_optional_child ("confirmation_history_size"));
ASSERT_TRUE (upgraded); ASSERT_TRUE (upgraded);
@ -755,7 +755,7 @@ TEST (node_config, v17_values)
nano::jsonconfig diagnostics_l; nano::jsonconfig diagnostics_l;
diagnostics_l.put_child ("txn_tracking", txn_tracking_l); diagnostics_l.put_child ("txn_tracking", txn_tracking_l);
tree.put_child ("diagnostics", diagnostics_l); tree.put_child ("diagnostics", diagnostics_l);
tree.put ("use_memory_pool", true); tree.put ("use_memory_pools", true);
tree.put ("confirmation_history_size", 2048); tree.put ("confirmation_history_size", 2048);
} }
@ -770,7 +770,7 @@ TEST (node_config, v17_values)
ASSERT_EQ (config.diagnostics_config.txn_tracking.min_read_txn_time.count (), 0); ASSERT_EQ (config.diagnostics_config.txn_tracking.min_read_txn_time.count (), 0);
ASSERT_EQ (config.diagnostics_config.txn_tracking.min_write_txn_time.count (), 0); ASSERT_EQ (config.diagnostics_config.txn_tracking.min_write_txn_time.count (), 0);
ASSERT_TRUE (config.diagnostics_config.txn_tracking.ignore_writes_below_block_processor_max_time); ASSERT_TRUE (config.diagnostics_config.txn_tracking.ignore_writes_below_block_processor_max_time);
ASSERT_TRUE (config.use_memory_pool); ASSERT_TRUE (config.use_memory_pools);
ASSERT_EQ (config.confirmation_history_size, 2048); ASSERT_EQ (config.confirmation_history_size, 2048);
// Check config is correct with other values // Check config is correct with other values
@ -788,7 +788,7 @@ TEST (node_config, v17_values)
nano::jsonconfig diagnostics_l; nano::jsonconfig diagnostics_l;
diagnostics_l.replace_child ("txn_tracking", txn_tracking_l); diagnostics_l.replace_child ("txn_tracking", txn_tracking_l);
tree.replace_child ("diagnostics", diagnostics_l); tree.replace_child ("diagnostics", diagnostics_l);
tree.put ("use_memory_pool", false); tree.put ("use_memory_pools", false);
tree.put ("confirmation_history_size", std::numeric_limits<unsigned long long>::max ()); tree.put ("confirmation_history_size", std::numeric_limits<unsigned long long>::max ());
upgraded = false; upgraded = false;
@ -805,7 +805,7 @@ TEST (node_config, v17_values)
ASSERT_EQ (config.tcp_incoming_connections_max, std::numeric_limits<unsigned>::max ()); ASSERT_EQ (config.tcp_incoming_connections_max, std::numeric_limits<unsigned>::max ());
ASSERT_EQ (config.diagnostics_config.txn_tracking.min_write_txn_time.count (), std::numeric_limits<unsigned>::max ()); ASSERT_EQ (config.diagnostics_config.txn_tracking.min_write_txn_time.count (), std::numeric_limits<unsigned>::max ());
ASSERT_FALSE (config.diagnostics_config.txn_tracking.ignore_writes_below_block_processor_max_time); ASSERT_FALSE (config.diagnostics_config.txn_tracking.ignore_writes_below_block_processor_max_time);
ASSERT_FALSE (config.use_memory_pool); ASSERT_FALSE (config.use_memory_pools);
ASSERT_EQ (config.confirmation_history_size, std::numeric_limits<unsigned long long>::max ()); ASSERT_EQ (config.confirmation_history_size, std::numeric_limits<unsigned long long>::max ());
} }

View file

@ -18,10 +18,10 @@ bool blocks_equal (T const & first, nano::block const & second)
} }
template <typename block> template <typename block>
std::shared_ptr<block> deserialize_block (nano::stream & stream_a, bool use_memory_pool) std::shared_ptr<block> deserialize_block (nano::stream & stream_a)
{ {
auto error (false); auto error (false);
auto result = nano::make_shared<block> (use_memory_pool, error, stream_a); auto result = nano::make_shared<block> (error, stream_a);
if (error) if (error)
{ {
result = nullptr; result = nullptr;
@ -1259,46 +1259,46 @@ std::shared_ptr<nano::block> nano::deserialize_block_json (boost::property_tree:
return result; return result;
} }
std::shared_ptr<nano::block> nano::deserialize_block (nano::stream & stream_a, bool use_memory_pool) std::shared_ptr<nano::block> nano::deserialize_block (nano::stream & stream_a)
{ {
nano::block_type type; nano::block_type type;
auto error (try_read (stream_a, type)); auto error (try_read (stream_a, type));
std::shared_ptr<nano::block> result; std::shared_ptr<nano::block> result;
if (!error) if (!error)
{ {
result = nano::deserialize_block (stream_a, type, use_memory_pool); result = nano::deserialize_block (stream_a, type);
} }
return result; return result;
} }
std::shared_ptr<nano::block> nano::deserialize_block (nano::stream & stream_a, nano::block_type type_a, bool use_memory_pool, nano::block_uniquer * uniquer_a) std::shared_ptr<nano::block> nano::deserialize_block (nano::stream & stream_a, nano::block_type type_a, nano::block_uniquer * uniquer_a)
{ {
std::shared_ptr<nano::block> result; std::shared_ptr<nano::block> result;
switch (type_a) switch (type_a)
{ {
case nano::block_type::receive: case nano::block_type::receive:
{ {
result = ::deserialize_block<nano::receive_block> (stream_a, use_memory_pool); result = ::deserialize_block<nano::receive_block> (stream_a);
break; break;
} }
case nano::block_type::send: case nano::block_type::send:
{ {
result = ::deserialize_block<nano::send_block> (stream_a, use_memory_pool); result = ::deserialize_block<nano::send_block> (stream_a);
break; break;
} }
case nano::block_type::open: case nano::block_type::open:
{ {
result = ::deserialize_block<nano::open_block> (stream_a, use_memory_pool); result = ::deserialize_block<nano::open_block> (stream_a);
break; break;
} }
case nano::block_type::change: case nano::block_type::change:
{ {
result = ::deserialize_block<nano::change_block> (stream_a, use_memory_pool); result = ::deserialize_block<nano::change_block> (stream_a);
break; break;
} }
case nano::block_type::state: case nano::block_type::state:
{ {
result = ::deserialize_block<nano::state_block> (stream_a, use_memory_pool); result = ::deserialize_block<nano::state_block> (stream_a);
break; break;
} }
default: default:

View file

@ -356,8 +356,8 @@ private:
std::unique_ptr<seq_con_info_component> collect_seq_con_info (block_uniquer & block_uniquer, const std::string & name); std::unique_ptr<seq_con_info_component> collect_seq_con_info (block_uniquer & block_uniquer, const std::string & name);
std::shared_ptr<nano::block> deserialize_block (nano::stream &, bool use_memory_pool); std::shared_ptr<nano::block> deserialize_block (nano::stream &);
std::shared_ptr<nano::block> deserialize_block (nano::stream &, nano::block_type, bool use_memory_pool, nano::block_uniquer * = nullptr); std::shared_ptr<nano::block> deserialize_block (nano::stream &, nano::block_type, nano::block_uniquer * = nullptr);
std::shared_ptr<nano::block> deserialize_block_json (boost::property_tree::ptree const &, nano::block_uniquer * = nullptr); std::shared_ptr<nano::block> deserialize_block_json (boost::property_tree::ptree const &, nano::block_uniquer * = nullptr);
void serialize_block (nano::stream &, nano::block const &); void serialize_block (nano::stream &, nano::block const &);
void block_memory_pool_purge (); void block_memory_pool_purge ();

View file

@ -1,5 +1,7 @@
#include <nano/lib/memory.hpp> #include <nano/lib/memory.hpp>
bool nano::use_memory_pools{ true };
nano::cleanup_guard::cleanup_guard (std::vector<std::function<void()>> const & cleanup_funcs_a) : nano::cleanup_guard::cleanup_guard (std::vector<std::function<void()>> const & cleanup_funcs_a) :
cleanup_funcs (cleanup_funcs_a) cleanup_funcs (cleanup_funcs_a)
{ {

View file

@ -8,6 +8,8 @@
namespace nano namespace nano
{ {
extern bool use_memory_pools;
/** This makes some heuristic assumptions about the implementation defined shared_ptr internals. /** This makes some heuristic assumptions about the implementation defined shared_ptr internals.
Should only be used in the memory pool purge functions at exit, which doesn't matter much if Should only be used in the memory pool purge functions at exit, which doesn't matter much if
it is incorrect (other than reports from heap memory analysers) */ it is incorrect (other than reports from heap memory analysers) */
@ -42,9 +44,9 @@ private:
}; };
template <typename T, typename... Args> template <typename T, typename... Args>
std::shared_ptr<T> make_shared (bool use_memory_pool, Args &&... args) std::shared_ptr<T> make_shared (Args &&... args)
{ {
if (use_memory_pool) if (nano::use_memory_pools)
{ {
return std::allocate_shared<T> (boost::fast_pool_allocator<T> (), std::forward<Args> (args)...); return std::allocate_shared<T> (boost::fast_pool_allocator<T> (), std::forward<Args> (args)...);
} }

View file

@ -50,6 +50,8 @@ void write_config_files (boost::filesystem::path const & data_path, int index)
json.read_and_update (daemon_config, data_path / "config.json"); json.read_and_update (daemon_config, data_path / "config.json");
auto node_l = json.get_required_child ("node"); auto node_l = json.get_required_child ("node");
node_l.put ("peering_port", peering_port_start + index); node_l.put ("peering_port", peering_port_start + index);
// Alternate use of memory pool
node_l.put ("use_memory_pools", (index % 2) == 0);
auto tcp = node_l.get_required_child ("ipc").get_required_child ("tcp"); auto tcp = node_l.get_required_child ("ipc").get_required_child ("tcp");
tcp.put ("enable", true); tcp.put ("enable", true);
tcp.put ("port", ipc_port_start + index); tcp.put ("port", ipc_port_start + index);

View file

@ -91,6 +91,7 @@ void nano_daemon::daemon::run (boost::filesystem::path const & data_path, nano::
std::unique_ptr<nano::thread_runner> runner; std::unique_ptr<nano::thread_runner> runner;
nano::daemon_config config (data_path); nano::daemon_config config (data_path);
auto error = nano::read_and_update_daemon_config (data_path, config); auto error = nano::read_and_update_daemon_config (data_path, config);
nano::use_memory_pools = config.node.use_memory_pools;
if (!error) if (!error)
{ {

View file

@ -431,7 +431,7 @@ bool nano::active_transactions::add (std::shared_ptr<nano::block> block_a, std::
auto existing (roots.find (root)); auto existing (roots.find (root));
if (existing == roots.end ()) if (existing == roots.end ())
{ {
auto election (nano::make_shared<nano::election> (node.config.use_memory_pool, node, block_a, confirmation_action_a)); auto election (nano::make_shared<nano::election> (node, block_a, confirmation_action_a));
uint64_t difficulty (0); uint64_t difficulty (0);
auto error (nano::work_validate (*block_a, &difficulty)); auto error (nano::work_validate (*block_a, &difficulty));
release_assert (!error); release_assert (!error);

View file

@ -434,7 +434,7 @@ void nano::bulk_pull_client::received_block (boost::system::error_code const & e
if (!ec) if (!ec)
{ {
nano::bufferstream stream (connection->receive_buffer->data (), size_a); nano::bufferstream stream (connection->receive_buffer->data (), size_a);
std::shared_ptr<nano::block> block (nano::deserialize_block (stream, type_a, connection->node->config.use_memory_pool)); std::shared_ptr<nano::block> block (nano::deserialize_block (stream, type_a));
if (block != nullptr && !nano::work_validate (*block)) if (block != nullptr && !nano::work_validate (*block))
{ {
auto hash (block->hash ()); auto hash (block->hash ());
@ -2215,7 +2215,7 @@ void nano::bootstrap_server::receive_confirm_ack_action (boost::system::error_co
{ {
auto error (false); auto error (false);
nano::bufferstream stream (receive_buffer->data (), size_a); nano::bufferstream stream (receive_buffer->data (), size_a);
std::unique_ptr<nano::confirm_ack> request (new nano::confirm_ack (error, stream, header_a, node->config.use_memory_pool)); std::unique_ptr<nano::confirm_ack> request (new nano::confirm_ack (error, stream, header_a));
if (!error) if (!error)
{ {
if (node_id_handshake_finished) if (node_id_handshake_finished)
@ -3123,7 +3123,7 @@ void nano::bulk_push_server::received_block (boost::system::error_code const & e
if (!ec) if (!ec)
{ {
nano::bufferstream stream (receive_buffer->data (), size_a); nano::bufferstream stream (receive_buffer->data (), size_a);
auto block (nano::deserialize_block (stream, type_a, connection->node->config.use_memory_pool)); auto block (nano::deserialize_block (stream, type_a));
if (block != nullptr && !nano::work_validate (*block)) if (block != nullptr && !nano::work_validate (*block))
{ {
if (!connection->node->block_processor.full ()) if (!connection->node->block_processor.full ())

View file

@ -520,10 +520,10 @@ void nano::publish::serialize (nano::stream & stream_a) const
block->serialize (stream_a); block->serialize (stream_a);
} }
bool nano::publish::deserialize (nano::stream & stream_a, bool use_memory_pool, nano::block_uniquer * uniquer_a) bool nano::publish::deserialize (nano::stream & stream_a, nano::block_uniquer * uniquer_a)
{ {
assert (header.type == nano::message_type::publish); assert (header.type == nano::message_type::publish);
block = nano::deserialize_block (stream_a, header.block_type (), use_memory_pool, uniquer_a); block = nano::deserialize_block (stream_a, header.block_type (), uniquer_a);
auto result (block == nullptr); auto result (block == nullptr);
return result; return result;
} }
@ -599,7 +599,7 @@ void nano::confirm_req::serialize (nano::stream & stream_a) const
} }
} }
bool nano::confirm_req::deserialize (nano::stream & stream_a, bool use_memory_pool, nano::block_uniquer * uniquer_a) bool nano::confirm_req::deserialize (nano::stream & stream_a, nano::block_uniquer * uniquer_a)
{ {
bool result (false); bool result (false);
assert (header.type == nano::message_type::confirm_req); assert (header.type == nano::message_type::confirm_req);
@ -627,7 +627,7 @@ bool nano::confirm_req::deserialize (nano::stream & stream_a, bool use_memory_po
} }
else else
{ {
block = nano::deserialize_block (stream_a, header.block_type (), true, uniquer_a); block = nano::deserialize_block (stream_a, header.block_type (), uniquer_a);
result = block == nullptr; result = block == nullptr;
} }
} }
@ -680,9 +680,9 @@ size_t nano::confirm_req::size (nano::block_type type_a, size_t count)
return result; return result;
} }
nano::confirm_ack::confirm_ack (bool & error_a, nano::stream & stream_a, nano::message_header const & header_a, bool use_memory_pool, nano::vote_uniquer * uniquer_a) : nano::confirm_ack::confirm_ack (bool & error_a, nano::stream & stream_a, nano::message_header const & header_a, nano::vote_uniquer * uniquer_a) :
message (header_a), message (header_a),
vote (nano::make_shared<nano::vote> (use_memory_pool, error_a, stream_a, header.block_type (), use_memory_pool)) vote (nano::make_shared<nano::vote> (error_a, stream_a, header.block_type ()))
{ {
if (!error_a && uniquer_a) if (!error_a && uniquer_a)
{ {

View file

@ -298,7 +298,7 @@ public:
explicit publish (std::shared_ptr<nano::block>); explicit publish (std::shared_ptr<nano::block>);
void visit (nano::message_visitor &) const override; void visit (nano::message_visitor &) const override;
void serialize (nano::stream &) const override; void serialize (nano::stream &) const override;
bool deserialize (nano::stream &, bool use_memory_pool, nano::block_uniquer * = nullptr); bool deserialize (nano::stream &, nano::block_uniquer * = nullptr);
bool operator== (nano::publish const &) const; bool operator== (nano::publish const &) const;
std::shared_ptr<nano::block> block; std::shared_ptr<nano::block> block;
}; };
@ -310,7 +310,7 @@ public:
confirm_req (std::vector<std::pair<nano::block_hash, nano::block_hash>> const &); confirm_req (std::vector<std::pair<nano::block_hash, nano::block_hash>> const &);
confirm_req (nano::block_hash const &, nano::block_hash const &); confirm_req (nano::block_hash const &, nano::block_hash const &);
void serialize (nano::stream &) const override; void serialize (nano::stream &) const override;
bool deserialize (nano::stream &, bool use_memory_pool, nano::block_uniquer * = nullptr); bool deserialize (nano::stream &, nano::block_uniquer * = nullptr);
void visit (nano::message_visitor &) const override; void visit (nano::message_visitor &) const override;
bool operator== (nano::confirm_req const &) const; bool operator== (nano::confirm_req const &) const;
std::shared_ptr<nano::block> block; std::shared_ptr<nano::block> block;
@ -321,7 +321,7 @@ public:
class confirm_ack final : public message class confirm_ack final : public message
{ {
public: public:
confirm_ack (bool &, nano::stream &, nano::message_header const &, bool use_memory_pool, nano::vote_uniquer * = nullptr); confirm_ack (bool &, nano::stream &, nano::message_header const &, nano::vote_uniquer * = nullptr);
explicit confirm_ack (std::shared_ptr<nano::vote>); explicit confirm_ack (std::shared_ptr<nano::vote>);
void serialize (nano::stream &) const override; void serialize (nano::stream &) const override;
void visit (nano::message_visitor &) const override; void visit (nano::message_visitor &) const override;

View file

@ -147,10 +147,9 @@ void * nano::write_mdb_txn::get_handle () const
return handle; return handle;
} }
nano::mdb_val::mdb_val (bool use_memory_pool_a, nano::epoch epoch_a) : nano::mdb_val::mdb_val (nano::epoch epoch_a) :
value ({ 0, nullptr }), value ({ 0, nullptr }),
epoch (epoch_a), epoch (epoch_a)
use_memory_pool (use_memory_pool_a)
{ {
} }
@ -197,8 +196,8 @@ mdb_val (sizeof (val_a), const_cast<nano::pending_key *> (&val_a))
static_assert (std::is_standard_layout<nano::pending_key>::value, "Standard layout is required"); static_assert (std::is_standard_layout<nano::pending_key>::value, "Standard layout is required");
} }
nano::mdb_val::mdb_val (nano::unchecked_info const & val_a, bool use_memory_pool_a) : nano::mdb_val::mdb_val (nano::unchecked_info const & val_a) :
buffer (std::make_shared<std::vector<uint8_t>> ()), use_memory_pool (use_memory_pool_a) buffer (std::make_shared<std::vector<uint8_t>> ())
{ {
{ {
nano::vectorstream stream (*buffer); nano::vectorstream stream (*buffer);
@ -219,8 +218,8 @@ mdb_val (sizeof (val_a), const_cast<nano::endpoint_key *> (&val_a))
static_assert (std::is_standard_layout<nano::endpoint_key>::value, "Standard layout is required"); static_assert (std::is_standard_layout<nano::endpoint_key>::value, "Standard layout is required");
} }
nano::mdb_val::mdb_val (std::shared_ptr<nano::block> const & val_a, bool use_memory_pool_a) : nano::mdb_val::mdb_val (std::shared_ptr<nano::block> const & val_a) :
buffer (std::make_shared<std::vector<uint8_t>> ()), use_memory_pool (use_memory_pool_a) buffer (std::make_shared<std::vector<uint8_t>> ())
{ {
{ {
nano::vectorstream stream (*buffer); nano::vectorstream stream (*buffer);
@ -298,7 +297,7 @@ nano::mdb_val::operator nano::unchecked_info () const
{ {
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (value.mv_data), value.mv_size); nano::bufferstream stream (reinterpret_cast<uint8_t const *> (value.mv_data), value.mv_size);
nano::unchecked_info result; nano::unchecked_info result;
bool error (result.deserialize (stream, use_memory_pool)); bool error (result.deserialize (stream));
assert (!error); assert (!error);
return result; return result;
} }
@ -343,7 +342,7 @@ nano::mdb_val::operator nano::no_value () const
nano::mdb_val::operator std::shared_ptr<nano::block> () const nano::mdb_val::operator std::shared_ptr<nano::block> () const
{ {
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (value.mv_data), value.mv_size); nano::bufferstream stream (reinterpret_cast<uint8_t const *> (value.mv_data), value.mv_size);
std::shared_ptr<nano::block> result (nano::deserialize_block (stream, use_memory_pool)); std::shared_ptr<nano::block> result (nano::deserialize_block (stream));
return result; return result;
} }
@ -396,7 +395,7 @@ nano::mdb_val::operator std::shared_ptr<nano::vote> () const
{ {
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (value.mv_data), value.mv_size); nano::bufferstream stream (reinterpret_cast<uint8_t const *> (value.mv_data), value.mv_size);
auto error (false); auto error (false);
auto result (nano::make_shared<nano::vote> (use_memory_pool, error, stream, use_memory_pool)); auto result (nano::make_shared<nano::vote> (error, stream));
assert (!error); assert (!error);
return result; return result;
} }
@ -602,8 +601,8 @@ bool nano::mdb_iterator<T, U>::operator== (nano::store_iterator_impl<T, U> const
template <typename T, typename U> template <typename T, typename U>
void nano::mdb_iterator<T, U>::clear () void nano::mdb_iterator<T, U>::clear ()
{ {
current.first = nano::mdb_val (current.first.use_memory_pool, current.first.epoch); current.first = nano::mdb_val (current.first.epoch);
current.second = nano::mdb_val (current.second.use_memory_pool, current.second.epoch); current.second = nano::mdb_val (current.second.epoch);
assert (is_end_sentinal ()); assert (is_end_sentinal ());
} }
@ -823,12 +822,11 @@ nano::store_iterator<nano::account, std::shared_ptr<nano::vote>> nano::mdb_store
return nano::store_iterator<nano::account, std::shared_ptr<nano::vote>> (nullptr); return nano::store_iterator<nano::account, std::shared_ptr<nano::vote>> (nullptr);
} }
nano::mdb_store::mdb_store (bool & error_a, nano::logger_mt & logger_a, boost::filesystem::path const & path_a, bool use_memory_pool_a, nano::txn_tracking_config const & txn_tracking_config_a, std::chrono::milliseconds block_processor_batch_max_time_a, int lmdb_max_dbs, bool drop_unchecked, size_t const batch_size) : nano::mdb_store::mdb_store (bool & error_a, nano::logger_mt & logger_a, boost::filesystem::path const & path_a, nano::txn_tracking_config const & txn_tracking_config_a, std::chrono::milliseconds block_processor_batch_max_time_a, int lmdb_max_dbs, bool drop_unchecked, size_t const batch_size) :
logger (logger_a), logger (logger_a),
env (error_a, path_a, lmdb_max_dbs), env (error_a, path_a, lmdb_max_dbs),
mdb_txn_tracker (logger_a, txn_tracking_config_a, block_processor_batch_max_time_a), mdb_txn_tracker (logger_a, txn_tracking_config_a, block_processor_batch_max_time_a),
txn_tracking_enabled (txn_tracking_config_a.enable), txn_tracking_enabled (txn_tracking_config_a.enable)
use_memory_pool (use_memory_pool_a)
{ {
if (!error_a) if (!error_a)
{ {
@ -964,7 +962,7 @@ void nano::mdb_store::version_put (nano::transaction const & transaction_a, int
int nano::mdb_store::version_get (nano::transaction const & transaction_a) const int nano::mdb_store::version_get (nano::transaction const & transaction_a) const
{ {
nano::uint256_union version_key (1); nano::uint256_union version_key (1);
nano::mdb_val data (use_memory_pool); nano::mdb_val data;
auto error (mdb_get (env.tx (transaction_a), meta, nano::mdb_val (version_key), data)); auto error (mdb_get (env.tx (transaction_a), meta, nano::mdb_val (version_key), data));
int result (1); int result (1);
if (error != MDB_NOTFOUND) if (error != MDB_NOTFOUND)
@ -1474,7 +1472,7 @@ void nano::mdb_store::block_put (nano::transaction const & transaction_a, nano::
boost::optional<MDB_val> nano::mdb_store::block_raw_get_by_type (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const boost::optional<MDB_val> nano::mdb_store::block_raw_get_by_type (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const
{ {
nano::mdb_val value (use_memory_pool); nano::mdb_val value;
auto status (MDB_NOTFOUND); auto status (MDB_NOTFOUND);
switch (type_a) switch (type_a)
{ {
@ -1526,7 +1524,7 @@ boost::optional<MDB_val> nano::mdb_store::block_raw_get_by_type (nano::transacti
MDB_val nano::mdb_store::block_raw_get (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const MDB_val nano::mdb_store::block_raw_get (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_type & type_a) const
{ {
nano::mdb_val result (use_memory_pool); nano::mdb_val result;
// Table lookups are ordered by match probability // Table lookups are ordered by match probability
nano::block_type block_types[]{ nano::block_type::state, nano::block_type::send, nano::block_type::receive, nano::block_type::open, nano::block_type::change }; nano::block_type block_types[]{ nano::block_type::state, nano::block_type::send, nano::block_type::receive, nano::block_type::open, nano::block_type::change };
for (auto current_type : block_types) for (auto current_type : block_types)
@ -1681,7 +1679,7 @@ std::shared_ptr<nano::block> nano::mdb_store::block_get (nano::transaction const
if (value.mv_size != 0) if (value.mv_size != 0)
{ {
nano::bufferstream stream (reinterpret_cast<uint8_t const *> (value.mv_data), value.mv_size); nano::bufferstream stream (reinterpret_cast<uint8_t const *> (value.mv_data), value.mv_size);
result = nano::deserialize_block (stream, type, use_memory_pool); result = nano::deserialize_block (stream, type);
assert (result != nullptr); assert (result != nullptr);
if (sideband_a) if (sideband_a)
{ {
@ -2161,7 +2159,7 @@ nano::store_iterator<nano::pending_key, nano::pending_info> nano::mdb_store::pen
bool nano::mdb_store::block_info_get (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_info & block_info_a) const bool nano::mdb_store::block_info_get (nano::transaction const & transaction_a, nano::block_hash const & hash_a, nano::block_info & block_info_a) const
{ {
assert (!full_sideband (transaction_a)); assert (!full_sideband (transaction_a));
nano::mdb_val value (use_memory_pool); nano::mdb_val value;
auto status (mdb_get (env.tx (transaction_a), blocks_info, nano::mdb_val (hash_a), value)); auto status (mdb_get (env.tx (transaction_a), blocks_info, nano::mdb_val (hash_a), value));
release_assert (status == 0 || status == MDB_NOTFOUND); release_assert (status == 0 || status == MDB_NOTFOUND);
bool result (true); bool result (true);
@ -2180,7 +2178,7 @@ bool nano::mdb_store::block_info_get (nano::transaction const & transaction_a, n
nano::uint128_t nano::mdb_store::representation_get (nano::transaction const & transaction_a, nano::account const & account_a) nano::uint128_t nano::mdb_store::representation_get (nano::transaction const & transaction_a, nano::account const & account_a)
{ {
nano::mdb_val value (use_memory_pool); nano::mdb_val value;
auto status (mdb_get (env.tx (transaction_a), representation, nano::mdb_val (account_a), value)); auto status (mdb_get (env.tx (transaction_a), representation, nano::mdb_val (account_a), value));
release_assert (status == 0 || status == MDB_NOTFOUND); release_assert (status == 0 || status == MDB_NOTFOUND);
nano::uint128_t result = 0; nano::uint128_t result = 0;
@ -2210,7 +2208,7 @@ void nano::mdb_store::unchecked_clear (nano::transaction const & transaction_a)
void nano::mdb_store::unchecked_put (nano::transaction const & transaction_a, nano::unchecked_key const & key_a, nano::unchecked_info const & info_a) void nano::mdb_store::unchecked_put (nano::transaction const & transaction_a, nano::unchecked_key const & key_a, nano::unchecked_info const & info_a)
{ {
auto status (mdb_put (env.tx (transaction_a), unchecked, nano::mdb_val (key_a), nano::mdb_val (info_a, use_memory_pool), 0)); auto status (mdb_put (env.tx (transaction_a), unchecked, nano::mdb_val (key_a), nano::mdb_val (info_a), 0));
release_assert (status == 0); release_assert (status == 0);
} }
@ -2223,7 +2221,7 @@ void nano::mdb_store::unchecked_put (nano::transaction const & transaction_a, na
std::shared_ptr<nano::vote> nano::mdb_store::vote_get (nano::transaction const & transaction_a, nano::account const & account_a) std::shared_ptr<nano::vote> nano::mdb_store::vote_get (nano::transaction const & transaction_a, nano::account const & account_a)
{ {
nano::mdb_val value (use_memory_pool); nano::mdb_val value;
auto status (mdb_get (env.tx (transaction_a), vote, nano::mdb_val (account_a), value)); auto status (mdb_get (env.tx (transaction_a), vote, nano::mdb_val (account_a), value));
release_assert (status == 0 || status == MDB_NOTFOUND); release_assert (status == 0 || status == MDB_NOTFOUND);
if (status == 0) if (status == 0)

View file

@ -76,20 +76,20 @@ public:
class mdb_val class mdb_val
{ {
public: public:
mdb_val (bool use_memory_pool = true, nano::epoch = nano::epoch::unspecified); mdb_val (nano::epoch = nano::epoch::unspecified);
mdb_val (nano::account_info const &); mdb_val (nano::account_info const &);
mdb_val (nano::account_info_v13 const &); mdb_val (nano::account_info_v13 const &);
mdb_val (nano::block_info const &); mdb_val (nano::block_info const &);
mdb_val (MDB_val const &, nano::epoch = nano::epoch::unspecified); mdb_val (MDB_val const &, nano::epoch = nano::epoch::unspecified);
mdb_val (nano::pending_info const &); mdb_val (nano::pending_info const &);
mdb_val (nano::pending_key const &); mdb_val (nano::pending_key const &);
mdb_val (nano::unchecked_info const &, bool); mdb_val (nano::unchecked_info const &);
mdb_val (size_t, void *); mdb_val (size_t, void *);
mdb_val (nano::uint128_union const &); mdb_val (nano::uint128_union const &);
mdb_val (nano::uint256_union const &); mdb_val (nano::uint256_union const &);
mdb_val (nano::endpoint_key const &); mdb_val (nano::endpoint_key const &);
mdb_val (std::shared_ptr<nano::block> const &, bool); mdb_val (std::shared_ptr<nano::block> const &);
mdb_val (std::shared_ptr<nano::vote> const &, bool); mdb_val (std::shared_ptr<nano::vote> const &);
mdb_val (uint64_t); mdb_val (uint64_t);
void * data () const; void * data () const;
size_t size () const; size_t size () const;
@ -117,7 +117,6 @@ public:
MDB_val value; MDB_val value;
std::shared_ptr<std::vector<uint8_t>> buffer; std::shared_ptr<std::vector<uint8_t>> buffer;
nano::epoch epoch{ nano::epoch::unspecified }; nano::epoch epoch{ nano::epoch::unspecified };
bool use_memory_pool{ true };
}; };
class block_store; class block_store;
@ -183,7 +182,7 @@ class mdb_store : public block_store
friend class nano::block_predecessor_set; friend class nano::block_predecessor_set;
public: public:
mdb_store (bool &, nano::logger_mt &, boost::filesystem::path const &, bool use_memory_pool_a = true, nano::txn_tracking_config const & txn_tracking_config_a = nano::txn_tracking_config{}, std::chrono::milliseconds block_processor_batch_max_time_a = std::chrono::milliseconds (5000), int lmdb_max_dbs = 128, bool drop_unchecked = false, size_t batch_size = 512); mdb_store (bool &, nano::logger_mt &, boost::filesystem::path const &, nano::txn_tracking_config const & txn_tracking_config_a = nano::txn_tracking_config{}, std::chrono::milliseconds block_processor_batch_max_time_a = std::chrono::milliseconds (5000), int lmdb_max_dbs = 128, bool drop_unchecked = false, size_t batch_size = 512);
nano::write_transaction tx_begin_write () override; nano::write_transaction tx_begin_write () override;
nano::read_transaction tx_begin_read () override; nano::read_transaction tx_begin_read () override;
@ -442,7 +441,6 @@ private:
nano::mdb_txn_tracker mdb_txn_tracker; nano::mdb_txn_tracker mdb_txn_tracker;
nano::mdb_txn_callbacks create_txn_callbacks (); nano::mdb_txn_callbacks create_txn_callbacks ();
bool txn_tracking_enabled; bool txn_tracking_enabled;
bool use_memory_pool;
static int constexpr version{ 14 }; static int constexpr version{ 14 };
}; };
class wallet_value class wallet_value

View file

@ -201,7 +201,7 @@ flags (flags_a),
alarm (alarm_a), alarm (alarm_a),
work (work_a), work (work_a),
logger (config_a.logging.min_time_between_log_output), logger (config_a.logging.min_time_between_log_output),
store_impl (std::make_unique<nano::mdb_store> (init_a.block_store_init, logger, application_path_a / "data.ldb", config_a.use_memory_pool, config_a.diagnostics_config.txn_tracking, config_a.block_processor_batch_max_time, config_a.lmdb_max_dbs, !flags.disable_unchecked_drop, flags.sideband_batch_size)), store_impl (std::make_unique<nano::mdb_store> (init_a.block_store_init, logger, application_path_a / "data.ldb", config_a.diagnostics_config.txn_tracking, config_a.block_processor_batch_max_time, config_a.lmdb_max_dbs, !flags.disable_unchecked_drop, flags.sideband_batch_size)),
store (*store_impl), store (*store_impl),
wallets_store_impl (std::make_unique<nano::mdb_wallets_store> (init_a.wallets_store_init, application_path_a / "wallets.ldb", config_a.lmdb_max_dbs)), wallets_store_impl (std::make_unique<nano::mdb_wallets_store> (init_a.wallets_store_init, application_path_a / "wallets.ldb", config_a.lmdb_max_dbs)),
wallets_store (*wallets_store_impl), wallets_store (*wallets_store_impl),

View file

@ -120,7 +120,7 @@ nano::error nano::node_config::serialize_json (nano::jsonconfig & json) const
json.put ("external_address", external_address.to_string ()); json.put ("external_address", external_address.to_string ());
json.put ("external_port", external_port); json.put ("external_port", external_port);
json.put ("tcp_incoming_connections_max", tcp_incoming_connections_max); json.put ("tcp_incoming_connections_max", tcp_incoming_connections_max);
json.put ("use_memory_pool", use_memory_pool); json.put ("use_memory_pools", use_memory_pools);
nano::jsonconfig websocket_l; nano::jsonconfig websocket_l;
websocket_config.serialize_json (websocket_l); websocket_config.serialize_json (websocket_l);
json.put_child ("websocket", websocket_l); json.put_child ("websocket", websocket_l);
@ -247,7 +247,7 @@ bool nano::node_config::upgrade_json (unsigned version_a, nano::jsonconfig & jso
json.put ("external_port", external_port); json.put ("external_port", external_port);
json.put ("tcp_incoming_connections_max", tcp_incoming_connections_max); json.put ("tcp_incoming_connections_max", tcp_incoming_connections_max);
json.put ("vote_generator_delay", vote_generator_delay.count ()); json.put ("vote_generator_delay", vote_generator_delay.count ());
json.put ("use_memory_pool", use_memory_pool); json.put ("use_memory_pools", use_memory_pools);
json.put ("confirmation_history_size", confirmation_history_size); json.put ("confirmation_history_size", confirmation_history_size);
} }
case 17: case 17:
@ -395,7 +395,7 @@ nano::error nano::node_config::deserialize_json (bool & upgraded_a, nano::jsonco
auto pow_sleep_interval_l (pow_sleep_interval.count ()); auto pow_sleep_interval_l (pow_sleep_interval.count ());
json.get (pow_sleep_interval_key, pow_sleep_interval_l); json.get (pow_sleep_interval_key, pow_sleep_interval_l);
pow_sleep_interval = std::chrono::nanoseconds (pow_sleep_interval_l); pow_sleep_interval = std::chrono::nanoseconds (pow_sleep_interval_l);
json.get<bool> ("use_memory_pool", use_memory_pool); json.get<bool> ("use_memory_pools", use_memory_pools);
json.get<size_t> ("confirmation_history_size", confirmation_history_size); json.get<size_t> ("confirmation_history_size", confirmation_history_size);
// Validate ranges // Validate ranges

View file

@ -69,7 +69,7 @@ public:
std::chrono::nanoseconds pow_sleep_interval{ 0 }; std::chrono::nanoseconds pow_sleep_interval{ 0 };
/** Default maximum incoming TCP connections, including realtime network & bootstrap */ /** Default maximum incoming TCP connections, including realtime network & bootstrap */
unsigned tcp_incoming_connections_max{ 1024 }; unsigned tcp_incoming_connections_max{ 1024 };
bool use_memory_pool{ true }; bool use_memory_pools{ true };
static std::chrono::seconds constexpr keepalive_period = std::chrono::seconds (60); static std::chrono::seconds constexpr keepalive_period = std::chrono::seconds (60);
static std::chrono::seconds constexpr keepalive_cutoff = keepalive_period * 5; static std::chrono::seconds constexpr keepalive_cutoff = keepalive_period * 5;
static std::chrono::minutes constexpr wallet_backup_interval = std::chrono::minutes (5); static std::chrono::minutes constexpr wallet_backup_interval = std::chrono::minutes (5);

View file

@ -1,3 +1,4 @@
#include <nano/lib/memory.hpp>
#include <nano/node/common.hpp> #include <nano/node/common.hpp>
#include <gtest/gtest.h> #include <gtest/gtest.h>
@ -10,6 +11,7 @@ void force_nano_test_network ();
int main (int argc, char ** argv) int main (int argc, char ** argv)
{ {
nano::force_nano_test_network (); nano::force_nano_test_network ();
nano::use_memory_pools = false;
nano::node_singleton_memory_pool_purge_guard cleanup_guard; nano::node_singleton_memory_pool_purge_guard cleanup_guard;
testing::InitGoogleTest (&argc, argv); testing::InitGoogleTest (&argc, argv);
auto res = RUN_ALL_TESTS (); auto res = RUN_ALL_TESTS ();

View file

@ -311,9 +311,9 @@ void nano::unchecked_info::serialize (nano::stream & stream_a) const
nano::write (stream_a, verified); nano::write (stream_a, verified);
} }
bool nano::unchecked_info::deserialize (nano::stream & stream_a, bool use_memory_pool) bool nano::unchecked_info::deserialize (nano::stream & stream_a)
{ {
block = nano::deserialize_block (stream_a, use_memory_pool); block = nano::deserialize_block (stream_a);
bool error (block == nullptr); bool error (block == nullptr);
if (!error) if (!error)
{ {
@ -432,12 +432,12 @@ signature (other_a.signature)
{ {
} }
nano::vote::vote (bool & error_a, nano::stream & stream_a, bool use_memory_pool, nano::block_uniquer * uniquer_a) nano::vote::vote (bool & error_a, nano::stream & stream_a, nano::block_uniquer * uniquer_a)
{ {
error_a = deserialize (stream_a, use_memory_pool, uniquer_a); error_a = deserialize (stream_a, uniquer_a);
} }
nano::vote::vote (bool & error_a, nano::stream & stream_a, nano::block_type type_a, bool use_memory_pool, nano::block_uniquer * uniquer_a) nano::vote::vote (bool & error_a, nano::stream & stream_a, nano::block_type type_a, nano::block_uniquer * uniquer_a)
{ {
try try
{ {
@ -455,7 +455,7 @@ nano::vote::vote (bool & error_a, nano::stream & stream_a, nano::block_type type
} }
else else
{ {
std::shared_ptr<nano::block> block (nano::deserialize_block (stream_a, type_a, use_memory_pool, uniquer_a)); std::shared_ptr<nano::block> block (nano::deserialize_block (stream_a, type_a, uniquer_a));
if (block == nullptr) if (block == nullptr)
{ {
throw std::runtime_error ("Block is null"); throw std::runtime_error ("Block is null");
@ -588,7 +588,7 @@ void nano::vote::serialize (nano::stream & stream_a) const
} }
} }
bool nano::vote::deserialize (nano::stream & stream_a, bool use_memory_pool, nano::block_uniquer * uniquer_a) bool nano::vote::deserialize (nano::stream & stream_a, nano::block_uniquer * uniquer_a)
{ {
auto error (false); auto error (false);
try try
@ -615,7 +615,7 @@ bool nano::vote::deserialize (nano::stream & stream_a, bool use_memory_pool, nan
} }
else else
{ {
std::shared_ptr<nano::block> block (nano::deserialize_block (stream_a, type, use_memory_pool, uniquer_a)); std::shared_ptr<nano::block> block (nano::deserialize_block (stream_a, type, uniquer_a));
if (block == nullptr) if (block == nullptr)
{ {
throw std::runtime_error ("Block is empty"); throw std::runtime_error ("Block is empty");

View file

@ -182,7 +182,7 @@ public:
unchecked_info () = default; unchecked_info () = default;
unchecked_info (std::shared_ptr<nano::block>, nano::account const &, uint64_t, nano::signature_verification = nano::signature_verification::unknown); unchecked_info (std::shared_ptr<nano::block>, nano::account const &, uint64_t, nano::signature_verification = nano::signature_verification::unknown);
void serialize (nano::stream &) const; void serialize (nano::stream &) const;
bool deserialize (nano::stream &, bool use_memory_pool); bool deserialize (nano::stream &);
std::shared_ptr<nano::block> block; std::shared_ptr<nano::block> block;
nano::account account{ 0 }; nano::account account{ 0 };
/** Seconds since posix epoch */ /** Seconds since posix epoch */
@ -221,8 +221,8 @@ class vote final
public: public:
vote () = default; vote () = default;
vote (nano::vote const &); vote (nano::vote const &);
vote (bool &, nano::stream &, bool use_memory_pool, nano::block_uniquer * = nullptr); vote (bool &, nano::stream &, nano::block_uniquer * = nullptr);
vote (bool &, nano::stream &, nano::block_type, bool use_memory_pool, nano::block_uniquer * = nullptr); vote (bool &, nano::stream &, nano::block_type, nano::block_uniquer * = nullptr);
vote (nano::account const &, nano::raw_key const &, uint64_t, std::shared_ptr<nano::block>); vote (nano::account const &, nano::raw_key const &, uint64_t, std::shared_ptr<nano::block>);
vote (nano::account const &, nano::raw_key const &, uint64_t, std::vector<nano::block_hash> const &); vote (nano::account const &, nano::raw_key const &, uint64_t, std::vector<nano::block_hash> const &);
std::string hashes_string () const; std::string hashes_string () const;
@ -233,7 +233,7 @@ public:
void serialize (nano::stream &, nano::block_type) const; void serialize (nano::stream &, nano::block_type) const;
void serialize (nano::stream &) const; void serialize (nano::stream &) const;
void serialize_json (boost::property_tree::ptree & tree) const; void serialize_json (boost::property_tree::ptree & tree) const;
bool deserialize (nano::stream &, bool use_memory_pool, nano::block_uniquer * = nullptr); bool deserialize (nano::stream &, nano::block_uniquer * = nullptr);
bool validate () const; bool validate () const;
boost::transform_iterator<nano::iterate_vote_blocks_as_hash, nano::vote_blocks_vec_iter> begin () const; boost::transform_iterator<nano::iterate_vote_blocks_as_hash, nano::vote_blocks_vec_iter> begin () const;
boost::transform_iterator<nano::iterate_vote_blocks_as_hash, nano::vote_blocks_vec_iter> end () const; boost::transform_iterator<nano::iterate_vote_blocks_as_hash, nano::vote_blocks_vec_iter> end () const;