conesnsu: follow up to removing some consensus params (#2427)

* follow up to removing some consensus params Refs #2382
* change args type to int64 in state#makeParams
* make valsCount and evidenceCount ints again
* MaxEvidenceBytesPerBlock: include magic number in godoc
* [spec] creating a proposal
* test state#TxFilter
* panic if MaxDataBytes is less than 0
* fixes after review
* use amino#UvarintSize to calculate overhead
https://github.com/tendermint/go-amino/blob/0c74291f3bb61e24f8ea1d13148cece479f79d35/encoder.go#L85-L90
* avoid cyclic imports
* you can do better Go, come on
* remove testdouble package
This commit is contained in:
Anton Kaliaev
2018-09-21 11:00:36 +02:00
committed by Alexander Simmerl
parent 7b727bf3d0
commit 8d50bb9dad
27 changed files with 347 additions and 175 deletions
+1 -6
View File
@@ -145,12 +145,7 @@ func (blockExec *BlockExecutor) Commit(state State, block *types.Block) ([]byte,
"appHash", fmt.Sprintf("%X", res.Data))
// Update mempool.
maxDataBytes := types.MaxDataBytesUnknownEvidence(
state.ConsensusParams.BlockSize.MaxBytes,
state.Validators.Size(),
)
filter := func(tx types.Tx) bool { return len(tx) <= maxDataBytes }
if err := blockExec.mempool.Update(block.Height, block.Txs, filter); err != nil {
if err := blockExec.mempool.Update(block.Height, block.Txs, TxFilter(state)); err != nil {
return nil, err
}
+4 -4
View File
@@ -22,7 +22,7 @@ type Mempool interface {
Size() int
CheckTx(types.Tx, func(*abci.Response)) error
ReapMaxBytesMaxGas(maxBytes int, maxGas int64) types.Txs
ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs
Update(height int64, txs types.Txs, filter func(types.Tx) bool) error
Flush()
FlushAppConn() error
@@ -40,7 +40,7 @@ func (MockMempool) Lock()
func (MockMempool) Unlock() {}
func (MockMempool) Size() int { return 0 }
func (MockMempool) CheckTx(tx types.Tx, cb func(*abci.Response)) error { return nil }
func (MockMempool) ReapMaxBytesMaxGas(maxBytes int, maxGas int64) types.Txs { return types.Txs{} }
func (MockMempool) ReapMaxBytesMaxGas(maxBytes, maxGas int64) types.Txs { return types.Txs{} }
func (MockMempool) Update(height int64, txs types.Txs, filter func(types.Tx) bool) error { return nil }
func (MockMempool) Flush() {}
func (MockMempool) FlushAppConn() error { return nil }
@@ -73,7 +73,7 @@ type BlockStore interface {
// EvidencePool defines the EvidencePool interface used by the ConsensusState.
type EvidencePool interface {
PendingEvidence(int) []types.Evidence
PendingEvidence(int64) []types.Evidence
AddEvidence(types.Evidence) error
Update(*types.Block, State)
}
@@ -81,6 +81,6 @@ type EvidencePool interface {
// MockMempool is an empty implementation of a Mempool, useful for testing.
type MockEvidencePool struct{}
func (m MockEvidencePool) PendingEvidence(int) []types.Evidence { return nil }
func (m MockEvidencePool) PendingEvidence(int64) []types.Evidence { return nil }
func (m MockEvidencePool) AddEvidence(types.Evidence) error { return nil }
func (m MockEvidencePool) Update(*types.Block, State) {}
+5 -5
View File
@@ -328,7 +328,7 @@ func TestConsensusParamsChangesSaveLoad(t *testing.T) {
params[0] = state.ConsensusParams
for i := 1; i < N+1; i++ {
params[i] = *types.DefaultConsensusParams()
params[i].BlockSize.MaxBytes += i
params[i].BlockSize.MaxBytes += int64(i)
}
// Build the params history by running updateState
@@ -373,14 +373,14 @@ func TestConsensusParamsChangesSaveLoad(t *testing.T) {
}
}
func makeParams(txsBytes, blockGas, evidenceAge int) types.ConsensusParams {
func makeParams(blockBytes, blockGas, evidenceAge int64) types.ConsensusParams {
return types.ConsensusParams{
BlockSize: types.BlockSize{
MaxBytes: txsBytes,
MaxGas: int64(blockGas),
MaxBytes: blockBytes,
MaxGas: blockGas,
},
EvidenceParams: types.EvidenceParams{
MaxAge: int64(evidenceAge),
MaxAge: evidenceAge,
},
}
}
+15
View File
@@ -0,0 +1,15 @@
package state
import (
"github.com/tendermint/tendermint/types"
)
// TxFilter returns a function to filter transactions. The function limits the
// size of a transaction to the maximum block's data size.
func TxFilter(state State) func(tx types.Tx) bool {
maxDataBytes := types.MaxDataBytesUnknownEvidence(
state.ConsensusParams.BlockSize.MaxBytes,
state.Validators.Size(),
)
return func(tx types.Tx) bool { return int64(len(tx)) <= maxDataBytes }
}
+47
View File
@@ -0,0 +1,47 @@
package state
import (
"os"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/tendermint/tendermint/crypto/ed25519"
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"
"github.com/tendermint/tendermint/types"
tmtime "github.com/tendermint/tendermint/types/time"
)
func TestTxFilter(t *testing.T) {
genDoc := randomGenesisDoc()
genDoc.ConsensusParams.BlockSize.MaxBytes = 3000
testCases := []struct {
tx types.Tx
isTxValid bool
}{
{types.Tx(cmn.RandBytes(250)), true},
{types.Tx(cmn.RandBytes(3001)), false},
}
for i, tc := range testCases {
stateDB := dbm.NewDB("state", "memdb", os.TempDir())
state, err := LoadStateFromDBOrGenesisDoc(stateDB, genDoc)
require.NoError(t, err)
f := TxFilter(state)
assert.Equal(t, tc.isTxValid, f(tc.tx), "#%v", i)
}
}
func randomGenesisDoc() *types.GenesisDoc {
pubkey := ed25519.GenPrivKey().PubKey()
return &types.GenesisDoc{
GenesisTime: tmtime.Now(),
ChainID: "abc",
Validators: []types.GenesisValidator{{pubkey.Address(), pubkey, 10, "myval"}},
ConsensusParams: types.DefaultConsensusParams(),
}
}