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

backport: merge bitcoin#21817, #21966, #21824, #21969, #23653, #23438, #24190, #24253, #24231, #26258, #28012, partial bitcoin#25001, #25296, #23595, #27927 (serialization updates) #5901

Merged
merged 17 commits into from
Feb 28, 2024

Conversation

kwvg
Copy link
Collaborator

@kwvg kwvg commented Feb 23, 2024

Additional Information

  • Dependency for backport: merge bitcoin#27985, #27993, #28008, #28267, #28374, #28100 (p2p primitives) #5902

  • bitcoin#24231 is merged after bitcoin#24253 due to a MinGW bug (comment)

  • bitcoin#25001 is listed as unmerged despite being committed upstream as bitcoin@132d5f8

  • bitcoin#25296 is listed as unmerged despite being committed upstream as bitcoin@79e007d

  • bitcoin#21966 was partially backported in dash#4197 as f946c68, including only 2be4cd9.
    The excluded commits have been backported, marking the pull request as fully merged.

  • bitcoin#23438 was partially backported in dash#5574 as de54b87, including only fa65bbf.
    The excluded commits have been backported, marking the pull request as fully merged.

  • bitcoin#27927 opened a fresh can of hell thanks to being (possibly?) the first pull request to include std::byte BOOST_CHECK's to the unit test suite. For reasons still unbeknownst to me, it refused to compile, despite being perfectly happy when checked-out as a commit directly and built as-is from upstream.

    The compile error was like this (edited for brevity):

      CXX      test/test_dash-serialize_tests.o
    In file included from test/serialize_tests.cpp:13:
    In file included from /src/dash/depends/x86_64-pc-linux-gnu/include/boost/test/unit_test.hpp:18:
    In file included from /src/dash/depends/x86_64-pc-linux-gnu/include/boost/test/test_tools.hpp:46:
    In file included from /src/dash/depends/x86_64-pc-linux-gnu/include/boost/test/tools/old/impl.hpp:24:
    /src/dash/depends/x86_64-pc-linux-gnu/include/boost/test/tools/detail/print_helper.hpp:53:13: error: static assertion failed due to requirement 'boost::has_left_shift<std::basic_ostream<char, std::char_traits<char>>, std::byte, boost::binary_op_detail::dont_care>::value': Type has to implement operator<< to be printable
                BOOST_STATIC_ASSERT_MSG( (boost::has_left_shift<std::ostream,T>::value),
                ^                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    [...]
    <scratch space>:206:1: note: expanded from here
    BOOST_PP_REPEAT_1
    ^
    test/serialize_tests.cpp:347:9: note: in instantiation of function template specialization 'boost::test_tools::tt_detail::check_frwd<boost::test_tools::tt_detail::equal_impl_frwd, std::byte, std::byte>' requested here
            BOOST_CHECK_EQUAL(out.at(0), std::byte{'a'});
            ^
    [...]
    In file included from test/serialize_tests.cpp:13:
    In file included from /src/dash/depends/x86_64-pc-linux-gnu/include/boost/test/unit_test.hpp:18:
    In file included from /src/dash/depends/x86_64-pc-linux-gnu/include/boost/test/test_tools.hpp:46:
    In file included from /src/dash/depends/x86_64-pc-linux-gnu/include/boost/test/tools/old/impl.hpp:24:
    /src/dash/depends/x86_64-pc-linux-gnu/include/boost/test/tools/detail/print_helper.hpp:55:18: error: invalid operands to binary expression ('std::ostream' (aka 'basic_ostream<char>') and 'const std::byte')
                ostr << t;
                ~~~~ ^  ~
    /usr/bin/../lib/gcc/x86_64-linux-gnu/9/../../../../include/c++/9/cstddef:130:5: note: candidate function template not viable: no known conversion from 'std::ostream' (aka 'basic_ostream<char>') to 'byte' for 1st argument
        operator<<(byte __b, _IntegerType __shift) noexcept
        ^
    [...]
    5 warnings and 2 errors generated.
    make[2]: *** [Makefile:17842: test/test_dash-serialize_tests.o] Error 1
    make[2]: *** Waiting for unfinished jobs....
    make[2]: Leaving directory '/src/dash/src'
    make[1]: *** [Makefile:18525: all-recursive] Error 1
    make[1]: Leaving directory '/src/dash/src'
    make: *** [Makefile:802: all-recursive] Error 1
    
    • No such error was present on Bitcoin.

      It is true, that no std::ostream& operator<<(std::ostream& a, const std::byte& b) is present by default but attempting to grep for any specializations didn't show anything relevant that Dash didn't have. Searching on GitHub didn't help either.

    • Then, assuming that perhaps Boost's assertion logic may have changed, upgraded the version of Boost to match the pull request at the time, Boost 1.81. That also did not do anything (and actually, caused a trailing slashes unit test to fail but doesn't cause any problem in Bitcoin because they got rid of their boost::filesystem usage by then).

    • If that isn't it, then let's try building Bitcoin with Dash's depends. It built successfully, ran successfully. The problem isn't in the dependency, it's in the codebase.

    • Since it seemed to be std::byte related, pull requests that are related to std::byte serialization were backported and std::byte serialization related changes needed for dash#5902 were cherry-picked. That's why this pull request came to be. But it didn't help this particular issue (though it did smooth out the cherry-picks).

    • Running out of ideas, gdb is used to step through serialize_tests's class_methods and understand why BOOST_CHECK_EQUAL(out.at(0), std::byte{'a'}); is valid in Bitcoin but not Dash by finding the elusive operator<<. This is where things go from bad to worse.

      Turns out, when you build with clang, gdb loses the ability to do breakpoints by file. So, an attempt is made to use lldb (which btw, is called lldb-16, running lldb with yield an error if you're using the develop container) and it refuses to work, erroring personality set failed: Operation not permitted.

      Turns out, the docker-compose.yml needs the following additions:

        cap_add:
          - SYS_PTRACE
        security_opt:
          - "seccomp:unconfined"
      

      After making these changes, lldb works and then we resume trying to find operator<<. After too many hours and nimbly alternating between next and step, tried making a return to gdb (compiling with gcc this time with the appropriate CXXFLAGS) hoping for different results and a while later, realized that it cannot step through Boost's headers (it doesn't recognize the filenames) and then recompile it with clang and return to lldb.

      This was a wild goose chase.

    • After a lot of futile efforts to find the operator by stepping through BOOST_CHECK_EQUAL, a basic example addressing the static assertion (that a left shift operator must exist of <type> (here std::byte) for std::ostream) was added in

      std::ostream& ostr = std::cout;
      ostr << std::byte{'a'};

      ...and it compiled in both codebases.

      So the left shift that Boost is asserting doesn't exist does exist but it isn't being detected for some reason. Upon hovering the <<, VSCode highlighted the source of the definition as setup_common.h thanks to the comment above it.

      Diffing between Bitcoin and Dash revealed the secret, the operator<< definition was placed under namespace std by bitcoin#23497 in bitcoin@f7086fd (see change).

      That change has now been made in a separate commit.

