Browse Source

use Hash as map key

pull/1628/head
Ethan Buchman 7 years ago
parent
commit
566024b64f
1 changed files with 11 additions and 7 deletions
  1. +11
    -7
      evidence/pool.go

+ 11
- 7
evidence/pool.go View File

@ -116,28 +116,28 @@ func (evpool *EvidencePool) AddEvidence(evidence types.Evidence) (err error) {
return nil return nil
} }
// MarkEvidenceAsCommitted marks all the evidence as committed.
// MarkEvidenceAsCommitted marks all the evidence as committed and removes it from the queue.
func (evpool *EvidencePool) MarkEvidenceAsCommitted(height int64, evidence []types.Evidence) { func (evpool *EvidencePool) MarkEvidenceAsCommitted(height int64, evidence []types.Evidence) {
// make a map of committed evidence to remove from the clist
blockEvidenceMap := make(map[string]struct{}) blockEvidenceMap := make(map[string]struct{})
for _, ev := range evidence { for _, ev := range evidence {
evpool.evidenceStore.MarkEvidenceAsCommitted(ev) evpool.evidenceStore.MarkEvidenceAsCommitted(ev)
blockEvidenceMap[ev.String()] = struct{}{}
blockEvidenceMap[evMapKey(ev)] = struct{}{}
} }
maxAge := evpool.State().ConsensusParams.EvidenceParams.MaxAge
// remove committed evidence from the clist // remove committed evidence from the clist
evpool.filterEvidence(height, maxAge, blockEvidenceMap)
maxAge := evpool.State().ConsensusParams.EvidenceParams.MaxAge
evpool.removeEvidence(height, maxAge, blockEvidenceMap)
} }
func (evpool *EvidencePool) filterEvidence(height, maxAge int64, blockEvidenceMap map[string]struct{}) {
func (evpool *EvidencePool) removeEvidence(height, maxAge int64, blockEvidenceMap map[string]struct{}) {
for e := evpool.evidenceList.Front(); e != nil; e = e.Next() { for e := evpool.evidenceList.Front(); e != nil; e = e.Next() {
ev := e.Value.(types.Evidence) ev := e.Value.(types.Evidence)
// Remove the evidence if it's already in a block // Remove the evidence if it's already in a block
// or if it's now too old. // or if it's now too old.
if _, ok := blockEvidenceMap[ev.String()]; ok ||
if _, ok := blockEvidenceMap[evMapKey(ev)]; ok ||
ev.Height() < height-maxAge { ev.Height() < height-maxAge {
// remove from clist // remove from clist
@ -146,3 +146,7 @@ func (evpool *EvidencePool) filterEvidence(height, maxAge int64, blockEvidenceMa
} }
} }
} }
func evMapKey(ev types.Evidence) string {
return string(ev.Hash())
}

Loading…
Cancel
Save