Bitcoin Forum

Bitcoin => Development & Technical Discussion => Topic started by: turboblade on December 09, 2017, 12:26:02 AM



Title: Github code
Post by: turboblade on December 09, 2017, 12:26:02 AM
Perhaps this is too simplistic for this board, though hopefully you can help me. I'm currently trying to interpret general crypto code, as a basic coder. Is it agreed that bitcoin code is inherently very inefficient. To me it appears much code is duplicated unnecessarily. Ultimately, to me, bitcoin's code is still pre-beta, with minimal comments and few modules.

Can someone please advise which .cpp file states which hashing algorithm, the coin is using. ie what differs between sha265 hashed coin's code vs an equihash.

Take bitcoin gold for example. How does their wallet know how to interpret both equihash and sha265, depending on which block is being interrogated.
Bitgoin gold has significantly more lines of code than bitcoin. Is this purely to allow the blockchain to cope with two completely different hashes?

I can recall older coins changing algorithm over the years, though most did a 1 to 1 swap at an exchange. To me that is cheating. Obviously it cant be done eg Bitgoin gold, though is an algorithm change mid blockchain difficult to implement?


Title: Re: Github code
Post by: achow101 on December 28, 2017, 06:12:22 AM
Is it agreed that bitcoin code is inherently very inefficient.
No, it is not agreed. Firstly, there is no "bitcoin code". There are multiple implementation of the Bitcoin consensus rules. If you are referring to Bitcoin Core, it can sometimes be inefficient but there is nothing inherent about consensus implementations for Bitcoin being inherently inefficient.

To me it appears much code is duplicated unnecessarily.
Bitcoin Core certainly has code duplication, but it is much better than it was in the past and it has become much more efficient.

Ultimately, to me, bitcoin's code is still pre-beta, with minimal comments and few modules.
Bitcoin Core may still be like that, but that is only one implementation.

Can someone please advise which .cpp file states which hashing algorithm, the coin is using. ie what differs between sha265 hashed coin's code vs an equihash.
There is not one place that specifies a hash function that is used; rather every time the hash function is used, the function itself is directly called. It's not like there are some UsePoWHash or UseConsensusHash functions.

The files that you are looking for are probably src/chainparams.cpp, src/validation.cpp, and the files under src/consensus/. However many other source files include consensus related things.

Take bitcoin gold for example. How does their wallet know how to interpret both equihash and sha265, depending on which block is being interrogated.
Presumably there is a swtich. Simply an if statement; if after activation height, use equihash, else use sha256d.

Bitgoin gold has significantly more lines of code than bitcoin. Is this purely to allow the blockchain to cope with two completely different hashes?
Yes.

I can recall older coins changing algorithm over the years, though most did a 1 to 1 swap at an exchange. To me that is cheating. Obviously it cant be done eg Bitgoin gold, though is an algorithm change mid blockchain difficult to implement?
Not necessarily.


Title: Re: Github code
Post by: washi on December 29, 2017, 09:27:30 PM
Try looking at the Go implementation, it is well commented and "clean":

https://github.com/btcsuite/btcd


Title: Re: Github code
Post by: Nicor on December 29, 2017, 11:33:53 PM
its a trade off.

Do you want faster code or more compact executable?

In this app i would not have cared about size, but about speed.