You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.0 KiB

max-bytes PR follow-up (#2318) * ReapMaxTxs: return all txs if max is negative this mirrors ReapMaxBytes behavior See https://github.com/tendermint/tendermint/pull/2184#discussion_r214439950 * increase MaxAminoOverheadForBlock tested with: ``` func TestMaxAminoOverheadForBlock(t *testing.T) { maxChainID := "" for i := 0; i < MaxChainIDLen; i++ { maxChainID += "𠜎" } h := Header{ ChainID: maxChainID, Height: 10, Time: time.Now().UTC(), NumTxs: 100, TotalTxs: 200, LastBlockID: makeBlockID(make([]byte, 20), 300, make([]byte, 20)), LastCommitHash: tmhash.Sum([]byte("last_commit_hash")), DataHash: tmhash.Sum([]byte("data_hash")), ValidatorsHash: tmhash.Sum([]byte("validators_hash")), NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")), ConsensusHash: tmhash.Sum([]byte("consensus_hash")), AppHash: tmhash.Sum([]byte("app_hash")), LastResultsHash: tmhash.Sum([]byte("last_results_hash")), EvidenceHash: tmhash.Sum([]byte("evidence_hash")), ProposerAddress: tmhash.Sum([]byte("proposer_address")), } b := Block{ Header: h, Data: Data{Txs: makeTxs(10000, 100)}, Evidence: EvidenceData{}, LastCommit: &Commit{}, } bz, err := cdc.MarshalBinary(b) require.NoError(t, err) assert.Equal(t, MaxHeaderBytes+MaxAminoOverheadForBlock-2, len(bz)-1000000-20000-1) } ``` * fix MaxYYY constants calculation by using math.MaxInt64 See https://github.com/tendermint/tendermint/pull/2184#discussion_r214444244 * pass mempool filter as an option See https://github.com/tendermint/tendermint/pull/2184#discussion_r214445869 * fixes after Dev's comments
6 years ago
max-bytes PR follow-up (#2318) * ReapMaxTxs: return all txs if max is negative this mirrors ReapMaxBytes behavior See https://github.com/tendermint/tendermint/pull/2184#discussion_r214439950 * increase MaxAminoOverheadForBlock tested with: ``` func TestMaxAminoOverheadForBlock(t *testing.T) { maxChainID := "" for i := 0; i < MaxChainIDLen; i++ { maxChainID += "𠜎" } h := Header{ ChainID: maxChainID, Height: 10, Time: time.Now().UTC(), NumTxs: 100, TotalTxs: 200, LastBlockID: makeBlockID(make([]byte, 20), 300, make([]byte, 20)), LastCommitHash: tmhash.Sum([]byte("last_commit_hash")), DataHash: tmhash.Sum([]byte("data_hash")), ValidatorsHash: tmhash.Sum([]byte("validators_hash")), NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")), ConsensusHash: tmhash.Sum([]byte("consensus_hash")), AppHash: tmhash.Sum([]byte("app_hash")), LastResultsHash: tmhash.Sum([]byte("last_results_hash")), EvidenceHash: tmhash.Sum([]byte("evidence_hash")), ProposerAddress: tmhash.Sum([]byte("proposer_address")), } b := Block{ Header: h, Data: Data{Txs: makeTxs(10000, 100)}, Evidence: EvidenceData{}, LastCommit: &Commit{}, } bz, err := cdc.MarshalBinary(b) require.NoError(t, err) assert.Equal(t, MaxHeaderBytes+MaxAminoOverheadForBlock-2, len(bz)-1000000-20000-1) } ``` * fix MaxYYY constants calculation by using math.MaxInt64 See https://github.com/tendermint/tendermint/pull/2184#discussion_r214444244 * pass mempool filter as an option See https://github.com/tendermint/tendermint/pull/2184#discussion_r214445869 * fixes after Dev's comments
6 years ago
max-bytes PR follow-up (#2318) * ReapMaxTxs: return all txs if max is negative this mirrors ReapMaxBytes behavior See https://github.com/tendermint/tendermint/pull/2184#discussion_r214439950 * increase MaxAminoOverheadForBlock tested with: ``` func TestMaxAminoOverheadForBlock(t *testing.T) { maxChainID := "" for i := 0; i < MaxChainIDLen; i++ { maxChainID += "𠜎" } h := Header{ ChainID: maxChainID, Height: 10, Time: time.Now().UTC(), NumTxs: 100, TotalTxs: 200, LastBlockID: makeBlockID(make([]byte, 20), 300, make([]byte, 20)), LastCommitHash: tmhash.Sum([]byte("last_commit_hash")), DataHash: tmhash.Sum([]byte("data_hash")), ValidatorsHash: tmhash.Sum([]byte("validators_hash")), NextValidatorsHash: tmhash.Sum([]byte("next_validators_hash")), ConsensusHash: tmhash.Sum([]byte("consensus_hash")), AppHash: tmhash.Sum([]byte("app_hash")), LastResultsHash: tmhash.Sum([]byte("last_results_hash")), EvidenceHash: tmhash.Sum([]byte("evidence_hash")), ProposerAddress: tmhash.Sum([]byte("proposer_address")), } b := Block{ Header: h, Data: Data{Txs: makeTxs(10000, 100)}, Evidence: EvidenceData{}, LastCommit: &Commit{}, } bz, err := cdc.MarshalBinary(b) require.NoError(t, err) assert.Equal(t, MaxHeaderBytes+MaxAminoOverheadForBlock-2, len(bz)-1000000-20000-1) } ``` * fix MaxYYY constants calculation by using math.MaxInt64 See https://github.com/tendermint/tendermint/pull/2184#discussion_r214444244 * pass mempool filter as an option See https://github.com/tendermint/tendermint/pull/2184#discussion_r214445869 * fixes after Dev's comments
6 years ago
  1. package types
  2. import (
  3. "math"
  4. "testing"
  5. "github.com/stretchr/testify/assert"
  6. "github.com/stretchr/testify/require"
  7. "github.com/tendermint/tendermint/crypto/secp256k1"
  8. "github.com/tendermint/tendermint/crypto/tmhash"
  9. )
  10. type voteData struct {
  11. vote1 *Vote
  12. vote2 *Vote
  13. valid bool
  14. }
  15. func makeVote(val PrivValidator, chainID string, valIndex int, height int64, round, step int, blockID BlockID) *Vote {
  16. v := &Vote{
  17. ValidatorAddress: val.GetAddress(),
  18. ValidatorIndex: valIndex,
  19. Height: height,
  20. Round: round,
  21. Type: byte(step),
  22. BlockID: blockID,
  23. }
  24. err := val.SignVote(chainID, v)
  25. if err != nil {
  26. panic(err)
  27. }
  28. return v
  29. }
  30. func TestEvidence(t *testing.T) {
  31. val := NewMockPV()
  32. val2 := NewMockPV()
  33. blockID := makeBlockID([]byte("blockhash"), 1000, []byte("partshash"))
  34. blockID2 := makeBlockID([]byte("blockhash2"), 1000, []byte("partshash"))
  35. blockID3 := makeBlockID([]byte("blockhash"), 10000, []byte("partshash"))
  36. blockID4 := makeBlockID([]byte("blockhash"), 10000, []byte("partshash2"))
  37. const chainID = "mychain"
  38. vote1 := makeVote(val, chainID, 0, 10, 2, 1, blockID)
  39. badVote := makeVote(val, chainID, 0, 10, 2, 1, blockID)
  40. err := val2.SignVote(chainID, badVote)
  41. if err != nil {
  42. panic(err)
  43. }
  44. cases := []voteData{
  45. {vote1, makeVote(val, chainID, 0, 10, 2, 1, blockID2), true}, // different block ids
  46. {vote1, makeVote(val, chainID, 0, 10, 2, 1, blockID3), true},
  47. {vote1, makeVote(val, chainID, 0, 10, 2, 1, blockID4), true},
  48. {vote1, makeVote(val, chainID, 0, 10, 2, 1, blockID), false}, // wrong block id
  49. {vote1, makeVote(val, "mychain2", 0, 10, 2, 1, blockID2), false}, // wrong chain id
  50. {vote1, makeVote(val, chainID, 1, 10, 2, 1, blockID2), false}, // wrong val index
  51. {vote1, makeVote(val, chainID, 0, 11, 2, 1, blockID2), false}, // wrong height
  52. {vote1, makeVote(val, chainID, 0, 10, 3, 1, blockID2), false}, // wrong round
  53. {vote1, makeVote(val, chainID, 0, 10, 2, 2, blockID2), false}, // wrong step
  54. {vote1, makeVote(val2, chainID, 0, 10, 2, 1, blockID), false}, // wrong validator
  55. {vote1, badVote, false}, // signed by wrong key
  56. }
  57. pubKey := val.GetPubKey()
  58. for _, c := range cases {
  59. ev := &DuplicateVoteEvidence{
  60. VoteA: c.vote1,
  61. VoteB: c.vote2,
  62. }
  63. if c.valid {
  64. assert.Nil(t, ev.Verify(chainID, pubKey), "evidence should be valid")
  65. } else {
  66. assert.NotNil(t, ev.Verify(chainID, pubKey), "evidence should be invalid")
  67. }
  68. }
  69. }
  70. func TestDuplicatedVoteEvidence(t *testing.T) {
  71. ev := randomDuplicatedVoteEvidence()
  72. assert.True(t, ev.Equal(ev))
  73. assert.False(t, ev.Equal(&DuplicateVoteEvidence{}))
  74. }
  75. func TestEvidenceList(t *testing.T) {
  76. ev := randomDuplicatedVoteEvidence()
  77. evl := EvidenceList([]Evidence{ev})
  78. assert.NotNil(t, evl.Hash())
  79. assert.True(t, evl.Has(ev))
  80. assert.False(t, evl.Has(&DuplicateVoteEvidence{}))
  81. }
  82. func TestMaxEvidenceBytes(t *testing.T) {
  83. val := NewMockPV()
  84. blockID := makeBlockID(tmhash.Sum([]byte("blockhash")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
  85. blockID2 := makeBlockID(tmhash.Sum([]byte("blockhash2")), math.MaxInt64, tmhash.Sum([]byte("partshash")))
  86. const chainID = "mychain"
  87. ev := &DuplicateVoteEvidence{
  88. PubKey: secp256k1.GenPrivKey().PubKey(), // use secp because it's pubkey is longer
  89. VoteA: makeVote(val, chainID, math.MaxInt64, math.MaxInt64, math.MaxInt64, math.MaxInt64, blockID),
  90. VoteB: makeVote(val, chainID, math.MaxInt64, math.MaxInt64, math.MaxInt64, math.MaxInt64, blockID2),
  91. }
  92. bz, err := cdc.MarshalBinary(ev)
  93. require.NoError(t, err)
  94. assert.Equal(t, MaxEvidenceBytes, len(bz))
  95. }
  96. func randomDuplicatedVoteEvidence() *DuplicateVoteEvidence {
  97. val := NewMockPV()
  98. blockID := makeBlockID([]byte("blockhash"), 1000, []byte("partshash"))
  99. blockID2 := makeBlockID([]byte("blockhash2"), 1000, []byte("partshash"))
  100. const chainID = "mychain"
  101. return &DuplicateVoteEvidence{
  102. VoteA: makeVote(val, chainID, 0, 10, 2, 1, blockID),
  103. VoteB: makeVote(val, chainID, 0, 10, 2, 1, blockID2),
  104. }
  105. }