store: proto migration (#4974)

## Description

migrate store to protobuf

Closes: #XXX
This commit is contained in:
Marko
2020-06-08 08:43:29 +02:00
committed by GitHub
parent 6cfbe1eb5c
commit f9f4916bc3
11 changed files with 225 additions and 132 deletions

View File

@@ -8,6 +8,8 @@ import (
"sync"
"time"
"github.com/gogo/protobuf/proto"
"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/merkle"
"github.com/tendermint/tendermint/crypto/tmhash"
@@ -140,9 +142,11 @@ func (b *Block) MakePartSet(partSize uint32) *PartSet {
b.mtx.Lock()
defer b.mtx.Unlock()
// We prefix the byte length, so that unmarshaling
// can easily happen via a reader.
bz, err := cdc.MarshalBinaryLengthPrefixed(b)
pbb, err := b.ToProto()
if err != nil {
panic(err)
}
bz, err := proto.Marshal(pbb)
if err != nil {
panic(err)
}
@@ -1121,7 +1125,7 @@ func (data *Data) ToProto() tmproto.Data {
return *tp
}
// DataFromProto takes a protobud representation of Data &
// DataFromProto takes a protobuf representation of Data &
// returns the native type.
func DataFromProto(dp *tmproto.Data) (Data, error) {
if dp == nil {

View File

@@ -660,6 +660,7 @@ func TestBlockProtoBuf(t *testing.T) {
} else {
require.Error(t, err, tc.msg)
}
block, err := BlockFromProto(pb)
if tc.expPass2 {
require.NoError(t, err, tc.msg)

View File

@@ -262,6 +262,7 @@ func EvidenceFromProto(evidence *tmproto.Evidence) (Evidence, error) {
return tp, tp.ValidateBasic()
case *tmproto.Evidence_LunaticValidatorEvidence:
h, err := HeaderFromProto(evi.LunaticValidatorEvidence.GetHeader())
if err != nil {
return nil, err
@@ -526,8 +527,6 @@ type ConflictingHeadersEvidence struct {
H2 *SignedHeader `json:"h_2"`
}
var _ Evidence = &ConflictingHeadersEvidence{}
var _ CompositeEvidence = &ConflictingHeadersEvidence{}
var _ Evidence = ConflictingHeadersEvidence{}
var _ CompositeEvidence = ConflictingHeadersEvidence{}
@@ -778,7 +777,6 @@ type PhantomValidatorEvidence struct {
LastHeightValidatorWasInSet int64 `json:"last_height_validator_was_in_set"`
}
var _ Evidence = &PhantomValidatorEvidence{}
var _ Evidence = PhantomValidatorEvidence{}
func (e PhantomValidatorEvidence) Height() int64 {
@@ -858,7 +856,6 @@ type LunaticValidatorEvidence struct {
InvalidHeaderField string `json:"invalid_header_field"`
}
var _ Evidence = &LunaticValidatorEvidence{}
var _ Evidence = LunaticValidatorEvidence{}
func (e LunaticValidatorEvidence) Height() int64 {
@@ -959,6 +956,10 @@ func (e LunaticValidatorEvidence) VerifyHeader(committedHeader *Header) error {
return fmt.Errorf("%s matches committed hash", field)
}
if committedHeader == nil {
return errors.New("committed header is nil")
}
switch e.InvalidHeaderField {
case ValidatorsHashField:
if bytes.Equal(committedHeader.ValidatorsHash, e.Header.ValidatorsHash) {
@@ -994,7 +995,6 @@ type PotentialAmnesiaEvidence struct {
VoteB *Vote `json:"vote_b"`
}
var _ Evidence = &PotentialAmnesiaEvidence{}
var _ Evidence = PotentialAmnesiaEvidence{}
func (e PotentialAmnesiaEvidence) Height() int64 {