-
Notifications
You must be signed in to change notification settings - Fork 38.7k
net: Use type-safe mockable time for peer connection time #23758
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
Conversation
4bc39a2 to
fac1b90
Compare
This allows to revert the temporary commit 0bfb920 (test: fix test failures in test/functional/p2p_timeouts.py).
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s/\<$1\>/$2/g" $( git grep -l "$1" ./src/ ) ; }
ren nLastBlockTime m_last_block_time
ren nLastTXTime m_last_tx_time
ren nTimeConnected m_connected
-END VERIFY SCRIPT-
fac1b90 to
fad9438
Compare
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsNo conflicts as of last run. |
shaavan
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Concept ACK
- Used type-safe std::chrono::seconds to ensure that the compiler will validate types while compiling and throw an error if tried to assign the wrong type to a variable.
- Checked that the std::chrono is introduced correctly in the first commit.
- The second commit uses std::chrono::seconds variable
time_initandtime_latertoSetMockTimeinsrc/test/denialofservices_tests.cppfile. I have checked that these variables are used toSetMockTimeat appropriate places.
However, I am not proficient enough (yet) to comment on if this fixes the bug that was initially described in #23739 - The third commit renames the three variables touched in this PR and names them to our latest naming convention.
I have some suggestions:
- Since the file
src/test/net_peer_eviction_tests.cppis touched in this PR, how about adding the clang formatting changes suggested by 🔽 to this PR itself.
git diff -U0 HEAD~1.. | ./contrib/devtools/clang-format-diff.py -p1 -i -v
| { | ||
| LOCK(cs_main); | ||
|
|
||
| int64_t time_in_seconds = GetTime(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| int64_t time_in_seconds = GetTime(); | |
| auto time_in_seconds = GetTime<std::chrono::seconds>(); | |
| EvictExtraOutboundPeers(time_in_seconds); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The diff as suggested wouldn't compile and needs more changes, so I'll leave it for a follow-up.
Looks like this will cause re-formats of lines in the file I haven't touched? Also, I think the file will/might be touched soon by other PRs, so I want to minimize the conflicts for now. Maybe it can be formatted in a pull that touches those lines directly? |
|
ACK fad9438 |
|
ACK fad9438
I wasn't aware of this. How about leaving a comment above this line explaining the needed follow-up.
Formatting can be taken up as a direct follow-up to this PR as soon as this one gets merged. |
Personally I am not a fan of adding comments to source code to list future refactoring that can be done. I think if it is worth it, it should be done in a pull request (or an issue created to track it). Do you want to work on that? |
I think I can give it a try! |
Nice. Let me know if you have any questions. If not, you can also ping me for review. |
|
These variable rename pull requests are a pain in the ass - I thought it had been agreed previously that PRs should not be created to rename variables? |
|
The purpose of this PR is not renaming variables; the point is moving to more type-safe representation of time. When code is being changed already, the developer guidelines state that the new code should follow the style guidelines, and that's what is happening here. Furthermore, in this specific case it also makes the change more reviewable. By changing the name, you know every access site is updated. |
…::chrono::seconds in net_processing.cpp 92082ea Change time variable type to std::chrono::seconds in src/net_processing.cpp (Shashwat) Pull request description: - This is a follow-up to PR #23758 - This changes the remaining time variable in `net_processing.cpp` from **int64_t** to **std::chrono::seconds** ACKs for top commit: naumenkogs: ACK 92082ea hebasto: re-ACK 92082ea Tree-SHA512: 559e351d9046d4ba2b842ae38da13b4befc7feee71f0762f97907812471e2840b0d43c90c92222d15619fe40cc21f11d40900500ca07b470f7ac8b0046cc1d68
Summary: This is a backport of [[bitcoin/bitcoin#23758 | core#23758]] [1/3] bitcoin/bitcoin@fad7ead Test Plan: `ninja all check-all bitcoin-bench bitcoin-fuzzers && src/bench/bitcoin-bench` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D11084
Summary: This allows to revert the temporary fix in test test/functional/p2p_timeouts.py (see 10965) This is a backport of [[bitcoin/bitcoin#23758 | core#23758]] [2/3] bitcoin/bitcoin@fa663a4 Depends on D11084 Note: due to out of sequence backports, we do not yet have `void SetMockTime(std::chrono::seconds mock_time_in)`, so I used `void SetMockTime(int64_t nMockTimeIn)` instead. Test Plan: `ninja all check-all` Reviewers: #bitcoin_abc, Fabien Reviewed By: #bitcoin_abc, Fabien Differential Revision: https://reviews.bitcoinabc.org/D11085
Summary:
```
-BEGIN VERIFY SCRIPT-
ren() { sed -i "s/\<$1\>/$2/g" $( git grep -l "$1" ./src/ ) ; }
ren nLastBlockTime m_last_block_time
ren nLastTXTime m_last_tx_time
ren nTimeConnected m_connected
ren nLastProofTime m_last_proof_time
-END VERIFY SCRIPT-
```
This is a backport of [[bitcoin/bitcoin#23758 | core#23758]] [3/3]
bitcoin/bitcoin@fad9438
Depends on D11085
Test Plan: `ninja all check-all bitcoin-bench bitcoin-fuzzers && src/bench/bitcoin-bench`
Reviewers: #bitcoin_abc, Fabien
Reviewed By: #bitcoin_abc, Fabien
Subscribers: Fabien
Differential Revision: https://reviews.bitcoinabc.org/D11086
Benefits: