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.

133 lines
3.4 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
  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. 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 field, which is a hash digest of the PubKey.
  37. ```go
  38. type Validator struct {
  39. Address []byte
  40. PubKey PubKey
  41. VotingPower int64
  42. }
  43. ```
  44. When hashing the Validator struct, the pubkey is not hashed,
  45. because the address is already the hash of the pubkey.
  46. The `state.Validators`, `state.LastValidators`, and `state.NextValidators`, must always by sorted by validator address,
  47. so that there is a canonical order for computing the SimpleMerkleRoot.
  48. We also define a `TotalVotingPower` function, to return the total voting power:
  49. ```go
  50. func TotalVotingPower(vals []Validators) int64{
  51. sum := 0
  52. for v := range vals{
  53. sum += v.VotingPower
  54. }
  55. return sum
  56. }
  57. ```
  58. ### ConsensusParams
  59. ConsensusParams define various limits for blockchain data structures.
  60. Like validator sets, they are set during genesis and can be updated by the application through ABCI.
  61. ```
  62. type ConsensusParams struct {
  63. BlockSize
  64. TxSize
  65. BlockGossip
  66. EvidenceParams
  67. }
  68. type BlockSize struct {
  69. MaxBytes int
  70. MaxGas int64
  71. }
  72. type TxSize struct {
  73. MaxBytes int
  74. MaxGas int64
  75. }
  76. type BlockGossip struct {
  77. BlockPartSizeBytes int
  78. }
  79. type EvidenceParams struct {
  80. MaxAge int64
  81. }
  82. ```
  83. #### BlockSize
  84. The total size of a block is limited in bytes by the `ConsensusParams.BlockSize.MaxBytes`.
  85. Proposed blocks must be less than this size, and will be considered invalid
  86. otherwise.
  87. Blocks should additionally be limited by the amount of "gas" consumed by the
  88. transactions in the block, though this is not yet implemented.
  89. #### TxSize
  90. These parameters are not yet enforced and may disappear. See [issue
  91. #2347](https://github.com/tendermint/tendermint/issues/2347).
  92. #### BlockGossip
  93. When gossipping blocks in the consensus, they are first split into parts. The
  94. size of each part is `ConsensusParams.BlockGossip.BlockPartSizeBytes`.
  95. #### EvidenceParams
  96. For evidence in a block to be valid, it must satisfy:
  97. ```
  98. block.Header.Height - evidence.Height < ConsensusParams.EvidenceParams.MaxAge
  99. ```