-
Notifications
You must be signed in to change notification settings - Fork 38.6k
Remove GetAdjustedTime from init.cpp #23636
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
Conversation
Also, add missing addrman.h includes
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. Coverage
Updated at: 2021-11-30T15:49:21.937703. |
faabea3 to
fa551b3
Compare
|
Before: After: |
|
Code Review ACK fa551b3 |
| const CBlockIndex* tip = chainstate->m_chain.Tip(); | ||
| RPCNotifyBlockChange(tip); | ||
| if (tip && tip->nTime > GetAdjustedTime() + 2 * 60 * 60) { | ||
| if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) { |
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.
Should we have some extra tolerance here in case the adjusted time had been forward a bit?
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.
This pull request is a refactor and I recommend to do any behavior changes in separate pull requests.
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 don't understand this: This PR argues that GetAdjustedTime() can't differ from GetTime() at this point in init, so I can't see how it could have been "forward a bit". Or do you mean the former adjusted time at the point in time when we validated the tip?
shaavan
left a comment
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 fa551b3
I confirmed that GetTime() and GetAdjustedTime() gives exactly same timestamp as output at this stage of init.cpp. So it makes sense to replace it with GetTime() to avoid unnecessary confusion.
Steps I took to confirm the above statement:
- Apply following patch:
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -1561,6 +1561,8 @@ bool AppInitMain(NodeContext& node, interfaces::BlockAndHeaderTipInfo* tip_info)
const CBlockIndex* tip = chainstate->m_chain.Tip();
RPCNotifyBlockChange(tip);
+ LogPrintf("GetTime() value: %s\n", GetTime());
+ LogPrintf("GetAdjustedTime() value: %s\n", GetAdjustedTime());
if (tip && tip->nTime > GetTime() + MAX_FUTURE_BLOCK_TIME) {
strLoadError = _("The block database contains a block which appears to be from the future. "
"This may be due to your computer's date and time being set incorrectly. "- Compile and run bitcoind
cat ~/.bitcoin/debug.logand search forGetTime()in the displayed text.
Here’s the screenshot of my debug.log file:

The added test is logically correct and worked successfully on my PC for both the PR and Master branches.
|
Code review ACK fa551b3 Connman hasn't started at this point in init, so there's no way that |
theStack
left a comment
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 fa551b3
fa551b3 Remove GetAdjustedTime from init.cpp (MarcoFalke) fa815f8 Replace addrman.h include with forward decl in net.h (MarcoFalke) Pull request description: It seems confusing to call `GetAdjustedTime` there, because no offset could have been retrieved from the network at this point. Even if connman was started, `timedata` needs at least 5 peer connections to calculate an offset. Fix the confusion by replacing `GetAdjustedTime` with `GetTime`, which does not change behavior. Also: * Replace magic number with `MAX_FUTURE_BLOCK_TIME` to clarify the context * Add test, which passes both on current master and this pull request * An unrelated refactoring commit, happy to drop ACKs for top commit: dongcarl: Code Review ACK fa551b3, noticed the exact same thing here: bitcoin/bitcoin@e073634 mzumsande: Code Review ACK fa551b3 jnewbery: Code review ACK fa551b3 shaavan: ACK fa551b3 theStack: Code-review ACK fa551b3 Tree-SHA512: 15807a0e943e3e8d8c5250c8f6d7b56afb26002b1e290bf93636a2c747f27e78f01f1de04ce1a83d6339e27284c69c43e077a8467545c4078746f4c1ecb1164d
fa551b3 Remove GetAdjustedTime from init.cpp (MarcoFalke) fa815f8 Replace addrman.h include with forward decl in net.h (MarcoFalke) Pull request description: It seems confusing to call `GetAdjustedTime` there, because no offset could have been retrieved from the network at this point. Even if connman was started, `timedata` needs at least 5 peer connections to calculate an offset. Fix the confusion by replacing `GetAdjustedTime` with `GetTime`, which does not change behavior. Also: * Replace magic number with `MAX_FUTURE_BLOCK_TIME` to clarify the context * Add test, which passes both on current master and this pull request * An unrelated refactoring commit, happy to drop ACKs for top commit: dongcarl: Code Review ACK fa551b3, noticed the exact same thing here: bitcoin@e073634 mzumsande: Code Review ACK fa551b3 jnewbery: Code review ACK fa551b3 shaavan: ACK fa551b3 theStack: Code-review ACK fa551b3 Tree-SHA512: 15807a0e943e3e8d8c5250c8f6d7b56afb26002b1e290bf93636a2c747f27e78f01f1de04ce1a83d6339e27284c69c43e077a8467545c4078746f4c1ecb1164d
|
This was merged. |
3bfde7d Remove GetAdjustedTime from init.cpp (MarcoFalke) ac31727 Replace addrman.h include with forward decl in net.h (MarcoFalke) Pull request description: It seems confusing to call `GetAdjustedTime` there, because no offset could have been retrieved from the network at this point. Even if connman was started, `timedata` needs at least 5 peer connections to calculate an offset. Fix the confusion by replacing `GetAdjustedTime` with `GetTime`, which does not change behavior. Also: * Replace magic number with `MAX_FUTURE_BLOCK_TIME` to clarify the context * Add test, which passes both on current master and this pull request * An unrelated refactoring commit, happy to drop ACKs for top commit: dongcarl: Code Review ACK 3bfde7d, noticed the exact same thing here: bitcoin/bitcoin@e073634 mzumsande: Code Review ACK 3bfde7d jnewbery: Code review ACK 3bfde7d shaavan: ACK 3bfde7d theStack: Code-review ACK 3bfde7d Tree-SHA512: 15807a0e943e3e8d8c5250c8f6d7b56afb26002b1e290bf93636a2c747f27e78f01f1de04ce1a83d6339e27284c69c43e077a8467545c4078746f4c1ecb1164d
Summary:
```
It seems confusing to call GetAdjustedTime there, because no offset could have been retrieved from the network at this point. Even if connman was started, timedata needs at least 5 peer connections to calculate an offset.
Fix the confusion by replacing GetAdjustedTime with GetTime, which does not change behavior.
Also:
Replace magic number with MAX_FUTURE_BLOCK_TIME to clarify the context
Add test, which passes both on current master and this pull request
An unrelated refactoring commit, happy to drop
```
Backport of [[bitcoin/bitcoin#23636 | core#23636]].
Depends on D12548 and D12552.
Test Plan:
ninja all check-all
Reviewers: #bitcoin_abc, PiRK
Reviewed By: #bitcoin_abc, PiRK
Differential Revision: https://reviews.bitcoinabc.org/D12554
It seems confusing to call
GetAdjustedTimethere, because no offset could have been retrieved from the network at this point. Even if connman was started,timedataneeds at least 5 peer connections to calculate an offset.Fix the confusion by replacing
GetAdjustedTimewithGetTime, which does not change behavior.Also:
MAX_FUTURE_BLOCK_TIMEto clarify the context