Skip to content

Conversation

jamescowens
Copy link
Member

@jamescowens jamescowens commented Jul 10, 2018

This is a port of Bitcoin’s internal hash implementation, which replaces the hashing provided by OpenSSL. It provides accelerated versions on CPUs with SSE4(1) and/or AVX2, although initial testing shows little performance benefit.

The call architecture and initialization code allows reasonably easy implementation of accelerated versions for the ARM architecture.

Note that byteswap.h and endian.h are also included.

Whether or not this provides an actual performance benefit it moves us down the road of merging the modern Bitcoin codebase into Gridcoin.

@jamescowens
Copy link
Member Author

Crap. How did those other commits get in there...

@TheCharlatan
Copy link
Contributor

Can you add the crypto subdirectory in a separate commit, such that the actual change in the source is more readable?

@jamescowens
Copy link
Member Author

Ok. Give me some time to back this commit out and split it up.

@jamescowens
Copy link
Member Author

jamescowens commented Jul 10, 2018

Done. I rebased it to the development branch... Ugh. I think I needed to switch to development and rebranch with the stash because my hashaccel already had commits in from staging that were not in dev?

@jamescowens
Copy link
Member Author

jamescowens commented Jul 10, 2018

Travis is failing because it is trying to build with the only last commit (a4cabbb) applied. That is stupid.

These are the adjustments to the Gridcoin core code required to accomodate the Bitcoin crypto backport
These are the added files from src/crypto which implement the internal hashing
@@ -133,7 +147,7 @@ GRIDCOIN_CORE_CPP = addrman.cpp \
script.cpp \
scrypt.cpp \
sync.cpp \
tally.cpp \
tally.cpp \
txdb-leveldb.cpp \
util.cpp \
version.cpp \
Copy link
Contributor

Choose a reason for hiding this comment

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

You probably need to add prevector.h here.

@jamescowens jamescowens changed the title Port of bitcoin hash implementation Port of Bitcoin hash implementation Jul 11, 2018
@jamescowens
Copy link
Member Author

jamescowens commented Jul 11, 2018 via email

@jamescowens jamescowens force-pushed the hashaccel branch 3 times, most recently from c2c7234 to 935adb7 Compare July 12, 2018 04:14
@jamescowens
Copy link
Member Author

jamescowens commented Jul 12, 2018

Interesting. One build type out of the five in travis is failing, the i686 Linux, which is the 32-bit Linux build, and it is failing at
crypto/sha256.cpp: In function ‘std::string SHA256AutoDetect()’:
crypto/sha256.cpp:537:83: error: inconsistent operand constraints in an ‘asm’
asm ("cpuid" : "=a"(a), "=b"(b), "=c"(c), "=d"(d) : "0"(leaf), "2"(subleaf));

Perhaps this is not valid after all for the i386 define as specified by Bitcoin...?

#if defined(USE_ASM) && (defined(x86_64) || defined(amd64) || defined(i386))`...

Turns out I was sorta right. A different call has to be used for 32 bit... see

bitcoin/bitcoin@63c16ed

On certain GCC versions, the 32 bit builds can fail unless a different CPUID call is used.
See bitcoin/bitcoin@63c16ed.
@tomasbrod
Copy link
Member

Why the proper implementation can't be selected at compile time?
A: because the way modern linux distributions work, leaves us stuck with probing cpuid.

@jamescowens
Copy link
Member Author

You are absolutely right, and then we end up with stupid things like the SHA256AutoDetect() function..., although runtime codepath switching does allow a single executable to be used across a wider domain of x86 chips without recompile...

// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#ifndef GRIDCOIN_COMPAT_BYTESWAP_H
Copy link
Member

Choose a reason for hiding this comment

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

I think we should keep the Bitcoin ifndefs so we stay closer to the original source.

Copy link
Member Author

Choose a reason for hiding this comment

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

I can change them back. If you are ok with it, I'll do it in another commit, because it is too hard to undo all of the above at this point...

This small commit reverts the ifndefs to standard Bitcoin nomenclature to allow for easier drop-in updates of this code.
@jamescowens
Copy link
Member Author

@denravonska I pushed the reversion of the ifndefs to Bitcoin nomenclature...

@denravonska denravonska merged commit 2a09d4c into gridcoin-community:development Jul 21, 2018
denravonska added a commit that referenced this pull request Oct 19, 2018
Added:
 - Linux nodes can now stake superblocks using forwarded contracts #1060 (@tomasbrod).

Changed:
 - Replace interest with constant block reward #1160 (@tomasbrod).
   Fork is set to trigger at block 1420000.
 - Raise coinstake output count limit to 8 #1261 (@tomasbrod).
 - Port of Bitcoin hash implementation #1208 (@jamescowens).
 - Minor canges for the build documentation #1091 (@Lenni).
 - Allow sendmany to be used without an account specified #1158 (@Foggyx420).

Fixed:
 - Fix `cpids` and `validcpids` not returning the correct data #1233
   (@Foggyx420).
 - Fix `listsinceblock` not showing mined blocks to change addresses #501 (@Foggyx420).
 - Fix crash when raining using a locked wallet #1236 (@Foggyx420).
 - Fix invalid stake reward/fee calculation (@jamescowens).
 - Fix divide by zero bug in `getblockstats` RPC #1292 (@Foggyx420).
 - Bypass historical bad blocks on testnet #1252 (@Quezacoatl1).
 - Fix MacOS memorybarrier warnings #1193 (@ghost).

Removed:
 - Remove neuralhash from the getpeerinfo and node stats #1123 (@Foggyx420).
 - Remove obsolete NN code #1121 (@Foggyx420).
 - Remove (lower) Mint Limiter #1212 (@tomasbrod).
@jamescowens jamescowens deleted the hashaccel branch October 23, 2019 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants