haskoin / haskoin-core

Haskoin Core is a Bitcoin and Bitcoin Cash library
MIT License
522 stars 94 forks source link

Question about protocol versions #413

Closed lontivero closed 1 year ago

lontivero commented 1 year ago

While reading the Message.hs file I noticed that the MessageHeader type contains the a CheckSum32 field for the payload checksum, however, old versions of Bitcoin didn't have a checksum as part of the header. In general I noticed that the protocol version is not checked to verify the peer supports/understands the messages.

Is this because haskcoin is primarily for Bitcoin Cash? Or is it because the team considers that it makes no much sense to keep compatibility with nodes older than a given version?

jprupp commented 1 year ago

It may be just because when we started developing Haskoin, that's what bitcoind was doing, and we implemented the Haskoin libraries based on that C++ codebase. Bitcoin Cash didn't exist then.

Haskoin is meant to work well for the subset of common features between Bitcoin Core and Bitcoin Cash, as well as for some relevant aspects that are specific to each, notably SegWit and Bech32/CashAddr formats.

It doesn't support fancier stuff, such as Schnorr signatures or Taproot, for various reasons. It may in the future. There's a developer that has been working on a Bitcoin Core exclusive fork that doesn't have Bitcoin Cash support. I don't know where he is publishing that, if it is something you are interested in.

wraithm commented 1 year ago

We're working on the Bitcoin only fork here:

https://github.com/haskell-bitcoin/bitcoin

We haven't made a release yet. We're actively working on this fork, and you should expect a release shortly.

lontivero commented 1 year ago

Thanks for your answers but my question is not about bitcoin core/cash but about compatibility with the p2p network. I mean, given you never check the peers protocol version, you don't know what messages will be understood by the connected peers. This means that haskoin doesn't try to be compatible with ~any particular~ previous versions of the protocol (this is not a critic, it is an observation).

It seems to me that kaskoin implements protocol version 70012 ~(without Alert, removed in 70013)~ am I right? What I want to understand is why that version and no other, and why not support older versions? I can imagine many reasons for not supporting old versions (for example, why to support a 10 years old protocol version that nobody will never run?)

I mentioned Bitcoin Cash because it forks in version 70014 or so and that could have be the reason for the chosen version. Perhaps there is not a strong reason and 70012 is the one just because it is a good non-controversial version.


Thanks for the link to haskhell-bitcoin, i didn't know about it.

jprupp commented 1 year ago

It's a bit more complicated than that. The version field in the Bitcoin peer-to-peer protocol works as specified in BIP 0009.

The Haskoin packages that set this field in any way are Haskoin Node, which is a library that supports the peer-to-peer protocol on the network, and Haskoin Store, that implements an actual client that stores the whole blockchain and provides an API for querying its contents.

Haskoin Core is a low-level library that doesn't set the version number itself. It only implements data types and serialisation code for messages. You can use this library, along with Haskoin Node to write a client that supports various features of the Bitcoin protocol, and set the version field value as needed.

Both Bitcoin Cash and Bitcoin Core's peer-to-peer protocols are for the most part compatible.

lontivero commented 1 year ago

I don't want to abuse of your time. I was simply curious about your decision but I assume you decided to start supporting 70012 and not older without any particular reason. Anyway, thanks for responding and thanks for haskoin.