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.

182 lines
5.9 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. "GRPCMaxOpenConnections",
  55. "MaxOpenConnections",
  56. "MaxSubscriptionClients",
  57. "MaxSubscriptionsPerClient",
  58. "TimeoutBroadcastTxCommit",
  59. "MaxBodyBytes",
  60. "MaxHeaderBytes",
  61. }
  62. for _, fieldName := range fieldsToTest {
  63. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
  64. assert.Error(t, cfg.ValidateBasic())
  65. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
  66. }
  67. }
  68. func TestP2PConfigValidateBasic(t *testing.T) {
  69. cfg := TestP2PConfig()
  70. assert.NoError(t, cfg.ValidateBasic())
  71. fieldsToTest := []string{
  72. "MaxNumInboundPeers",
  73. "MaxNumOutboundPeers",
  74. "FlushThrottleTimeout",
  75. "MaxPacketMsgPayloadSize",
  76. "SendRate",
  77. "RecvRate",
  78. }
  79. for _, fieldName := range fieldsToTest {
  80. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
  81. assert.Error(t, cfg.ValidateBasic())
  82. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
  83. }
  84. }
  85. func TestMempoolConfigValidateBasic(t *testing.T) {
  86. cfg := TestMempoolConfig()
  87. assert.NoError(t, cfg.ValidateBasic())
  88. fieldsToTest := []string{
  89. "Size",
  90. "MaxTxsBytes",
  91. "CacheSize",
  92. "MaxTxBytes",
  93. }
  94. for _, fieldName := range fieldsToTest {
  95. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
  96. assert.Error(t, cfg.ValidateBasic())
  97. reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
  98. }
  99. }
  100. func TestStateSyncConfigValidateBasic(t *testing.T) {
  101. cfg := TestStateSyncConfig()
  102. require.NoError(t, cfg.ValidateBasic())
  103. }
  104. func TestBlockSyncConfigValidateBasic(t *testing.T) {
  105. cfg := TestBlockSyncConfig()
  106. assert.NoError(t, cfg.ValidateBasic())
  107. }
  108. func TestConsensusConfig_ValidateBasic(t *testing.T) {
  109. // nolint: lll
  110. testcases := map[string]struct {
  111. modify func(*ConsensusConfig)
  112. expectErr bool
  113. }{
  114. "TimeoutPropose": {func(c *ConsensusConfig) { c.TimeoutPropose = time.Second }, false},
  115. "TimeoutPropose negative": {func(c *ConsensusConfig) { c.TimeoutPropose = -1 }, true},
  116. "TimeoutProposeDelta": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = time.Second }, false},
  117. "TimeoutProposeDelta negative": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = -1 }, true},
  118. "TimeoutPrevote": {func(c *ConsensusConfig) { c.TimeoutPrevote = time.Second }, false},
  119. "TimeoutPrevote negative": {func(c *ConsensusConfig) { c.TimeoutPrevote = -1 }, true},
  120. "TimeoutPrevoteDelta": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = time.Second }, false},
  121. "TimeoutPrevoteDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = -1 }, true},
  122. "TimeoutPrecommit": {func(c *ConsensusConfig) { c.TimeoutPrecommit = time.Second }, false},
  123. "TimeoutPrecommit negative": {func(c *ConsensusConfig) { c.TimeoutPrecommit = -1 }, true},
  124. "TimeoutPrecommitDelta": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = time.Second }, false},
  125. "TimeoutPrecommitDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = -1 }, true},
  126. "TimeoutCommit": {func(c *ConsensusConfig) { c.TimeoutCommit = time.Second }, false},
  127. "TimeoutCommit negative": {func(c *ConsensusConfig) { c.TimeoutCommit = -1 }, true},
  128. "PeerGossipSleepDuration": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = time.Second }, false},
  129. "PeerGossipSleepDuration negative": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = -1 }, true},
  130. "PeerQueryMaj23SleepDuration": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = time.Second }, false},
  131. "PeerQueryMaj23SleepDuration negative": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = -1 }, true},
  132. "DoubleSignCheckHeight negative": {func(c *ConsensusConfig) { c.DoubleSignCheckHeight = -1 }, true},
  133. }
  134. for desc, tc := range testcases {
  135. tc := tc // appease linter
  136. t.Run(desc, func(t *testing.T) {
  137. cfg := DefaultConsensusConfig()
  138. tc.modify(cfg)
  139. err := cfg.ValidateBasic()
  140. if tc.expectErr {
  141. assert.Error(t, err)
  142. } else {
  143. assert.NoError(t, err)
  144. }
  145. })
  146. }
  147. }
  148. func TestInstrumentationConfigValidateBasic(t *testing.T) {
  149. cfg := TestInstrumentationConfig()
  150. assert.NoError(t, cfg.ValidateBasic())
  151. // tamper with maximum open connections
  152. cfg.MaxOpenConnections = -1
  153. assert.Error(t, cfg.ValidateBasic())
  154. }