evidence: check peerstate exists; dont send old evidence

This commit is contained in:
Ethan Buchman 2018-06-04 13:21:05 -07:00
parent 53937a8129
commit 19d95b5410
1 changed files with 11 additions and 3 deletions

View File

@ -138,7 +138,7 @@ func (evR *EvidenceReactor) broadcastEvidenceListMsg(msg *EvidenceListMessage) {
// NOTE: we dont send evidence to peers higher than their height,
// because they can't validate it (don't have validators from the height).
// So, for now, only send the `msg` to peers synced to the highest height in the list.
// TODO: send each peer all the evidence below its current height -
// TODO: send each peer all the evidence below its current height within maxAge -
// might require a routine per peer, like the mempool.
var maxHeight int64
@ -149,9 +149,17 @@ func (evR *EvidenceReactor) broadcastEvidenceListMsg(msg *EvidenceListMessage) {
}
for _, peer := range evR.Switch.Peers().List() {
ps := peer.Get(types.PeerStateKey).(PeerState)
ps, ok := peer.Get(types.PeerStateKey).(PeerState)
if !ok {
evR.Logger.Info("Found peer without PeerState", "peer", peer)
continue
}
// only send to peer if maxHeight < peerHeight < maxHeight + maxAge
maxAge := evR.evpool.State().ConsensusParams.EvidenceParams.MaxAge
rs := ps.GetRoundState()
if rs.Height >= maxHeight {
if rs.Height >= maxHeight &&
rs.Height < maxAge+maxHeight {
peer.TrySend(EvidenceChannel, cdc.MustMarshalBinaryBare(msg))
}
}