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.

141 lines
3.7 KiB

7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
7 years ago
  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. ### Result
  24. ```go
  25. type Result struct {
  26. Code uint32
  27. Data []byte
  28. }
  29. ```
  30. `Result` is the result of executing a transaction against the application.
  31. It returns a result code and an arbitrary byte array (ie. a return value).
  32. NOTE: the Result needs to be updated to include more fields returned from
  33. processing transactions, like gas variables and tags - see
  34. [issue 1007](https://github.com/tendermint/tendermint/issues/1007).
  35. ### Validator
  36. A validator is an active participant in the consensus with a public key and a voting power.
  37. Validator's also contain an address field, which is a hash digest of the PubKey.
  38. ```go
  39. type Validator struct {
  40. Address []byte
  41. PubKey PubKey
  42. VotingPower int64
  43. }
  44. ```
  45. When hashing the Validator struct, the address is not included,
  46. because it is redundant with the pubkey.
  47. The `state.Validators`, `state.LastValidators`, and `state.NextValidators`, must always by sorted by validator address,
  48. so that there is a canonical order for computing the MerkleRoot.
  49. We also define a `TotalVotingPower` function, to return the total voting power:
  50. ```go
  51. func TotalVotingPower(vals []Validators) int64{
  52. sum := 0
  53. for v := range vals{
  54. sum += v.VotingPower
  55. }
  56. return sum
  57. }
  58. ```
  59. ### ConsensusParams
  60. ConsensusParams define various limits for blockchain data structures.
  61. Like validator sets, they are set during genesis and can be updated by the application through ABCI.
  62. When hashed, only a subset of the params are included, to allow the params to
  63. evolve without breaking the header.
  64. ```go
  65. type ConsensusParams struct {
  66. Block
  67. Evidence
  68. Validator
  69. }
  70. type hashedParams struct {
  71. BlockMaxBytes int64
  72. BlockMaxGas int64
  73. }
  74. func (params ConsensusParams) Hash() []byte {
  75. SHA256(hashedParams{
  76. BlockMaxBytes: params.Block.MaxBytes,
  77. BlockMaxGas: params.Block.MaxGas,
  78. })
  79. }
  80. type BlockParams struct {
  81. MaxBytes int64
  82. MaxGas int64
  83. TimeIotaMs int64
  84. }
  85. type EvidenceParams struct {
  86. MaxAge int64
  87. }
  88. type ValidatorParams struct {
  89. PubKeyTypes []string
  90. }
  91. ```
  92. #### Block
  93. The total size of a block is limited in bytes by the `ConsensusParams.Block.MaxBytes`.
  94. Proposed blocks must be less than this size, and will be considered invalid
  95. otherwise.
  96. Blocks should additionally be limited by the amount of "gas" consumed by the
  97. transactions in the block, though this is not yet implemented.
  98. The minimal time between consecutive blocks is controlled by the
  99. `ConsensusParams.Block.TimeIotaMs`.
  100. #### Evidence
  101. For evidence in a block to be valid, it must satisfy:
  102. ```
  103. block.Header.Height - evidence.Height < ConsensusParams.Evidence.MaxAge
  104. ```
  105. #### Validator
  106. Validators from genesis file and `ResponseEndBlock` must have pubkeys of type ∈
  107. `ConsensusParams.Validator.PubKeyTypes`.