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
index: avoid "failed to commit" errors on initialization #29671
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
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.
Isn't more natural to move the last locator update to the end of the loop?
I know what you mean by "more natural" but it requires a bigger change because 1. Maybe there is a simpler way to do this refactoring but I am not seeing it right now :) |
Why this is not possible? diff --git a/src/index/base.cpp b/src/index/base.cpp
--- a/src/index/base.cpp (revision aefa9a8fca467ffb26466741f0b6b90289d92e20)
+++ b/src/index/base.cpp (date 1710785794630)
@@ -184,13 +184,6 @@
last_log_time = current_time;
}
- if (pindex->pprev && last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
- SetBestBlockIndex(pindex->pprev);
- last_locator_write_time = current_time;
- // No need to handle errors in Commit. See rationale above.
- Commit();
- }
-
CBlock block;
interfaces::BlockInfo block_info = kernel::MakeBlockInfo(pindex);
if (!m_chainstate->m_blockman.ReadBlockFromDisk(block, *pindex)) {
@@ -205,6 +198,13 @@
__func__, pindex->GetBlockHash().ToString());
return;
}
+
+ if (last_locator_write_time + SYNC_LOCATOR_WRITE_INTERVAL < current_time) {
+ SetBestBlockIndex(pindex);
+ last_locator_write_time = current_time;
+ // No need to handle errors in Commit. See rationale above.
+ Commit();
+ }
}
}
|
aefa9a8
to
94e36d9
Compare
That works. I misunderstood your comment before, I thought by locator you meant |
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.
self ACK 94e36d9
Could update the PR title and description.
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.
Code review ACK 94e36d9 but I found the PR title and description confusing because "Skip commit during init when nothing can be committed" makes it sounds like this is trying to skip committing when there have been no changes since the last commit, when actually it is trying to skip committing when m_best_block_index
pointer is null and the index is completely empty. Also the title makes this sound like an efficiency improvement, when the actual goal of the PR is to fix is misleading error message. Would suggest title and description more like:
- index: avoid "failed to commit" errors on initialization
- In the index sync thread, when initializing an index for the first time, stop callng
BaseIndex::Commit
whenm_best_block_index
is null, to avoid a spurious "failed to commit" error from that function. This error started happening in commit 7878f97 from #25494 and was reported by pstratem in #26903 with an alternate fix.
94e36d9
to
87fe47f
Compare
…loop This avoids having commit print a needless error message during init. Co-authored-by: furszy <mfurszy@protonmail.com>
87fe47f
to
f65b0f6
Compare
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.
Code review ACK f65b0f6. Just moved log "Syncing" log line since last commit to avoid having to call now() twice.
|
||
auto current_time{std::chrono::steady_clock::now()}; | ||
if (last_log_time + SYNC_LOG_INTERVAL < current_time) { | ||
LogPrintf("Syncing %s with block chain from height %d\n", |
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 agree on the change with a small nuance: now the "syncing index from height " is not entirely accurate. When the log is triggered, the block presented here was already scanned.
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.
ACK f65b0f6
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.
ACK f65b0f6
ACK f65b0f6 |
In the index sync thread, when initializing an index for the first time, stop callng BaseIndex::Commit when m_best_block_index is null, to avoid a spurious "failed to commit" error from that function. This error started happening in commit 7878f97 from #25494 and was reported by pstratem in #26903 with an alternate fix.