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.

189 lines
6.0 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. // tamper with version
  108. cfg.Version = "v2"
  109. assert.Error(t, cfg.ValidateBasic())
  110. cfg.Version = "invalid"
  111. assert.Error(t, cfg.ValidateBasic())
  112. }
  113. func TestConsensusConfig_ValidateBasic(t *testing.T) {
  114. // nolint: lll
  115. testcases := map[string]struct {
  116. modify func(*ConsensusConfig)
  117. expectErr bool
  118. }{
  119. "TimeoutPropose": {func(c *ConsensusConfig) { c.TimeoutPropose = time.Second }, false},
  120. "TimeoutPropose negative": {func(c *ConsensusConfig) { c.TimeoutPropose = -1 }, true},
  121. "TimeoutProposeDelta": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = time.Second }, false},
  122. "TimeoutProposeDelta negative": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = -1 }, true},
  123. "TimeoutPrevote": {func(c *ConsensusConfig) { c.TimeoutPrevote = time.Second }, false},
  124. "TimeoutPrevote negative": {func(c *ConsensusConfig) { c.TimeoutPrevote = -1 }, true},
  125. "TimeoutPrevoteDelta": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = time.Second }, false},
  126. "TimeoutPrevoteDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = -1 }, true},
  127. "TimeoutPrecommit": {func(c *ConsensusConfig) { c.TimeoutPrecommit = time.Second }, false},
  128. "TimeoutPrecommit negative": {func(c *ConsensusConfig) { c.TimeoutPrecommit = -1 }, true},
  129. "TimeoutPrecommitDelta": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = time.Second }, false},
  130. "TimeoutPrecommitDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = -1 }, true},
  131. "TimeoutCommit": {func(c *ConsensusConfig) { c.TimeoutCommit = time.Second }, false},
  132. "TimeoutCommit negative": {func(c *ConsensusConfig) { c.TimeoutCommit = -1 }, true},
  133. "PeerGossipSleepDuration": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = time.Second }, false},
  134. "PeerGossipSleepDuration negative": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = -1 }, true},
  135. "PeerQueryMaj23SleepDuration": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = time.Second }, false},
  136. "PeerQueryMaj23SleepDuration negative": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = -1 }, true},
  137. "DoubleSignCheckHeight negative": {func(c *ConsensusConfig) { c.DoubleSignCheckHeight = -1 }, true},
  138. }
  139. for desc, tc := range testcases {
  140. tc := tc // appease linter
  141. t.Run(desc, func(t *testing.T) {
  142. cfg := DefaultConsensusConfig()
  143. tc.modify(cfg)
  144. err := cfg.ValidateBasic()
  145. if tc.expectErr {
  146. assert.Error(t, err)
  147. } else {
  148. assert.NoError(t, err)
  149. }
  150. })
  151. }
  152. }
  153. func TestInstrumentationConfigValidateBasic(t *testing.T) {
  154. cfg := TestInstrumentationConfig()
  155. assert.NoError(t, cfg.ValidateBasic())
  156. // tamper with maximum open connections
  157. cfg.MaxOpenConnections = -1
  158. assert.Error(t, cfg.ValidateBasic())
  159. }