From 06dfc349451f6e48303030aab72495b817fe7a0d Mon Sep 17 00:00:00 2001 From: evoskuil Date: Mon, 5 Aug 2024 12:29:50 -0400 Subject: [PATCH 1/2] Track allocations. --- src/messages/block.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/messages/block.cpp b/src/messages/block.cpp index 49c92978c..5190c2c1e 100644 --- a/src/messages/block.cpp +++ b/src/messages/block.cpp @@ -59,12 +59,12 @@ typename block::cptr block::deserialize(memory& memory, uint32_t version, return nullptr; // Must have at least maximal_block available to prevent block overflow. - ////uint8_t* begin = nullptr; + 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(arena->allocate(zero)); + else + begin = system::pointer_cast(arena->allocate(zero)); system::istream source{ data }; system::byte_reader reader{ source, arena }; @@ -75,8 +75,8 @@ typename block::cptr block::deserialize(memory& memory, uint32_t version, if (!reader) return nullptr; - ////const auto end = system::pointer_cast(arena->allocate(zero)); - ////const auto size = system::limit(std::distance(begin, end)); + const auto end = system::pointer_cast(arena->allocate(zero)); + const auto size = system::limit(std::distance(begin, end)); // Cache header hash. constexpr auto header_size = chain::header::serialized_size(); @@ -114,7 +114,7 @@ typename block::cptr block::deserialize(memory& memory, uint32_t version, } // WARNING: retainer does not track objects shared from block (e.g. tx). - message->block_ptr->set_retainer(memory.get_retainer()); + message->block_ptr->set_retainer(memory.get_retainer(size)); return message; } From d16d2c9fef28db723a99106964a8d1bc03499611 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Tue, 6 Aug 2024 14:18:35 -0400 Subject: [PATCH 2/2] Set maximal_block to 30'000'000. --- src/messages/block.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/messages/block.cpp b/src/messages/block.cpp index 5190c2c1e..362432a11 100644 --- a/src/messages/block.cpp +++ b/src/messages/block.cpp @@ -33,8 +33,8 @@ namespace messages { using namespace system; -// Measured through block 550,000 - assumes consistent platform sizing. -constexpr auto maximal_block = 11'904'912_size; +// Measured through block 840,000 - assumes consistent platform sizing. +constexpr auto maximal_block = 30'000'000_size; const std::string block::command = "block"; const identifier block::id = identifier::block; @@ -51,6 +51,10 @@ typename block::cptr block::deserialize(uint32_t version, // static // TODO: Move cached hashes to arena. +// Must have at least maximal_block available to prevent block overflow. +// Since the block allocation is unknown, a maximal block is assumed. +// message, block and block_ptr are not allocated by reader's arena. +// chain::block consists only of three pointers and two integral values. typename block::cptr block::deserialize(memory& memory, uint32_t version, const system::data_chunk& data, bool witness) NOEXCEPT { @@ -58,26 +62,15 @@ typename block::cptr block::deserialize(memory& memory, uint32_t version, 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(arena->allocate(zero)); + istream source{ data }; + byte_reader reader{ source, arena }; - system::istream source{ data }; - 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. + // May block until all retainers of the arena are released. + const auto begin = pointer_cast(arena->require(maximal_block)); const auto message = to_shared(deserialize(version, reader, witness)); if (!reader) return nullptr; - const auto end = system::pointer_cast(arena->allocate(zero)); - const auto size = system::limit(std::distance(begin, end)); - // Cache header hash. constexpr auto header_size = chain::header::serialized_size(); const auto& header = message->block_ptr->header(); @@ -113,8 +106,12 @@ typename block::cptr block::deserialize(memory& memory, uint32_t version, std::advance(start, full); } + // TODO: system::limit is not necessary if allocation begin < end. + const auto end = pointer_cast(arena->allocate(zero)); + const auto allocated = limit(std::distance(begin, end)); + // WARNING: retainer does not track objects shared from block (e.g. tx). - message->block_ptr->set_retainer(memory.get_retainer(size)); + message->block_ptr->set_retainer(memory.get_retainer(allocated)); return message; }