evidence: cap evidence to an absolute number (#4780)

The number of evidence that can be committed in a single block is capped by a new evidence parameter called MaxNum
This commit is contained in:
Callum Waters
2020-05-11 15:28:08 +02:00
committed by GitHub
parent fed2502618
commit a620e5fd96
25 changed files with 130 additions and 99 deletions

View File

@@ -82,8 +82,16 @@ func NewPool(stateDB, evidenceDB dbm.DB, blockStore *store.BlockStore) (*Pool, e
// PendingEvidence is used primarily as part of block proposal and returns up to maxNum of uncommitted evidence.
// If maxNum is -1, all evidence is returned. Pending evidence is prioritised based on time.
func (evpool *Pool) PendingEvidence(maxNum int64) []types.Evidence {
evidence, err := evpool.listEvidence(baseKeyPending, maxNum)
func (evpool *Pool) PendingEvidence(maxNum uint32) []types.Evidence {
evidence, err := evpool.listEvidence(baseKeyPending, int64(maxNum))
if err != nil {
evpool.logger.Error("Unable to retrieve pending evidence", "err", err)
}
return evidence
}
func (evpool *Pool) AllPendingEvidence() []types.Evidence {
evidence, err := evpool.listEvidence(baseKeyPending, -1)
if err != nil {
evpool.logger.Error("Unable to retrieve pending evidence", "err", err)
}
@@ -300,7 +308,6 @@ func (evpool *Pool) removePendingEvidence(evidence types.Evidence) {
}
// listEvidence lists up to maxNum pieces of evidence for the given prefix key.
// It is wrapped by PriorityEvidence and PendingEvidence for convenience.
// If maxNum is -1, there's no cap on the size of returned evidence.
func (evpool *Pool) listEvidence(prefixKey byte, maxNum int64) ([]types.Evidence, error) {
var count int64

View File

@@ -96,7 +96,7 @@ func TestProposingAndCommittingEvidence(t *testing.T) {
assert.False(t, pool.IsCommitted(evidence))
// test evidence is proposed
proposedEvidence := pool.PendingEvidence(-1)
proposedEvidence := pool.AllPendingEvidence()
assert.Equal(t, proposedEvidence[0], evidence)
// evidence seen and committed:

View File

@@ -92,11 +92,11 @@ func _waitForEvidence(
reactors []*Reactor,
) {
evpool := reactors[reactorIdx].evpool
for len(evpool.PendingEvidence(-1)) != len(evs) {
for len(evpool.AllPendingEvidence()) != len(evs) {
time.Sleep(time.Millisecond * 100)
}
reapedEv := evpool.PendingEvidence(-1)
reapedEv := evpool.AllPendingEvidence()
// put the reaped evidence in a map so we can quickly check we got everything
evMap := make(map[string]types.Evidence)
for _, e := range reapedEv {