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.

127 lines
3.2 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 SimpleMerkleRoot.
  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. ```go
  63. type ConsensusParams struct {
  64. BlockSize
  65. Evidence
  66. Validator
  67. }
  68. type BlockSize struct {
  69. MaxBytes int64
  70. MaxGas int64
  71. }
  72. type Evidence struct {
  73. MaxAge int64
  74. }
  75. type Validator struct {
  76. PubKeyTypes []string
  77. }
  78. type ValidatorParams struct {
  79. PubKeyTypes []string
  80. }
  81. ```
  82. #### BlockSize
  83. The total size of a block is limited in bytes by the `ConsensusParams.BlockSize.MaxBytes`.
  84. Proposed blocks must be less than this size, and will be considered invalid
  85. otherwise.
  86. Blocks should additionally be limited by the amount of "gas" consumed by the
  87. transactions in the block, though this is not yet implemented.
  88. #### Evidence
  89. For evidence in a block to be valid, it must satisfy:
  90. ```
  91. block.Header.Height - evidence.Height < ConsensusParams.Evidence.MaxAge
  92. ```
  93. #### Validator
  94. Validators from genesis file and `ResponseEndBlock` must have pubkeys of type ∈
  95. `ConsensusParams.Validator.PubKeyTypes`.