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.

161 lines
5.4 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 TestBlockSyncConfigValidateBasic(t *testing.T) {
  87. cfg := TestBlockSyncConfig()
  88. assert.NoError(t, cfg.ValidateBasic())
  89. }
  90. func TestConsensusConfig_ValidateBasic(t *testing.T) {
  91. // nolint: lll
  92. testcases := map[string]struct {
  93. modify func(*ConsensusConfig)
  94. expectErr bool
  95. }{
  96. "TimeoutPropose": {func(c *ConsensusConfig) { c.TimeoutPropose = time.Second }, false},
  97. "TimeoutPropose negative": {func(c *ConsensusConfig) { c.TimeoutPropose = -1 }, true},
  98. "TimeoutProposeDelta": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = time.Second }, false},
  99. "TimeoutProposeDelta negative": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = -1 }, true},
  100. "TimeoutPrevote": {func(c *ConsensusConfig) { c.TimeoutPrevote = time.Second }, false},
  101. "TimeoutPrevote negative": {func(c *ConsensusConfig) { c.TimeoutPrevote = -1 }, true},
  102. "TimeoutPrevoteDelta": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = time.Second }, false},
  103. "TimeoutPrevoteDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = -1 }, true},
  104. "TimeoutPrecommit": {func(c *ConsensusConfig) { c.TimeoutPrecommit = time.Second }, false},
  105. "TimeoutPrecommit negative": {func(c *ConsensusConfig) { c.TimeoutPrecommit = -1 }, true},
  106. "TimeoutPrecommitDelta": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = time.Second }, false},
  107. "TimeoutPrecommitDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = -1 }, true},
  108. "TimeoutCommit": {func(c *ConsensusConfig) { c.TimeoutCommit = time.Second }, false},
  109. "TimeoutCommit negative": {func(c *ConsensusConfig) { c.TimeoutCommit = -1 }, true},
  110. "PeerGossipSleepDuration": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = time.Second }, false},
  111. "PeerGossipSleepDuration negative": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = -1 }, true},
  112. "PeerQueryMaj23SleepDuration": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = time.Second }, false},
  113. "PeerQueryMaj23SleepDuration negative": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = -1 }, true},
  114. "DoubleSignCheckHeight negative": {func(c *ConsensusConfig) { c.DoubleSignCheckHeight = -1 }, true},
  115. }
  116. for desc, tc := range testcases {
  117. tc := tc // appease linter
  118. t.Run(desc, func(t *testing.T) {
  119. cfg := DefaultConsensusConfig()
  120. tc.modify(cfg)
  121. err := cfg.ValidateBasic()
  122. if tc.expectErr {
  123. assert.Error(t, err)
  124. } else {
  125. assert.NoError(t, err)
  126. }
  127. })
  128. }
  129. }
  130. func TestInstrumentationConfigValidateBasic(t *testing.T) {
  131. cfg := TestInstrumentationConfig()
  132. assert.NoError(t, cfg.ValidateBasic())
  133. // tamper with maximum open connections
  134. cfg.MaxOpenConnections = -1
  135. assert.Error(t, cfg.ValidateBasic())
  136. }