Skip to content
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

p2p: Make timeout mockable and type safe, speed up test #19499

Merged
merged 2 commits into from Dec 10, 2021

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Jul 12, 2020

Use type-safe time for better code readability/maintainability and mockable time for better testability. This speeds up the p2p_timeout test.

This is also a bugfix for intermittent test issues like: https://cirrus-ci.com/task/4769904156999680?command=ci#L2836

Fixes #20654

@DrahtBot
Copy link
Contributor

DrahtBot commented Jul 12, 2020

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #22778 (net processing: Reduce resource usage for inbound block-relay-only connections by jnewbery)
  • #21160 (net/net processing: Move tx inventory into net_processing by jnewbery)

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.

@practicalswift
Copy link
Contributor

Concept ACK: mockable is good

@luke-jr
Copy link
Member

luke-jr commented Jul 29, 2020

Doesn't this defeat the purpose of the test?

@jnewbery
Copy link
Contributor

Concept ACK. There's a lot of refactor/tidyup in this PR. I wonder if that can be split out to make this more focused on the functional changes.

@maflcko
Copy link
Member Author

maflcko commented Oct 22, 2021

Concept ACK. There's a lot of refactor/tidyup in this PR. I wonder if that can be split out to make this more focused on the functional changes.

Good idea. Split up a scripted-diff as the first commit.

@maflcko
Copy link
Member Author

maflcko commented Oct 22, 2021

Doesn't this defeat the purpose of the test?

This is a bugfix for the test. Currently it intermittently fails, see OP.

-BEGIN VERIFY SCRIPT-

ren() { sed -i "s/\<$1\>/$2/g" $(git grep -l "$1" ./src) ; }

ren nLastSend m_last_send
ren nLastRecv m_last_recv

-END VERIFY SCRIPT-
@laanwj laanwj added this to Blockers in High-priority for review Dec 2, 2021
Copy link
Contributor

@mzumsande mzumsande left a comment

Choose a reason for hiding this comment

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

Concept ACK

Reviewed the non-GUI-related parts so far and played with p2p_timeouts.py - looks good to me, just some nits.


if (!ShouldRunInactivityChecks(node, now)) return false;

if (node.m_last_recv == 0 || node.m_last_send == 0) {
LogPrint(BCLog::NET, "socket no message in first %i seconds, %d %d peer=%d\n", m_peer_connect_timeout, node.m_last_recv != 0, node.m_last_send != 0, node.GetId());
if (last_recv.count() == 0 || last_send.count() == 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why sometimes .count() and sometimes count_seconds()?

Copy link
Member Author

Choose a reason for hiding this comment

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

last_recv is a bit like std::optional. I use .count(), when .has_value() would be used and I use count_seconds(), when .value() would be used.

src/net_processing.cpp Outdated Show resolved Hide resolved
src/net.cpp Outdated Show resolved Hide resolved
peer.m_ping_nonce_sent &&
now > peer.m_ping_start.load() + std::chrono::seconds{TIMEOUT_INTERVAL}) {
now > peer.m_ping_start.load() + TIMEOUT_INTERVAL)
{
Copy link
Member

Choose a reason for hiding this comment

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

More consistent to keep the { on the same line?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think (and other seem to agree, see #21735) that multiline if conditions are hard to read because there is no break between condition and body, so changed it here.

Happy to revert, though.

Copy link
Member

Choose a reason for hiding this comment

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

I don't particularly want to get into discussion about code style, it just seemed inconsistent to me (as all other if cases have the { on the same line), if you have a good reason for it it's fine with me.

@laanwj
Copy link
Member

laanwj commented Dec 9, 2021

Code review ACK fadc0c8

@naumenkogs
Copy link
Member

ACK fadc0c8

@maflcko maflcko merged commit 9f7661c into bitcoin:master Dec 10, 2021
@maflcko maflcko deleted the 2007-p2pMockTimeout branch December 10, 2021 09:15
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Dec 10, 2021
@fanquake fanquake removed this from Blockers in High-priority for review Dec 11, 2021
RandyMcMillan pushed a commit to RandyMcMillan/mempool-tab that referenced this pull request Dec 23, 2021
…, speed up test

bc55c30 p2p: Make timeout mockable and type safe, speed up test (MarcoFalke)
fdc1c9d scripted-diff: Rename m_last_send and m_last_recv (MarcoFalke)

Pull request description:

  Use type-safe time for better code readability/maintainability and mockable time for better testability. This speeds up the p2p_timeout test.

  This is also a bugfix for intermittent test issues like: https://cirrus-ci.com/task/4769904156999680?command=ci#L2836

  Fixes #20654

ACKs for top commit:
  laanwj:
    Code review ACK bc55c30
  naumenkogs:
    ACK bc55c30

Tree-SHA512: 28c6544c97f188c8a0fbc80411c74ab74ffd055885322c325aa3d1c404b29c3fd70a737e86083eecae58ef394db1cb56bc122d06cff63742aa89a8e868730c64
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Feb 2, 2022
Summary:
```
-BEGIN VERIFY SCRIPT-

ren() { sed -i "s/\<$1\>/$2/g" $(git grep -l "$1" ./src) ; }

ren nLastSend m_last_send
ren nLastRecv m_last_recv

-END VERIFY SCRIPT-
```

This is a backport of [[bitcoin/bitcoin#19499 | core#19499]] [1/2]
bitcoin/bitcoin@fa6d5a2

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

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

qa: AssertionError in p2p_timeouts.py
8 participants