Repository navigation
rpc: add additional ban time fields to listbanned - #21602
Conversation
|
I'm not sure about this. Would this change cause versioning/compatibility issues with previous/existing ban entries? (test coverage needed). It may be better to avoid changing As a human user, I've found myself wishing for a "time_remaining" field in |
You're right, taking into consideration compatibility guarantees, performing the calculation is the simplest path.
I will look into adding this field, thanks for the review! |
|
updated from 9c896134b12f012d0736742693df4b50c133e506 to 8e34b5ed06f3ca0865b9b7dca6e31f2e95c6f5c8, addressed @jonatack suggestions:
|
|
utACK 833bebd |
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
@jarolrod feel free to pull in the last commit in this branch https://github.com/jonatack/bitcoin/commits/pr21602-suggestions to add unit test coverage for these changes |
A ban expires after its creation. Therefore, for the listbanned RPC, position banned_until after ban_created in help and output.
Add descriptions for the address, ban_created, and banned_until fields.
Add test coverage for the new ban_duration and time_remaining fields. While here, some code improvements.
|
updated from 833bebd to c5c920f, addressed @jonatack suggestions
|
jonatack
left a comment
There was a problem hiding this comment.
Tested ACK c5c920f394891f1d6958913330da564bf24a71a9
|
Updated from c5c920f to d3b0b08 Changes:
|
|
re-ACK d3b0b08 There's a small potential race in the added unit tests. I didn't hit while running the test, even with valgrind to slow it down, but maybe something like this would provide a margin: @@ -277,6 +277,7 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("setban 127.0.0.0/24 add 200")));
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned")));
+ const int64_t now{GetTime()};
ar = r.get_array();
o1 = ar[0].get_obj();
adr = find_value(o1, "address");
@@ -284,12 +285,13 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
const int64_t ban_created{find_value(o1, "ban_created").get_int64()};
const int64_t ban_duration{find_value(o1, "ban_duration").get_int64()};
const int64_t time_remaining{find_value(o1, "time_remaining").get_int64()};
- const int64_t now{GetTime()};
BOOST_CHECK_EQUAL(adr.get_str(), "127.0.0.0/24");
BOOST_CHECK(banned_until > now);
BOOST_CHECK(banned_until - now <= 200);
- BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created);
- BOOST_CHECK_EQUAL(time_remaining, banned_until - now);
+ BOOST_CHECK(ban_duration >= banned_until - ban_created - 1);
+ BOOST_CHECK(ban_duration <= banned_until - ban_created + 1);
+ BOOST_CHECK(time_remaining >= banned_until - now - 1);
+ BOOST_CHECK(time_remaining <= banned_until - now + 1); |
|
Concept ACK on:
|
hebasto
left a comment
There was a problem hiding this comment.
Approach ACK d3b0b08.
I found this helpful in adding additional context columns to the GUI
bantablemodelas part of a follow-up PR.
It seems, that adding additional time-related fields to the "Banned peers" table in the GUI does not depend on this PR :)
|
|
||
| banmap_t banMap; | ||
| node.banman->GetBanned(banMap); | ||
| const int64_t current_time{GetTime()}; |
There was a problem hiding this comment.
Lines 40 to 44 in dd01dc6
| const int64_t current_time{GetTime()}; | |
| const int64_t current_time{GetSystemTimeInSeconds()}; |
There was a problem hiding this comment.
banman uses GetTime() (mockable), so mixing non-mockable and mockable should be avoided
There was a problem hiding this comment.
So it should be GetTime<std::chrono::seconds>?
There was a problem hiding this comment.
I guess so, but that refactor should also be done for nCreateTime, banman, ...
maflcko
left a comment
There was a problem hiding this comment.
review ACK d3b0b08 🕙
Show signature and timestamp
Signature:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
review ACK d3b0b08b0f04d2f1dbebbafd7ab0384dfe045dec 🕙
-----BEGIN PGP SIGNATURE-----
iQGzBAEBCgAdFiEE+rVPoUahrI9sLGYTzit1aX5ppUgFAlwqrYAACgkQzit1aX5p
pUgCnQv+Pt8SJP4wssUe0R41DmjzJ0d0nEqEiWA38vaipjeD6zNgy5yBhuOmtsm/
vdlSvsOogPjoXM7nrCEaODFRdM8Sj9cfFtPi94U6dmU8lIv92urpREeUm92Zf1PI
2z0mMJwktzszLVK1t3p6Qh90iV3RDy/OE/kkKYOjs41wLMtt1akHchkGVVMuA6P9
w3L8rVoG/6dlWsWd9H9bWvJ/0QEm12zK9hlHZONGBCHC4NmM/QEYLFqULmsAVmuw
7h9XysqcQVCVTFcUD4Qk7y2WOM3vtW3OI2N+DzLK9tOcYvJ0LlGByNe5RSGnLzgl
wewt7k2piUr8qSQNKIvCSIFoy3K3BuVAGWpvFmMgR6tEidhrMhMxFc+rCcvPQbDI
gHypLP4J3DwU55PQ/vAO4IpsSudiVmgUbO9gkrZCJ5r9qMTgJhWtN7epkTgcVLUn
aXbS1eLlMrEcnRt1VdLc42VOo4P755/lNg/QmZcQTub3Z46KxhOhf+gSTOut3KL6
3lJzmjRC
=qw8I
-----END PGP SIGNATURE-----
Timestamp of file with hash 4d1380dd6579b539625e1fcb8f85f0b5ec4b795d7be43d7e91a24d790b488c20 -
|
(edited OP to remove |
| BOOST_CHECK(banned_until > now); | ||
| BOOST_CHECK(banned_until - now <= 200); | ||
| BOOST_CHECK_EQUAL(ban_duration, banned_until - ban_created); | ||
| BOOST_CHECK_EQUAL(time_remaining, banned_until - now); |
There was a problem hiding this comment.
this may fail:
Running 1 test case...
test/rpc_tests.cpp(293): error: in "rpc_tests/rpc_ban": check time_remaining == banned_until - now has failed [200 != 199]
*** 1 failure is detected in the test module "Bitcoin Core Test Suite"
diff:
diff --git a/src/test/rpc_tests.cpp b/src/test/rpc_tests.cpp
index 3b6faf7bbb..be0d79aa86 100644
--- a/src/test/rpc_tests.cpp
+++ b/src/test/rpc_tests.cpp
@@ -277,6 +277,7 @@ BOOST_AUTO_TEST_CASE(rpc_ban)
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("setban 127.0.0.0/24 add 200")));
BOOST_CHECK_NO_THROW(r = CallRPC(std::string("listbanned")));
+ std::this_thread::sleep_for(std::chrono::milliseconds(1100)); // CPU scheduler puts this thread to sleep
ar = r.get_array();
o1 = ar[0].get_obj();
adr = find_value(o1, "address");Can be fixed by using mocktime (SetTime()), or by relaxing the test.
Also, the whole test can be moved to the functional test suite. For example, ./test/functional/rpc_setban.py
…_tests fa40d6a test: Reset mocktime in the common setup (MarcoFalke) fa78590 test: Use mocktime to avoid intermittent failure (MarcoFalke) Pull request description: See #21602 (comment) ACKs for top commit: jonatack: Code review ACK fa40d6a jarolrod: ACK fa40d6a Tree-SHA512: 4967e006f3d2c4eb92f03c9086a6abe3190ad54755d251c30d20422c574bb1a154c06f3d5bcb0d4deaa3c4abfd3864d743b71d84897edd358e829bb42233ad12
A ban expires after its creation. Therefore, for the listbanned RPC, position banned_until after ban_created in help and output. Github-Pull: bitcoin#21602 Rebased-From: dd3c8ea
Add descriptions for the address, ban_created, and banned_until fields. Github-Pull: bitcoin#21602 Rebased-From: c95c616
Github-Pull: bitcoin#21602 Rebased-From: 5456b34
Github-Pull: bitcoin#21602 Rebased-From: 3e978d1
Add test coverage for the new ban_duration and time_remaining fields. While here, some code improvements. Github-Pull: bitcoin#21602 Rebased-From: 60290d3
New ban table columns that incorporate: bitcoin/bitcoin#21602 New columns: IP/Netmask, Ban creation time, Ban Until time, Duration of Ban, time remaining for node to unban
New ban table columns that incorporate: bitcoin/bitcoin#21602 New columns: IP/Netmask, Ban creation time, Ban Until time, Duration of Ban, time remaining for node to unban
New ban table columns that incorporate: bitcoin/bitcoin#21602 New columns: IP/Netmask, Ban creation time, Ban Until time, Duration of Ban, time remaining for node to unban
New ban table columns that incorporate: bitcoin/bitcoin#21602 New columns: IP/Netmask, Ban creation time, Ban Until time, Duration of Ban, time remaining for node to unban
New ban table columns that incorporate: bitcoin/bitcoin#21602 New columns: IP/Netmask, Ban creation time, Ban Until time, Duration of Ban, time remaining for node to unban
New ban table columns that incorporate: bitcoin/bitcoin#21602 New columns: IP/Netmask, Ban creation time, Ban Until time, Duration of Ban, time remaining for node to unban
…ng ban da349f1 test: check ban_duration and time_remaining after setting ban (brunoerg) Pull request description: This PR adds functional test coverage for `ban_duration` and `time_remaining` introduced in #21602 ACKs for top commit: shaavan: ACK da349f1 theStack: Tested ACK da349f1 Tree-SHA512: 51e63f3a36adb1c81e4d49426486af2cd9c8c4319f94e06a47fa7da8100a8b53c029d28d4a4771bdbf4e0a2bfb4ddd3740b9974bd08d8ff06f2a0fc2b6d8a6b5
This PR adds a
ban_durationandtime_remainingfield to thelistbannedRPC command. Thanks to jonatack, this PR also expands thelistbannedtest coverage to include these new fieldsIt's useful to keep track of
ban_durationas this is another data point on which to sort banned peers. I found this helpful in adding additional context columns to the GUIbantablemodelas part of a follow-up PR. As suggested by jonatack,time_remainingis another useful user-centric data point.Since a ban always expires after its created, the
ban_createdfield is now placed before thebanned_untilfield. This new ordering is more logical.This PR also improves the
help listbannedoutput by providing additional context to the descriptions of theaddress,ban_created, andbanned_untilfields.Master: listbanned
PR: listbanned