Skip to content

Conversation

kwvg
Copy link
Collaborator

@kwvg kwvg commented Jan 9, 2021

Overview

std::random_shuffle has been deprecated and Bitcoin has opted to implement an alternative to std::shuffle for FastRandomContext due to a bug specific to libstdc++ named Shuffle.

Unlike std::random_shuffle, std::shuffle does not accept only two arguments so those invocations now use FastRandomContext.

Replicating the commit would only implement changes to Bitcoin-derived logic while leaving Dash-specific logic using the deprecated call, changes have been made for LLMQ, Governance and Privatesend accordingly.

Disclosure

Dash-specific changes have not been tested, only compilation has been ensured. Running the client on (a) testnet may be necessary.

Resources

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.

Thanks for looking into it 👍 Those random_shuffle deprecation warnings on compilation are pretty annoying and concerning indeed.

Few thoughts/suggestions:

  • The original commit was included into btc 0.18 and was not backported to 0.17 afaik. Are there any real issues or is it simply to fix compilation warnings/make it C++17 compatible?
  • PR title should say smth like Partial merge bitcoin#14624: Some simple improvements to the RNG code (makes it easier to track backported PRs in git log)
  • see below

kwvg and others added 2 commits January 10, 2021 09:07
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
@kwvg
Copy link
Collaborator Author

kwvg commented Jan 10, 2021

I was attempting to have Dash compile with Apple Clang and it wasn't happy with the deprecated references. PR title has been changed and changes have been committed! I mixed up the Bitcoin versions, I was looking at bitcoin@f686002 instead of bitcoin@3db746b, my bad.

@kwvg kwvg changed the title random: backport bitcoin 0.17 random changes, apply them to dash-specific logic Partial merge bitcoin#14624: Some simple improvements to the RNG code Jan 10, 2021
@kwvg kwvg requested a review from UdjinM6 January 10, 2021 10:35
Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>
@UdjinM6
Copy link

UdjinM6 commented Jan 10, 2021

I was attempting to have Dash compile with Apple Clang and it wasn't happy with the deprecated references.

Does it fail to compile or does it simply complain via warnings (but succeeds otherwise)? Cause I'm on mac too (macOS 10.14.6, Apple clang version 11.0.0) and it compiles just fine for me.

@kwvg
Copy link
Collaborator Author

kwvg commented Jan 10, 2021

governance/governance.cpp:1023:10: error: 'random_shuffle<std::__1::__wrap_iter<uint256 *>, FastRandomContext &>' is deprecated [-Werror,-Wdeprecated-declarations]
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/algorithm:3116:1: note: 'random_shuffle<std::__1::__wrap_iter<uint256 *>, FastRandomContext &>' has been explicitly marked deprecated here
_LIBCPP_DEPRECATED_IN_CXX14 void
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__config:1036:39: note: expanded from macro '_LIBCPP_DEPRECATED_IN_CXX14'
#  define _LIBCPP_DEPRECATED_IN_CXX14 _LIBCPP_DEPRECATED
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/__config:1019:48: note: expanded from macro '_LIBCPP_DEPRECATED'
#    define _LIBCPP_DEPRECATED __attribute__ ((deprecated))

I'm using clang-1200.0.32.28 (shipped with Xcode) on macOS Catalina 10.15.7

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.

Interesting. Makes sense to fix it then I guess.

utACK

@UdjinM6 UdjinM6 added this to the 17 milestone Jan 10, 2021
Copy link

@xdustinface xdustinface left a comment

Choose a reason for hiding this comment

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

utACK, nice that those deprecation warning will be gone now :)

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. Be aware, your contribution may be worthy of a bounty https://trello.com/c/dbkj327J/86-dash-core-contributions

@PastaPastaPasta PastaPastaPasta merged commit 4f38f5c into dashpay:develop Jan 14, 2021
@UdjinM6 UdjinM6 mentioned this pull request Jul 19, 2021
gades pushed a commit to cosanta/cosanta-core that referenced this pull request Mar 15, 2022
…dashpay#3923)

* random: Introduce std::shuffle alternative for FastRandomContext

bitcoin@3db746b

* random: change std::random_shuffle calls to std::shuffle

https://en.cppreference.com/w/cpp/algorithm/random_shuffle (deprecated in c++14)

* random: change FastRandomContext std::random_shuffle calls to shuffle

* random: change last std::shuffle calls to Shuffle

std::shuffle doesn't accept only two arguments so we use FastRandomContext()

* llmq: use inherited FastRandomContext

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>

* llmq: use inherited FastRandomContext

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>

* Make the linter happy :)

Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>

Co-authored-by: UdjinM6 <UdjinM6@users.noreply.github.com>
Co-authored-by: dustinface <35775977+xdustinface@users.noreply.github.com>
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.

4 participants