Browse Source

evidence: Refactored the evidence message to process Evidence instead of EvidenceList (#7700)

* evidence: Refactored the evidence message to send/recieve Evidence instead of EvidenceList

Peers send evidences one by one. The refactored code reflects this behaviour.

* Update internal/evidence/reactor.go

Co-authored-by: M. J. Fromberger <fromberger@interchain.io>

Co-authored-by: M. J. Fromberger <fromberger@interchain.io>
Co-authored-by: William Banfield <4561443+williambanfield@users.noreply.github.com>
pull/7769/head
Jasmina Malicevic 3 years ago
committed by GitHub
parent
commit
74864f7fdb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 25 deletions
  1. +17
    -24
      internal/evidence/reactor.go
  2. +1
    -1
      internal/evidence/reactor_test.go

+ 17
- 24
internal/evidence/reactor.go View File

@ -35,7 +35,7 @@ const (
func GetChannelDescriptor() *p2p.ChannelDescriptor { func GetChannelDescriptor() *p2p.ChannelDescriptor {
return &p2p.ChannelDescriptor{ return &p2p.ChannelDescriptor{
ID: EvidenceChannel, ID: EvidenceChannel,
MessageType: new(tmproto.EvidenceList),
MessageType: new(tmproto.Evidence),
Priority: 6, Priority: 6,
RecvMessageCapacity: maxMsgSize, RecvMessageCapacity: maxMsgSize,
RecvBufferCapacity: 32, RecvBufferCapacity: 32,
@ -120,25 +120,19 @@ func (r *Reactor) handleEvidenceMessage(envelope *p2p.Envelope) error {
logger := r.logger.With("peer", envelope.From) logger := r.logger.With("peer", envelope.From)
switch msg := envelope.Message.(type) { switch msg := envelope.Message.(type) {
case *tmproto.EvidenceList:
// TODO: Refactor the Evidence type to not contain a list since we only ever
// send and receive one piece of evidence at a time. Or potentially consider
// batching evidence.
//
// see: https://github.com/tendermint/tendermint/issues/4729
for i := 0; i < len(msg.Evidence); i++ {
ev, err := types.EvidenceFromProto(&msg.Evidence[i])
if err != nil {
logger.Error("failed to convert evidence", "err", err)
continue
}
if err := r.evpool.AddEvidence(ev); err != nil {
// If we're given invalid evidence by the peer, notify the router that
// we should remove this peer by returning an error.
if _, ok := err.(*types.ErrInvalidEvidence); ok {
return err
}
case *tmproto.Evidence:
// Process the evidence received from a peer
// Evidence is sent and received one by one
ev, err := types.EvidenceFromProto(msg)
if err != nil {
logger.Error("failed to convert evidence", "err", err)
return err
}
if err := r.evpool.AddEvidence(ev); err != nil {
// If we're given invalid evidence by the peer, notify the router that
// we should remove this peer by returning an error.
if _, ok := err.(*types.ErrInvalidEvidence); ok {
return err
} }
} }
@ -320,11 +314,10 @@ func (r *Reactor) broadcastEvidenceLoop(ctx context.Context, peerID types.NodeID
// and thus would not be able to process the evidence correctly. Also, the // and thus would not be able to process the evidence correctly. Also, the
// peer may receive this piece of evidence multiple times if it added and // peer may receive this piece of evidence multiple times if it added and
// removed frequently from the broadcasting peer. // removed frequently from the broadcasting peer.
if err := r.evidenceCh.Send(ctx, p2p.Envelope{ if err := r.evidenceCh.Send(ctx, p2p.Envelope{
To: peerID,
Message: &tmproto.EvidenceList{
Evidence: []tmproto.Evidence{*evProto},
},
To: peerID,
Message: evProto,
}); err != nil { }); err != nil {
return return
} }


+ 1
- 1
internal/evidence/reactor_test.go View File

@ -63,7 +63,7 @@ func setup(ctx context.Context, t *testing.T, stateStores []sm.Store, chBuf uint
peerChans: make(map[types.NodeID]chan p2p.PeerUpdate, numStateStores), peerChans: make(map[types.NodeID]chan p2p.PeerUpdate, numStateStores),
} }
chDesc := &p2p.ChannelDescriptor{ID: evidence.EvidenceChannel, MessageType: new(tmproto.EvidenceList)}
chDesc := &p2p.ChannelDescriptor{ID: evidence.EvidenceChannel, MessageType: new(tmproto.Evidence)}
rts.evidenceChannels = rts.network.MakeChannelsNoCleanup(ctx, t, chDesc) rts.evidenceChannels = rts.network.MakeChannelsNoCleanup(ctx, t, chDesc)
require.Len(t, rts.network.RandomNode().PeerManager.Peers(), 0) require.Len(t, rts.network.RandomNode().PeerManager.Peers(), 0)


Loading…
Cancel
Save