Remove GetAdjustedTime from init.cpp #23636
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
|
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.
Should we have some extra tolerance here in case the adjusted time had been forward a bit?
There was a problem hiding this comment.
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.
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.
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 |
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