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.

130 lines
3.3 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
  1. # Tendermint 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. LastResults []Result
  15. AppHash []byte
  16. LastValidators []Validator
  17. Validators []Validator
  18. NextValidators []Validator
  19. ConsensusParams ConsensusParams
  20. }
  21. ```
  22. ### Result
  23. ```go
  24. type Result struct {
  25. Code uint32
  26. Data []byte
  27. }
  28. ```
  29. `Result` is the result of executing a transaction against the application.
  30. It returns a result code and an arbitrary byte array (ie. a return value).
  31. NOTE: the Result needs to be updated to include more fields returned from
  32. processing transactions, like gas variables and tags - see
  33. [issue 1007](https://github.com/tendermint/tendermint/issues/1007).
  34. ### Validator
  35. A validator is an active participant in the consensus with a public key and a voting power.
  36. Validator's also contain an address which is derived from the PubKey:
  37. ```go
  38. type Validator struct {
  39. Address []byte
  40. PubKey PubKey
  41. VotingPower int64
  42. }
  43. ```
  44. The `state.Validators`, `state.LastValidators`, and `state.NextValidators`, must always by sorted by validator address,
  45. so that there is a canonical order for computing the SimpleMerkleRoot.
  46. We also define a `TotalVotingPower` function, to return the total voting power:
  47. ```go
  48. func TotalVotingPower(vals []Validators) int64{
  49. sum := 0
  50. for v := range vals{
  51. sum += v.VotingPower
  52. }
  53. return sum
  54. }
  55. ```
  56. ### ConsensusParams
  57. ConsensusParams define various limits for blockchain data structures.
  58. Like validator sets, they are set during genesis and can be updated by the application through ABCI.
  59. ```
  60. type ConsensusParams struct {
  61. BlockSize
  62. TxSize
  63. BlockGossip
  64. EvidenceParams
  65. }
  66. type BlockSize struct {
  67. MaxBytes int
  68. MaxGas int64
  69. }
  70. type TxSize struct {
  71. MaxBytes int
  72. MaxGas int64
  73. }
  74. type BlockGossip struct {
  75. BlockPartSizeBytes int
  76. }
  77. type EvidenceParams struct {
  78. MaxAge int64
  79. }
  80. ```
  81. #### BlockSize
  82. The total size of a block is limitted in bytes by the `ConsensusParams.BlockSize.MaxBytes`.
  83. Proposed blocks must be less than this size, and will be considered invalid
  84. otherwise.
  85. Blocks should additionally be limitted by the amount of "gas" consumed by the
  86. transactions in the block, though this is not yet implemented.
  87. #### TxSize
  88. These parameters are not yet enforced and may disappear. See [issue
  89. #2347](https://github.com/tendermint/tendermint/issues/2347).
  90. #### BlockGossip
  91. When gossipping blocks in the consensus, they are first split into parts. The
  92. size of each part is `ConsensusParams.BlockGossip.BlockPartSizeBytes`.
  93. #### EvidenceParams
  94. For evidence in a block to be valid, it must satisfy:
  95. ```
  96. block.Header.Height - evidence.Height < ConsensusParams.EvidenceParams.MaxAge
  97. ```