Skip to content

Commit

Permalink
Manage block memory allocation wrapping in linear allocator.
Browse files Browse the repository at this point in the history
  • Loading branch information
evoskuil committed Aug 5, 2024
1 parent f314690 commit b3a8d36
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/messages/block.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ namespace network {
namespace messages {

using namespace system;

// Measured through block 550,000 - assumes consistent platform sizing.
constexpr auto maximal_block = 11'904'912_size;

const std::string block::command = "block";
const identifier block::id = identifier::block;
Expand All @@ -47,17 +50,34 @@ typename block::cptr block::deserialize(uint32_t version,
}

// static
// TODO: Move cached hashes to arena.
typename block::cptr block::deserialize(memory& memory, uint32_t version,
const system::data_chunk& data, bool witness) NOEXCEPT
{
const auto arena = memory.get_arena();
if (arena == nullptr)
return nullptr;

// Must have at least maximal_block available to prevent block overflow.
////uint8_t* begin = nullptr;
const auto capacity = arena->get_capacity();
if (capacity < maximal_block)
arena->deallocate(arena->allocate(capacity), capacity);
////else
//// begin = system::pointer_cast<uint8_t>(arena->allocate(zero));

system::istream source{ data };
system::byte_reader reader{ source, memory.get_arena() };
system::byte_reader reader{ source, arena };

// message, block and block_ptr are not allocated by reader's arena.
// chain::block consists only of three pointers and two integral values.
const auto message = to_shared(deserialize(version, reader, witness));
if (!reader)
return nullptr;

////const auto end = system::pointer_cast<uint8_t>(arena->allocate(zero));
////const auto size = system::limit<size_t>(std::distance(begin, end));

// Cache header hash.
constexpr auto header_size = chain::header::serialized_size();
const auto& header = message->block_ptr->header();
Expand Down

0 comments on commit b3a8d36

Please sign in to comment.