-
Notifications
You must be signed in to change notification settings - Fork 38.1k
persist IBD latch across restarts #21106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
pstratem
wants to merge
1
commit into
bitcoin:master
from
pstratem:2021-02-07-isinitialblockdownload-timeout
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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> | ||
|
@@ -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 | ||
// | ||
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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will set ibd to false, when There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
@@ -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; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 insettings.json
, which is also chain-specific).There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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