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.

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