You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

301 lines
11 KiB

  1. # ADR 016: Protocol Versions
  2. ## TODO
  3. - How to / should we version the authenticated encryption handshake itself (ie.
  4. upfront protocol negotiation for the P2PVersion)
  5. ## Changelog
  6. - 03-08-2018: Updates from discussion with Jae:
  7. - ProtocolVersion contains Block/AppVersion, not Current/Next
  8. - signal upgrades to Tendermint using EndBlock fields
  9. - dont restrict peer compatibilty by version to simplify syncing old nodes
  10. - 28-07-2018: Updates from review
  11. - split into two ADRs - one for protocol, one for chains
  12. - include signalling for upgrades in header
  13. - 16-07-2018: Initial draft - was originally joint ADR for protocol and chain
  14. versions
  15. ## Context
  16. The Software Version is covered by SemVer and described elsewhere.
  17. It is not relevant to the protocol description, suffice to say that if any protocol version
  18. changes, the software version changes, but not necessarily vice versa.
  19. Software version shoudl be included in NodeInfo for convenience/diagnostics.
  20. We are also interested in versioning across different blockchains in a
  21. meaningful way, for instance to differentiate branches of a contentious
  22. hard-fork. We leave that for a later ADR.
  23. Here we focus on protocol versions.
  24. ## Requirements
  25. We need to version components of the blockchain that may be independently upgraded.
  26. We need to do it in a way that is scalable and maintainable - we can't just litter
  27. the code with conditionals.
  28. We can consider the complete version of the protocol to contain the following sub-versions:
  29. BlockVersion, P2PVersion, AppVersion. These versions reflect the major sub-components
  30. of the software that are likely to evolve together, at different rates, and in different ways,
  31. as described below.
  32. The BlockVersion defines the core of the blockchain data structures and
  33. should change infrequently.
  34. The P2PVersion defines how peers connect and communicate with eachother - it's
  35. not part of the blockchain data structures, but defines the protocols used to build the
  36. blockchain. It may change gradually.
  37. The AppVersion determines how we compute app specific information, like the
  38. AppHash and the Results.
  39. All of these versions may change over the life of a blockchain, and we need to
  40. be able to help new nodes sync up across version changes. This means we must be willing
  41. to connect to peers with older version.
  42. ### BlockVersion
  43. - All tendermint hashed data-structures (headers, votes, txs, responses, etc.).
  44. - Note the semantic meaning of a transaction may change according to the AppVersion, but the way txs are merklized into the header is part of the BlockVersion
  45. - It should be the least frequent/likely to change.
  46. - Tendermint should be stabilizing - it's just Atomic Broadcast.
  47. - We can start considering for Tendermint v2.0 in a year
  48. - It's easy to determine the version of a block from its serialized form
  49. ### P2PVersion
  50. - All p2p and reactor messaging (messages, detectable behaviour)
  51. - Will change gradually as reactors evolve to improve performance and support new features - eg proposed new message types BatchTx in the mempool and HasBlockPart in the consensus
  52. - It's easy to determine the version of a peer from its first serialized message/s
  53. - New versions must be compatible with at least one old version to allow gradual upgrades
  54. ### AppVersion
  55. - The ABCI state machine (txs, begin/endblock behaviour, commit hashing)
  56. - Behaviour and message types will change abruptly in the course of the life of a chain
  57. - Need to minimize complexity of the code for supporting different AppVersions at different heights
  58. - Ideally, each version of the software supports only a _single_ AppVersion at one time
  59. - this means we checkout different versions of the software at different heights instead of littering the code
  60. with conditionals
  61. - minimize the number of data migrations required across AppVersion (ie. most AppVersion should be able to read the same state from disk as previous AppVersion).
  62. ## Ideal
  63. Each component of the software is independently versioned in a modular way and its easy to mix and match and upgrade.
  64. Good luck pal ;)
  65. ## Proposal
  66. Each of BlockVersion, AppVersion, P2PVersion is a monotonically increasing int64.
  67. To use these versions, we need to update the block Header, the p2p NodeInfo, and the ABCI.
  68. ### Header
  69. Block Header should include a `Version` struct as its first field like:
  70. ```
  71. type Version struct {
  72. CurrentVersion ProtocolVersion
  73. ChainID string
  74. NextVersion ProtocolVersion
  75. }
  76. type ProtocolVersion struct {
  77. BlockVersion int64
  78. AppVersion int64
  79. }
  80. ```
  81. Note this effectively makes BlockVersion the first field in the block Header.
  82. Since we have settled on a proto3 header, the ability to read the BlockVersion out of the serialized header is unanimous.
  83. Using a Version struct gives us more flexibility to add fields without breaking
  84. the header.
  85. The ProtocolVersion struct includes both the Block and App versions - it should
  86. serve as a complete description of the consensus-critical protocol.
  87. Using the `NextVersion` field, proposer's can signal their readiness to upgrade
  88. to a new Block and/or App version.
  89. ### NodeInfo
  90. NodeInfo should include a Version struct as its first field like:
  91. ```
  92. type Version struct {
  93. P2PVersion int64
  94. ChainID string
  95. BlockVersion int64
  96. AppVersion int64
  97. SoftwareVersion string
  98. }
  99. ```
  100. Note this effectively makes P2PVersion the first field in the NodeInfo, so it
  101. should be easy to read this out of the serialized header if need be to facilitate an upgrade.
  102. The SoftwareVersion here should include the name of the software client and
  103. it's SemVer version - this is for convenience only. Eg.
  104. `tendermint-core/v0.22.8`.
  105. The other versions and ChainID will determine peer compatibility (described below).
  106. ### ABCI
  107. Since the ABCI is responsible for keeping Tendermint and the App in sync, we
  108. need to communicate version information through it.
  109. On startup, we use Info to perform a basic handshake. It should include all the
  110. version information.
  111. We also need to be able to update versions in the life of a blockchain. The
  112. natural place to do this is EndBlock.
  113. #### Info
  114. RequestInfo should add support for protocol versions like:
  115. ```
  116. message RequestInfo {
  117. string software_version
  118. int64 block_version
  119. int64 p2p_version
  120. }
  121. ```
  122. Similarly, ResponseInfo should return the versions:
  123. ```
  124. message ResponseInfo {
  125. string data
  126. string software_version
  127. int64 app_version
  128. int64 last_block_height
  129. bytes last_block_app_hash
  130. }
  131. ```
  132. #### EndBlock
  133. Updating the version could be done either with new fields or by using the
  134. existing `tags`. Since we're trying to communicate information that will be
  135. included in Tendermint block Headers, it should be native to the ABCI, and not
  136. something embedded through some scheme in the tags.
  137. ResponseEndBlock will include a new field `version_updates`:
  138. ```
  139. message ResponseEndBlock {
  140. repeated Validator validator_updates
  141. ConsensusParams consensus_param_updates
  142. repeated common.KVPair tags
  143. VersionUpdates version_updates
  144. }
  145. message VersionUpdates {
  146. ProtocolVersion current_version
  147. ProtocolVersion next_version
  148. }
  149. message ProtocolVersion {
  150. int64 block_version
  151. int64 app_version
  152. }
  153. ```
  154. Tendermint will use the information in VersionUpdates for the next block it
  155. proposes.
  156. ### BlockVersion
  157. BlockVersion is included in both the Header and the NodeInfo.
  158. Changing BlockVersion should happen quite infrequently and ideally only for extreme emergency.
  159. Note Ethereum has not had to make an upgrade like this (everything has been at state machine level, AFAIK).
  160. ### P2PVersion
  161. P2PVersion is not included in the block Header, just the NodeInfo.
  162. P2PVersion is the first field in the NodeInfo. NodeInfo is also proto3 so this is easy to read out.
  163. Note we need the peer/reactor protocols to take the versions of peers into account when sending messages:
  164. - don't send messages they don't understand
  165. - don't send messages they don't expect
  166. Doing this will be specific to the upgrades being made.
  167. Note we also include the list of reactor channels in the NodeInfo and already don't send messages for channels the peer doesn't understand.
  168. If upgrades always use new channels, this simplifies the development cost of backwards compatibility.
  169. Note NodeInfo is only exchanged after the authenticated encryption handshake to ensure that it's private.
  170. Doing any version exchange before encrypting could be considered information leakage, though I'm not sure
  171. how much that matters compared to being able to upgrade the protocol.
  172. XXX: if needed, can we change the meaning of the first byte of the first message to encode a handshake version?
  173. this is the first byte of a 32-byte ed25519 pubkey.
  174. ### AppVersion
  175. AppVersion is also included in the block Header and the NodeInfo.
  176. AppVersion essentially defines how the AppHash and Results are computed.
  177. ### Peer Compatibility
  178. Restricting peer compatibility based on version is complicated by the need to
  179. help old peers, possibly on older versions, sync the blockchain.
  180. We might be tempted to say that we only connect to peers with the same
  181. AppVersion and BlockVersion (since these define the consensus critical
  182. computations), and a select list of P2PVersions (ie. those compatible with
  183. ours), but then we'd need to make accomodations for connecting to peers with the
  184. right Block/AppVersion for the height they're on.
  185. For now, we will connect to peers with any version and restrict compatibility
  186. solely based on the ChainID. We leave more restrictive rules on peer
  187. compatibiltiy to a future proposal.
  188. ### Future Changes
  189. It may be valuable to support an `/unsafe_stop?height=_` endpoint to tell Tendermint to shutdown at a given height.
  190. This could be use by an external manager process that oversees upgrades by
  191. checking out and installing new software versions and restarting the process. It
  192. would subscribe to the relevant upgrade event (needs to be implemented) and call `/unsafe_stop` at
  193. the correct height (of course only after getting approval from its user!)
  194. ## Consequences
  195. ### Positive
  196. - Make tendermint and application versions native to the ABCI to more clearly
  197. communicate about them
  198. - Distinguish clearly between protocol versions and software version to
  199. facilitate implementations in other languages
  200. - Versions included in key data structures in easy to discern way
  201. - Allows proposers to signal for upgrades and apps to decide when to actually change the
  202. version (and start signalling for a new version)
  203. ### Neutral
  204. - Unclear how to version the initial P2P handshake itself
  205. - Versions aren't being used (yet) to restrict peer compatibility
  206. - Signalling for a new version happens through the proposer and must be
  207. tallied/tracked in the app.
  208. ### Negative
  209. - Adds more fields to the ABCI
  210. - Implies that a single codebase must be able to handle multiple versions