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.

170 lines
5.6 KiB

add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
4 years ago
add support for block pruning via ABCI Commit response (#4588) * Added BlockStore.DeleteBlock() * Added initial block pruner prototype * wip * Added BlockStore.PruneBlocks() * Added consensus setting for block pruning * Added BlockStore base * Error on replay if base does not have blocks * Handle missing blocks when sending VoteSetMaj23Message * Error message tweak * Properly update blockstore state * Error message fix again * blockchain: ignore peer missing blocks * Added FIXME * Added test for block replay with truncated history * Handle peer base in blockchain reactor * Improved replay error handling * Added tests for Store.PruneBlocks() * Fix non-RPC handling of truncated block history * Panic on missing block meta in needProofBlock() * Updated changelog * Handle truncated block history in RPC layer * Added info about earliest block in /status RPC * Reorder height and base in blockchain reactor messages * Updated changelog * Fix tests * Appease linter * Minor review fixes * Non-empty BlockStores should always have base > 0 * Update code to assume base > 0 invariant * Added blockstore tests for pruning to 0 * Make sure we don't prune below the current base * Added BlockStore.Size() * config: added retain_blocks recommendations * Update v1 blockchain reactor to handle blockstore base * Added state database pruning * Propagate errors on missing validator sets * Comment tweaks * Improved error message Co-Authored-By: Anton Kaliaev <anton.kalyaev@gmail.com> * use ABCI field ResponseCommit.retain_height instead of retain-blocks config option * remove State.RetainHeight, return value instead * fix minor issues * rename pruneHeights() to pruneBlocks() * noop to fix GitHub borkage Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
4 years ago
  1. package config
  2. import (
  3. "reflect"
  4. "testing"
  5. "time"
  6. "github.com/stretchr/testify/assert"
  7. "github.com/stretchr/testify/require"
  8. )
  9. func TestDefaultConfig(t *testing.T) {
  10. // set up some defaults
  11. cfg := DefaultConfig()
  12. assert.NotNil(t, cfg.P2P)
  13. assert.NotNil(t, cfg.Mempool)
  14. assert.NotNil(t, cfg.Consensus)
  15. // check the root dir stuff...
  16. cfg.SetRoot("/foo")
  17. cfg.Genesis = "bar"
  18. cfg.DBPath = "/opt/data"
  19. assert.Equal(t, "/foo/bar", cfg.GenesisFile())
  20. assert.Equal(t, "/opt/data", cfg.DBDir())
  21. }
  22. func TestConfigValidateBasic(t *testing.T) {
  23. cfg := DefaultConfig()
  24. assert.NoError(t, cfg.ValidateBasic())
  25. // tamper with timeout_propose
  26. cfg.Consensus.TimeoutPropose = -10 * time.Second
  27. assert.Error(t, cfg.ValidateBasic())
  28. }
  29. func TestTLSConfiguration(t *testing.T) {
  30. cfg := DefaultConfig()
  31. cfg.SetRoot("/home/user")
  32. cfg.RPC.TLSCertFile = "file.crt"
  33. assert.Equal(t, "/home/user/config/file.crt", cfg.RPC.CertFile())
  34. cfg.RPC.TLSKeyFile = "file.key"
  35. assert.Equal(t, "/home/user/config/file.key", cfg.RPC.KeyFile())
  36. cfg.RPC.TLSCertFile = "/abs/path/to/file.crt"
  37. assert.Equal(t, "/abs/path/to/file.crt", cfg.RPC.CertFile())
  38. cfg.RPC.TLSKeyFile = "/abs/path/to/file.key"
  39. assert.Equal(t, "/abs/path/to/file.key", cfg.RPC.KeyFile())
  40. }
  41. func TestBaseConfigValidateBasic(t *testing.T) {
  42. cfg := TestBaseConfig()
  43. assert.NoError(t, cfg.ValidateBasic())
  44. // tamper with log format
  45. cfg.LogFormat = "invalid"
  46. assert.Error(t, cfg.ValidateBasic())
  47. }
  48. func TestRPCConfigValidateBasic(t *testing.T) {
  49. cfg := TestRPCConfig()
  50. assert.NoError(t, cfg.ValidateBasic())
  51. fieldsToTest := []string{
  52. "MaxOpenConnections",
  53. "MaxSubscriptionClients",
  54. "MaxSubscriptionsPerClient",
  55. "TimeoutBroadcastTxCommit",
  56. "MaxBodyBytes",
  57. "MaxHeaderBytes",
  58. }
  59. for _, fieldName := range fieldsToTest {
  60. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
  61. assert.Error(t, cfg.ValidateBasic())
  62. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
  63. }
  64. }
  65. func TestMempoolConfigValidateBasic(t *testing.T) {
  66. cfg := TestMempoolConfig()
  67. assert.NoError(t, cfg.ValidateBasic())
  68. fieldsToTest := []string{
  69. "Size",
  70. "MaxTxsBytes",
  71. "CacheSize",
  72. "MaxTxBytes",
  73. }
  74. for _, fieldName := range fieldsToTest {
  75. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
  76. assert.Error(t, cfg.ValidateBasic())
  77. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
  78. }
  79. }
  80. func TestStateSyncConfigValidateBasic(t *testing.T) {
  81. cfg := TestStateSyncConfig()
  82. require.NoError(t, cfg.ValidateBasic())
  83. }
  84. func TestConsensusConfig_ValidateBasic(t *testing.T) {
  85. testcases := map[string]struct {
  86. modify func(*ConsensusConfig)
  87. expectErr bool
  88. }{
  89. "TimeoutPropose": {func(c *ConsensusConfig) { c.TimeoutPropose = time.Second }, false},
  90. "TimeoutPropose negative": {func(c *ConsensusConfig) { c.TimeoutPropose = -1 }, true},
  91. "TimeoutProposeDelta": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = time.Second }, false},
  92. "TimeoutProposeDelta negative": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = -1 }, true},
  93. "TimeoutPrevote": {func(c *ConsensusConfig) { c.TimeoutPrevote = time.Second }, false},
  94. "TimeoutPrevote negative": {func(c *ConsensusConfig) { c.TimeoutPrevote = -1 }, true},
  95. "TimeoutPrevoteDelta": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = time.Second }, false},
  96. "TimeoutPrevoteDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = -1 }, true},
  97. "TimeoutPrecommit": {func(c *ConsensusConfig) { c.TimeoutPrecommit = time.Second }, false},
  98. "TimeoutPrecommit negative": {func(c *ConsensusConfig) { c.TimeoutPrecommit = -1 }, true},
  99. "TimeoutPrecommitDelta": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = time.Second }, false},
  100. "TimeoutPrecommitDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = -1 }, true},
  101. "TimeoutCommit": {func(c *ConsensusConfig) { c.TimeoutCommit = time.Second }, false},
  102. "TimeoutCommit negative": {func(c *ConsensusConfig) { c.TimeoutCommit = -1 }, true},
  103. "PeerGossipSleepDuration": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = time.Second }, false},
  104. "PeerGossipSleepDuration negative": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = -1 }, true},
  105. "PeerQueryMaj23SleepDuration": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = time.Second }, false},
  106. "PeerQueryMaj23SleepDuration negative": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = -1 }, true},
  107. "DoubleSignCheckHeight negative": {func(c *ConsensusConfig) { c.DoubleSignCheckHeight = -1 }, true},
  108. }
  109. for desc, tc := range testcases {
  110. tc := tc // appease linter
  111. t.Run(desc, func(t *testing.T) {
  112. cfg := DefaultConsensusConfig()
  113. tc.modify(cfg)
  114. err := cfg.ValidateBasic()
  115. if tc.expectErr {
  116. assert.Error(t, err)
  117. } else {
  118. assert.NoError(t, err)
  119. }
  120. })
  121. }
  122. }
  123. func TestInstrumentationConfigValidateBasic(t *testing.T) {
  124. cfg := TestInstrumentationConfig()
  125. assert.NoError(t, cfg.ValidateBasic())
  126. // tamper with maximum open connections
  127. cfg.MaxOpenConnections = -1
  128. assert.Error(t, cfg.ValidateBasic())
  129. }
  130. func TestP2PConfigValidateBasic(t *testing.T) {
  131. cfg := TestP2PConfig()
  132. assert.NoError(t, cfg.ValidateBasic())
  133. fieldsToTest := []string{
  134. "FlushThrottleTimeout",
  135. "MaxPacketMsgPayloadSize",
  136. "SendRate",
  137. "RecvRate",
  138. }
  139. for _, fieldName := range fieldsToTest {
  140. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
  141. assert.Error(t, cfg.ValidateBasic())
  142. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
  143. }
  144. }