Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Oct 7, 2021

It is slightly confusing to use mocktime for some times, but not others.

Start fixing that by making the ping timeout use mocktime.

The only downside would be that tests that use mocktime disconnect peers after this patch. However, I don't think this is an issue, as the inactivity check is already disabled for all functional tests after commit 6d76b57. Only one unit test needed the inactivity check disabled as part of this patch.

A nice side effect of this patch is that the p2p_ping functional test now runs 4 seconds faster.

@maflcko maflcko added the Tests label Oct 7, 2021
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 7, 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:

  • #19499 (p2p: Make timeout mockable and type safe, speed up test by MarcoFalke)

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.

@laanwj
Copy link
Member

laanwj commented Oct 13, 2021

A nice side effect of this patch is that the p2p_ping functional test now runs 4 seconds faster.

Nice! Concept ACK.

@@ -4312,8 +4312,11 @@ void PeerManagerImpl::CheckForStaleTipAndEvictPeers()

void PeerManagerImpl::MaybeSendPing(CNode& node_to, Peer& peer, std::chrono::microseconds now)
{
if (m_connman.ShouldRunInactivityChecks(node_to) && peer.m_ping_nonce_sent &&
if (m_connman.ShouldRunInactivityChecks(node_to, std::chrono::duration_cast<std::chrono::seconds>(now).count()) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also nice simplification that this simply passes through now instead of indirectly querying GetTimeSeconds deep in the call stack.

@laanwj
Copy link
Member

laanwj commented Oct 13, 2021

Is the longer term idea here to get rid of unmockable GetTimeSeconds completely? It looks like the only uses after this are

src/bitcoin-cli.cpp:    const int64_t m_time_now{GetTimeSeconds()};
src/net.cpp:            node.nLastSend = GetTimeSeconds();
src/net.cpp:    int64_t now = GetTimeSeconds();
src/net.cpp:    : nTimeConnected(GetTimeSeconds()),
src/qt/rpcconsole.cpp:    const int64_t time_now{GetTimeSeconds()};

The ones in bitcoin-cli and rpcconsole are uncontroversial to replace.

@laanwj laanwj added the P2P label Oct 13, 2021
@maflcko
Copy link
Member Author

maflcko commented Oct 15, 2021

Yes, some more are handled in #19499, which is not ready for review yet.

@naumenkogs
Copy link
Member

Concept ACK

@laanwj
Copy link
Member

laanwj commented Oct 21, 2021

Code review ACK fadf118

@laanwj laanwj merged commit 8a083bc into bitcoin:master Oct 21, 2021
@maflcko maflcko deleted the 2110-mockPingTime branch October 21, 2021 20:02
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 21, 2021
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 2, 2022
Summary:
> It is slightly confusing to use mocktime for some times, but not others.
>
> Start fixing that by making the ping timeout use mocktime.

This is a backport of [[bitcoin/bitcoin#23218 | core#23218]]
Depends on D10956

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D10957
@bitcoin bitcoin locked and limited conversation to collaborators Oct 30, 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.

4 participants