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

@@ -219,6 +219,8 @@ func testFreeAddr(t *testing.T) string {
// create a proposal block using real and full
// mempool and evidence pool and validate it.
func TestCreateProposalBlock(t *testing.T) {
const minEvSize = 12
config := cfg.ResetTestRoot("node_create_proposal")
defer os.RemoveAll(config.RootDir)
cc := proxy.NewLocalClientCreator(kvstore.NewApplication())
@@ -232,7 +234,9 @@ func TestCreateProposalBlock(t *testing.T) {
var height int64 = 1
state, stateDB := state(1, height)
maxBytes := 16384
maxEvidence := 10
state.ConsensusParams.Block.MaxBytes = int64(maxBytes)
state.ConsensusParams.Evidence.MaxNum = uint32(maxEvidence)
proposerAddr, _ := state.Validators.GetByIndex(0)
// Make Mempool
@@ -258,10 +262,8 @@ func TestCreateProposalBlock(t *testing.T) {
// fill the evidence pool with more evidence
// than can fit in a block
minEvSize := 12
numEv := (maxBytes / types.MaxEvidenceBytesDenominator) / minEvSize
for i := 0; i < numEv; i++ {
ev := types.NewMockRandomEvidence(1, time.Now(), proposerAddr, tmrand.Bytes(minEvSize))
for i := 0; i < maxEvidence+1; i++ {
ev := types.NewMockRandomEvidence(height, time.Now(), proposerAddr, tmrand.Bytes(minEvSize))
err := evidencePool.AddEvidence(ev)
require.NoError(t, err)
}