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

test: adds outbound eviction functional tests, updates comment in ConsiderEviction #29122

Merged
merged 2 commits into from
May 9, 2024

Conversation

sr-gi
Copy link
Member

@sr-gi sr-gi commented Dec 20, 2023

Motivation

While checking the outbound eviction code I realized a case was not considered within the comments, which in turn made me realize we had no functional tests for the outbound eviction case (when I went to check/add the test case).

This PR updates the aforementioned comment and adds functional tests to cover the outbound eviction logic, in addition to the existing unit tests found at src/test/denialofservice_tests.cpp.

@DrahtBot
Copy link
Contributor

DrahtBot commented Dec 20, 2023

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

Code Coverage

For detailed information about the code coverage, see the test coverage report.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK davidgumberg, cbergqvist, tdb3, achow101
Concept ACK sipa, stratospher, marcofleon

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

No conflicts as of last run.

@DrahtBot DrahtBot added the Tests label Dec 20, 2023
@sr-gi
Copy link
Member Author

sr-gi commented Dec 20, 2023

While the tests seem to run fine, I noticed a warning that appears every now and then:

TestFramework.p2p (WARNING): Connection lost to 0:0 due to [Errno 54] Connection reset by peer

I'm not sure if something unintended is happening under the hood. Disconnections are expected, but it's our node who is supposed to trigger them, so maybe I'm missing something.

@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch from 445ddda to cd11dab Compare December 20, 2023 16:13
@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch 2 times, most recently from a6590c0 to 6d6eda7 Compare December 20, 2023 18:58
@sr-gi sr-gi changed the title test: adds outbound eviction functional tests, updated comment on ConsiderEviction test: adds outbound eviction functional tests, updates comment in ConsiderEviction Dec 20, 2023
@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch from 6d6eda7 to 9ba568c Compare December 20, 2023 19:51
@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch 2 times, most recently from 1444a26 to 8833aa6 Compare January 3, 2024 19:15
@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch from 8833aa6 to 599e984 Compare January 3, 2024 20:17
@DrahtBot DrahtBot removed the CI failed label Jan 3, 2024
@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch from 599e984 to 2e15c4f Compare January 4, 2024 16:12
@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch from 2e15c4f to 24b7906 Compare January 29, 2024 22:06
@sr-gi
Copy link
Member Author

sr-gi commented Jan 29, 2024

Rebased to fix CI

@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch from 24b7906 to b8b2370 Compare February 6, 2024 14:52
@sr-gi
Copy link
Member Author

sr-gi commented Feb 6, 2024

Rebased. This has failed CI once when waiting for the disconnection after:

cur_mock_time += (HEADERS_RESPONSE_TIME + 1)

I've tried to reproduce it but I cannot in my local setup, the only thing that comes to mind is that mock time may be too close to the timeout (only one second ahead), so I gave it a delta of 10 seconds instead.

PS: For context, you can check the failure here: https://cirrus-ci.com/task/4624744360706048?logs=ci#L6520. See how the peer is given the final notice by sending a getheaders message, but the check is performed before the peer gets disconnected.

@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch from b8b2370 to edc14bc Compare February 6, 2024 15:45
@DrahtBot DrahtBot removed the CI failed label Feb 6, 2024
Copy link
Contributor

@tdb3 tdb3 left a comment

Choose a reason for hiding this comment

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

Excellent work finding a gap and filling it by increasing functional test robustness.
ACK for edc14bc

Checked out the PR branch, built, and ran all functional tests (all passed).

The review was focused on verifying edge case coverage of the tests and that tests will accurately catch both pass and fail conditions.

Did not observe previously reported warning message:

TestFramework.p2p (WARNING): Connection lost to 0:0 due to [Errno 54] Connection reset by peer

Copy link
Member Author

@sr-gi sr-gi left a comment

Choose a reason for hiding this comment

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

Thanks for the review @tdb3

@sr-gi
Copy link
Member Author

sr-gi commented Feb 12, 2024

I redefined how peers are split in p2p_eviction:test_outbound_eviction_protected_mixed to address #29122 (comment). Both commits can be squashed (leaving them as they are for now in case someone does not agree with the approach)

@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch from 91005f7 to 986329f Compare February 12, 2024 21:31
@DrahtBot DrahtBot requested a review from cbergqvist April 22, 2024 11:09
@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch 2 times, most recently from 15a00a9 to 8980e15 Compare April 25, 2024 18:17
@sr-gi
Copy link
Member Author

sr-gi commented Apr 25, 2024

Rebased on top of #29736. Now this is using wait_for_getheaders to reduce the boilerplate of having to manually pop the results from last_message.

cc/ @stratospher

@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch from 8980e15 to be2c551 Compare April 25, 2024 18:21
@DrahtBot
Copy link
Contributor

🚧 At least one of the CI tasks failed. Make sure to run all tests locally, according to the
documentation.

Possibly this is due to a silent merge conflict (the changes in this pull request being
incompatible with the current code in the target branch). If so, make sure to rebase on the latest
commit of the target branch.

Leave a comment here, if you need help tracking down a confusing failure.

