Skip to content

Commit

Permalink
Merge pull request #677 from evoskuil/master
Browse files Browse the repository at this point in the history
Enable block deserialization disable via config.
  • Loading branch information
evoskuil authored Aug 21, 2024
2 parents 924dd6f + 8ed1a01 commit 926ae40
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 25 deletions.
8 changes: 3 additions & 5 deletions include/bitcoin/node/block_memory.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,18 @@ class BCN_API block_memory final
DELETE_COPY_MOVE_DESTRUCT(block_memory);

/// Per thread multiple of wire size for each linear allocation chunk.
/// Returns default_arena if multiple is zero or threads exceeded.
block_memory(size_t multiple, size_t threads) NOEXCEPT;

/// Each thread obtains an arena.
arena* get_arena() NOEXCEPT override;

protected:
block_arena* get_block_arena() const THROWS;

private:
// This is thread safe.
mutable std::atomic_size_t count_;
std::atomic_size_t count_{};

// This is protected by constructor init and thread_local indexation.
mutable std::vector<block_arena> arenas_;
std::vector<block_arena> arenas_{};
};

} // namespace node
Expand Down
27 changes: 8 additions & 19 deletions src/block_memory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,30 +28,19 @@ namespace node {
BC_PUSH_WARNING(NO_THROW_IN_NOEXCEPT)

block_memory::block_memory(size_t multiple, size_t threads) NOEXCEPT
: count_{}, arenas_{}
{
arenas_.reserve(threads);
for (auto index = zero; index < threads; ++index)
arenas_.emplace_back(multiple);
if (is_nonzero(multiple))
{
arenas_.reserve(threads);
for (auto index = zero; index < threads; ++index)
arenas_.emplace_back(multiple);
}
}

arena* block_memory::get_arena() NOEXCEPT
{
return get_block_arena();
}

// protected
block_arena* block_memory::get_block_arena() const THROWS
{
static thread_local auto index = count_.fetch_add(one,
std::memory_order_relaxed);

// More threads are requesting an arena than specified at construct.
////BC_ASSERT(index < arenas_.size());
if (index >= arenas_.size())
throw allocation_exception{};

return &arenas_.at(index);
thread_local auto thread = count_.fetch_add(one, std::memory_order_relaxed);
return thread < arenas_.size() ? &arenas_.at(thread) : default_arena::get();
}

BC_POP_WARNING()
Expand Down
2 changes: 1 addition & 1 deletion src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ options_metadata parser::load_settings() THROWS
(
"node.allocation_multiple",
value<uint16_t>(&configured.node.allocation_multiple),
"Per thread block deserialization buffer multiple of wire size, defaults to 20."
"Block deserialization buffer multiple of wire size, defaults to 20 (0 disables)."
)
(
"node.maximum_height",
Expand Down

0 comments on commit 926ae40

Please sign in to comment.