Skip to content

Conversation

jonatack
Copy link
Member

@jonatack jonatack commented Oct 15, 2020

Change Announcement::m_state in tx_request.cpp from type State to uint8_t and add a getter and setter for the conversion to/from State. This should silence these travis ci gcc compiler warnings:

txrequest.cpp:73:21: warning: ‘{anonymous}::Announcement::m_state’ is
too small to hold all values of ‘enum class {anonymous}::State’
     State m_state : 3;
                     ^

The gcc warnings are based on the maximum value held by the underlying uint8_t enumerator type, even though the intention of the bitfield declaration is the maximum declared enumerator value. They have apparently been silenced in gcc 8.4+ and 9.3+ according to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414.

@sipa
Copy link
Member

sipa commented Oct 15, 2020

If you increase the size of m_state, please also decrease the size of m_sequence (54 bits is still plenty!), otherwise the memory usage of an Announcement object will increase by 16 bytes.

An alternative is changing the type to uint8_t, and having a getter/setter on Announcement to convert/from to State.

@ajtowns
Copy link
Contributor

ajtowns commented Oct 15, 2020

Needs to shrink m_sequence by 5 bits to keep the overall data structure size the same.

The original solution was making m_state be a uint8_t : 3 and having a getter and setter that did the conversion to/from State rather than accessing it directly. I think that's better than shrinking the sequence by 5 bits, but don't have an opinion between doing the getter/setter and spurious warning in older versions of gcc. (EDIT: sequence not priority, duh)

@sipa
Copy link
Member

sipa commented Oct 15, 2020

@ajtowns Priority isn't stored anywhere, it's computed on the fly. But sequence can be shrunk with no downside really.

@jonatack jonatack force-pushed the bitfield-too-small-warning branch from fa1cf39 to 0f298a2 Compare October 15, 2020 23:48
@jonatack
Copy link
Member Author

Thanks -- adjusted m_sequence accordingly. It's late so will re-look at this tomorrow.

@jonatack jonatack force-pushed the bitfield-too-small-warning branch 2 times, most recently from 0bd2602 to 39cb2ba Compare October 16, 2020 21:01
@jonatack
Copy link
Member Author

Previous commit 0bd2602 added 5 bits to m_state and removed 5 from m_sequence.

Current commit 39cb2ba follows your suggestions to do uint8_t m_state : 3 with a getter and setter.

to silence these Travis CI GCC compiler warnings:

txrequest.cpp:73:21: warning: ‘{anonymous}::Announcement::m_state’ is
too small to hold all values of ‘enum class {anonymous}::State’
     State m_state : 3;
                     ^
The warnings are based on the maximum value held by the underlying uint8_t
enumerator type, though the intention of the bitfield declaration is the
maximum declared enumerator value.

The warning been silenced in GCC 8.4+ and 9.3+ according to
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414
@jonatack jonatack force-pushed the bitfield-too-small-warning branch from 39cb2ba to c8abbc9 Compare October 16, 2020 21:36
@jonatack jonatack changed the title p2p, compiler warnings: specify Announcement::m_state bitfield to be 8 bits p2p: declare Announcement::m_state as uint8_t, add getter/setter Oct 16, 2020
@sipa
Copy link
Member

sipa commented Oct 16, 2020

utACK c8abbc9

@DrahtBot DrahtBot added the P2P label Oct 16, 2020
@ajtowns
Copy link
Contributor

ajtowns commented Oct 17, 2020

ACK c8abbc9 -- quick code review

Copy link
Member

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

ACK c8abbc9, tested on Bionic (x86_64, gcc 7.5.0):

$ make clean && make > /dev/null
txrequest.cpp:73:21: warning: ‘{anonymous}::Announcement::m_state’ is too small to hold all values of ‘enum class {anonymous}::State’
     State m_state : 3;
                     ^
$ make clean && make > /dev/null
# no warnings :)

I verified that the following statements did not changed:

  • sizeof(Announcement) == size_t(56)
  • alignof(Announcement) == size_t(8)

@maflcko maflcko merged commit 4538501 into bitcoin:master Oct 19, 2020
@jonatack jonatack deleted the bitfield-too-small-warning branch October 19, 2020 11:47
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Oct 19, 2020
…dd getter/setter

c8abbc9 p2p: declare Announcement::m_state as uint8_t, add getter/setter (Jon Atack)

Pull request description:

  Change `Announcement::m_state` in `tx_request.cpp` from type `State` to `uint8_t` and add a getter and setter for the conversion to/from `State`. This should silence these travis ci gcc compiler warnings:

  ```
  txrequest.cpp:73:21: warning: ‘{anonymous}::Announcement::m_state’ is
  too small to hold all values of ‘enum class {anonymous}::State’
       State m_state : 3;
                       ^
  ```

  The gcc warnings are based on the maximum value held by the underlying uint8_t enumerator type, even though the intention of the bitfield declaration is the maximum declared enumerator value. They have apparently been silenced in gcc 8.4+ and 9.3+ according to https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61414.

ACKs for top commit:
  sipa:
    utACK c8abbc9
  ajtowns:
    ACK c8abbc9 -- quick code review
  hebasto:
    ACK c8abbc9, tested on Bionic (x86_64, gcc 7.5.0):

Tree-SHA512: 026721dd7a78983a72da77638d3327d2b252bef804e489278a852f000046c028d6557bbd6c2b4cea391d4e01f9264a1be842d502047cb90b2997cc37bee59e61
maflcko pushed a commit to maflcko/bitcoin-core that referenced this pull request Dec 4, 2020
…ocument exceptions

2f6fe4e ci: Build with --enable-werror by default, and document exceptions (Hennadii Stepanov)

Pull request description:

  This PR prevents introducing of new compiler warnings in the master branch, e.g., bitcoin#19986, bitcoin#20162.

ACKs for top commit:
  practicalswift:
    cr ACK 2f6fe4e: patch looks correct
  MarcoFalke:
    re-ACK 2f6fe4e 🏏
  vasild:
    ACK 2f6fe4e

Tree-SHA512: 23b5feb5bc472658c992d882ef61af23496f25adaa19f9c79bfaef5d2db273d44981aa93b1631a7d37cb58755283c1dacf3f2d68e501522d3fa8c965ab646d19
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 20, 2021
Summary:
```
This adds a new module (unused for now) which defines TxRequestTracker,
a data structure that maintains all information about transaction
requests, and coordinates requests.
```

Partial backport of [[bitcoin/bitcoin#19988 | core#19988]]:
bitcoin/bitcoin@da3b8fd#diff-e3e574cb6dabe01b6149f9d121fc7e286abb49c04442a0a816977ef2a4103ed8

This also includes a GCC workaround that would cause the build to fail:
Partial backport of [[bitcoin/bitcoin#20162 | core#20162]]. This backport will be completed as
PR19988 is ported because it impacts the code from other commits.

Since this is a lot of changes the tests are done in separate diffs (as
per the PR commits). For now the code is not used so this is safe.

Test Plan:
  ninja

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Subscribers: majcosta

Differential Revision: https://reviews.bitcoinabc.org/D9547
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request May 20, 2021
Summary:
```
Add unit tests for TxRequestTracker. Several scenarios are tested,
randomly interleaved with eachother.

Includes a test by Antoine Riard (ariard).
```

Partial backport of [[bitcoin/bitcoin#19988 | core#19988]]:
bitcoin/bitcoin@3c7fe0e

Partial backport of [[bitcoin/bitcoin#20162 | core#20162]].

Depends on D9547.

Test Plan:
  ninja check

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Subscribers: PiRK

Differential Revision: https://reviews.bitcoinabc.org/D9548
@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.

6 participants