Breaking Changes

Changes in serialization APIs will make backports predating bitcoin#23438 annoying but will not change how data is stored on disk.

Checklist:

Go over all the following points, and put an x in all the boxes that apply.

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas (note: N/A)
  • I have added or updated relevant unit/integration/functional/e2e tests (note: N/A)
  • I have made corresponding changes to the documentation (note: N/A)
  • I have assigned this pull request to a milestone (for repository code-owners and collaborators only)

@kwvg kwvg added this to the 20.1 milestone Feb 23, 2024
@kwvg kwvg force-pushed the byte branch 3 times, most recently from a73a01d to b3d204e Compare February 24, 2024 09:10
@kwvg kwvg changed the title backport: merge bitcoin#21817, #21966, #21824, #21969, #23653, #23438, #24231, #26258, #28012, partial bitcoin#25001, #25296, #23595, #27927 (serialization updates) backport: merge bitcoin#21817, #21966, #21824, #21969, #23653, #23438, #24190, #24253, #24231, #26258, #28012, partial bitcoin#25001, #25296, #23595, #27927 (serialization updates) Feb 24, 2024
@kwvg kwvg marked this pull request as ready for review February 24, 2024 15:05
UdjinM6
UdjinM6 previously approved these changes Feb 25, 2024
Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

utACK

Copy link

