Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/test/util/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
void TestChainState::ResetIbd()
{
m_cached_finished_ibd = false;
fs::remove(GetDataDir() / ".ibd_complete");
assert(IsInitialBlockDownload());
}

Expand Down
15 changes: 15 additions & 0 deletions src/validation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include <consensus/validation.h>
#include <cuckoocache.h>
#include <flatfile.h>
#include <fs.h>
#include <hash.h>
#include <index/txindex.h>
#include <logging.h>
Expand Down Expand Up @@ -1294,15 +1295,23 @@ void CChainState::InitCoinsCache(size_t cache_size_bytes)
// `const` so that `CValidationInterface` clients (which are given a `const CChainState*`)
// can call it.
//
// The file .ibd_complete is used to latch the datadir to IBD false across restarts
Copy link
Member

@jonatack jonatack Feb 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this moves forward, noting that a file description should be added to doc/files.md (alternatively, perhaps persist the latch in settings.json, which is also chain-specific).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this as a separate file so that users can easily add the file to override, with GetDataDir() it should be chain specific, no?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think they should both be.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Users can easily override settings.json as well - they're just interpreted as command-line options.

So something like --ibd_complete=0/1 would work

//
bool CChainState::IsInitialBlockDownload() const
{
static const fs::path latch_filename = GetDataDir() / ".ibd_complete";
// Optimization: pre-test latch before taking the lock.
if (m_cached_finished_ibd.load(std::memory_order_relaxed))
return false;

LOCK(cs_main);
if (m_cached_finished_ibd.load(std::memory_order_relaxed))
return false;
if (fs::exists(latch_filename)) {
LogPrintf("Leaving InitialBlockDownload (latching to false)\n");
m_cached_finished_ibd.store(true, std::memory_order_relaxed);
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will set ibd to false, when -reindex? If yes, that seems wrong

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it is wrong

}
if (fImporting || fReindex)
return true;
if (m_chain.Tip() == nullptr)
Expand All @@ -1312,6 +1321,12 @@ bool CChainState::IsInitialBlockDownload() const
if (m_chain.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge))
return true;
LogPrintf("Leaving InitialBlockDownload (latching to false)\n");
FILE* f = fsbridge::fopen(latch_filename, "wb");
if (f) {
fclose(f);
} else {
LogPrintf("Failed to write %s\n", latch_filename.string().c_str());
}
m_cached_finished_ibd.store(true, std::memory_order_relaxed);
return false;
}
Expand Down