Debug: https://github.com/bitcoin/bitcoin/runs/24266342152

@davidgumberg
Copy link
Contributor

ACK be2c551
Re-reviewed code, and attempted to break tests by making ConsiderEviction misbehave.

It is worth noting that these tests will not catch if outbound eviction logic gets triggered too early. e.g.:

/** How long to wait for a peer to respond to a getheaders request */
static constexpr auto HEADERS_RESPONSE_TIME{0s};
// [...]
/** Timeout for (unprotected) outbound peers to sync to our chainwork */
static constexpr auto CHAIN_SYNC_TIMEOUT{0s};

will pass. That seems fine to me, maybe something for a follow up.

@DrahtBot DrahtBot requested a review from tdb3 April 25, 2024 23:11
sr-gi added 2 commits April 26, 2024 11:14
Peer protection is only given to outbound-full-relay peers. Add a negative
test to check that other type of outbound peers are not given protection under
the circumstances that outbound-full-relay would
@sr-gi
Copy link
Member Author

sr-gi commented Apr 26, 2024

ACK be2c551 Re-reviewed code, and attempted to break tests by making ConsiderEviction misbehave.

It is worth noting that these tests will not catch if outbound eviction logic gets triggered too early. e.g.:

/** How long to wait for a peer to respond to a getheaders request */
static constexpr auto HEADERS_RESPONSE_TIME{0s};
// [...]
/** Timeout for (unprotected) outbound peers to sync to our chainwork */
static constexpr auto CHAIN_SYNC_TIMEOUT{0s};

will pass. That seems fine to me, maybe something for a follow-up.

I don't think I follow you here. HEADERS_RESPONSE_TIME and CHAIN_SYNC_TIMEOUT are constants hardcoded in net_processing.cpp (and mapped here). I would expect unit test to fail if those are updated.

@sr-gi sr-gi force-pushed the 2023-12-20-eviction-tests branch from be2c551 to d53d848 Compare April 26, 2024 15:20
@sr-gi
Copy link
Member Author

sr-gi commented Apr 26, 2024

Updated to address #29122 (comment)

@davidgumberg
Copy link
Contributor

reACK d53d848

I don't think I follow you here. HEADERS_RESPONSE_TIME and CHAIN_SYNC_TIMEOUT are constants hardcoded in net_processing.cpp (and mapped here). I would expect unit test to fail if those are updated.

I didn't mean to say that these tests should be responsible for enforcing the particular values of HEADERS_RESPONSE_TIME and CHAIN_SYNC_TIMEOUT, just that they would not catch a regression where outbound eviction logic gets triggered earlier than expected on peers, which can be demonstrated by setting both values to zero.

Anyways, I think if what I'm saying isn't confused in some way, it is more pedantic than useful.

Copy link
Contributor

@cbergqvist cbergqvist left a comment

Choose a reason for hiding this comment

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

ACK d53d848

Functional including --extended tests passed (skipped unrelated feature_dbcrash).

@tdb3
Copy link
Contributor

tdb3 commented May 5, 2024

Re ACK for d53d848
Pulled, built, ran all unit/functional tests (all passed).
Performed code review, but didn't see anything noteworthy over previous review.

@bitcoin bitcoin deleted a comment from Ferrydh May 5, 2024
Copy link
Contributor

@marcofleon marcofleon left a comment

Choose a reason for hiding this comment

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

Re ACK. Reviewed the code and the tests look good to me. I ran p2p_outbound_eviction.py individually and along with all the other functional tests and everything looks good.

@achow101
Copy link
Member

achow101 commented May 9, 2024

ACK d53d848

@DrahtBot DrahtBot requested a review from marcofleon May 9, 2024 20:14
@achow101 achow101 merged commit 012e540 into bitcoin:master May 9, 2024
16 checks passed
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Feb 17, 2025
…pdates comment in ConsiderEviction

d53d848 test: adds outbound eviction tests for non outbound-full-relay peers (Sergi Delgado Segura)
a8d9a0e test: adds outbound eviction functional tests, updates comment in ConsiderEviction (Sergi Delgado Segura)

Pull request description:

  ## Motivation

  While checking the outbound eviction code I realized a case was not considered within the comments, which in turn made me realize we had no functional tests for the outbound eviction case (when I went to check/add the test case).

  This PR updates the aforementioned comment and adds functional tests to cover the outbound eviction logic, in addition to the existing unit tests found at `src/test/denialofservice_tests.cpp`.

ACKs for top commit:
  davidgumberg:
    reACK bitcoin@d53d848
  tdb3:
    Re ACK for d53d848
  achow101:
    ACK d53d848
  cbergqvist:
    ACK d53d848

Tree-SHA512: 633b84bb1229fe21e2f650c1beada33ca7f190b64eafd64df2266516d21175e5d652e019ff7114f00cb8bd19f5817dc19e65adf75767a88e24dc0842ce40c63e
PastaPastaPasta added a commit to PastaPastaPasta/dash that referenced this pull request Feb 17, 2025
…tests, updates comment in ConsiderEviction"

This reverts commit 9db73d2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants