mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-07 22:05:18 +00:00
Fixes #828. Adds state sync, as outlined in [ADR-053](https://github.com/tendermint/tendermint/blob/master/docs/architecture/adr-053-state-sync-prototype.md). See related PRs in Cosmos SDK (https://github.com/cosmos/cosmos-sdk/pull/5803) and Gaia (https://github.com/cosmos/gaia/pull/327). This is split out of the previous PR #4645, and branched off of the ABCI interface in #4704. * Adds a new P2P reactor which exchanges snapshots with peers, and bootstraps an empty local node from remote snapshots when requested. * Adds a new configuration section `[statesync]` that enables state sync and configures the light client. Also enables `statesync:info` logging by default. * Integrates state sync into node startup. Does not support the v2 blockchain reactor, since it needs some reorganization to defer startup.
192 lines
6.0 KiB
Go
192 lines
6.0 KiB
Go
package config
|
|
|
|
import (
|
|
"reflect"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
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 TestStateSyncConfigValidateBasic(t *testing.T) {
|
|
cfg := TestStateSyncConfig()
|
|
require.NoError(t, cfg.ValidateBasic())
|
|
}
|
|
|
|
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())
|
|
}
|