This pull request has conflicts, please rebase.

Copy link

@UdjinM6 UdjinM6 left a comment

Choose a reason for hiding this comment

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

re-utACK

Copy link
Member

@PastaPastaPasta PastaPastaPasta left a comment

Choose a reason for hiding this comment

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

utACK for merging via merge commit

this is required to prevent the tests introduced in bitcoin#27927 from
failing to compile because boost::has_left_shift<std::ostream,T>::value
returns false for the std::byte specialization, resulting in a static
assertion failure in Boost.Test

this change was introduced in f7086fd in bitcoin#23497
@PastaPastaPasta PastaPastaPasta merged commit 96c4442 into dashpay:develop Feb 28, 2024
4 of 6 checks passed
PastaPastaPasta added a commit that referenced this pull request Mar 6, 2024
, bitcoin#28267, bitcoin#28374, bitcoin#28100 (p2p primitives)

b60c493 merge bitcoin#28100: more Span<std::byte> modernization & follow-ups (Kittywhiskers Van Gogh)
c2aa01c merge bitcoin#28374: python cryptography required for BIP 324 functional tests (Kittywhiskers Van Gogh)
7c5edf7 merge bitcoin#28267: BIP324 ciphersuite follow-up (Kittywhiskers Van Gogh)
1b1924e merge bitcoin#28008: BIP324 ciphersuite (Kittywhiskers Van Gogh)
ff54219 merge bitcoin#27993: Make poly1305 support incremental computation + modernize (Kittywhiskers Van Gogh)
d7482eb merge bitcoin#27985: Add support for RFC8439 variant of ChaCha20 (Kittywhiskers Van Gogh)

Pull request description:

  ## Additional Information

  * Dependent on #5900

  * Dependent on #5901

  * Without modifications, tests introduced in [bitcoin#28008](bitcoin#28008) will fail due to salt comprising of a fixed string (`bitcoin_v2_shared_secret`) and network bytes ([source](https://github.com/sipa/bitcoin/blob/1c7582ead6e1119899922041c1af2b4169b0bc74/src/bip324.cpp#L39-L40)). Bitcoin uses [`{0xf9, 0xbe, 0xb4, 0xd9}`](https://github.com/sipa/bitcoin/blob/1c7582ead6e1119899922041c1af2b4169b0bc74/src/kernel/chainparams.cpp#L114-L117) for mainnet while Dash uses [`{0xbf, 0x0c, 0x6b, 0xbd}`](https://github.com/dashpay/dash/blob/37f43e4e56de0d510110a7f790df34ea77748dc9/src/chainparams.cpp#L238-L241).
    * The replacement parameters are generated by:
      * Cloning https://github.com/bitcoin/bips (as of this writing, at bitcoin/bips@b3701fa)
      * Editing `bip-0324/reference.py`
        * Changing `NETWORK_MAGIC` to Dash's network magic
      * Running `gen_test_vectors.py` to get a new `packet_encoding_test_vectors.csv`
      * Using [this python script](https://github.com/bitcoin/bitcoin/blob/1c7582ead6e1119899922041c1af2b4169b0bc74/src/test/bip324_tests.cpp#L174-L196) mentioned in a comment in `src/test/bip324_tests.cpp`, generate the values that will be used to replace the ones in `bip324_tests.cpp` (it will print to `stdout` so it's recommended to pipe it to a file)
      * Paste the new values over the old ones

  ## Breaking Changes

  None. Changes are restricted to BIP324 cryptosuite, tests and associated logic.

  ## Checklist:
    _Go over all the following points, and put an `x` in all the boxes that apply._
  - [x] I have performed a self-review of my own code
  - [x] I have commented my code, particularly in hard-to-understand areas **(note: N/A)**
  - [x] I have added or updated relevant unit/integration/functional/e2e tests **(note: N/A)**
  - [x] I have made corresponding changes to the documentation **(note: N/A)**
  - [x] I have assigned this pull request to a milestone _(for repository code-owners and collaborators only)_

Top commit has no ACKs.

Tree-SHA512: bb056de8588026adae63e78d56878274ff3934a439e2eae81606fa9c0a37dab432a129315bb9c1b754400b5c883bf460eea3a0c857a3be0816c8fbf55c479843
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants