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.

146 lines
3.9 KiB

  1. # State
  2. ## State
  3. The state contains information whose cryptographic digest is included in block headers, and thus is
  4. necessary for validating new blocks. For instance, the validators set and the results of
  5. transactions are never included in blocks, but their Merkle roots are - the state keeps track of them.
  6. Note that the `State` object itself is an implementation detail, since it is never
  7. included in a block or gossipped over the network, and we never compute
  8. its hash. Thus we do not include here details of how the `State` object is
  9. persisted or queried. That said, the types it contains are part of the specification, since
  10. their Merkle roots are included in blocks and their values are used in
  11. validation.
  12. ```go
  13. type State struct {
  14. Version Version
  15. LastResults []Result
  16. AppHash []byte
  17. LastValidators []Validator
  18. Validators []Validator
  19. NextValidators []Validator
  20. ConsensusParams ConsensusParams
  21. }
  22. ```
  23. Note there is a hard-coded limit of 10000 validators. This is inherited from the
  24. limit on the number of votes in a commit.
  25. ### Result
  26. ```go
  27. type Result struct {
  28. Code uint32
  29. Data []byte
  30. }
  31. ```
  32. `Result` is the result of executing a transaction against the application.
  33. It returns a result code and an arbitrary byte array (ie. a return value).
  34. NOTE: the Result needs to be updated to include more fields returned from
  35. processing transactions, like gas variables and tags - see
  36. [issue 1007](https://github.com/tendermint/tendermint/issues/1007).
  37. ### Validator
  38. A validator is an active participant in the consensus with a public key and a voting power.
  39. Validator's also contain an address field, which is a hash digest of the PubKey.
  40. ```go
  41. type Validator struct {
  42. Address []byte
  43. PubKey PubKey
  44. VotingPower int64
  45. }
  46. ```
  47. When hashing the Validator struct, the address is not included,
  48. because it is redundant with the pubkey.
  49. The `state.Validators`, `state.LastValidators`, and `state.NextValidators`, must always be sorted by validator address,
  50. so that there is a canonical order for computing the MerkleRoot.
  51. We also define a `TotalVotingPower` function, to return the total voting power:
  52. ```go
  53. func TotalVotingPower(vals []Validators) int64{
  54. sum := 0
  55. for v := range vals{
  56. sum += v.VotingPower
  57. }
  58. return sum
  59. }
  60. ```
  61. ### ConsensusParams
  62. ConsensusParams define various limits for blockchain data structures.
  63. Like validator sets, they are set during genesis and can be updated by the application through ABCI.
  64. When hashed, only a subset of the params are included, to allow the params to
  65. evolve without breaking the header.
  66. ```go
  67. type ConsensusParams struct {
  68. Block
  69. Evidence
  70. Validator
  71. }
  72. type hashedParams struct {
  73. BlockMaxBytes int64
  74. BlockMaxGas int64
  75. }
  76. func (params ConsensusParams) Hash() []byte {
  77. SHA256(hashedParams{
  78. BlockMaxBytes: params.Block.MaxBytes,
  79. BlockMaxGas: params.Block.MaxGas,
  80. })
  81. }
  82. type BlockParams struct {
  83. MaxBytes int64
  84. MaxGas int64
  85. TimeIotaMs int64
  86. }
  87. type EvidenceParams struct {
  88. MaxAgeNumBlocks int64
  89. MaxAgeDuration time.Duration
  90. }
  91. type ValidatorParams struct {
  92. PubKeyTypes []string
  93. }
  94. ```
  95. #### Block
  96. The total size of a block is limited in bytes by the `ConsensusParams.Block.MaxBytes`.
  97. Proposed blocks must be less than this size, and will be considered invalid
  98. otherwise.
  99. Blocks should additionally be limited by the amount of "gas" consumed by the
  100. transactions in the block, though this is not yet implemented.
  101. The minimal time between consecutive blocks is controlled by the
  102. `ConsensusParams.Block.TimeIotaMs`.
  103. #### Evidence
  104. For evidence in a block to be valid, it must satisfy:
  105. ```
  106. block.Header.Height - evidence.Height < ConsensusParams.Evidence.MaxAgeNumBlocks
  107. block.Header.Time - evidence.Time < ConsensusParams.Evidence.MaxAgeDuration
  108. ```
  109. #### Validator
  110. Validators from genesis file and `ResponseEndBlock` must have pubkeys of type ∈
  111. `ConsensusParams.Validator.PubKeyTypes`.