proto: seperate native and proto types (#5994)

## Description

Separate protobuf and domain types. We should avoid using protobuf in our core logic. 

ref #5460
This commit is contained in:
Marko
2021-01-27 20:14:27 +00:00
committed by GitHub
parent 4dca066aab
commit 70bb8cc8b7
36 changed files with 301 additions and 157 deletions
+10 -10
View File
@@ -18,7 +18,6 @@ import (
tmmath "github.com/tendermint/tendermint/libs/math"
tmsync "github.com/tendermint/tendermint/libs/sync"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
"github.com/tendermint/tendermint/version"
)
@@ -311,7 +310,7 @@ func MaxDataBytesNoEvidence(maxBytes int64, valsCount int) int64 {
func MakeBlock(height int64, txs []Tx, lastCommit *Commit, evidence []Evidence) *Block {
block := &Block{
Header: Header{
Version: tmversion.Consensus{Block: version.BlockProtocol, App: 0},
Version: version.Consensus{Block: version.BlockProtocol, App: 0},
Height: height,
},
Data: Data{
@@ -333,10 +332,10 @@ func MakeBlock(height int64, txs []Tx, lastCommit *Commit, evidence []Evidence)
// - https://github.com/tendermint/spec/blob/master/spec/blockchain/blockchain.md
type Header struct {
// basic block info
Version tmversion.Consensus `json:"version"`
ChainID string `json:"chain_id"`
Height int64 `json:"height"`
Time time.Time `json:"time"`
Version version.Consensus `json:"version"`
ChainID string `json:"chain_id"`
Height int64 `json:"height"`
Time time.Time `json:"time"`
// prev block info
LastBlockID BlockID `json:"last_block_id"`
@@ -361,7 +360,7 @@ type Header struct {
// Populate the Header with state-derived data.
// Call this after MakeBlock to complete the Header.
func (h *Header) Populate(
version tmversion.Consensus, chainID string,
version version.Consensus, chainID string,
timestamp time.Time, lastBlockID BlockID,
valHash, nextValHash []byte,
consensusHash, appHash, lastResultsHash []byte,
@@ -449,7 +448,8 @@ func (h *Header) Hash() tmbytes.HexBytes {
if h == nil || len(h.ValidatorsHash) == 0 {
return nil
}
hbz, err := h.Version.Marshal()
hpb := h.Version.ToProto()
hbz, err := hpb.Marshal()
if err != nil {
return nil
}
@@ -527,7 +527,7 @@ func (h *Header) ToProto() *tmproto.Header {
}
return &tmproto.Header{
Version: h.Version,
Version: h.Version.ToProto(),
ChainID: h.ChainID,
Height: h.Height,
Time: h.Time,
@@ -558,7 +558,7 @@ func HeaderFromProto(ph *tmproto.Header) (Header, error) {
return Header{}, err
}
h.Version = ph.Version
h.Version = version.Consensus{Block: ph.Version.Block, App: ph.Version.App}
h.ChainID = ph.ChainID
h.Height = ph.Height
h.Time = ph.Time
+25 -21
View File
@@ -320,7 +320,7 @@ func TestHeaderHash(t *testing.T) {
expectHash bytes.HexBytes
}{
{"Generates expected hash", &Header{
Version: tmversion.Consensus{Block: 1, App: 2},
Version: version.Consensus{Block: 1, App: 2},
ChainID: "chainId",
Height: 3,
Time: time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC),
@@ -337,7 +337,7 @@ func TestHeaderHash(t *testing.T) {
}, hexBytesFromString("F740121F553B5418C3EFBD343C2DBFE9E007BB67B0D020A0741374BAB65242A4")},
{"nil header yields nil", nil, nil},
{"nil ValidatorsHash yields nil", &Header{
Version: tmversion.Consensus{Block: 1, App: 2},
Version: version.Consensus{Block: 1, App: 2},
ChainID: "chainId",
Height: 3,
Time: time.Date(2019, 10, 13, 16, 14, 44, 0, time.UTC),
@@ -377,8 +377,12 @@ func TestHeaderHash(t *testing.T) {
bz, err := gogotypes.StdTimeMarshal(f)
require.NoError(t, err)
byteSlices = append(byteSlices, bz)
case tmversion.Consensus:
bz, err := f.Marshal()
case version.Consensus:
pbc := tmversion.Consensus{
Block: f.Block,
App: f.App,
}
bz, err := pbc.Marshal()
require.NoError(t, err)
byteSlices = append(byteSlices, bz)
case BlockID:
@@ -412,7 +416,7 @@ func TestMaxHeaderBytes(t *testing.T) {
timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
h := Header{
Version: tmversion.Consensus{Block: math.MaxInt64, App: math.MaxInt64},
Version: version.Consensus{Block: math.MaxInt64, App: math.MaxInt64},
ChainID: maxChainID,
Height: math.MaxInt64,
Time: timestamp,
@@ -750,7 +754,7 @@ func makeRandHeader() Header {
randBytes := tmrand.Bytes(tmhash.Size)
randAddress := tmrand.Bytes(crypto.AddressSize)
h := Header{
Version: tmversion.Consensus{Block: version.BlockProtocol, App: 1},
Version: version.Consensus{Block: version.BlockProtocol, App: 1},
ChainID: chainID,
Height: height,
Time: t,
@@ -956,13 +960,13 @@ func TestHeader_ValidateBasic(t *testing.T) {
}{
{
"invalid version block",
Header{Version: tmversion.Consensus{Block: version.BlockProtocol + 1}},
Header{Version: version.Consensus{Block: version.BlockProtocol + 1}},
true, "block protocol is incorrect",
},
{
"invalid chain ID length",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen+1)),
},
true, "chainID is too long",
@@ -970,7 +974,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid height (negative)",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: -1,
},
@@ -979,7 +983,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid height (zero)",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 0,
},
@@ -988,7 +992,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid block ID hash",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
@@ -1000,7 +1004,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid block ID parts header hash",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
@@ -1015,7 +1019,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid last commit hash",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
@@ -1031,7 +1035,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid data hash",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
@@ -1048,7 +1052,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid evidence hash",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
@@ -1066,7 +1070,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid proposer address",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
@@ -1085,7 +1089,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid validator hash",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
@@ -1105,7 +1109,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid next validator hash",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
@@ -1126,7 +1130,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid consensus hash",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
@@ -1148,7 +1152,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"invalid last results hash",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
@@ -1171,7 +1175,7 @@ func TestHeader_ValidateBasic(t *testing.T) {
{
"valid header",
Header{
Version: tmversion.Consensus{Block: version.BlockProtocol},
Version: version.Consensus{Block: version.BlockProtocol},
ChainID: string(make([]byte, MaxChainIDLen)),
Height: 1,
LastBlockID: BlockID{
+1 -2
View File
@@ -12,7 +12,6 @@ import (
"github.com/tendermint/tendermint/crypto/tmhash"
tmrand "github.com/tendermint/tendermint/libs/rand"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
"github.com/tendermint/tendermint/version"
)
@@ -244,7 +243,7 @@ func makeVote(
func makeHeaderRandom() *Header {
return &Header{
Version: tmversion.Consensus{Block: version.BlockProtocol, App: 1},
Version: version.Consensus{Block: version.BlockProtocol, App: 1},
ChainID: tmrand.Str(12),
Height: int64(tmrand.Uint16()) + 1,
Time: time.Now(),
+8 -9
View File
@@ -11,7 +11,6 @@ import (
"github.com/tendermint/tendermint/crypto"
tmbytes "github.com/tendermint/tendermint/libs/bytes"
tmjson "github.com/tendermint/tendermint/libs/json"
tmproto "github.com/tendermint/tendermint/proto/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
@@ -36,13 +35,13 @@ type GenesisValidator struct {
// GenesisDoc defines the initial conditions for a tendermint blockchain, in particular its validator set.
type GenesisDoc struct {
GenesisTime time.Time `json:"genesis_time"`
ChainID string `json:"chain_id"`
InitialHeight int64 `json:"initial_height"`
ConsensusParams *tmproto.ConsensusParams `json:"consensus_params,omitempty"`
Validators []GenesisValidator `json:"validators,omitempty"`
AppHash tmbytes.HexBytes `json:"app_hash"`
AppState json.RawMessage `json:"app_state,omitempty"`
GenesisTime time.Time `json:"genesis_time"`
ChainID string `json:"chain_id"`
InitialHeight int64 `json:"initial_height"`
ConsensusParams *ConsensusParams `json:"consensus_params,omitempty"`
Validators []GenesisValidator `json:"validators,omitempty"`
AppHash tmbytes.HexBytes `json:"app_hash"`
AppState json.RawMessage `json:"app_state,omitempty"`
}
// SaveAs is a utility method for saving GenensisDoc as a JSON file.
@@ -83,7 +82,7 @@ func (genDoc *GenesisDoc) ValidateAndComplete() error {
if genDoc.ConsensusParams == nil {
genDoc.ConsensusParams = DefaultConsensusParams()
} else if err := ValidateConsensusParams(*genDoc.ConsensusParams); err != nil {
} else if err := genDoc.ConsensusParams.ValidateConsensusParams(); err != nil {
return err
}
+1 -2
View File
@@ -8,7 +8,6 @@ import (
"github.com/stretchr/testify/assert"
"github.com/tendermint/tendermint/crypto"
tmversion "github.com/tendermint/tendermint/proto/tendermint/version"
"github.com/tendermint/tendermint/version"
)
@@ -115,7 +114,7 @@ func TestSignedHeaderValidateBasic(t *testing.T) {
chainID := "𠜎"
timestamp := time.Date(math.MaxInt64, 0, 0, 0, 0, 0, math.MaxInt64, time.UTC)
h := Header{
Version: tmversion.Consensus{Block: version.BlockProtocol, App: math.MaxInt64},
Version: version.Consensus{Block: version.BlockProtocol, App: math.MaxInt64},
ChainID: chainID,
Height: commit.Height,
Time: timestamp,
+102 -16
View File
@@ -21,9 +21,53 @@ const (
MaxBlockPartsCount = (MaxBlockSizeBytes / BlockPartSizeBytes) + 1
)
// 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"`
}
// 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"`
MaxGas int64 `json:"max_gas"`
// Minimum time increment between consecutive blocks (in milliseconds)
// Not exposed to the application.
TimeIotaMs int64 `json:"time_iota_ms"`
}
// EvidenceParams determine how we handle evidence of malfeasance.
type EvidenceParams struct {
MaxAgeNumBlocks int64 `json:"max_age_num_blocks"` // only accept new evidence more recent than this
MaxAgeDuration time.Duration `json:"max_age_duration"`
MaxBytes int64 `json:"max_bytes"`
}
// 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"`
}
// DefaultConsensusParams returns a default ConsensusParams.
func DefaultConsensusParams() *tmproto.ConsensusParams {
return &tmproto.ConsensusParams{
func DefaultConsensusParams() *ConsensusParams {
return &ConsensusParams{
Block: DefaultBlockParams(),
Evidence: DefaultEvidenceParams(),
Validator: DefaultValidatorParams(),
@@ -32,8 +76,8 @@ func DefaultConsensusParams() *tmproto.ConsensusParams {
}
// DefaultBlockParams returns a default BlockParams.
func DefaultBlockParams() tmproto.BlockParams {
return tmproto.BlockParams{
func DefaultBlockParams() BlockParams {
return BlockParams{
MaxBytes: 22020096, // 21MB
MaxGas: -1,
TimeIotaMs: 1, // 1s, parameter is now unused
@@ -41,8 +85,8 @@ func DefaultBlockParams() tmproto.BlockParams {
}
// DefaultEvidenceParams returns a default EvidenceParams.
func DefaultEvidenceParams() tmproto.EvidenceParams {
return tmproto.EvidenceParams{
func DefaultEvidenceParams() EvidenceParams {
return EvidenceParams{
MaxAgeNumBlocks: 100000, // 27.8 hrs at 1block/s
MaxAgeDuration: 48 * time.Hour,
MaxBytes: 1048576, // 1MB
@@ -51,21 +95,21 @@ func DefaultEvidenceParams() tmproto.EvidenceParams {
// DefaultValidatorParams returns a default ValidatorParams, which allows
// only ed25519 pubkeys.
func DefaultValidatorParams() tmproto.ValidatorParams {
return tmproto.ValidatorParams{
func DefaultValidatorParams() ValidatorParams {
return ValidatorParams{
PubKeyTypes: []string{ABCIPubKeyTypeEd25519},
}
}
func DefaultVersionParams() tmproto.VersionParams {
return tmproto.VersionParams{
func DefaultVersionParams() VersionParams {
return VersionParams{
AppVersion: 0,
}
}
func IsValidPubkeyType(params tmproto.ValidatorParams, pubkeyType string) bool {
for i := 0; i < len(params.PubKeyTypes); i++ {
if params.PubKeyTypes[i] == pubkeyType {
func (val *ValidatorParams) IsValidPubkeyType(pubkeyType string) bool {
for i := 0; i < len(val.PubKeyTypes); i++ {
if val.PubKeyTypes[i] == pubkeyType {
return true
}
}
@@ -74,7 +118,7 @@ func IsValidPubkeyType(params tmproto.ValidatorParams, pubkeyType string) bool {
// Validate validates the ConsensusParams to ensure all values are within their
// allowed limits, and returns an error if they are not.
func ValidateConsensusParams(params tmproto.ConsensusParams) error {
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)
@@ -134,7 +178,7 @@ func ValidateConsensusParams(params tmproto.ConsensusParams) error {
// 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 HashConsensusParams(params tmproto.ConsensusParams) []byte {
func (params ConsensusParams) HashConsensusParams() []byte {
hasher := tmhash.New()
hp := tmproto.HashedParams{
@@ -156,7 +200,7 @@ func HashConsensusParams(params tmproto.ConsensusParams) []byte {
// Update returns a copy of the params with updates from the non-zero fields of p2.
// NOTE: note: must not modify the original
func UpdateConsensusParams(params tmproto.ConsensusParams, params2 *abci.ConsensusParams) tmproto.ConsensusParams {
func (params ConsensusParams) UpdateConsensusParams(params2 *abci.ConsensusParams) ConsensusParams {
res := params // explicit copy
if params2 == nil {
@@ -183,3 +227,45 @@ func UpdateConsensusParams(params tmproto.ConsensusParams, params2 *abci.Consens
}
return res
}
func (params ConsensusParams) ToProto() tmproto.ConsensusParams {
return tmproto.ConsensusParams{
Block: tmproto.BlockParams{
MaxBytes: params.Block.MaxBytes,
MaxGas: params.Block.MaxGas,
TimeIotaMs: params.Block.TimeIotaMs,
},
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,
},
}
}
func ConsensusParamsFromProto(pbParams tmproto.ConsensusParams) ConsensusParams {
return ConsensusParams{
Block: BlockParams{
MaxBytes: pbParams.Block.MaxBytes,
MaxGas: pbParams.Block.MaxGas,
TimeIotaMs: pbParams.Block.TimeIotaMs,
},
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,
},
}
}
+36 -14
View File
@@ -19,7 +19,7 @@ var (
func TestConsensusParamsValidation(t *testing.T) {
testCases := []struct {
params tmproto.ConsensusParams
params ConsensusParams
valid bool
}{
// test block params
@@ -44,9 +44,9 @@ func TestConsensusParamsValidation(t *testing.T) {
}
for i, tc := range testCases {
if tc.valid {
assert.NoErrorf(t, ValidateConsensusParams(tc.params), "expected no error for valid params (#%d)", i)
assert.NoErrorf(t, tc.params.ValidateConsensusParams(), "expected no error for valid params (#%d)", i)
} else {
assert.Errorf(t, ValidateConsensusParams(tc.params), "expected error for non valid params (#%d)", i)
assert.Errorf(t, tc.params.ValidateConsensusParams(), "expected error for non valid params (#%d)", i)
}
}
}
@@ -57,26 +57,26 @@ func makeParams(
evidenceAge int64,
maxEvidenceBytes int64,
pubkeyTypes []string,
) tmproto.ConsensusParams {
return tmproto.ConsensusParams{
Block: tmproto.BlockParams{
) ConsensusParams {
return ConsensusParams{
Block: BlockParams{
MaxBytes: blockBytes,
MaxGas: blockGas,
TimeIotaMs: blockTimeIotaMs,
},
Evidence: tmproto.EvidenceParams{
Evidence: EvidenceParams{
MaxAgeNumBlocks: evidenceAge,
MaxAgeDuration: time.Duration(evidenceAge),
MaxBytes: maxEvidenceBytes,
},
Validator: tmproto.ValidatorParams{
Validator: ValidatorParams{
PubKeyTypes: pubkeyTypes,
},
}
}
func TestConsensusParamsHash(t *testing.T) {
params := []tmproto.ConsensusParams{
params := []ConsensusParams{
makeParams(4, 2, 10, 3, 1, valEd25519),
makeParams(1, 4, 10, 3, 1, valEd25519),
makeParams(1, 2, 10, 4, 1, valEd25519),
@@ -89,7 +89,7 @@ func TestConsensusParamsHash(t *testing.T) {
hashes := make([][]byte, len(params))
for i := range params {
hashes[i] = HashConsensusParams(params[i])
hashes[i] = params[i].HashConsensusParams()
}
// make sure there are no duplicates...
@@ -104,9 +104,9 @@ func TestConsensusParamsHash(t *testing.T) {
func TestConsensusParamsUpdate(t *testing.T) {
testCases := []struct {
params tmproto.ConsensusParams
params ConsensusParams
updates *abci.ConsensusParams
updatedParams tmproto.ConsensusParams
updatedParams ConsensusParams
}{
// empty updates
{
@@ -135,7 +135,7 @@ func TestConsensusParamsUpdate(t *testing.T) {
},
}
for _, tc := range testCases {
assert.Equal(t, tc.updatedParams, UpdateConsensusParams(tc.params, tc.updates))
assert.Equal(t, tc.updatedParams, tc.params.UpdateConsensusParams(tc.updates))
}
}
@@ -144,8 +144,30 @@ func TestConsensusParamsUpdate_AppVersion(t *testing.T) {
assert.EqualValues(t, 0, params.Version.AppVersion)
updated := UpdateConsensusParams(params,
updated := params.UpdateConsensusParams(
&abci.ConsensusParams{Version: &tmproto.VersionParams{AppVersion: 1}})
assert.EqualValues(t, 1, updated.Version.AppVersion)
}
func TestProto(t *testing.T) {
params := []ConsensusParams{
makeParams(4, 2, 10, 3, 1, valEd25519),
makeParams(1, 4, 10, 3, 1, valEd25519),
makeParams(1, 2, 10, 4, 1, valEd25519),
makeParams(2, 5, 10, 7, 1, valEd25519),
makeParams(1, 7, 10, 6, 1, valEd25519),
makeParams(9, 5, 10, 4, 1, valEd25519),
makeParams(7, 8, 10, 9, 1, valEd25519),
makeParams(4, 6, 10, 5, 1, valEd25519),
}
for i := range params {
pbParams := params[i].ToProto()
oriParams := ConsensusParamsFromProto(pbParams)
assert.Equal(t, params[i], oriParams)
}
}
+13 -4
View File
@@ -34,7 +34,7 @@ type tm2pb struct{}
func (tm2pb) Header(header *Header) tmproto.Header {
return tmproto.Header{
Version: header.Version,
Version: header.Version.ToProto(),
ChainID: header.ChainID,
Height: header.Height,
Time: header.Time,
@@ -97,14 +97,23 @@ func (tm2pb) ValidatorUpdates(vals *ValidatorSet) []abci.ValidatorUpdate {
return validators
}
func (tm2pb) ConsensusParams(params *tmproto.ConsensusParams) *abci.ConsensusParams {
func (tm2pb) ConsensusParams(params *ConsensusParams) *abci.ConsensusParams {
return &abci.ConsensusParams{
Block: &abci.BlockParams{
MaxBytes: params.Block.MaxBytes,
MaxGas: params.Block.MaxGas,
},
Evidence: &params.Evidence,
Validator: &params.Validator,
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,
},
}
}
+1 -1
View File
@@ -55,7 +55,7 @@ func TestABCIValidators(t *testing.T) {
func TestABCIConsensusParams(t *testing.T) {
cp := DefaultConsensusParams()
abciCP := TM2PB.ConsensusParams(cp)
cp2 := UpdateConsensusParams(*cp, abciCP)
cp2 := cp.UpdateConsensusParams(abciCP)
assert.Equal(t, *cp, cp2)
}