diff --git a/include/bitcoin/node/block_arena.hpp b/include/bitcoin/node/block_arena.hpp index d0ad096a..de928447 100644 --- a/include/bitcoin/node/block_arena.hpp +++ b/include/bitcoin/node/block_arena.hpp @@ -26,7 +26,7 @@ namespace libbitcoin { namespace node { -/// Thread UNSAFE linked-linear memory arena. +/// Thread UNSAFE detachable linked-linear memory arena. class BCN_API block_arena final : public arena { diff --git a/include/bitcoin/node/full_node.hpp b/include/bitcoin/node/full_node.hpp index aa5b6eb8..c0b4e6bf 100644 --- a/include/bitcoin/node/full_node.hpp +++ b/include/bitcoin/node/full_node.hpp @@ -30,10 +30,17 @@ namespace libbitcoin { namespace node { /// Thread safe. +/// WARNING: when full node is using block_memory controller, all shared block +/// components invalidate when the block destructs. Lifetime of the block is +/// assured for the extent of all methods below, however if a sub-object is +/// retained by shared_ptr, beyond method completion, a copy of the block +/// shared_ptr must also be be retained. Taking a block or sub-object copy is +/// insufficient, as copies are shallow (copy internal shared_ptr objects). class BCN_API full_node : public network::p2p { public: + using memory_controller = block_memory; using store = node::store; using query = node::query; typedef std::shared_ptr ptr; @@ -166,10 +173,10 @@ class BCN_API full_node // These are thread safe. const configuration& config_; + memory_controller memory_; query& query_; // These are protected by strand. - block_memory memory_; chaser_block chaser_block_; chaser_header chaser_header_; chaser_check chaser_check_; diff --git a/include/bitcoin/node/sessions/attach.hpp b/include/bitcoin/node/sessions/attach.hpp index f618c343..5e8177e2 100644 --- a/include/bitcoin/node/sessions/attach.hpp +++ b/include/bitcoin/node/sessions/attach.hpp @@ -106,7 +106,6 @@ class attach network::channel::ptr create_channel(const network::socket::ptr& socket, bool quiet) NOEXCEPT override { - // This memory arena is NOT thread safe. return std::make_shared(session::get_memory(), network::session::log, socket, network::session::settings(), network::session::create_key(), quiet); diff --git a/src/full_node.cpp b/src/full_node.cpp index 6a9d1f5d..653678bd 100644 --- a/src/full_node.cpp +++ b/src/full_node.cpp @@ -40,9 +40,8 @@ full_node::full_node(query& query, const configuration& configuration, const logger& log) NOEXCEPT : p2p(configuration.network, log), config_(configuration), + memory_(config_.node.allocation_multiple, config_.network.threads), query_(query), - memory_(configuration.node.allocation_multiple, - configuration.network.threads), chaser_block_(*this), chaser_header_(*this), chaser_check_(*this),