2018-09-21 07:39:55 -04:00
|
|
|
# State
|
2017-12-26 18:43:03 -05:00
|
|
|
|
|
|
|
## State
|
|
|
|
|
2018-01-03 10:46:43 +01:00
|
|
|
The state contains information whose cryptographic digest is included in block headers, and thus is
|
2018-07-31 21:19:57 +03:00
|
|
|
necessary for validating new blocks. For instance, the validators set and the results of
|
2018-01-21 18:19:38 -05:00
|
|
|
transactions are never included in blocks, but their Merkle roots are - the state keeps track of them.
|
|
|
|
|
|
|
|
Note that the `State` object itself is an implementation detail, since it is never
|
|
|
|
included in a block or gossipped over the network, and we never compute
|
2018-09-06 12:47:26 -04:00
|
|
|
its hash. Thus we do not include here details of how the `State` object is
|
|
|
|
persisted or queried. That said, the types it contains are part of the specification, since
|
|
|
|
their Merkle roots are included in blocks and their values are used in
|
|
|
|
validation.
|
2017-12-26 18:43:03 -05:00
|
|
|
|
2018-01-03 10:46:43 +01:00
|
|
|
```go
|
2017-12-26 18:43:03 -05:00
|
|
|
type State struct {
|
2018-10-17 15:30:53 -04:00
|
|
|
Version Version
|
2017-12-26 18:43:03 -05:00
|
|
|
LastResults []Result
|
|
|
|
AppHash []byte
|
|
|
|
|
|
|
|
LastValidators []Validator
|
2018-07-31 21:19:57 +03:00
|
|
|
Validators []Validator
|
|
|
|
NextValidators []Validator
|
2017-12-26 18:43:03 -05:00
|
|
|
|
|
|
|
ConsensusParams ConsensusParams
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### Result
|
|
|
|
|
2018-01-03 10:46:43 +01:00
|
|
|
```go
|
2017-12-26 18:43:03 -05:00
|
|
|
type Result struct {
|
|
|
|
Code uint32
|
|
|
|
Data []byte
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
`Result` is the result of executing a transaction against the application.
|
2018-09-06 12:47:26 -04:00
|
|
|
It returns a result code and an arbitrary byte array (ie. a return value).
|
|
|
|
|
|
|
|
NOTE: the Result needs to be updated to include more fields returned from
|
|
|
|
processing transactions, like gas variables and tags - see
|
|
|
|
[issue 1007](https://github.com/tendermint/tendermint/issues/1007).
|
2017-12-26 18:43:03 -05:00
|
|
|
|
|
|
|
### Validator
|
|
|
|
|
|
|
|
A validator is an active participant in the consensus with a public key and a voting power.
|
2018-10-05 16:26:52 -07:00
|
|
|
Validator's also contain an address field, which is a hash digest of the PubKey.
|
2017-12-26 18:43:03 -05:00
|
|
|
|
2018-01-03 10:46:43 +01:00
|
|
|
```go
|
2017-12-26 18:43:03 -05:00
|
|
|
type Validator struct {
|
|
|
|
Address []byte
|
|
|
|
PubKey PubKey
|
|
|
|
VotingPower int64
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
2018-10-05 16:26:52 -07:00
|
|
|
When hashing the Validator struct, the pubkey is not hashed,
|
|
|
|
because the address is already the hash of the pubkey.
|
|
|
|
|
2018-09-06 12:41:57 -04:00
|
|
|
The `state.Validators`, `state.LastValidators`, and `state.NextValidators`, must always by sorted by validator address,
|
2017-12-26 18:43:03 -05:00
|
|
|
so that there is a canonical order for computing the SimpleMerkleRoot.
|
|
|
|
|
|
|
|
We also define a `TotalVotingPower` function, to return the total voting power:
|
|
|
|
|
2018-01-03 10:46:43 +01:00
|
|
|
```go
|
2017-12-26 18:43:03 -05:00
|
|
|
func TotalVotingPower(vals []Validators) int64{
|
|
|
|
sum := 0
|
|
|
|
for v := range vals{
|
|
|
|
sum += v.VotingPower
|
|
|
|
}
|
|
|
|
return sum
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
### ConsensusParams
|
|
|
|
|
2018-09-06 12:41:57 -04:00
|
|
|
ConsensusParams define various limits for blockchain data structures.
|
|
|
|
Like validator sets, they are set during genesis and can be updated by the application through ABCI.
|
|
|
|
|
|
|
|
```
|
|
|
|
type ConsensusParams struct {
|
|
|
|
BlockSize
|
|
|
|
TxSize
|
|
|
|
BlockGossip
|
|
|
|
EvidenceParams
|
|
|
|
}
|
|
|
|
|
|
|
|
type BlockSize struct {
|
|
|
|
MaxBytes int
|
|
|
|
MaxGas int64
|
|
|
|
}
|
|
|
|
|
|
|
|
type TxSize struct {
|
|
|
|
MaxBytes int
|
|
|
|
MaxGas int64
|
|
|
|
}
|
|
|
|
|
|
|
|
type BlockGossip struct {
|
|
|
|
BlockPartSizeBytes int
|
|
|
|
}
|
|
|
|
|
|
|
|
type EvidenceParams struct {
|
|
|
|
MaxAge int64
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
#### BlockSize
|
|
|
|
|
2018-09-07 11:40:16 +04:00
|
|
|
The total size of a block is limited in bytes by the `ConsensusParams.BlockSize.MaxBytes`.
|
2018-09-06 12:41:57 -04:00
|
|
|
Proposed blocks must be less than this size, and will be considered invalid
|
|
|
|
otherwise.
|
|
|
|
|
2018-09-07 11:40:16 +04:00
|
|
|
Blocks should additionally be limited by the amount of "gas" consumed by the
|
2018-09-06 12:41:57 -04:00
|
|
|
transactions in the block, though this is not yet implemented.
|
|
|
|
|
|
|
|
#### TxSize
|
|
|
|
|
|
|
|
These parameters are not yet enforced and may disappear. See [issue
|
|
|
|
#2347](https://github.com/tendermint/tendermint/issues/2347).
|
|
|
|
|
|
|
|
#### BlockGossip
|
|
|
|
|
|
|
|
When gossipping blocks in the consensus, they are first split into parts. The
|
|
|
|
size of each part is `ConsensusParams.BlockGossip.BlockPartSizeBytes`.
|
|
|
|
|
|
|
|
#### EvidenceParams
|
|
|
|
|
|
|
|
For evidence in a block to be valid, it must satisfy:
|
|
|
|
|
|
|
|
```
|
|
|
|
block.Header.Height - evidence.Height < ConsensusParams.EvidenceParams.MaxAge
|
|
|
|
```
|