Skip to content

Commit

Permalink
Disable unchecked cleanup if node is not synchronized
Browse files Browse the repository at this point in the history
Based on built-in bootstrap_weight_max_blocks
Similar to nanocurrency#2257
  • Loading branch information
SergiySW committed Sep 2, 2019
1 parent ded2b26 commit 5c99ff0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion nano/node/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,10 @@ void nano::node::unchecked_cleanup ()
}
}
}
if (!cleaning_list.empty ())
{
logger.always_log (boost::str (boost::format ("Deleting %1% old unchecked blocks") % cleaning_list.size ()));
}
// Delete old unchecked keys in batches
while (!cleaning_list.empty ())
{
Expand All @@ -931,7 +935,7 @@ void nano::node::unchecked_cleanup ()

void nano::node::ongoing_unchecked_cleanup ()
{
if (!bootstrap_initiator.in_progress ())
if (!bootstrap_initiator.in_progress () && ledger.block_count () >= ledger.bootstrap_weight_max_blocks)
{
unchecked_cleanup ();
}
Expand Down
7 changes: 7 additions & 0 deletions nano/secure/ledger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,13 @@ bool nano::ledger::block_not_confirmed_or_not_exists (nano::block const & block_
return result;
}

size_t nano::ledger::block_count () const
{
auto transaction (store.tx_begin_read ());
auto result (store.block_count (transaction).sum ());
return result;
}

namespace nano
{
std::unique_ptr<seq_con_info_component> collect_seq_con_info (ledger & ledger, const std::string & name)
Expand Down
1 change: 1 addition & 0 deletions nano/secure/ledger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ledger final
void dump_account_chain (nano::account const &);
bool could_fit (nano::transaction const &, nano::block const &);
bool is_epoch_link (nano::uint256_union const &);
size_t block_count () const;
static nano::uint128_t const unit;
nano::network_params network_params;
nano::block_store & store;
Expand Down

0 comments on commit 5c99ff0

Please sign in to comment.