Skip to content

Conversation

@brunoerg
Copy link
Contributor

@brunoerg brunoerg commented Jan 5, 2023

We shouldn't allow call setban with past absolute timestamp. First, because doesn't make sense to ban a node until ~ past ~. Besides that, it could make an unnecessary write to the DB since BanMan::Ban calls DumpBanlist and it calls SweepBanned which will remove this new ban (because of the timestamp) of the array.

@DrahtBot
Copy link
Contributor

DrahtBot commented Jan 5, 2023

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

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK 1440000bytes
Concept ACK andrewtoth

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #19825 (rpc: simpler setban and new ban manipulation commands by dhruv)

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.

Copy link
Contributor

@andrewtoth andrewtoth 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
Banning with an absolute timestamp in the past is surely a user error, so it should not just fail to ban silently.

Perhaps out of scope of this PR but I see there is a rpc_setban.py functional test file that largely overlaps with p2p_disconnect_ban.py. Should they be merged into a single file?

Copy link

@ghost ghost 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

@brunoerg
Copy link
Contributor Author

brunoerg commented Jan 6, 2023

Thanks @andrewtoth and @1440000bytes. Force-pushed addressing #26822 (comment) and #26822 (comment)

@brunoerg
Copy link
Contributor Author

brunoerg commented Jan 6, 2023

Perhaps out of scope of this PR but I see there is a rpc_setban.py functional test file that largely overlaps with p2p_disconnect_ban.py. Should they be merged into a single file?

I think so, specially part of them are testing same thing (e.g. the persistence across node restart).

Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

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

What is the point of adding this check if relative times still accept -1?

@brunoerg
Copy link
Contributor Author

brunoerg commented Jan 6, 2023

What is the point of adding this check if relative times still accept -1?

I think both accepts -1 but sets the ban to the default time (86400), it's the behavior of the BanMan::Ban, not sure why:

bitcoin/src/banman.cpp

Lines 134 to 137 in 911a40e

if (ban_time_offset <= 0) {
normalized_ban_time_offset = m_default_ban_time;
normalized_since_unix_epoch = false;
}

However, there is no check for past absolute timestamp, and I think it's more appropriate throws an error than setting the ban to the default time (if it would be an option). Maybe the RPC should not accept negative values for any time (relative or absolute).

@brunoerg brunoerg force-pushed the 2023-01-fix-ban-time branch from ff52aaf to abccb27 Compare January 6, 2023 16:34
Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

ACK abccb27

@andrewtoth
Copy link
Contributor

What is the point of adding this check if relative times still accept -1?

A relative time of -1 will still ban the peer for the default time, so it will succeed. Banning with an absolute time in the past will not ban the peer, so it will fail silently.

maflcko pushed a commit to bitcoin-core/gui that referenced this pull request Jan 9, 2023
…stamp in `setban`

abccb27 test: add coverage for absolute timestamp in `setban` (brunoerg)
b99f1f2 p2p, rpc: don't allow past absolute timestamp in `setban` (brunoerg)

Pull request description:

  We shouldn't allow call `setban` with past absolute timestamp. First, because doesn't make sense to ban a node until ~ past ~. Besides that, it could make an unnecessary write to the DB since `BanMan::Ban` calls `DumpBanlist` and it calls `SweepBanned` which will remove this new ban (because of the timestamp) of the array.

ACKs for top commit:
  1440000bytes:
    ACK bitcoin/bitcoin@abccb27

Tree-SHA512: 6d0cadf99fc4f78d77d3bafd6f5c85ac56e243ebc376210fdb2bee751e7b139ec7d6f5f346317fd0b10051b685f2d0ee1d8e40f4bc10f4dbdbbddd5e1ee84de5
@maflcko maflcko closed this Jan 9, 2023
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 9, 2023
… `setban`

abccb27 test: add coverage for absolute timestamp in `setban` (brunoerg)
b99f1f2 p2p, rpc: don't allow past absolute timestamp in `setban` (brunoerg)

Pull request description:

  We shouldn't allow call `setban` with past absolute timestamp. First, because doesn't make sense to ban a node until ~ past ~. Besides that, it could make an unnecessary write to the DB since `BanMan::Ban` calls `DumpBanlist` and it calls `SweepBanned` which will remove this new ban (because of the timestamp) of the array.

ACKs for top commit:
  1440000bytes:
    ACK bitcoin@abccb27

Tree-SHA512: 6d0cadf99fc4f78d77d3bafd6f5c85ac56e243ebc376210fdb2bee751e7b139ec7d6f5f346317fd0b10051b685f2d0ee1d8e40f4bc10f4dbdbbddd5e1ee84de5
@bitcoin bitcoin locked and limited conversation to collaborators Jan 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants