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.

174 lines
5.7 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>
5 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>
5 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. assert := assert.New(t)
  11. // set up some defaults
  12. cfg := DefaultConfig()
  13. assert.NotNil(cfg.P2P)
  14. assert.NotNil(cfg.Mempool)
  15. assert.NotNil(cfg.Consensus)
  16. // check the root dir stuff...
  17. cfg.SetRoot("/foo")
  18. cfg.Genesis = "bar"
  19. cfg.DBPath = "/opt/data"
  20. assert.Equal("/foo/bar", cfg.GenesisFile())
  21. assert.Equal("/opt/data", cfg.DBDir())
  22. }
  23. func TestConfigValidateBasic(t *testing.T) {
  24. cfg := DefaultConfig()
  25. assert.NoError(t, cfg.ValidateBasic())
  26. // tamper with timeout_propose
  27. cfg.Consensus.TimeoutPropose = -10 * time.Second
  28. assert.Error(t, cfg.ValidateBasic())
  29. }
  30. func TestTLSConfiguration(t *testing.T) {
  31. assert := assert.New(t)
  32. cfg := DefaultConfig()
  33. cfg.SetRoot("/home/user")
  34. cfg.RPC.TLSCertFile = "file.crt"
  35. assert.Equal("/home/user/config/file.crt", cfg.RPC.CertFile())
  36. cfg.RPC.TLSKeyFile = "file.key"
  37. assert.Equal("/home/user/config/file.key", cfg.RPC.KeyFile())
  38. cfg.RPC.TLSCertFile = "/abs/path/to/file.crt"
  39. assert.Equal("/abs/path/to/file.crt", cfg.RPC.CertFile())
  40. cfg.RPC.TLSKeyFile = "/abs/path/to/file.key"
  41. assert.Equal("/abs/path/to/file.key", cfg.RPC.KeyFile())
  42. }
  43. func TestBaseConfigValidateBasic(t *testing.T) {
  44. cfg := TestBaseConfig()
  45. assert.NoError(t, cfg.ValidateBasic())
  46. // tamper with log format
  47. cfg.LogFormat = "invalid"
  48. assert.Error(t, cfg.ValidateBasic())
  49. }
  50. func TestRPCConfigValidateBasic(t *testing.T) {
  51. cfg := TestRPCConfig()
  52. assert.NoError(t, cfg.ValidateBasic())
  53. fieldsToTest := []string{
  54. "MaxOpenConnections",
  55. "MaxSubscriptionClients",
  56. "MaxSubscriptionsPerClient",
  57. "TimeoutBroadcastTxCommit",
  58. "MaxBodyBytes",
  59. "MaxHeaderBytes",
  60. }
  61. for _, fieldName := range fieldsToTest {
  62. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
  63. assert.Error(t, cfg.ValidateBasic())
  64. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
  65. }
  66. }
  67. func TestMempoolConfigValidateBasic(t *testing.T) {
  68. cfg := TestMempoolConfig()
  69. assert.NoError(t, cfg.ValidateBasic())
  70. fieldsToTest := []string{
  71. "Size",
  72. "MaxTxsBytes",
  73. "CacheSize",
  74. "MaxTxBytes",
  75. }
  76. for _, fieldName := range fieldsToTest {
  77. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
  78. assert.Error(t, cfg.ValidateBasic())
  79. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
  80. }
  81. }
  82. func TestStateSyncConfigValidateBasic(t *testing.T) {
  83. cfg := TestStateSyncConfig()
  84. require.NoError(t, cfg.ValidateBasic())
  85. }
  86. func TestConsensusConfig_ValidateBasic(t *testing.T) {
  87. // nolint: lll
  88. testcases := map[string]struct {
  89. modify func(*ConsensusConfig)
  90. expectErr bool
  91. }{
  92. "TimeoutPropose": {func(c *ConsensusConfig) { c.TimeoutPropose = time.Second }, false},
  93. "TimeoutPropose negative": {func(c *ConsensusConfig) { c.TimeoutPropose = -1 }, true},
  94. "TimeoutProposeDelta": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = time.Second }, false},
  95. "TimeoutProposeDelta negative": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = -1 }, true},
  96. "TimeoutPrevote": {func(c *ConsensusConfig) { c.TimeoutPrevote = time.Second }, false},
  97. "TimeoutPrevote negative": {func(c *ConsensusConfig) { c.TimeoutPrevote = -1 }, true},
  98. "TimeoutPrevoteDelta": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = time.Second }, false},
  99. "TimeoutPrevoteDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = -1 }, true},
  100. "TimeoutPrecommit": {func(c *ConsensusConfig) { c.TimeoutPrecommit = time.Second }, false},
  101. "TimeoutPrecommit negative": {func(c *ConsensusConfig) { c.TimeoutPrecommit = -1 }, true},
  102. "TimeoutPrecommitDelta": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = time.Second }, false},
  103. "TimeoutPrecommitDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = -1 }, true},
  104. "TimeoutCommit": {func(c *ConsensusConfig) { c.TimeoutCommit = time.Second }, false},
  105. "TimeoutCommit negative": {func(c *ConsensusConfig) { c.TimeoutCommit = -1 }, true},
  106. "PeerGossipSleepDuration": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = time.Second }, false},
  107. "PeerGossipSleepDuration negative": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = -1 }, true},
  108. "PeerQueryMaj23SleepDuration": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = time.Second }, false},
  109. "PeerQueryMaj23SleepDuration negative": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = -1 }, true},
  110. "DoubleSignCheckHeight negative": {func(c *ConsensusConfig) { c.DoubleSignCheckHeight = -1 }, true},
  111. }
  112. for desc, tc := range testcases {
  113. tc := tc // appease linter
  114. t.Run(desc, func(t *testing.T) {
  115. cfg := DefaultConsensusConfig()
  116. tc.modify(cfg)
  117. err := cfg.ValidateBasic()
  118. if tc.expectErr {
  119. assert.Error(t, err)
  120. } else {
  121. assert.NoError(t, err)
  122. }
  123. })
  124. }
  125. }
  126. func TestInstrumentationConfigValidateBasic(t *testing.T) {
  127. cfg := TestInstrumentationConfig()
  128. assert.NoError(t, cfg.ValidateBasic())
  129. // tamper with maximum open connections
  130. cfg.MaxOpenConnections = -1
  131. assert.Error(t, cfg.ValidateBasic())
  132. }
  133. func TestP2PConfigValidateBasic(t *testing.T) {
  134. cfg := TestP2PConfig()
  135. assert.NoError(t, cfg.ValidateBasic())
  136. fieldsToTest := []string{
  137. "FlushThrottleTimeout",
  138. "MaxPacketMsgPayloadSize",
  139. "SendRate",
  140. "RecvRate",
  141. }
  142. for _, fieldName := range fieldsToTest {
  143. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
  144. assert.Error(t, cfg.ValidateBasic())
  145. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
  146. }
  147. }