Skip to content

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Feb 10, 2022

Before this patch, when writing a negative lowest_compatible value, it would be read as a positive value. For example -32 will be read as 224. There is generally nothing wrong with that. Though, similarly there shouldn't be anything wrong with refusing to read a negative value. I find the code after this patch more logical than before. Also, this allows dropping a file-wide sanitizer suppression.

In practice none of this should ever happen. Bitcoin Core would never write a negative lowest_compatible in normal operation, unless the file storage is later corrupted by external influence.

@DrahtBot
Copy link
Contributor

DrahtBot commented Feb 11, 2022

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

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #23962 (Use int32_t type for transaction size/weight consistently by hebasto)

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.

@maflcko maflcko force-pushed the 2202-logNeg branch 2 times, most recently from fa943a0 to fac3277 Compare February 11, 2022 18:31
@maflcko maflcko changed the title addrman: Log negative lowest_compatible addrman: Log too low compat value Feb 11, 2022
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.

Code Review ACK fac3277

I wish we had a hidden RPC for:

write_addrman(peers_dat, lowest_compatible=-32)

@maflcko
Copy link
Member Author

maflcko commented Feb 12, 2022

I wish we had a hidden RPC for:

I wish we don't. Generally I am not a fan of baking test code into the production system, unless there is a need for it.

Copy link
Contributor

@shaavan shaavan left a comment

Choose a reason for hiding this comment

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

ACK fac3277

Changes since my last review:

  • Instead of changing the type of lowest_compatible from unsigned to signed integer, a condition statement has been added, which removes the need for signed lowest_compatible.

I think the wording of added failure message is correct and adequate. I experimented with several different values of the lowest_compatible argument in the test, and each time the error message remained logical and consistent, with changing values of compat.

Note:
The test failed with lowest_compatible=-33, as this would make compat=-1, which is out of range, but I don't think this condition would ever arise in real-life situations.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

Is the first commit test: Remove no longer needed suppressions related to the low compat issue? The commit message does not explain why the suppressions are no longer needed.

@vasild
Copy link
Contributor

vasild commented Feb 14, 2022

The test failed with lowest_compatible=-33, as this would make compat=-1, which is out of range, but I don't think this condition would ever arise in real-life situations.

The test fails with struct.error: ubyte format requires 0 <= number <= 255 because the python test code refuses to write -1 with the B format (see https://docs.python.org/3/library/struct.html) to disk. The addrman deserialization is not even invoked in this case.

@maflcko
Copy link
Member Author

maflcko commented Feb 14, 2022

A compat value of -1 doesn't exist. compat is unsigned in both Bitcoin Core and the python mock.

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK faaa6c2

What about #24312 (review)?

@fanquake fanquake requested a review from mzumsande February 23, 2022 16:21
Copy link
Contributor

@mzumsande mzumsande 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 faaa6c2 - also did some light testing.

@mzumsande
Copy link
Contributor

ACK fa0fb76

Only change: Rewording of the error message

Also remove uint8_t{} casts from values that are already of the same
type.
@mzumsande
Copy link
Contributor

re-ACK fa097d0

Copy link
Contributor

@vasild vasild left a comment

Choose a reason for hiding this comment

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

ACK fa097d0

Even better wording, thanks @mzumsande!

@bitcoin bitcoin deleted a comment Mar 8, 2022
@maflcko maflcko merged commit b07fdd7 into bitcoin:master Mar 8, 2022
@maflcko maflcko deleted the 2202-logNeg branch March 8, 2022 15:50
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Mar 8, 2022
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Oct 21, 2022
Summary:
```
Also remove uint8_t{} casts from values that are already of the same type.
```

Backport of [[bitcoin/bitcoin#24312 | core#24312]].

Depends on D12348.

Test Plan:
  ninja all check-all

Reviewers: #bitcoin_abc, PiRK

Reviewed By: #bitcoin_abc, PiRK

Differential Revision: https://reviews.bitcoinabc.org/D12349
@bitcoin bitcoin locked and limited conversation to collaborators Mar 8, 2023
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