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.

81 lines
2.0 KiB

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 set of validators 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. For details on an implementation of `State` with persistence, see TODO
  11. ```go
  12. type State struct {
  13. LastResults []Result
  14. AppHash []byte
  15. Validators []Validator
  16. LastValidators []Validator
  17. ConsensusParams ConsensusParams
  18. }
  19. ```
  20. ### Result
  21. ```go
  22. type Result struct {
  23. Code uint32
  24. Data []byte
  25. Tags []KVPair
  26. }
  27. type KVPair struct {
  28. Key []byte
  29. Value []byte
  30. }
  31. ```
  32. `Result` is the result of executing a transaction against the application.
  33. It returns a result code, an arbitrary byte array (ie. a return value),
  34. and a list of key-value pairs ordered by key. The key-value pairs, or tags,
  35. can be used to index transactions according to their "effects", which are
  36. represented in the tags.
  37. ### Validator
  38. A validator is an active participant in the consensus with a public key and a voting power.
  39. Validator's also contain an address which is derived from the PubKey:
  40. ```go
  41. type Validator struct {
  42. Address []byte
  43. PubKey PubKey
  44. VotingPower int64
  45. }
  46. ```
  47. The `state.Validators` and `state.LastValidators` 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. TODO: