A field labelled "version" appears in many contexts regarding the Bitcoin protocol. Sometimes one uses the current version of the Bitcoin client (version message), sometimes 1 is used (block, tx), why is that? What are the rules in numbering those versions? For the context that uses 1s, would other values validate, or would they be rejected by the client?
1 Answer
The format of messages occasionally needs to change. This is done in a backward-compatible way by exchanging versions in version messages and communicating in the "language" of the client with the lowest version. Through this mechanism, clients running version 0.1 should still be able to talk to the latest clients.
Blocks and transactions are special. When these formats are updated, nodes can't modify old messages to use the new format because this breaks the crypto. So version 2 nodes have to store and communicate both version 1 and version 2 blocks, and special version numbers are necessary to distinguish them.
Block/transaction versions other than 1 are not accepted.
In version messages, use the same version as the client version that you're trying to be compatible with.
-
Meanwhile, there are transaction and block version numbers of up to 4, for as much as I can see right now. E.g.: Block 407041: blockstream.info/block/… Commented Aug 3, 2022 at 20:33