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.

104 lines
2.6 KiB

7 years ago
  1. # Tendermint State
  2. ## State
  3. The state contains information whose cryptographic digest is included in block headers,
  4. and thus is necessary for validating new blocks.
  5. For instance, the Merkle root of the results from executing the previous block, or the Merkle root of the current validators.
  6. While neither the results of transactions now the validators are ever included in the blockchain itself,
  7. the Merkle roots are, and hence we need a separate data structure to track them.
  8. ```
  9. type State struct {
  10. LastResults []Result
  11. AppHash []byte
  12. Validators []Validator
  13. LastValidators []Validator
  14. ConsensusParams ConsensusParams
  15. }
  16. ```
  17. ### Result
  18. ```
  19. type Result struct {
  20. Code uint32
  21. Data []byte
  22. Tags []KVPair
  23. }
  24. type KVPair struct {
  25. Key []byte
  26. Value []byte
  27. }
  28. ```
  29. `Result` is the result of executing a transaction against the application.
  30. It returns a result code, an arbitrary byte array (ie. a return value),
  31. and a list of key-value pairs ordered by key. The key-value pairs, or tags,
  32. can be used to index transactions according to their "effects", which are
  33. represented in the tags.
  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. ```
  38. type Validator struct {
  39. Address []byte
  40. PubKey PubKey
  41. VotingPower int64
  42. }
  43. ```
  44. The `state.Validators` and `state.LastValidators` 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. ```
  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. ### PubKey
  57. TODO:
  58. ### ConsensusParams
  59. TODO:
  60. ## Execution
  61. We define an `Execute` function that takes a state and a block,
  62. executes the block against the application, and returns an updated state.
  63. ```
  64. Execute(s State, app ABCIApp, block Block) State {
  65. abciResponses := app.ApplyBlock(block)
  66. return State{
  67. LastResults: abciResponses.DeliverTxResults,
  68. AppHash: abciResponses.AppHash,
  69. Validators: UpdateValidators(state.Validators, abciResponses.ValidatorChanges),
  70. LastValidators: state.Validators,
  71. ConsensusParams: UpdateConsensusParams(state.ConsensusParams, abci.Responses.ConsensusParamChanges),
  72. }
  73. }
  74. type ABCIResponses struct {
  75. DeliverTxResults []Result
  76. ValidatorChanges []Validator
  77. ConsensusParamChanges ConsensusParams
  78. AppHash []byte
  79. }
  80. ```