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.

80 lines
2.2 KiB

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. However, the types it contains are part of the specification, since
  9. their Merkle roots are included in blocks.
  10. Details on an implementation of `State` with persistence is forthcoming, see [this issue](https://github.com/tendermint/tendermint/issues/1152)
  11. ```go
  12. type State struct {
  13. LastResults []Result
  14. AppHash []byte
  15. LastValidators []Validator
  16. Validators []Validator
  17. NextValidators []Validator
  18. ConsensusParams ConsensusParams
  19. }
  20. ```
  21. ### Result
  22. ```go
  23. type Result struct {
  24. Code uint32
  25. Data []byte
  26. Tags []KVPair
  27. }
  28. type KVPair struct {
  29. Key []byte
  30. Value []byte
  31. }
  32. ```
  33. `Result` is the result of executing a transaction against the application.
  34. It returns a result code, an arbitrary byte array (ie. a return value),
  35. and a list of key-value pairs ordered by key. The key-value pairs, or tags,
  36. can be used to index transactions according to their "effects", which are
  37. represented in the tags.
  38. ### Validator
  39. A validator is an active participant in the consensus with a public key and a voting power.
  40. Validator's also contain an address which is derived from the PubKey:
  41. ```go
  42. type Validator struct {
  43. Address []byte
  44. PubKey PubKey
  45. VotingPower int64
  46. }
  47. ```
  48. The `state.Validators` and `state.LastValidators` must always by sorted by validator address,
  49. so that there is a canonical order for computing the SimpleMerkleRoot.
  50. We also define a `TotalVotingPower` function, to return the total voting power:
  51. ```go
  52. func TotalVotingPower(vals []Validators) int64{
  53. sum := 0
  54. for v := range vals{
  55. sum += v.VotingPower
  56. }
  57. return sum
  58. }
  59. ```
  60. ### ConsensusParams
  61. This section is forthcoming. See [this issue](https://github.com/tendermint/tendermint/issues/1152).