AddEvidence checks the evidence is valid and adds it to the pool.
(ev types.Evidence)
| 132 | |
| 133 | // AddEvidence checks the evidence is valid and adds it to the pool. |
| 134 | func (evpool *Pool) AddEvidence(ev types.Evidence) error { |
| 135 | evpool.logger.Debug("Attempting to add evidence", "ev", ev) |
| 136 | |
| 137 | // We have already verified this piece of evidence - no need to do it again |
| 138 | if evpool.isPending(ev) { |
| 139 | evpool.logger.Debug("Evidence already pending, ignoring this one", "ev", ev) |
| 140 | return nil |
| 141 | } |
| 142 | |
| 143 | // check that the evidence isn't already committed |
| 144 | if evpool.isCommitted(ev) { |
| 145 | // this can happen if the peer that sent us the evidence is behind so we shouldn't |
| 146 | // punish the peer. |
| 147 | evpool.logger.Debug("Evidence was already committed, ignoring this one", "ev", ev) |
| 148 | return nil |
| 149 | } |
| 150 | |
| 151 | // 1) Verify against state. |
| 152 | err := evpool.verify(ev) |
| 153 | if err != nil { |
| 154 | return types.NewErrInvalidEvidence(ev, err) |
| 155 | } |
| 156 | |
| 157 | // 2) Save to store. |
| 158 | if err := evpool.addPendingEvidence(ev); err != nil { |
| 159 | return fmt.Errorf("can't add evidence to pending list: %w", err) |
| 160 | } |
| 161 | |
| 162 | // 3) Add evidence to clist. |
| 163 | evpool.evidenceList.PushBack(ev) |
| 164 | |
| 165 | evpool.logger.Info("Verified new evidence of byzantine behavior", "evidence", ev) |
| 166 | |
| 167 | return nil |
| 168 | } |
| 169 | |
| 170 | // ReportConflictingVotes takes two conflicting votes and forms duplicate vote evidence, |
| 171 | // adding it eventually to the evidence pool. |