Skip to content

Conversation

@maflcko
Copy link
Member

@maflcko maflcko commented Oct 12, 2023

See commit messages

MarcoFalke added 2 commits October 12, 2023 11:14
Also, remove wrong nChainTx comment and cast.
Also, fix a bug in an assert_debug_log call.
@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 12, 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, theStack

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

@DrahtBot DrahtBot changed the title refactor: Remove unused nchaintx from SnapshotMetadata constructor, fix test, add test refactor: Remove unused nchaintx from SnapshotMetadata constructor, fix test, add test Oct 12, 2023
// Cast required because univalue doesn't have serialization specified for
// `unsigned int`, nChainTx's type.
result.pushKV("nchaintx", uint64_t{tip->nChainTx});
result.pushKV("nchaintx", tip->nChainTx);
Copy link
Member

Choose a reason for hiding this comment

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

faa90f6: was this always wrong or is there some recent change to UniValue?

Copy link
Member Author

Choose a reason for hiding this comment

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


expected_log = f"assumeutxo height in snapshot metadata not recognized ({bad_snapshot_height}) - refusing to load snapshot"
with self.nodes[1].assert_debug_log(expected_log):
with self.nodes[1].assert_debug_log([expected_log]):
Copy link
Member

Choose a reason for hiding this comment

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

fafde92: I verified this test indeed would pass regardless of expected_log. Wen type safety?

@Sjors
Copy link
Member

Sjors commented Oct 12, 2023

utACK fafde92

Copy link
Contributor

@theStack theStack left a comment

Choose a reason for hiding this comment

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

ACK fafde92

Thanks for fixing the sneaky assert_debug_log bug.

assert_raises_rpc_error(-32603, "Unable to load UTXO snapshot", self.nodes[1].loadtxoutset, bad_snapshot_path)

self.log.info(" - snapshot file with wrong number of coins")
valid_num_coins = struct.unpack("<I", valid_snapshot_contents[32:32 + 4])[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could do the same without the struct module by using int.from_bytes (and int.to_bytes below):

Suggested change
valid_num_coins = struct.unpack("<I", valid_snapshot_contents[32:32 + 4])[0]
valid_num_coins = int.from_bytes(valid_snapshot_contents[32:32 + 4], 'little')

(mostly a matter of taste I guess though)

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, will do in a follow-up

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, 4 bytes is wrong. The count is u64, which is closer to 8 bytes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed both in #28647

@achow101 achow101 added this to the 26.0 milestone Oct 12, 2023
@fanquake fanquake requested a review from jamesob October 12, 2023 15:43
@maflcko maflcko modified the milestone: 26.0 Oct 12, 2023
@fanquake fanquake merged commit 448790c into bitcoin:master Oct 13, 2023
@maflcko maflcko deleted the 2310-au-test- branch October 13, 2023 09:16
achow101 added a commit to bitcoin-core/gui that referenced this pull request Oct 13, 2023
…ugs, add type checks

ac4caf3 test: fix `assert_debug_log` call-site bugs, add type checks (Sebastian Falbesoner)

Pull request description:

  Two recently added tests (PR #28625 / commit 2e31250 and PR #28634 / commit 3bb51c2) introduced bugs by wrongly using the `assert_debug_log` helper:

  https://github.com/bitcoin/bitcoin/blob/5ea4fc05edde66c5c90383bc054590dfbdb2b645/test/functional/feature_assumeutxo.py#L84-L85 (already fixed in bitcoin/bitcoin#28639)

  https://github.com/bitcoin/bitcoin/blob/5ea4fc05edde66c5c90383bc054590dfbdb2b645/test/functional/p2p_v2_transport.py#L148
  https://github.com/bitcoin/bitcoin/blob/5ea4fc05edde66c5c90383bc054590dfbdb2b645/test/functional/p2p_v2_transport.py#L159

  Instead of passing the expected debug string in a list as expected, it was passed as bare string, which is then interpretered as a list of characters, very likely leading the debug log assertion pass even if the intended message is not appearing. Thanks to maflcko for discovering: bitcoin/bitcoin#28625 (comment)

  In order to avoid bugs like this in the future, enforce that the `{un}expected_msgs` parameters are lists, as discussed in bitcoin/bitcoin#28625 (comment). Using mypy might be an alternative, but I guess it takes quite a bit of effort to properly integrate this into CI for the whole functional test suite (including taking care of false-positives), so I decided to go with the simpler "manual asserts" hack. Suggestions are very welcome of course.

ACKs for top commit:
  achow101:
    ACK ac4caf3
  maflcko:
    lgtm ACK ac4caf3
  dergoegge:
    ACK ac4caf3

Tree-SHA512: a9677af76a0c370e71f0411339807b1dc6b2a81763db4ec049cd6d766404b916e2bdd002883db5a79c9c388d7d8ebfcbd5f31d43d50be868eeb928e3c906a746
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Oct 13, 2023
…tadata constructor, fix test, add test

fafde92 test: Check snapshot file with wrong number of coins (MarcoFalke)
faa90f6 refactor: Remove unused nchaintx from SnapshotMetadata constructor (MarcoFalke)

Pull request description:

  See commit messages

ACKs for top commit:
  Sjors:
    utACK fafde92
  theStack:
    ACK fafde92

Tree-SHA512: 9ed2720b50d1c0938f30543ba143e1a4c6af3a0ff166f8b3eb452e1d99ddee6e3443a4c99f77efe94b8c3eb2feff984bf5259807ee8085e1e0e1e0d1de98227e
Frank-GER pushed a commit to syscoin/syscoin that referenced this pull request Oct 21, 2023
… type checks

ac4caf3 test: fix `assert_debug_log` call-site bugs, add type checks (Sebastian Falbesoner)

Pull request description:

  Two recently added tests (PR bitcoin#28625 / commit 2e31250 and PR bitcoin#28634 / commit 3bb51c2) introduced bugs by wrongly using the `assert_debug_log` helper:

  https://github.com/bitcoin/bitcoin/blob/5ea4fc05edde66c5c90383bc054590dfbdb2b645/test/functional/feature_assumeutxo.py#L84-L85 (already fixed in bitcoin#28639)

  https://github.com/bitcoin/bitcoin/blob/5ea4fc05edde66c5c90383bc054590dfbdb2b645/test/functional/p2p_v2_transport.py#L148
  https://github.com/bitcoin/bitcoin/blob/5ea4fc05edde66c5c90383bc054590dfbdb2b645/test/functional/p2p_v2_transport.py#L159

  Instead of passing the expected debug string in a list as expected, it was passed as bare string, which is then interpretered as a list of characters, very likely leading the debug log assertion pass even if the intended message is not appearing. Thanks to maflcko for discovering: bitcoin#28625 (comment)

  In order to avoid bugs like this in the future, enforce that the `{un}expected_msgs` parameters are lists, as discussed in bitcoin#28625 (comment). Using mypy might be an alternative, but I guess it takes quite a bit of effort to properly integrate this into CI for the whole functional test suite (including taking care of false-positives), so I decided to go with the simpler "manual asserts" hack. Suggestions are very welcome of course.

ACKs for top commit:
  achow101:
    ACK ac4caf3
  maflcko:
    lgtm ACK ac4caf3
  dergoegge:
    ACK ac4caf3

Tree-SHA512: a9677af76a0c370e71f0411339807b1dc6b2a81763db4ec049cd6d766404b916e2bdd002883db5a79c9c388d7d8ebfcbd5f31d43d50be868eeb928e3c906a746
@bitcoin bitcoin locked and limited conversation to collaborators Oct 12, 2024
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.

6 participants