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.

173 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>
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. 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. testcases := map[string]struct {
  88. modify func(*ConsensusConfig)
  89. expectErr bool
  90. }{
  91. "TimeoutPropose": {func(c *ConsensusConfig) { c.TimeoutPropose = time.Second }, false},
  92. "TimeoutPropose negative": {func(c *ConsensusConfig) { c.TimeoutPropose = -1 }, true},
  93. "TimeoutProposeDelta": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = time.Second }, false},
  94. "TimeoutProposeDelta negative": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = -1 }, true},
  95. "TimeoutPrevote": {func(c *ConsensusConfig) { c.TimeoutPrevote = time.Second }, false},
  96. "TimeoutPrevote negative": {func(c *ConsensusConfig) { c.TimeoutPrevote = -1 }, true},
  97. "TimeoutPrevoteDelta": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = time.Second }, false},
  98. "TimeoutPrevoteDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = -1 }, true},
  99. "TimeoutPrecommit": {func(c *ConsensusConfig) { c.TimeoutPrecommit = time.Second }, false},
  100. "TimeoutPrecommit negative": {func(c *ConsensusConfig) { c.TimeoutPrecommit = -1 }, true},
  101. "TimeoutPrecommitDelta": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = time.Second }, false},
  102. "TimeoutPrecommitDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = -1 }, true},
  103. "TimeoutCommit": {func(c *ConsensusConfig) { c.TimeoutCommit = time.Second }, false},
  104. "TimeoutCommit negative": {func(c *ConsensusConfig) { c.TimeoutCommit = -1 }, true},
  105. "PeerGossipSleepDuration": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = time.Second }, false},
  106. "PeerGossipSleepDuration negative": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = -1 }, true},
  107. "PeerQueryMaj23SleepDuration": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = time.Second }, false},
  108. "PeerQueryMaj23SleepDuration negative": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = -1 }, true},
  109. "DoubleSignCheckHeight negative": {func(c *ConsensusConfig) { c.DoubleSignCheckHeight = -1 }, true},
  110. }
  111. for desc, tc := range testcases {
  112. tc := tc // appease linter
  113. t.Run(desc, func(t *testing.T) {
  114. cfg := DefaultConsensusConfig()
  115. tc.modify(cfg)
  116. err := cfg.ValidateBasic()
  117. if tc.expectErr {
  118. assert.Error(t, err)
  119. } else {
  120. assert.NoError(t, err)
  121. }
  122. })
  123. }
  124. }
  125. func TestInstrumentationConfigValidateBasic(t *testing.T) {
  126. cfg := TestInstrumentationConfig()
  127. assert.NoError(t, cfg.ValidateBasic())
  128. // tamper with maximum open connections
  129. cfg.MaxOpenConnections = -1
  130. assert.Error(t, cfg.ValidateBasic())
  131. }
  132. func TestP2PConfigValidateBasic(t *testing.T) {
  133. cfg := TestP2PConfig()
  134. assert.NoError(t, cfg.ValidateBasic())
  135. fieldsToTest := []string{
  136. "FlushThrottleTimeout",
  137. "MaxPacketMsgPayloadSize",
  138. "SendRate",
  139. "RecvRate",
  140. }
  141. for _, fieldName := range fieldsToTest {
  142. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
  143. assert.Error(t, cfg.ValidateBasic())
  144. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
  145. }
  146. }