Skip to content

Commit 34e92ad

Browse files
committed
Release header tree hashmap once candidate chain is current.
1 parent 63c9b14 commit 34e92ad

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

include/bitcoin/node/chasers/chaser_organize.hpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ class chaser_organize
176176
// Remove tree blocks at/below the top reached checkpoint (conflicted).
177177
void purge_under_checkpoint() NOEXCEPT;
178178

179+
// Release tree buckets retained from accumulation (once, when current).
180+
void shrink_tree(bool current) NOEXCEPT;
181+
179182
// Getters.
180183
// ------------------------------------------------------------------------
181184

@@ -201,11 +204,10 @@ class chaser_organize
201204

202205
// These are protected by strand.
203206
bool bumped_{};
207+
bool shrunk_{};
204208
size_t next_checkpoint_{};
205209
size_t active_checkpoint_{};
206210
chain_state::cptr state_{};
207-
208-
// TODO: optimize, default bucket count is around 8.
209211
block_tree tree_{};
210212
};
211213

include/bitcoin/node/impl/chasers/chaser_organize.ipp

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,9 +299,12 @@ void CLASS::do_organize(typename Block::cptr block,
299299
// Reset top chain state and notify.
300300
// ........................................................................
301301

302+
// Evaluated independently of the block short-circuit below.
303+
const auto current = is_current_time(header.timestamp());
304+
302305
// Delay so headers can get current before block download starts.
303306
// Checking currency before notify also avoids excessive work backlog.
304-
if (is_block() || is_current_time(header.timestamp()))
307+
if (is_block() || current)
305308
{
306309
if (!bumped_)
307310
{
@@ -326,6 +329,7 @@ void CLASS::do_organize(typename Block::cptr block,
326329

327330
// Advance top reached checkpoint and purge the tree at/below it.
328331
update_checkpoint(height);
332+
shrink_tree(current);
329333
handler(error::success, height);
330334
}
331335

@@ -608,6 +612,18 @@ void CLASS::purge_under_checkpoint() NOEXCEPT
608612
}
609613
}
610614

615+
TEMPLATE
616+
void CLASS::shrink_tree(bool current) NOEXCEPT
617+
{
618+
BC_ASSERT(stranded());
619+
if (shrunk_ || !current)
620+
return;
621+
622+
shrunk_ = true;
623+
tree_.rehash(zero);
624+
LOGV("Tree buckets reduced to (" << tree_.bucket_count() << ").");
625+
}
626+
611627
// Private getters
612628
// ----------------------------------------------------------------------------
613629

0 commit comments

Comments
 (0)