mirror of
https://github.com/EvernodeXRPL/hpcore.git
synced 2026-04-29 15:37:59 +00:00
Skip ledger truncation when full history is enabled (#177)
* Skip ledger truncation when full history is enabled. * Skip clearing ledger if full history is enabled.
This commit is contained in:
@@ -197,6 +197,7 @@ namespace ledger
|
||||
|
||||
if (!sync_ctx.target_lcl.empty())
|
||||
{
|
||||
// If target lcl is genesis lcl, Clear the ledger history and reset target sequence number.
|
||||
if (sync_ctx.target_lcl == GENESIS_LEDGER)
|
||||
{
|
||||
LOG_INFO << "lcl sync: Target is GENESIS. Clearing our history.";
|
||||
@@ -205,9 +206,10 @@ namespace ledger
|
||||
sync_ctx.target_lcl_seq_no = 0;
|
||||
sync_ctx.is_syncing = false;
|
||||
}
|
||||
// Check the target lcl seq no. to see whether it's too far ahead. That means no one probably has our
|
||||
// If full history mode is not enabled check the target lcl seq no
|
||||
// to see whether it's too far ahead. That means no one probably has our
|
||||
// lcl in their ledgers. So we should clear our entire ledger history before requesting from peers.
|
||||
else if (current_lcl != GENESIS_LEDGER && sync_ctx.target_lcl_seq_no > (ctx.get_seq_no() + MAX_LEDGER_SEQUENCE))
|
||||
else if (!conf::cfg.fullhistory && current_lcl != GENESIS_LEDGER && sync_ctx.target_lcl_seq_no > (ctx.get_seq_no() + MAX_LEDGER_SEQUENCE))
|
||||
{
|
||||
LOG_INFO << "lcl sync: Target " << sync_ctx.target_lcl.substr(0, 15) << " is too far ahead. Clearing our history.";
|
||||
clear_ledger();
|
||||
@@ -354,20 +356,24 @@ namespace ledger
|
||||
*/
|
||||
void remove_old_ledgers(const uint64_t led_seq_no)
|
||||
{
|
||||
std::map<uint64_t, const std::string>::iterator itr;
|
||||
|
||||
for (itr = ctx.cache.begin();
|
||||
itr != ctx.cache.lower_bound(led_seq_no + 1);
|
||||
itr++)
|
||||
// Remove old ledgers if full history mode is not enabled.
|
||||
if (!conf::cfg.fullhistory)
|
||||
{
|
||||
const std::string file_path = conf::ctx.hist_dir + "/" + itr->second + ".lcl";
|
||||
std::map<uint64_t, const std::string>::iterator itr;
|
||||
|
||||
if (util::is_file_exists(file_path))
|
||||
util::remove_file(file_path);
|
||||
for (itr = ctx.cache.begin();
|
||||
itr != ctx.cache.lower_bound(led_seq_no + 1);
|
||||
itr++)
|
||||
{
|
||||
const std::string file_path = conf::ctx.hist_dir + "/" + itr->second + ".lcl";
|
||||
|
||||
if (util::is_file_exists(file_path))
|
||||
util::remove_file(file_path);
|
||||
}
|
||||
|
||||
if (!ctx.cache.empty())
|
||||
ctx.cache.erase(ctx.cache.begin(), ctx.cache.lower_bound(led_seq_no + 1));
|
||||
}
|
||||
|
||||
if (!ctx.cache.empty())
|
||||
ctx.cache.erase(ctx.cache.begin(), ctx.cache.lower_bound(led_seq_no + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,7 +38,7 @@ namespace ledger
|
||||
// Map of closed ledgers (lcl string) with sequence number as map key.
|
||||
// Contains closed ledgers from oldest to latest - MAX_LEDGER_SEQUENCE.
|
||||
// This is loaded when node started and updated throughout consensus.
|
||||
// Deletes ledgers that falls behind MAX_LEDGER_SEQUENCE range.
|
||||
// If full history mode is not enabled, deletes ledgers that falls behind MAX_LEDGER_SEQUENCE range.
|
||||
std::map<uint64_t, const std::string> cache;
|
||||
|
||||
std::mutex ledger_mutex;
|
||||
|
||||
Reference in New Issue
Block a user