mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-09 06:33:16 +00:00
## Summary This pull request adds a default set of values to the new Synchrony parameters. These values were chosen by after observation of three live networks: Emoney, Osmosis, and the Cosmos Hub. For the default Precision value, `505ms` was selected. The reasoning for this is summarized in https://github.com/tendermint/tendermint/issues/7724 For each observed chain, an experimental Message Delay was collected over a 24 hour period and an average over this period was calculated using this data. Values over 10s were considered outliers and treated separately for the average since the majority of observations were far below 10s. The message delay was calculated both for the quorum and the 'full' prevote. Description of the technique for collecting the experimental values can found in #7202. This value is calculated only using timestamps given by processes on the network, so large variation in values is almost certainly due to clock skew among the validator set. `12s` is proposed for the default MessageDelay value. This value would easily accomodates all non-outlier values, allowing even E-money's 4.25s value to be valid. This would also allow some validators with skewed clocks to still participate without allowing for huge variation in the timestamps produced by the network. Additionally, for the currently listed use-cases of PBTS, such as unbonding period, and light client trust period, the current bounds for these are in weeks. Adding a few seconds of tolerance by default is therefore unlikely to have serious side-effects. ## Data ### Cosmos Hub Observation Period: 2022-02-03 20:22-2022-02-04 20:22 Avg Full Prevote Message Delay: 1.27s Outliers: 11s,13s,50s,106s,144s Total Outlier Heights: 86 Avg Quorum Prevote Message Delay: .77s Outliers: 10s,14s,107s,144s Total Outlier Heights: 617 Total heights: 11528 ### Osmosis Observation Period: 2022-01-29 20:26-2022-01-28 20:26 Avg Quorum Prevote Message Delay: .46s Outliers: 21s,50s Total Outlier Heights: 26 NOTE: During the observation period, a 'full' prevote was not observed. Total heights: 13983 ### E-Money Observation Period: 2022-02-07 04:29-2022-02-08 04:29 Avg Full Prevote Message Delay: 4.25s Outliers: 12s,15s,39s Total Outlier Heights: 128 Avg Quorum Prevote Message Delay: .20s Outliers: 28s Total Outlier Heights: 15 Total heights: 3791
331 lines
10 KiB
Go
331 lines
10 KiB
Go
package types
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"time"
|
|
|
|
"github.com/tendermint/tendermint/crypto/ed25519"
|
|
"github.com/tendermint/tendermint/crypto/secp256k1"
|
|
"github.com/tendermint/tendermint/crypto/sr25519"
|
|
"github.com/tendermint/tendermint/crypto/tmhash"
|
|
tmstrings "github.com/tendermint/tendermint/libs/strings"
|
|
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
|
|
)
|
|
|
|
const (
|
|
// MaxBlockSizeBytes is the maximum permitted size of the blocks.
|
|
MaxBlockSizeBytes = 104857600 // 100MB
|
|
|
|
// BlockPartSizeBytes is the size of one block part.
|
|
BlockPartSizeBytes uint32 = 65536 // 64kB
|
|
|
|
// MaxBlockPartsCount is the maximum number of block parts.
|
|
MaxBlockPartsCount = (MaxBlockSizeBytes / BlockPartSizeBytes) + 1
|
|
|
|
ABCIPubKeyTypeEd25519 = ed25519.KeyType
|
|
ABCIPubKeyTypeSecp256k1 = secp256k1.KeyType
|
|
ABCIPubKeyTypeSr25519 = sr25519.KeyType
|
|
)
|
|
|
|
var ABCIPubKeyTypesToNames = map[string]string{
|
|
ABCIPubKeyTypeEd25519: ed25519.PubKeyName,
|
|
ABCIPubKeyTypeSecp256k1: secp256k1.PubKeyName,
|
|
ABCIPubKeyTypeSr25519: sr25519.PubKeyName,
|
|
}
|
|
|
|
// ConsensusParams contains consensus critical parameters that determine the
|
|
// validity of blocks.
|
|
type ConsensusParams struct {
|
|
Block BlockParams `json:"block"`
|
|
Evidence EvidenceParams `json:"evidence"`
|
|
Validator ValidatorParams `json:"validator"`
|
|
Version VersionParams `json:"version"`
|
|
Synchrony SynchronyParams `json:"synchrony"`
|
|
}
|
|
|
|
// HashedParams is a subset of ConsensusParams.
|
|
// It is amino encoded and hashed into
|
|
// the Header.ConsensusHash.
|
|
type HashedParams struct {
|
|
BlockMaxBytes int64
|
|
BlockMaxGas int64
|
|
}
|
|
|
|
// BlockParams define limits on the block size and gas plus minimum time
|
|
// between blocks.
|
|
type BlockParams struct {
|
|
MaxBytes int64 `json:"max_bytes,string"`
|
|
MaxGas int64 `json:"max_gas,string"`
|
|
}
|
|
|
|
// EvidenceParams determine how we handle evidence of malfeasance.
|
|
type EvidenceParams struct {
|
|
MaxAgeNumBlocks int64 `json:"max_age_num_blocks,string"` // only accept new evidence more recent than this
|
|
MaxAgeDuration time.Duration `json:"max_age_duration,string"`
|
|
MaxBytes int64 `json:"max_bytes,string"`
|
|
}
|
|
|
|
// ValidatorParams restrict the public key types validators can use.
|
|
// NOTE: uses ABCI pubkey naming, not Amino names.
|
|
type ValidatorParams struct {
|
|
PubKeyTypes []string `json:"pub_key_types"`
|
|
}
|
|
|
|
type VersionParams struct {
|
|
AppVersion uint64 `json:"app_version,string"`
|
|
}
|
|
|
|
// SynchronyParams influence the validity of block timestamps.
|
|
// For more information on the relationship of the synchrony parameters to
|
|
// block validity, see the Proposer-Based Timestamps specification:
|
|
// https://github.com/tendermint/tendermint/blob/master/spec/consensus/proposer-based-timestamp/README.md
|
|
type SynchronyParams struct {
|
|
Precision time.Duration `json:"precision,string"`
|
|
MessageDelay time.Duration `json:"message_delay,string"`
|
|
}
|
|
|
|
// DefaultConsensusParams returns a default ConsensusParams.
|
|
func DefaultConsensusParams() *ConsensusParams {
|
|
return &ConsensusParams{
|
|
Block: DefaultBlockParams(),
|
|
Evidence: DefaultEvidenceParams(),
|
|
Validator: DefaultValidatorParams(),
|
|
Version: DefaultVersionParams(),
|
|
Synchrony: DefaultSynchronyParams(),
|
|
}
|
|
}
|
|
|
|
// DefaultBlockParams returns a default BlockParams.
|
|
func DefaultBlockParams() BlockParams {
|
|
return BlockParams{
|
|
MaxBytes: 22020096, // 21MB
|
|
MaxGas: -1,
|
|
}
|
|
}
|
|
|
|
// DefaultEvidenceParams returns a default EvidenceParams.
|
|
func DefaultEvidenceParams() EvidenceParams {
|
|
return EvidenceParams{
|
|
MaxAgeNumBlocks: 100000, // 27.8 hrs at 1block/s
|
|
MaxAgeDuration: 48 * time.Hour,
|
|
MaxBytes: 1048576, // 1MB
|
|
}
|
|
}
|
|
|
|
// DefaultValidatorParams returns a default ValidatorParams, which allows
|
|
// only ed25519 pubkeys.
|
|
func DefaultValidatorParams() ValidatorParams {
|
|
return ValidatorParams{
|
|
PubKeyTypes: []string{ABCIPubKeyTypeEd25519},
|
|
}
|
|
}
|
|
|
|
func DefaultVersionParams() VersionParams {
|
|
return VersionParams{
|
|
AppVersion: 0,
|
|
}
|
|
}
|
|
|
|
func DefaultSynchronyParams() SynchronyParams {
|
|
return SynchronyParams{
|
|
// 505ms was selected as the default to enable chains that have validators in
|
|
// mixed leap-second handling environments.
|
|
// For more information, see: https://github.com/tendermint/tendermint/issues/7724
|
|
Precision: 505 * time.Millisecond,
|
|
MessageDelay: 12 * time.Second,
|
|
}
|
|
}
|
|
|
|
func (val *ValidatorParams) IsValidPubkeyType(pubkeyType string) bool {
|
|
for i := 0; i < len(val.PubKeyTypes); i++ {
|
|
if val.PubKeyTypes[i] == pubkeyType {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
func (params *ConsensusParams) Complete() {
|
|
if params.Synchrony == (SynchronyParams{}) {
|
|
params.Synchrony = DefaultSynchronyParams()
|
|
}
|
|
}
|
|
|
|
// Validate validates the ConsensusParams to ensure all values are within their
|
|
// allowed limits, and returns an error if they are not.
|
|
func (params ConsensusParams) ValidateConsensusParams() error {
|
|
if params.Block.MaxBytes <= 0 {
|
|
return fmt.Errorf("block.MaxBytes must be greater than 0. Got %d",
|
|
params.Block.MaxBytes)
|
|
}
|
|
if params.Block.MaxBytes > MaxBlockSizeBytes {
|
|
return fmt.Errorf("block.MaxBytes is too big. %d > %d",
|
|
params.Block.MaxBytes, MaxBlockSizeBytes)
|
|
}
|
|
|
|
if params.Block.MaxGas < -1 {
|
|
return fmt.Errorf("block.MaxGas must be greater or equal to -1. Got %d",
|
|
params.Block.MaxGas)
|
|
}
|
|
|
|
if params.Evidence.MaxAgeNumBlocks <= 0 {
|
|
return fmt.Errorf("evidence.MaxAgeNumBlocks must be greater than 0. Got %d",
|
|
params.Evidence.MaxAgeNumBlocks)
|
|
}
|
|
|
|
if params.Evidence.MaxAgeDuration <= 0 {
|
|
return fmt.Errorf("evidence.MaxAgeDuration must be greater than 0 if provided, Got %v",
|
|
params.Evidence.MaxAgeDuration)
|
|
}
|
|
|
|
if params.Evidence.MaxBytes > params.Block.MaxBytes {
|
|
return fmt.Errorf("evidence.MaxBytesEvidence is greater than upper bound, %d > %d",
|
|
params.Evidence.MaxBytes, params.Block.MaxBytes)
|
|
}
|
|
|
|
if params.Evidence.MaxBytes < 0 {
|
|
return fmt.Errorf("evidence.MaxBytes must be non negative. Got: %d",
|
|
params.Evidence.MaxBytes)
|
|
}
|
|
|
|
if params.Synchrony.MessageDelay <= 0 {
|
|
return fmt.Errorf("synchrony.MessageDelay must be greater than 0. Got: %d",
|
|
params.Synchrony.MessageDelay)
|
|
}
|
|
|
|
if params.Synchrony.Precision <= 0 {
|
|
return fmt.Errorf("synchrony.Precision must be greater than 0. Got: %d",
|
|
params.Synchrony.Precision)
|
|
}
|
|
|
|
if len(params.Validator.PubKeyTypes) == 0 {
|
|
return errors.New("len(Validator.PubKeyTypes) must be greater than 0")
|
|
}
|
|
|
|
// Check if keyType is a known ABCIPubKeyType
|
|
for i := 0; i < len(params.Validator.PubKeyTypes); i++ {
|
|
keyType := params.Validator.PubKeyTypes[i]
|
|
if _, ok := ABCIPubKeyTypesToNames[keyType]; !ok {
|
|
return fmt.Errorf("params.Validator.PubKeyTypes[%d], %s, is an unknown pubkey type",
|
|
i, keyType)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// Hash returns a hash of a subset of the parameters to store in the block header.
|
|
// Only the Block.MaxBytes and Block.MaxGas are included in the hash.
|
|
// This allows the ConsensusParams to evolve more without breaking the block
|
|
// protocol. No need for a Merkle tree here, just a small struct to hash.
|
|
func (params ConsensusParams) HashConsensusParams() []byte {
|
|
hasher := tmhash.New()
|
|
|
|
hp := tmproto.HashedParams{
|
|
BlockMaxBytes: params.Block.MaxBytes,
|
|
BlockMaxGas: params.Block.MaxGas,
|
|
}
|
|
|
|
bz, err := hp.Marshal()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
|
|
_, err = hasher.Write(bz)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return hasher.Sum(nil)
|
|
}
|
|
|
|
func (params *ConsensusParams) Equals(params2 *ConsensusParams) bool {
|
|
return params.Block == params2.Block &&
|
|
params.Evidence == params2.Evidence &&
|
|
params.Version == params2.Version &&
|
|
params.Synchrony == params2.Synchrony &&
|
|
tmstrings.StringSliceEqual(params.Validator.PubKeyTypes, params2.Validator.PubKeyTypes)
|
|
}
|
|
|
|
// Update returns a copy of the params with updates from the non-zero fields of p2.
|
|
// NOTE: note: must not modify the original
|
|
func (params ConsensusParams) UpdateConsensusParams(params2 *tmproto.ConsensusParams) ConsensusParams {
|
|
res := params // explicit copy
|
|
|
|
if params2 == nil {
|
|
return res
|
|
}
|
|
|
|
// we must defensively consider any structs may be nil
|
|
if params2.Block != nil {
|
|
res.Block.MaxBytes = params2.Block.MaxBytes
|
|
res.Block.MaxGas = params2.Block.MaxGas
|
|
}
|
|
if params2.Evidence != nil {
|
|
res.Evidence.MaxAgeNumBlocks = params2.Evidence.MaxAgeNumBlocks
|
|
res.Evidence.MaxAgeDuration = params2.Evidence.MaxAgeDuration
|
|
res.Evidence.MaxBytes = params2.Evidence.MaxBytes
|
|
}
|
|
if params2.Validator != nil {
|
|
// Copy params2.Validator.PubkeyTypes, and set result's value to the copy.
|
|
// This avoids having to initialize the slice to 0 values, and then write to it again.
|
|
res.Validator.PubKeyTypes = append([]string{}, params2.Validator.PubKeyTypes...)
|
|
}
|
|
if params2.Version != nil {
|
|
res.Version.AppVersion = params2.Version.AppVersion
|
|
}
|
|
if params2.Synchrony != nil {
|
|
res.Synchrony.Precision = params2.Synchrony.Precision
|
|
res.Synchrony.MessageDelay = params2.Synchrony.MessageDelay
|
|
}
|
|
return res
|
|
}
|
|
|
|
func (params *ConsensusParams) ToProto() tmproto.ConsensusParams {
|
|
return tmproto.ConsensusParams{
|
|
Block: &tmproto.BlockParams{
|
|
MaxBytes: params.Block.MaxBytes,
|
|
MaxGas: params.Block.MaxGas,
|
|
},
|
|
Evidence: &tmproto.EvidenceParams{
|
|
MaxAgeNumBlocks: params.Evidence.MaxAgeNumBlocks,
|
|
MaxAgeDuration: params.Evidence.MaxAgeDuration,
|
|
MaxBytes: params.Evidence.MaxBytes,
|
|
},
|
|
Validator: &tmproto.ValidatorParams{
|
|
PubKeyTypes: params.Validator.PubKeyTypes,
|
|
},
|
|
Version: &tmproto.VersionParams{
|
|
AppVersion: params.Version.AppVersion,
|
|
},
|
|
Synchrony: &tmproto.SynchronyParams{
|
|
MessageDelay: params.Synchrony.MessageDelay,
|
|
Precision: params.Synchrony.Precision,
|
|
},
|
|
}
|
|
}
|
|
|
|
func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams {
|
|
return ConsensusParams{
|
|
Block: BlockParams{
|
|
MaxBytes: pbParams.Block.MaxBytes,
|
|
MaxGas: pbParams.Block.MaxGas,
|
|
},
|
|
Evidence: EvidenceParams{
|
|
MaxAgeNumBlocks: pbParams.Evidence.MaxAgeNumBlocks,
|
|
MaxAgeDuration: pbParams.Evidence.MaxAgeDuration,
|
|
MaxBytes: pbParams.Evidence.MaxBytes,
|
|
},
|
|
Validator: ValidatorParams{
|
|
PubKeyTypes: pbParams.Validator.PubKeyTypes,
|
|
},
|
|
Version: VersionParams{
|
|
AppVersion: pbParams.Version.AppVersion,
|
|
},
|
|
Synchrony: SynchronyParams{
|
|
MessageDelay: pbParams.Synchrony.MessageDelay,
|
|
Precision: pbParams.Synchrony.Precision,
|
|
},
|
|
}
|
|
}
|