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.

95 lines
3.2 KiB

  1. # ADR 025 Commit
  2. ## Context
  3. Currently the `Commit` structure contains a lot of potentially redundant or unnecessary data.
  4. It contains a list of precommits from every validator, where the precommit
  5. includes the whole `Vote` structure. Thus each of the commit height, round,
  6. type, and blockID are repeated for every validator, and could be deduplicated.
  7. ```
  8. type Commit struct {
  9. BlockID BlockID `json:"block_id"`
  10. Precommits []*Vote `json:"precommits"`
  11. }
  12. type Vote struct {
  13. ValidatorAddress Address `json:"validator_address"`
  14. ValidatorIndex int `json:"validator_index"`
  15. Height int64 `json:"height"`
  16. Round int `json:"round"`
  17. Timestamp time.Time `json:"timestamp"`
  18. Type byte `json:"type"`
  19. BlockID BlockID `json:"block_id"`
  20. Signature []byte `json:"signature"`
  21. }
  22. ```
  23. References:
  24. [#1648](https://github.com/tendermint/tendermint/issues/1648)
  25. [#2179](https://github.com/tendermint/tendermint/issues/2179)
  26. [#2226](https://github.com/tendermint/tendermint/issues/2226)
  27. ## Proposed Solution
  28. We can improve efficiency by replacing the usage of the `Vote` struct with a subset of each vote, and by storing the constant values (`Height`, `Round`, `BlockID`) in the Commit itself.
  29. ```
  30. type Commit struct {
  31. Height int64
  32. Round int
  33. BlockID BlockID `json:"block_id"`
  34. Precommits []*CommitSig `json:"precommits"`
  35. }
  36. type CommitSig struct {
  37. BlockID BlockIDFlag
  38. ValidatorAddress Address
  39. Timestamp time.Time
  40. Signature []byte
  41. }
  42. // indicate which BlockID the signature is for
  43. type BlockIDFlag int
  44. const (
  45. BlockIDFlagAbsent BlockIDFlag = iota // vote is not included in the Commit.Precommits
  46. BlockIDFlagCommit // voted for the Commit.BlockID
  47. BlockIDFlagNil // voted for nil
  48. )
  49. ```
  50. Note the need for an extra byte to indicate whether the signature is for the BlockID or for nil.
  51. This byte can also be used to indicate an absent vote, rather than using a nil object like we currently do,
  52. which has been [problematic for compatibility between Amino and proto3](https://github.com/tendermint/go-amino/issues/260).
  53. Note we also continue to store the `ValidatorAddress` in the `CommitSig`.
  54. While this still takes 20-bytes per signature, it ensures that the Commit has all
  55. information necessary to reconstruct Vote, which simplifies mapping between Commit and Vote objects
  56. and with debugging. It also may be necessary for the light-client to know which address a signature corresponds to if
  57. it is trying to verify a current commit with an older validtor set.
  58. ## Status
  59. Proposed
  60. ## Consequences
  61. ### Positive
  62. Removing the Type/Height/Round/Index and the BlockID saves roughly 80 bytes per precommit.
  63. It varies because some integers are varint. The BlockID contains two 32-byte hashes an integer,
  64. and the Height is 8-bytes.
  65. For a chain with 100 validators, that's up to 8kB in savings per block!
  66. ### Negative
  67. - Large breaking change to the block and commit structure
  68. - Requires differentiating in code between the Vote and CommitSig objects, which may add some complexity (votes need to be reconstructed to be verified and gossiped)
  69. ### Neutral
  70. - Commit.Precommits no longer contains nil values