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.

144 lines
3.8 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. MaxAge int64
  89. }
  90. type ValidatorParams struct {
  91. PubKeyTypes []string
  92. }
  93. ```
  94. #### Block
  95. The total size of a block is limited in bytes by the `ConsensusParams.Block.MaxBytes`.
  96. Proposed blocks must be less than this size, and will be considered invalid
  97. otherwise.
  98. Blocks should additionally be limited by the amount of "gas" consumed by the
  99. transactions in the block, though this is not yet implemented.
  100. The minimal time between consecutive blocks is controlled by the
  101. `ConsensusParams.Block.TimeIotaMs`.
  102. #### Evidence
  103. For evidence in a block to be valid, it must satisfy:
  104. ```
  105. block.Header.Height - evidence.Height < ConsensusParams.Evidence.MaxAge
  106. ```
  107. #### Validator
  108. Validators from genesis file and `ResponseEndBlock` must have pubkeys of type ∈
  109. `ConsensusParams.Validator.PubKeyTypes`.