From 99985278d46a5e3a49ebee8c8d1ab32d0af89eeb Mon Sep 17 00:00:00 2001 From: Marko Date: Tue, 9 Jun 2020 09:54:47 +0200 Subject: [PATCH] evidence: migrate reactor to proto (#4949) ## Description migration of evidence reactor to proto Closes: #XXX --- CHANGELOG_PENDING.md | 1 + evidence/codec.go | 21 ------ evidence/pool.go | 91 ++++++++++++++++++++---- evidence/pool_test.go | 14 +++- evidence/reactor.go | 125 ++++++++++++++++---------------- evidence/reactor_test.go | 28 -------- node/node_test.go | 1 - proto/evidence/msgs.pb.go | 31 ++++---- proto/evidence/msgs.proto | 2 +- proto/types/evidence.pb.go | 141 +++++++++++++++++++------------------ proto/types/evidence.proto | 4 +- types/evidence.go | 57 ++++++++++++++- types/evidence_test.go | 39 ++++++++++ 13 files changed, 336 insertions(+), 219 deletions(-) delete mode 100644 evidence/codec.go diff --git a/CHANGELOG_PENDING.md b/CHANGELOG_PENDING.md index a7a376459..69db2c8e3 100644 --- a/CHANGELOG_PENDING.md +++ b/CHANGELOG_PENDING.md @@ -41,6 +41,7 @@ Friendly reminder, we have a [bug bounty program](https://hackerone.com/tendermi - [store] \#4778 Transition store module to protobuf encoding - `BlockStoreStateJSON` is now `BlockStoreState` and is encoded as binary in the database - [rpc] \#4968 JSON encoding is now handled by `libs/json`, not Amino + - [evidence] \#4949 `evidence` reactor migration to Protobuf encoding - Apps diff --git a/evidence/codec.go b/evidence/codec.go deleted file mode 100644 index 650a34607..000000000 --- a/evidence/codec.go +++ /dev/null @@ -1,21 +0,0 @@ -package evidence - -import ( - amino "github.com/tendermint/go-amino" - - cryptoamino "github.com/tendermint/tendermint/crypto/encoding/amino" - "github.com/tendermint/tendermint/types" -) - -var cdc = amino.NewCodec() - -func init() { - RegisterMessages(cdc) - cryptoamino.RegisterAmino(cdc) - types.RegisterEvidences(cdc) -} - -// For testing purposes only -func RegisterMockEvidences() { - types.RegisterMockEvidences(cdc) -} diff --git a/evidence/pool.go b/evidence/pool.go index fca53ac96..35c8a0b05 100644 --- a/evidence/pool.go +++ b/evidence/pool.go @@ -5,10 +5,13 @@ import ( "sync" "time" + "github.com/gogo/protobuf/proto" + gogotypes "github.com/gogo/protobuf/types" dbm "github.com/tendermint/tm-db" clist "github.com/tendermint/tendermint/libs/clist" "github.com/tendermint/tendermint/libs/log" + tmproto "github.com/tendermint/tendermint/proto/types" sm "github.com/tendermint/tendermint/state" "github.com/tendermint/tendermint/store" "github.com/tendermint/tendermint/types" @@ -131,7 +134,14 @@ func (evpool *Pool) Update(block *types.Block, state sm.State) { // that may be needed in the future to verify votes func (evpool *Pool) AddPOLC(polc types.ProofOfLockChange) error { key := keyPOLC(polc) - polcBytes := cdc.MustMarshalBinaryBare(polc) + pbplc, err := polc.ToProto() + if err != nil { + return err + } + polcBytes, err := proto.Marshal(pbplc) + if err != nil { + return fmt.Errorf("addPOLC: unable to marshal ProofOfLockChange: %w", err) + } return evpool.evidenceStore.Set(key, polcBytes) } @@ -214,7 +224,13 @@ func (evpool *Pool) MarkEvidenceAsCommitted(height int64, lastBlockTime time.Tim for _, ev := range evidence { // As the evidence is stored in the block store we only need to record the height that it was saved at. key := keyCommitted(ev) - evBytes := cdc.MustMarshalBinaryBare(height) + + h := gogotypes.Int64Value{Value: height} + evBytes, err := proto.Marshal(&h) + if err != nil { + panic(err) + } + if err := evpool.evidenceStore.Set(key, evBytes); err != nil { evpool.logger.Error("Unable to add committed evidence", "err", err) // if we can't move evidence to committed then don't remove the evidence from pending @@ -276,18 +292,28 @@ func (evpool *Pool) IsPending(evidence types.Evidence) bool { } // RetrievePOLC attempts to find a polc at the given height and round, if not there it returns an error -func (evpool *Pool) RetrievePOLC(height int64, round int32) (types.ProofOfLockChange, error) { - var polc types.ProofOfLockChange +func (evpool *Pool) RetrievePOLC(height int64, round int32) (polc types.ProofOfLockChange, err error) { + var pbpolc tmproto.ProofOfLockChange key := keyPOLCFromHeightAndRound(height, round) polcBytes, err := evpool.evidenceStore.Get(key) if err != nil { return polc, err } + if polcBytes == nil { return polc, fmt.Errorf("unable to find polc at height %d and round %d", height, round) } - err = cdc.UnmarshalBinaryBare(polcBytes, &polc) - return polc, err + + err = proto.Unmarshal(polcBytes, &pbpolc) + if err != nil { + return polc, err + } + plc, err := types.ProofOfLockChangeFromProto(&pbpolc) + if err != nil { + return polc, err + } + + return *plc, err } // EvidenceFront goes to the first evidence in the clist @@ -338,8 +364,18 @@ func (evpool *Pool) State() sm.State { } func (evpool *Pool) addPendingEvidence(evidence types.Evidence) error { - evBytes := cdc.MustMarshalBinaryBare(evidence) + evi, err := types.EvidenceToProto(evidence) + if err != nil { + return err + } + + evBytes, err := proto.Marshal(evi) + if err != nil { + return fmt.Errorf("unable to marshal evidence: %w", err) + } + key := keyPending(evidence) + return evpool.evidenceStore.Set(key, evBytes) } @@ -370,13 +406,23 @@ func (evpool *Pool) listEvidence(prefixKey byte, maxNum int64) ([]types.Evidence } count++ - var ev types.Evidence - err := cdc.UnmarshalBinaryBare(val, &ev) + var ( + ev types.Evidence + evpb tmproto.Evidence + ) + err := proto.Unmarshal(val, &evpb) if err != nil { return nil, err } + + ev, err = types.EvidenceFromProto(&evpb) + if err != nil { + return nil, err + } + evidence = append(evidence, ev) } + return evidence, nil } @@ -390,16 +436,26 @@ func (evpool *Pool) removeExpiredPendingEvidence() { blockEvidenceMap := make(map[string]struct{}) for ; iter.Valid(); iter.Next() { evBytes := iter.Value() - var ev types.Evidence - err := cdc.UnmarshalBinaryBare(evBytes, &ev) + var ( + ev types.Evidence + evpb tmproto.Evidence + ) + err := proto.Unmarshal(evBytes, &evpb) if err != nil { - evpool.logger.Error("Unable to unmarshal POLC", "err", err) + evpool.logger.Error("Unable to unmarshal Evidence", "err", err) + continue + } + + ev, err = types.EvidenceFromProto(&evpb) + if err != nil { + evpool.logger.Error("Error in transition evidence from protobuf", "err", err) continue } if !evpool.IsExpired(ev.Height()-1, ev.Time()) { if len(blockEvidenceMap) != 0 { evpool.removeEvidenceFromList(blockEvidenceMap) } + return } evpool.removePendingEvidence(ev) @@ -430,12 +486,19 @@ func (evpool *Pool) pruneExpiredPOLC() { defer iter.Close() for ; iter.Valid(); iter.Next() { proofBytes := iter.Value() - var proof types.ProofOfLockChange - err := cdc.UnmarshalBinaryBare(proofBytes, &proof) + var ( + pbproof tmproto.ProofOfLockChange + ) + err := proto.Unmarshal(proofBytes, &pbproof) if err != nil { evpool.logger.Error("Unable to unmarshal POLC", "err", err) continue } + proof, err := types.ProofOfLockChangeFromProto(&pbproof) + if err != nil { + evpool.logger.Error("Unable to transition POLC from protobuf", "err", err) + continue + } if !evpool.IsExpired(proof.Height()-1, proof.Time()) { return } diff --git a/evidence/pool_test.go b/evidence/pool_test.go index f1a2af83e..5aa56e28d 100644 --- a/evidence/pool_test.go +++ b/evidence/pool_test.go @@ -5,6 +5,7 @@ import ( "testing" "time" + "github.com/gogo/protobuf/proto" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -21,7 +22,6 @@ import ( ) func TestMain(m *testing.M) { - RegisterMockEvidences() code := m.Run() os.Exit(code) @@ -269,12 +269,20 @@ func TestRecoverPendingEvidence(t *testing.T) { // load good evidence goodKey := keyPending(goodEvidence) - goodEvidenceBytes := cdc.MustMarshalBinaryBare(goodEvidence) + evi, err := types.EvidenceToProto(goodEvidence) + require.NoError(t, err) + goodEvidenceBytes, err := proto.Marshal(evi) + require.NoError(t, err) _ = evidenceDB.Set(goodKey, goodEvidenceBytes) // load expired evidence expiredKey := keyPending(expiredEvidence) - expiredEvidenceBytes := cdc.MustMarshalBinaryBare(expiredEvidence) + eevi, err := types.EvidenceToProto(expiredEvidence) + require.NoError(t, err) + + expiredEvidenceBytes, err := proto.Marshal(eevi) + require.NoError(t, err) + _ = evidenceDB.Set(expiredKey, expiredEvidenceBytes) pool, err := NewPool(stateDB, evidenceDB, blockStore) require.NoError(t, err) diff --git a/evidence/reactor.go b/evidence/reactor.go index 827db9ba2..4ac9c33e4 100644 --- a/evidence/reactor.go +++ b/evidence/reactor.go @@ -2,14 +2,14 @@ package evidence import ( "fmt" - "reflect" "time" - amino "github.com/tendermint/go-amino" - + "github.com/gogo/protobuf/proto" clist "github.com/tendermint/tendermint/libs/clist" "github.com/tendermint/tendermint/libs/log" "github.com/tendermint/tendermint/p2p" + ep "github.com/tendermint/tendermint/proto/evidence" + tmproto "github.com/tendermint/tendermint/proto/types" "github.com/tendermint/tendermint/types" ) @@ -64,39 +64,26 @@ func (evR *Reactor) AddPeer(peer p2p.Peer) { // Receive implements Reactor. // It adds any received evidence to the evpool. func (evR *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) { - msg, err := decodeMsg(msgBytes) + evis, err := decodeMsg(msgBytes) if err != nil { - evR.Logger.Error("Error decoding message", "src", src, "chId", chID, "msg", msg, "err", err, "bytes", msgBytes) - evR.Switch.StopPeerForError(src, err) - return - } - - if err = msg.ValidateBasic(); err != nil { - evR.Logger.Error("Peer sent us invalid msg", "peer", src, "msg", msg, "err", err) + evR.Logger.Error("Error decoding message", "src", src, "chId", chID, "err", err, "bytes", msgBytes) evR.Switch.StopPeerForError(src, err) return } - evR.Logger.Debug("Receive", "src", src, "chId", chID, "msg", msg) - - switch msg := msg.(type) { - case *ListMessage: - for _, ev := range msg.Evidence { - err := evR.evpool.AddEvidence(ev) - switch err.(type) { - case ErrInvalidEvidence: - evR.Logger.Error("Evidence is not valid", "evidence", msg.Evidence, "err", err) - // punish peer - evR.Switch.StopPeerForError(src, err) - return - case nil: - default: - evR.Logger.Error("Evidence has not been added", "evidence", msg.Evidence, "err", err) - return - } + for _, ev := range evis { + err := evR.evpool.AddEvidence(ev) + switch err.(type) { + case ErrInvalidEvidence: + evR.Logger.Error("Evidence is not valid", "evidence", evis, "err", err) + // punish peer + evR.Switch.StopPeerForError(src, err) + return + case nil: + default: + evR.Logger.Error("Evidence has not been added", "evidence", evis, "err", err) + return } - default: - evR.Logger.Error(fmt.Sprintf("Unknown message type %v", reflect.TypeOf(msg))) } } @@ -131,9 +118,14 @@ func (evR *Reactor) broadcastEvidenceRoutine(peer p2p.Peer) { } ev := next.Value.(types.Evidence) - msg, retry := evR.checkSendEvidenceMessage(peer, ev) - if msg != nil { - success := peer.Send(EvidenceChannel, cdc.MustMarshalBinaryBare(msg)) + evis, retry := evR.checkSendEvidenceMessage(peer, ev) + if len(evis) > 0 { + msgBytes, err := encodeMsg(evis) + if err != nil { + panic(err) + } + + success := peer.Send(EvidenceChannel, msgBytes) retry = !success } @@ -164,7 +156,7 @@ func (evR *Reactor) broadcastEvidenceRoutine(peer p2p.Peer) { func (evR Reactor) checkSendEvidenceMessage( peer p2p.Peer, ev types.Evidence, -) (msg Message, retry bool) { +) (evis []types.Evidence, retry bool) { // make sure the peer is up to date evHeight := ev.Height() @@ -212,8 +204,7 @@ func (evR Reactor) checkSendEvidenceMessage( } // send evidence - msg = &ListMessage{[]types.Evidence{ev}} - return msg, false + return []types.Evidence{ev}, false } // PeerState describes the state of a peer. @@ -221,43 +212,45 @@ type PeerState interface { GetHeight() int64 } -//----------------------------------------------------------------------------- -// Messages - -// Message is a message sent or received by the Reactor. -type Message interface { - ValidateBasic() error -} +// encodemsg takes a array of evidence +// returns the byte encoding of the List Message +func encodeMsg(evis []types.Evidence) ([]byte, error) { + evi := make([]*tmproto.Evidence, len(evis)) + for i := 0; i < len(evis); i++ { + ev, err := types.EvidenceToProto(evis[i]) + if err != nil { + return nil, err + } + evi[i] = ev + } -func RegisterMessages(cdc *amino.Codec) { - cdc.RegisterInterface((*Message)(nil), nil) - cdc.RegisterConcrete(&ListMessage{}, - "tendermint/evidence/ListMessage", nil) -} + epl := ep.List{ + Evidence: evi, + } -func decodeMsg(bz []byte) (msg Message, err error) { - err = cdc.UnmarshalBinaryBare(bz, &msg) - return + return proto.Marshal(&epl) } -//------------------------------------- - -// ListMessage contains a list of evidence. -type ListMessage struct { - Evidence []types.Evidence -} +// decodemsg takes an array of bytes +// returns an array of evidence +func decodeMsg(bz []byte) (evis []types.Evidence, err error) { + lm := ep.List{} + proto.Unmarshal(bz, &lm) + + evis = make([]types.Evidence, len(lm.Evidence)) + for i := 0; i < len(lm.Evidence); i++ { + ev, err := types.EvidenceFromProto(lm.Evidence[i]) + if err != nil { + return nil, err + } + evis[i] = ev + } -// ValidateBasic performs basic validation. -func (m *ListMessage) ValidateBasic() error { - for i, ev := range m.Evidence { + for i, ev := range evis { if err := ev.ValidateBasic(); err != nil { - return fmt.Errorf("invalid evidence (#%d): %v", i, err) + return nil, fmt.Errorf("invalid evidence (#%d): %v", i, err) } } - return nil -} -// String returns a string representation of the ListMessage. -func (m *ListMessage) String() string { - return fmt.Sprintf("[ListMessage %v]", m.Evidence) + return evis, nil } diff --git a/evidence/reactor_test.go b/evidence/reactor_test.go index 7b068df78..764b17ade 100644 --- a/evidence/reactor_test.go +++ b/evidence/reactor_test.go @@ -205,31 +205,3 @@ func TestReactorSelectiveBroadcast(t *testing.T) { peers := reactors[1].Switch.Peers().List() assert.Equal(t, 1, len(peers)) } -func TestListMessageValidationBasic(t *testing.T) { - - testCases := []struct { - testName string - malleateEvListMsg func(*ListMessage) - expectErr bool - }{ - {"Good ListMessage", func(evList *ListMessage) {}, false}, - {"Invalid ListMessage", func(evList *ListMessage) { - evList.Evidence = append(evList.Evidence, - &types.DuplicateVoteEvidence{}) - }, true}, - } - for _, tc := range testCases { - tc := tc - t.Run(tc.testName, func(t *testing.T) { - evListMsg := &ListMessage{} - n := 3 - valAddr := []byte("myval") - evListMsg.Evidence = make([]types.Evidence, n) - for i := 0; i < n; i++ { - evListMsg.Evidence[i] = types.NewMockEvidence(int64(i+1), time.Now(), valAddr) - } - tc.malleateEvListMsg(evListMsg) - assert.Equal(t, tc.expectErr, evListMsg.ValidateBasic() != nil, "Validate Basic had an unexpected result") - }) - } -} diff --git a/node/node_test.go b/node/node_test.go index 6f5060a30..e7f3bfe89 100644 --- a/node/node_test.go +++ b/node/node_test.go @@ -252,7 +252,6 @@ func TestCreateProposalBlock(t *testing.T) { // Make EvidencePool types.RegisterMockEvidencesGlobal() // XXX! - evidence.RegisterMockEvidences() evidenceDB := dbm.NewMemDB() blockStore := store.NewBlockStore(dbm.NewMemDB()) evidencePool, err := evidence.NewPool(stateDB, evidenceDB, blockStore) diff --git a/proto/evidence/msgs.pb.go b/proto/evidence/msgs.pb.go index 86000ba5a..5259444df 100644 --- a/proto/evidence/msgs.pb.go +++ b/proto/evidence/msgs.pb.go @@ -25,7 +25,7 @@ var _ = math.Inf const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package type List struct { - Evidence []types.Evidence `protobuf:"bytes,1,rep,name=evidence,proto3" json:"evidence"` + Evidence []*types.Evidence `protobuf:"bytes,1,rep,name=evidence,proto3" json:"evidence,omitempty"` } func (m *List) Reset() { *m = List{} } @@ -61,7 +61,7 @@ func (m *List) XXX_DiscardUnknown() { var xxx_messageInfo_List proto.InternalMessageInfo -func (m *List) GetEvidence() []types.Evidence { +func (m *List) GetEvidence() []*types.Evidence { if m != nil { return m.Evidence } @@ -136,23 +136,24 @@ func init() { func init() { proto.RegisterFile("proto/evidence/msgs.proto", fileDescriptor_df8322769b0bd7d6) } var fileDescriptor_df8322769b0bd7d6 = []byte{ - // 253 bytes of a gzipped FileDescriptorProto + // 258 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2c, 0x28, 0xca, 0x2f, 0xc9, 0xd7, 0x4f, 0x2d, 0xcb, 0x4c, 0x49, 0xcd, 0x4b, 0x4e, 0xd5, 0xcf, 0x2d, 0x4e, 0x2f, 0xd6, 0x03, 0x8b, 0x09, 0x49, 0x96, 0xa4, 0xe6, 0xa5, 0xa4, 0x16, 0xe5, 0x66, 0xe6, 0x95, 0x40, 0x44, 0xf4, 0x60, 0xaa, 0xa4, 0xd4, 0x4a, 0x32, 0x32, 0x8b, 0x52, 0xe2, 0x0b, 0x12, 0x8b, 0x4a, 0x2a, 0xf5, 0x21, 0x26, 0xa4, 0xe7, 0xa7, 0xe7, 0x23, 0x58, 0x10, 0x0d, 0x52, 0x52, 0x10, 0x91, 0x92, - 0xca, 0x82, 0xd4, 0x62, 0xb8, 0x1d, 0x10, 0x39, 0x25, 0x2f, 0x2e, 0x16, 0x9f, 0xcc, 0xe2, 0x12, - 0x21, 0x27, 0x2e, 0x0e, 0x98, 0x8c, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x82, 0x1e, 0x86, - 0xcd, 0x60, 0x13, 0xf4, 0x5c, 0xa1, 0xea, 0x9c, 0x58, 0x4e, 0xdc, 0x93, 0x67, 0x08, 0x82, 0xeb, - 0x53, 0x6a, 0x61, 0xe4, 0x62, 0xf1, 0xcc, 0x4b, 0xcb, 0x17, 0x92, 0xe1, 0xe2, 0x4c, 0xce, 0xcf, - 0xcd, 0xcd, 0x2c, 0x29, 0x49, 0x4d, 0x91, 0x60, 0x54, 0x60, 0xd4, 0xe0, 0x08, 0x42, 0x08, 0x08, - 0x49, 0x71, 0x71, 0x14, 0x14, 0x65, 0xe6, 0x17, 0x65, 0x96, 0x54, 0x4a, 0x30, 0x29, 0x30, 0x6a, - 0x30, 0x07, 0xc1, 0xf9, 0x28, 0xce, 0x60, 0x56, 0x60, 0x24, 0xc7, 0x19, 0x4e, 0x9e, 0x27, 0x1e, - 0xc9, 0x31, 0x5e, 0x78, 0x24, 0xc7, 0xf8, 0xe0, 0x91, 0x1c, 0xe3, 0x84, 0xc7, 0x72, 0x0c, 0x17, - 0x1e, 0xcb, 0x31, 0xdc, 0x78, 0x2c, 0xc7, 0x10, 0xa5, 0x9f, 0x9e, 0x59, 0x92, 0x51, 0x9a, 0xa4, - 0x97, 0x9c, 0x9f, 0xab, 0x8f, 0x30, 0x15, 0x99, 0x89, 0x1a, 0x0f, 0x49, 0x6c, 0x60, 0xbe, 0x31, - 0x20, 0x00, 0x00, 0xff, 0xff, 0xf7, 0xf9, 0xc5, 0xd0, 0xa0, 0x01, 0x00, 0x00, + 0xca, 0x82, 0xd4, 0x62, 0xb8, 0x1d, 0x10, 0x39, 0x25, 0x17, 0x2e, 0x16, 0x9f, 0xcc, 0xe2, 0x12, + 0x21, 0x1b, 0x2e, 0x0e, 0x98, 0x8c, 0x04, 0xa3, 0x02, 0xb3, 0x06, 0xb7, 0x91, 0x82, 0x1e, 0x86, + 0xcd, 0x60, 0x13, 0xf4, 0x5c, 0xa1, 0xea, 0x82, 0xe0, 0x3a, 0x94, 0x5a, 0x18, 0xb9, 0x58, 0x3c, + 0xf3, 0xd2, 0xf2, 0x85, 0x64, 0xb8, 0x38, 0x93, 0xf3, 0x73, 0x73, 0x33, 0x4b, 0x4a, 0x52, 0x53, + 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x82, 0x10, 0x02, 0x42, 0x52, 0x5c, 0x1c, 0x05, 0x45, 0x99, + 0xf9, 0x45, 0x99, 0x25, 0x95, 0x12, 0x4c, 0x0a, 0x8c, 0x1a, 0xcc, 0x41, 0x70, 0xbe, 0x90, 0x13, + 0x92, 0x03, 0x98, 0x15, 0x18, 0x89, 0x71, 0x80, 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x08, 0x67, + 0x38, 0x79, 0x9e, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, 0x83, 0x47, 0x72, 0x8c, 0x13, + 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, 0x43, 0x94, 0x7e, 0x7a, 0x66, + 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0xae, 0x3e, 0xc2, 0x54, 0x64, 0x26, 0x6a, 0x0c, 0x24, + 0xb1, 0x81, 0xf9, 0xc6, 0x80, 0x00, 0x00, 0x00, 0xff, 0xff, 0x79, 0x46, 0xba, 0xe0, 0x9a, 0x01, + 0x00, 0x00, } func (m *List) Marshal() (dAtA []byte, err error) { @@ -347,7 +348,7 @@ func (m *List) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Evidence = append(m.Evidence, types.Evidence{}) + m.Evidence = append(m.Evidence, &types.Evidence{}) if err := m.Evidence[len(m.Evidence)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/proto/evidence/msgs.proto b/proto/evidence/msgs.proto index 1f8056fea..836fbbf5f 100644 --- a/proto/evidence/msgs.proto +++ b/proto/evidence/msgs.proto @@ -7,7 +7,7 @@ import "third_party/proto/gogoproto/gogo.proto"; import "proto/types/evidence.proto"; message List { - repeated tendermint.proto.types.Evidence evidence = 1 [(gogoproto.nullable) = false]; + repeated tendermint.proto.types.Evidence evidence = 1; } message Info { diff --git a/proto/types/evidence.pb.go b/proto/types/evidence.pb.go index 8736683da..d129c04c9 100644 --- a/proto/types/evidence.pb.go +++ b/proto/types/evidence.pb.go @@ -566,8 +566,8 @@ func (m *EvidenceData) GetHash() []byte { } type ProofOfLockChange struct { - Votes []Vote `protobuf:"bytes,1,rep,name=votes,proto3" json:"votes"` - PubKey keys.PublicKey `protobuf:"bytes,2,opt,name=pub_key,json=pubKey,proto3" json:"pub_key"` + Votes []*Vote `protobuf:"bytes,1,rep,name=votes,proto3" json:"votes,omitempty"` + PubKey *keys.PublicKey `protobuf:"bytes,2,opt,name=pub_key,json=pubKey,proto3" json:"pub_key,omitempty"` } func (m *ProofOfLockChange) Reset() { *m = ProofOfLockChange{} } @@ -603,18 +603,18 @@ func (m *ProofOfLockChange) XXX_DiscardUnknown() { var xxx_messageInfo_ProofOfLockChange proto.InternalMessageInfo -func (m *ProofOfLockChange) GetVotes() []Vote { +func (m *ProofOfLockChange) GetVotes() []*Vote { if m != nil { return m.Votes } return nil } -func (m *ProofOfLockChange) GetPubKey() keys.PublicKey { +func (m *ProofOfLockChange) GetPubKey() *keys.PublicKey { if m != nil { return m.PubKey } - return keys.PublicKey{} + return nil } func init() { @@ -632,57 +632,57 @@ func init() { func init() { proto.RegisterFile("proto/types/evidence.proto", fileDescriptor_86495eef24aeacc0) } var fileDescriptor_86495eef24aeacc0 = []byte{ - // 789 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0xcf, 0x4f, 0xe3, 0x46, - 0x14, 0xb6, 0xc9, 0x8f, 0xc2, 0x23, 0xf4, 0x87, 0x05, 0x25, 0xb2, 0x20, 0x20, 0xab, 0x2a, 0xb4, - 0x6a, 0x1d, 0x08, 0x55, 0xd5, 0x2b, 0x81, 0xa2, 0x54, 0x50, 0x15, 0xb9, 0x15, 0x87, 0x1e, 0x6a, - 0x8d, 0xed, 0x89, 0x3d, 0x8a, 0xed, 0xb1, 0xec, 0x71, 0xa4, 0x1c, 0xab, 0xf6, 0xd0, 0x23, 0x97, - 0xfe, 0x19, 0x7b, 0xdd, 0xbf, 0x81, 0x23, 0xda, 0xd3, 0x9e, 0x76, 0x57, 0xf0, 0x8f, 0xac, 0x3c, - 0x1e, 0xdb, 0x41, 0xe0, 0x88, 0xdb, 0x6a, 0x2f, 0xd1, 0xe4, 0xcd, 0xfb, 0xde, 0xf7, 0x8d, 0xdf, - 0x9b, 0x6f, 0x40, 0x8d, 0x62, 0xca, 0x68, 0x9f, 0xcd, 0x22, 0x9c, 0xf4, 0xf1, 0x94, 0x38, 0x38, - 0xb4, 0xb1, 0xce, 0x83, 0xca, 0x97, 0x0c, 0x87, 0x0e, 0x8e, 0x03, 0x12, 0xb2, 0x3c, 0xa2, 0xf3, - 0x34, 0xf5, 0x6b, 0xe6, 0x91, 0xd8, 0x31, 0x23, 0x14, 0xb3, 0x59, 0x3f, 0xc7, 0xbb, 0xd4, 0xa5, - 0xd5, 0x2a, 0xcf, 0x56, 0x37, 0xe7, 0x6b, 0xf3, 0x5f, 0xb1, 0xb1, 0xe3, 0x52, 0xea, 0xfa, 0x38, - 0xc7, 0x5a, 0xe9, 0xb8, 0xcf, 0x48, 0x80, 0x13, 0x86, 0x82, 0x48, 0x24, 0x6c, 0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 0x9e, 0x89, 0x32, 0xed, 0x28, 0xb5, 0xb2, 0x7f, 0x67, 0x37, 0x77, 0x3d, 0xf9, - 0xf6, 0xae, 0x27, 0xbf, 0xbb, 0xeb, 0xc9, 0xd7, 0xf7, 0x3d, 0xe9, 0xf6, 0xbe, 0x27, 0xbd, 0xbe, - 0xef, 0x49, 0x7f, 0x7e, 0xe7, 0x12, 0xe6, 0xa5, 0x96, 0x6e, 0xd3, 0xa0, 0x5f, 0x95, 0x9e, 0x5f, - 0xce, 0xbd, 0xf6, 0x56, 0x9b, 0xff, 0x39, 0x7a, 0x1f, 0x00, 0x00, 0xff, 0xff, 0xca, 0x62, 0x59, - 0xfb, 0x5f, 0x08, 0x00, 0x00, + // 786 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xd4, 0x55, 0xcf, 0x4f, 0xdc, 0x46, + 0x14, 0xb6, 0xd9, 0x1f, 0x85, 0xc7, 0xd2, 0x1f, 0x16, 0x94, 0x95, 0x05, 0x0b, 0xb2, 0xaa, 0x42, + 0xab, 0xd6, 0x0b, 0x4b, 0xd5, 0x73, 0x59, 0x28, 0xda, 0x0a, 0xaa, 0x22, 0x37, 0xe2, 0x90, 0x43, + 0xac, 0xb1, 0x3d, 0x6b, 0x8f, 0xd6, 0xf6, 0x58, 0xf6, 0x78, 0x25, 0x1f, 0xa3, 0xe4, 0x90, 0xdc, + 0xf8, 0x47, 0x72, 0xcd, 0xdf, 0xc0, 0x11, 0xe5, 0x94, 0x53, 0x12, 0xc1, 0x3f, 0x12, 0x79, 0xfc, + 0x6b, 0x11, 0x18, 0xed, 0x2d, 0xca, 0x65, 0x35, 0xfb, 0xe6, 0x7d, 0xef, 0xfb, 0xc6, 0xef, 0xcd, + 0x37, 0x20, 0x07, 0x21, 0x65, 0xb4, 0xcf, 0x92, 0x00, 0x47, 0x7d, 0x3c, 0x25, 0x16, 0xf6, 0x4d, + 0xac, 0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, 0x34, 0xbe, 0x56, 0x5e, 0x8b, 0xf0, 0xc3, 0x79, 0x48, 0xe9, + 0xf8, 0xbf, 0xf1, 0x19, 0x35, 0x27, 0x47, 0x0e, 0xf2, 0x6d, 0x2c, 0x0d, 0x80, 0xbb, 0x7a, 0x94, + 0x53, 0xcd, 0xf1, 0x00, 0x44, 0xd2, 0x5f, 0xf0, 0x4d, 0x10, 0x1b, 0xfa, 0x04, 0x27, 0xf9, 0xb0, + 0xee, 0xdc, 0x47, 0x65, 0xef, 0xa8, 0x9a, 0xbe, 0xa3, 0xea, 0x79, 0x6c, 0xb8, 0xc4, 0x3c, 0xc5, + 0x89, 0xd6, 0x0e, 0x62, 0xe3, 0x14, 0x27, 0xc3, 0x93, 0xab, 0x9b, 0x9e, 0x78, 0x7d, 0xd3, 0x13, + 0x3f, 0xdd, 0xf4, 0xc4, 0xcb, 0xdb, 0x9e, 0x70, 0x7d, 0xdb, 0x13, 0xde, 0xdf, 0xf6, 0x84, 0xa7, + 0xbf, 0xd9, 0x84, 0x39, 0xb1, 0xa1, 0x9a, 0xd4, 0xeb, 0x57, 0x45, 0x67, 0x97, 0x33, 0x2f, 0xbc, + 0xd1, 0xe6, 0x7f, 0x0e, 0x3e, 0x07, 0x00, 0x00, 0xff, 0xff, 0x6a, 0x4c, 0xe5, 0x0b, 0x53, 0x08, + 0x00, 0x00, } func (m *DuplicateVoteEvidence) Marshal() (dAtA []byte, err error) { @@ -1195,16 +1195,18 @@ func (m *ProofOfLockChange) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - { - size, err := m.PubKey.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err + if m.PubKey != nil { + { + size, err := m.PubKey.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintEvidence(dAtA, i, uint64(size)) } - i -= size - i = encodeVarintEvidence(dAtA, i, uint64(size)) + i-- + dAtA[i] = 0x12 } - i-- - dAtA[i] = 0x12 if len(m.Votes) > 0 { for iNdEx := len(m.Votes) - 1; iNdEx >= 0; iNdEx-- { { @@ -1460,8 +1462,10 @@ func (m *ProofOfLockChange) Size() (n int) { n += 1 + l + sovEvidence(uint64(l)) } } - l = m.PubKey.Size() - n += 1 + l + sovEvidence(uint64(l)) + if m.PubKey != nil { + l = m.PubKey.Size() + n += 1 + l + sovEvidence(uint64(l)) + } return n } @@ -2757,7 +2761,7 @@ func (m *ProofOfLockChange) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Votes = append(m.Votes, Vote{}) + m.Votes = append(m.Votes, &Vote{}) if err := m.Votes[len(m.Votes)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -2791,6 +2795,9 @@ func (m *ProofOfLockChange) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } + if m.PubKey == nil { + m.PubKey = &keys.PublicKey{} + } if err := m.PubKey.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/proto/types/evidence.proto b/proto/types/evidence.proto index 3a8ff126c..894382f7f 100644 --- a/proto/types/evidence.proto +++ b/proto/types/evidence.proto @@ -65,6 +65,6 @@ message EvidenceData { } message ProofOfLockChange { - repeated Vote votes = 1 [(gogoproto.nullable) = false]; - tendermint.proto.crypto.keys.PublicKey pub_key = 2 [(gogoproto.nullable) = false]; + repeated Vote votes = 1; + tendermint.proto.crypto.keys.PublicKey pub_key = 2; } diff --git a/types/evidence.go b/types/evidence.go index 8018b1890..39b16064d 100644 --- a/types/evidence.go +++ b/types/evidence.go @@ -10,6 +10,7 @@ import ( amino "github.com/tendermint/go-amino" "github.com/tendermint/tendermint/crypto" + cryptoenc "github.com/tendermint/tendermint/crypto/encoding" "github.com/tendermint/tendermint/crypto/merkle" "github.com/tendermint/tendermint/crypto/tmhash" tmjson "github.com/tendermint/tendermint/libs/json" @@ -1257,6 +1258,59 @@ func (e ProofOfLockChange) String() string { e.Votes[0].Round) } +func (e *ProofOfLockChange) ToProto() (*tmproto.ProofOfLockChange, error) { + if e == nil { + return nil, errors.New("nil proof of lock change") + } + plc := new(tmproto.ProofOfLockChange) + vpb := make([]*tmproto.Vote, len(e.Votes)) + + for i, v := range e.Votes { + pb := v.ToProto() + if pb != nil { + vpb[i] = pb + } + } + + pk, err := cryptoenc.PubKeyToProto(e.PubKey) + if err != nil { + return nil, err + } + plc.PubKey = &pk + plc.Votes = vpb + + return plc, nil +} + +func ProofOfLockChangeFromProto(pb *tmproto.ProofOfLockChange) (*ProofOfLockChange, error) { + if pb == nil { + return nil, errors.New("nil proof of lock change") + } + + plc := new(ProofOfLockChange) + vpb := make([]Vote, len(pb.Votes)) + for i, v := range pb.Votes { + vi, err := VoteFromProto(v) + if err != nil { + return nil, err + } + vpb[i] = *vi + } + + if pb.PubKey == nil { + return nil, errors.New("proofOfLockChange: nil PubKey") + } + pk, err := cryptoenc.PubKeyFromProto(*pb.PubKey) + if err != nil { + return nil, err + } + + plc.PubKey = pk + plc.Votes = vpb + + return plc, nil +} + //----------------------------------------------------------------- // UNSTABLE @@ -1297,7 +1351,8 @@ func NewMockEvidence(height int64, eTime time.Time, address []byte) MockEvidence return MockEvidence{ EvidenceHeight: height, EvidenceTime: eTime, - EvidenceAddress: address} + EvidenceAddress: address, + } } func (e MockEvidence) Height() int64 { return e.EvidenceHeight } diff --git a/types/evidence_test.go b/types/evidence_test.go index 0afe8a13e..6f4488346 100644 --- a/types/evidence_test.go +++ b/types/evidence_test.go @@ -573,3 +573,42 @@ func TestEvidenceProto(t *testing.T) { }) } } + +func TestProofOfLockChangeProtoBuf(t *testing.T) { + // -------- Votes -------- + val := NewMockPV() + val2 := NewMockPV() + val3 := NewMockPV() + blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt32, tmhash.Sum([]byte("partshash"))) + const chainID = "mychain" + v := makeVote(t, val, chainID, math.MaxInt32, math.MaxInt64, 1, 0x01, blockID, defaultVoteTime) + v2 := makeVote(t, val2, chainID, math.MaxInt32, math.MaxInt64, 1, 0x01, blockID, defaultVoteTime) + + testCases := []struct { + msg string + polc ProofOfLockChange + expErr bool + expErr2 bool + }{ + {"failure, empty key", ProofOfLockChange{Votes: []Vote{*v, *v2}}, true, true}, + {"failure empty ProofOfLockChange", ProofOfLockChange{}, true, true}, + {"success", ProofOfLockChange{Votes: []Vote{*v, *v2}, PubKey: val3.PrivKey.PubKey()}, false, false}, + } + for _, tc := range testCases { + tc := tc + pbpolc, err := tc.polc.ToProto() + if tc.expErr { + require.Error(t, err) + } else { + require.NoError(t, err) + } + + c, err := ProofOfLockChangeFromProto(pbpolc) + if !tc.expErr2 { + require.NoError(t, err, tc.msg) + require.Equal(t, &tc.polc, c, tc.msg) + } else { + require.Error(t, err, tc.msg) + } + } +}