mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 05:46:32 +00:00
* 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>
186 lines
5.8 KiB
Go
186 lines
5.8 KiB
Go
package config
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestDefaultConfig(t *testing.T) {
|
|
assert := assert.New(t)
|
|
|
|
// set up some defaults
|
|
cfg := DefaultConfig()
|
|
assert.NotNil(cfg.P2P)
|
|
assert.NotNil(cfg.Mempool)
|
|
assert.NotNil(cfg.Consensus)
|
|
|
|
// check the root dir stuff...
|
|
cfg.SetRoot("/foo")
|
|
cfg.Genesis = "bar"
|
|
cfg.DBPath = "/opt/data"
|
|
cfg.Mempool.WalPath = "wal/mem/"
|
|
|
|
assert.Equal("/foo/bar", cfg.GenesisFile())
|
|
assert.Equal("/opt/data", cfg.DBDir())
|
|
assert.Equal("/foo/wal/mem", cfg.Mempool.WalDir())
|
|
|
|
}
|
|
|
|
func TestConfigValidateBasic(t *testing.T) {
|
|
cfg := DefaultConfig()
|
|
assert.NoError(t, cfg.ValidateBasic())
|
|
|
|
// tamper with timeout_propose
|
|
cfg.Consensus.TimeoutPropose = -10 * time.Second
|
|
assert.Error(t, cfg.ValidateBasic())
|
|
}
|
|
|
|
func TestTLSConfiguration(t *testing.T) {
|
|
assert := assert.New(t)
|
|
cfg := DefaultConfig()
|
|
cfg.SetRoot("/home/user")
|
|
|
|
cfg.RPC.TLSCertFile = "file.crt"
|
|
assert.Equal("/home/user/config/file.crt", cfg.RPC.CertFile())
|
|
cfg.RPC.TLSKeyFile = "file.key"
|
|
assert.Equal("/home/user/config/file.key", cfg.RPC.KeyFile())
|
|
|
|
cfg.RPC.TLSCertFile = "/abs/path/to/file.crt"
|
|
assert.Equal("/abs/path/to/file.crt", cfg.RPC.CertFile())
|
|
cfg.RPC.TLSKeyFile = "/abs/path/to/file.key"
|
|
assert.Equal("/abs/path/to/file.key", cfg.RPC.KeyFile())
|
|
}
|
|
|
|
func TestBaseConfigValidateBasic(t *testing.T) {
|
|
cfg := TestBaseConfig()
|
|
assert.NoError(t, cfg.ValidateBasic())
|
|
|
|
// tamper with log format
|
|
cfg.LogFormat = "invalid"
|
|
assert.Error(t, cfg.ValidateBasic())
|
|
}
|
|
|
|
func TestRPCConfigValidateBasic(t *testing.T) {
|
|
cfg := TestRPCConfig()
|
|
assert.NoError(t, cfg.ValidateBasic())
|
|
|
|
fieldsToTest := []string{
|
|
"GRPCMaxOpenConnections",
|
|
"MaxOpenConnections",
|
|
"MaxSubscriptionClients",
|
|
"MaxSubscriptionsPerClient",
|
|
"TimeoutBroadcastTxCommit",
|
|
"MaxBodyBytes",
|
|
"MaxHeaderBytes",
|
|
}
|
|
|
|
for _, fieldName := range fieldsToTest {
|
|
reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
|
|
assert.Error(t, cfg.ValidateBasic())
|
|
reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
|
|
}
|
|
}
|
|
|
|
func TestP2PConfigValidateBasic(t *testing.T) {
|
|
cfg := TestP2PConfig()
|
|
assert.NoError(t, cfg.ValidateBasic())
|
|
|
|
fieldsToTest := []string{
|
|
"MaxNumInboundPeers",
|
|
"MaxNumOutboundPeers",
|
|
"FlushThrottleTimeout",
|
|
"MaxPacketMsgPayloadSize",
|
|
"SendRate",
|
|
"RecvRate",
|
|
}
|
|
|
|
for _, fieldName := range fieldsToTest {
|
|
reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
|
|
assert.Error(t, cfg.ValidateBasic())
|
|
reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
|
|
}
|
|
}
|
|
|
|
func TestMempoolConfigValidateBasic(t *testing.T) {
|
|
cfg := TestMempoolConfig()
|
|
assert.NoError(t, cfg.ValidateBasic())
|
|
|
|
fieldsToTest := []string{
|
|
"Size",
|
|
"MaxTxsBytes",
|
|
"CacheSize",
|
|
"MaxTxBytes",
|
|
}
|
|
|
|
for _, fieldName := range fieldsToTest {
|
|
reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(-1)
|
|
assert.Error(t, cfg.ValidateBasic())
|
|
reflect.ValueOf(cfg).Elem().FieldByName(fieldName).SetInt(0)
|
|
}
|
|
}
|
|
|
|
func TestFastSyncConfigValidateBasic(t *testing.T) {
|
|
cfg := TestFastSyncConfig()
|
|
assert.NoError(t, cfg.ValidateBasic())
|
|
|
|
// tamper with version
|
|
cfg.Version = "v1"
|
|
assert.NoError(t, cfg.ValidateBasic())
|
|
|
|
cfg.Version = "invalid"
|
|
assert.Error(t, cfg.ValidateBasic())
|
|
}
|
|
|
|
func TestConsensusConfig_ValidateBasic(t *testing.T) {
|
|
// nolint: lll
|
|
testcases := map[string]struct {
|
|
modify func(*ConsensusConfig)
|
|
expectErr bool
|
|
}{
|
|
"TimeoutPropose": {func(c *ConsensusConfig) { c.TimeoutPropose = time.Second }, false},
|
|
"TimeoutPropose negative": {func(c *ConsensusConfig) { c.TimeoutPropose = -1 }, true},
|
|
"TimeoutProposeDelta": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = time.Second }, false},
|
|
"TimeoutProposeDelta negative": {func(c *ConsensusConfig) { c.TimeoutProposeDelta = -1 }, true},
|
|
"TimeoutPrevote": {func(c *ConsensusConfig) { c.TimeoutPrevote = time.Second }, false},
|
|
"TimeoutPrevote negative": {func(c *ConsensusConfig) { c.TimeoutPrevote = -1 }, true},
|
|
"TimeoutPrevoteDelta": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = time.Second }, false},
|
|
"TimeoutPrevoteDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrevoteDelta = -1 }, true},
|
|
"TimeoutPrecommit": {func(c *ConsensusConfig) { c.TimeoutPrecommit = time.Second }, false},
|
|
"TimeoutPrecommit negative": {func(c *ConsensusConfig) { c.TimeoutPrecommit = -1 }, true},
|
|
"TimeoutPrecommitDelta": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = time.Second }, false},
|
|
"TimeoutPrecommitDelta negative": {func(c *ConsensusConfig) { c.TimeoutPrecommitDelta = -1 }, true},
|
|
"TimeoutCommit": {func(c *ConsensusConfig) { c.TimeoutCommit = time.Second }, false},
|
|
"TimeoutCommit negative": {func(c *ConsensusConfig) { c.TimeoutCommit = -1 }, true},
|
|
"PeerGossipSleepDuration": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = time.Second }, false},
|
|
"PeerGossipSleepDuration negative": {func(c *ConsensusConfig) { c.PeerGossipSleepDuration = -1 }, true},
|
|
"PeerQueryMaj23SleepDuration": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = time.Second }, false},
|
|
"PeerQueryMaj23SleepDuration negative": {func(c *ConsensusConfig) { c.PeerQueryMaj23SleepDuration = -1 }, true},
|
|
}
|
|
for desc, tc := range testcases {
|
|
tc := tc // appease linter
|
|
t.Run(desc, func(t *testing.T) {
|
|
cfg := DefaultConsensusConfig()
|
|
tc.modify(cfg)
|
|
|
|
err := cfg.ValidateBasic()
|
|
if tc.expectErr {
|
|
assert.Error(t, err)
|
|
} else {
|
|
assert.NoError(t, err)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestInstrumentationConfigValidateBasic(t *testing.T) {
|
|
cfg := TestInstrumentationConfig()
|
|
assert.NoError(t, cfg.ValidateBasic())
|
|
|
|
// tamper with maximum open connections
|
|
cfg.MaxOpenConnections = -1
|
|
assert.Error(t, cfg.ValidateBasic())
|
|
}
|