Skip to content

Conversation

adaminsky
Copy link
Contributor

This addresses an issue brought up in #19587.

Currently, the target_confirmations parameter to listsinceblock is not checked for being too large. When target_confirmations is greater than one more than the current number of blocks, listsinceblock fails with error code -1. In comparison, when target_confirmations is less than 1, a -8 "Invalid parameter" error code is thrown.

This PR fixes the issue by returning a -8 "Invalid parameter" error if the target_confirmations value corresponds to a block with more confirmations than the genesis block. This happens if target_confirmations exceeds one more than the number of blocks.

@luke-jr
Copy link
Member

luke-jr commented Aug 11, 2020

I think technically -1 is correct?

@adaminsky
Copy link
Contributor Author

The -1 is from a CHECK_NONFATAL so the error says an internal bug is detected. I was thinking that the -8 error is more helpful since it is consistent with the result when target_confirmations = 0.

@luke-jr
Copy link
Member

luke-jr commented Aug 11, 2020

But target_confirmations 0 is in fact an invalid parameter. A too-large height just doesn't yield a useful result yet.

@adaminsky
Copy link
Contributor Author

Yeah, so I guess the problem mentioned in the issue has been fixed by returning a -1 error. Maybe giving the genesis block hash when target_confirmations is too large makes sense.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK 88ce8c9. Simple fix and nice new tests.

I think returning genesis block hash in this case as suggested would be an improvement, and maybe invalid parameter error code doesn't give enough hope for the future, but either way new behavior is probably better than returning invalid 0 hash.

@adaminsky
Copy link
Contributor Author

@ryanofsky thank you for the review. My commit message is actually incorrect because the problem with the 0 hash was already fixed from when it was reported by returning the -1 error. I'll update this to return genesis block hash instead.

Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK c0e57fe. Thanks for the fix and updates! Suggest squashing commits

Previously, listsinceblock would fail with error code -1 when the
target_confirmations exceeded the number of confirmations of the genesis
block. This commit allows target_confirmations to refer to a lastblock
hash with more confirmations than exist in the chain by setting the
lastblock hash to the genesis hash in this case. This allows for
`listsinceblock "" 6` to not fail if the block count is less than 5
which may happen on regtest.

Includes update to the functional test for listsinceblock to test for
this case.
Copy link
Contributor

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK c133cdc. Just suggested changes since last review. Thanks!

@laanwj
Copy link
Member

laanwj commented Aug 13, 2020

Code review ACK c133cdc
Test looks good too.

@laanwj laanwj merged commit 6757b3a into bitcoin:master Aug 13, 2020
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Sep 8, 2021
Summary:
Previously, listsinceblock would fail with error code -1 when the
target_confirmations exceeded the number of confirmations of the genesis
block. This commit allows target_confirmations to refer to a lastblock
hash with more confirmations than exist in the chain by setting the
lastblock hash to the genesis hash in this case. This allows for
`listsinceblock "" 6` to not fail if the block count is less than 5
which may happen on regtest.

Includes update to the functional test for listsinceblock to test for
this case.

This is a backport of [[bitcoin/bitcoin#19655 | core#19655]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D10073
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Feb 15, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants