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

bugfix: throw an error if an invalid parameter is passed to getnetworkhashps RPC #28554

Merged
merged 1 commit into from Nov 28, 2023

Conversation

jlopp
Copy link
Contributor

@jlopp jlopp commented Sep 30, 2023

When writing some scripts that iterated over many blocks to generate hashrate estimates I realized that my script was going out of range of the current chain tip height but was not encountering any errors.

I believe that passing an invalid block height to this function but receiving the hashrate estimate for the chain tip instead should be considered unexpected behavior.

@DrahtBot
Copy link
Contributor

DrahtBot commented Sep 30, 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 Sjors, kevkevinpal, achow101
Concept ACK luke-jr
Stale ACK maflcko

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.

@jlopp jlopp changed the title throw an error if an invalid block height is passed to getnetworkhashps RPC endpoint bugfix: throw an error if an invalid block height is passed to getnetworkhashps RPC Sep 30, 2023
Copy link
Contributor

@kevkevinpal kevkevinpal left a comment

Choose a reason for hiding this comment

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

ACK 057b3e0

test/functional/rpc_blockchain.py Outdated Show resolved Hide resolved
@jlopp jlopp force-pushed the getnetworkhashps_height_validation branch from 057b3e0 to 6074de6 Compare September 30, 2023 20:17
@kevkevinpal
Copy link
Contributor

reACK 6074de6

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.

Seems fine to do this. Not sure if a release note is needed, because strictly speaking this could be a breaking change.

src/rpc/mining.cpp Outdated Show resolved Hide resolved
test/functional/rpc_blockchain.py Outdated Show resolved Hide resolved
@kevkevinpal
Copy link
Contributor

I would prefer 6074de6 and 786ba64 be squashed together in one commit

@jlopp jlopp force-pushed the getnetworkhashps_height_validation branch from 786ba64 to 1fd3715 Compare October 2, 2023 18:03
Copy link
Member

@luke-jr luke-jr left a comment

Choose a reason for hiding this comment

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

utACK

nit: Remove pb == nullptr check below, as it is no longer possible.

@kevkevinpal
Copy link
Contributor

reACK 1fd3715

@DrahtBot DrahtBot removed the request for review from kevkevinpal October 3, 2023 05:53
@maflcko
Copy link
Member

maflcko commented Oct 3, 2023

lgtm ACK 1fd3715

@DrahtBot DrahtBot removed the request for review from maflcko October 3, 2023 07:55
@jlopp jlopp force-pushed the getnetworkhashps_height_validation branch from 1fd3715 to ec54efd Compare October 3, 2023 12:53
@jlopp
Copy link
Contributor Author

jlopp commented Oct 3, 2023

Upon further inspection I realized that the "lookup" nblocks parameter also had insufficient validation so I've added checks to ensure that it's either a positive number or -1.

@jlopp jlopp changed the title bugfix: throw an error if an invalid block height is passed to getnetworkhashps RPC bugfix: throw an error if an invalid parameter is passed to getnetworkhashps RPC Oct 3, 2023
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.

not sure about the last change

src/rpc/mining.cpp Outdated Show resolved Hide resolved
@jlopp jlopp force-pushed the getnetworkhashps_height_validation branch 3 times, most recently from 7198be5 to 565ad11 Compare October 3, 2023 15:43
@jlopp jlopp requested a review from maflcko October 3, 2023 15:45
src/rpc/mining.cpp Outdated Show resolved Hide resolved
@jlopp jlopp force-pushed the getnetworkhashps_height_validation branch from 565ad11 to 435ff29 Compare October 3, 2023 19:37
@jlopp jlopp requested a review from luke-jr October 4, 2023 11:22
@jlopp
Copy link
Contributor Author

jlopp commented Oct 4, 2023

Not sure what's going on with the windows build; it failed on a wallet address test with a socket timeout. Seems unrelated to my PR.

Looks like it's a known issue. #28509

Copy link
Member

@Sjors Sjors left a comment

Choose a reason for hiding this comment

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

Lightly tested ACK 435ff29

@DrahtBot DrahtBot requested review from kevkevinpal and removed request for kevkevinpal October 10, 2023 13:57
@jlopp
Copy link
Contributor Author

jlopp commented Oct 17, 2023

Any further concerns?

@DrahtBot DrahtBot requested review from kevkevinpal and removed request for kevkevinpal October 17, 2023 16:24
luke-jr pushed a commit to bitcoinknots/bitcoin that referenced this pull request Oct 19, 2023
@jlopp jlopp force-pushed the getnetworkhashps_height_validation branch from 435ff29 to 9ac114e Compare November 7, 2023 17:59
@jlopp jlopp requested a review from Sjors November 8, 2023 20:08
@Sjors
Copy link
Member

Sjors commented Nov 9, 2023

Thanks for rebasing.

re-utACK 9ac114e

@DrahtBot DrahtBot requested review from kevkevinpal and removed request for kevkevinpal and Sjors November 9, 2023 01:15
@kevkevinpal
Copy link
Contributor

reACK 9ac114e

@DrahtBot DrahtBot removed the request for review from kevkevinpal November 20, 2023 22:44
@achow101
Copy link
Member

ACK 9ac114e

@achow101 achow101 merged commit 75462b3 into bitcoin:master Nov 28, 2023
16 checks passed
@jlopp jlopp deleted the getnetworkhashps_height_validation branch November 29, 2023 12:37
glozow pushed a commit to glozow/bitcoin that referenced this pull request Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants