Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Nov 30, 2021

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

Also, add missing addrman.h includes
@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 30, 2021

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23280 (init: Coalesce Chainstate loading sequence between {,non-}unittest codepaths by dongcarl)

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

Coverage Change (pull 23636, 0386721afb7e984c01c284e79e52ba1a6563afc8) Reference (master, ffdf8ee)
Lines +0.0028 % 84.0014 %
Functions +0.0000 % 76.2420 %
Branches +0.0039 % 52.5420 %

Updated at: 2021-11-30T15:49:21.937703.

@dongcarl
Copy link
Contributor

dongcarl commented Nov 30, 2021

Code Review ACK fa551b3, noticed the exact same thing here: e073634

@mzumsande
Copy link
Contributor

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) {
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Contributor

@shaavan shaavan left a 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:

  1. 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. "
  1. Compile and run bitcoind
  2. cat ~/.bitcoin/debug.log and search for GetTime() in the displayed text.

Here’s the screenshot of my debug.log file:
Screenshot from 2021-12-02 15-28-45

The added test is logically correct and worked successfully on my PC for both the PR and Master branches.

@jnewbery
Copy link
Contributor

jnewbery commented Dec 2, 2021

Code review ACK fa551b3

Connman hasn't started at this point in init, so there's no way that GetAdjustedTime() can return a different value than GetTime().

Copy link
Contributor

@theStack theStack left a 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

maflcko pushed a commit to bitcoin-core/gui that referenced this pull request Dec 2, 2021
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
@maflcko maflcko closed this Dec 2, 2021
@maflcko maflcko deleted the 2111-noTimeInit branch December 2, 2021 14:31
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 2, 2021
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
@mzumsande
Copy link
Contributor

This was merged.

RandyMcMillan pushed a commit to RandyMcMillan/mempool-tab that referenced this pull request Dec 23, 2021
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
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Nov 21, 2022
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
@bitcoin bitcoin locked and limited conversation to collaborators Dec 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants