mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-06 13:26:23 +00:00
store: proto migration (#4974)
## Description migrate store to protobuf Closes: #XXX
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user