Merge pull request #3154 from tendermint/master

Merge master back to develop
This commit is contained in:
Ethan Buchman
2019-01-18 12:39:21 -05:00
committed by GitHub
17 changed files with 266 additions and 65 deletions

View File

@@ -29,7 +29,8 @@ type BlockExecutor struct {
// events
eventBus types.BlockEventPublisher
// update these with block results after commit
// manage the mempool lock during commit
// and update both with block results after commit.
mempool Mempool
evpool EvidencePool
@@ -73,6 +74,31 @@ func (blockExec *BlockExecutor) SetEventBus(eventBus types.BlockEventPublisher)
blockExec.eventBus = eventBus
}
// CreateProposalBlock calls state.MakeBlock with evidence from the evpool
// and txs from the mempool. The max bytes must be big enough to fit the commit.
// Up to 1/10th of the block space is allcoated for maximum sized evidence.
// The rest is given to txs, up to the max gas.
func (blockExec *BlockExecutor) CreateProposalBlock(
height int64,
state State, commit *types.Commit,
proposerAddr []byte,
) (*types.Block, *types.PartSet) {
maxBytes := state.ConsensusParams.BlockSize.MaxBytes
maxGas := state.ConsensusParams.BlockSize.MaxGas
// Fetch a limited amount of valid evidence
maxNumEvidence, _ := types.MaxEvidencePerBlock(maxBytes)
evidence := blockExec.evpool.PendingEvidence(maxNumEvidence)
// Fetch a limited amount of valid txs
maxDataBytes := types.MaxDataBytes(maxBytes, state.Validators.Size(), len(evidence))
txs := blockExec.mempool.ReapMaxBytesMaxGas(maxDataBytes, maxGas)
return state.MakeBlock(height, txs, commit, evidence, proposerAddr)
}
// ValidateBlock validates the given block against the given state.
// If the block is invalid, it returns an error.
// Validation does not mutate state, but does require historical information from the stateDB,

View File

@@ -133,10 +133,11 @@ func validateBlock(stateDB dbm.DB, state State, block *types.Block) error {
}
// Limit the amount of evidence
maxEvidenceBytes := types.MaxEvidenceBytesPerBlock(state.ConsensusParams.BlockSize.MaxBytes)
evidenceBytes := int64(len(block.Evidence.Evidence)) * types.MaxEvidenceBytes
if evidenceBytes > maxEvidenceBytes {
return types.NewErrEvidenceOverflow(maxEvidenceBytes, evidenceBytes)
maxNumEvidence, _ := types.MaxEvidencePerBlock(state.ConsensusParams.BlockSize.MaxBytes)
numEvidence := int64(len(block.Evidence.Evidence))
if numEvidence > maxNumEvidence {
return types.NewErrEvidenceOverflow(maxNumEvidence, numEvidence)
}
// Validate all evidence.

View File

@@ -109,10 +109,9 @@ func TestValidateBlockEvidence(t *testing.T) {
// A block with too much evidence fails.
maxBlockSize := state.ConsensusParams.BlockSize.MaxBytes
maxEvidenceBytes := types.MaxEvidenceBytesPerBlock(maxBlockSize)
maxEvidence := maxEvidenceBytes / types.MaxEvidenceBytes
require.True(t, maxEvidence > 2)
for i := int64(0); i < maxEvidence; i++ {
maxNumEvidence, _ := types.MaxEvidencePerBlock(maxBlockSize)
require.True(t, maxNumEvidence > 2)
for i := int64(0); i < maxNumEvidence; i++ {
block.Evidence.Evidence = append(block.Evidence.Evidence, goodEvidence)
}
block.EvidenceHash = block.Evidence.Hash()