Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v0.7-dev' into TD-30-dedicated-s…
Browse files Browse the repository at this point in the history
…lots
  • Loading branch information
lklimek committed Nov 4, 2021
2 parents 4a62ea5 + de0fa26 commit 1d92eac
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 15 deletions.
4 changes: 4 additions & 0 deletions abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ func NewPersistentKVStoreApplication(dbDir string) *PersistentKVStoreApplication
}
}

func (app *PersistentKVStoreApplication) Close() error {
return app.app.state.db.Close()
}

func (app *PersistentKVStoreApplication) SetLogger(l log.Logger) {
app.logger = l
}
Expand Down
19 changes: 19 additions & 0 deletions consensus/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -713,7 +714,10 @@ func randConsensusNet(nValidators int, initialHeight int64, testName string, tic
genDoc, privVals := randGenesisDoc(nValidators, false, 30, initialHeight)
css := make([]*State, nValidators)
logger := consensusLogger()

closeFuncs := make([]func() error, 0, nValidators)
configRootDirs := make([]string, 0, nValidators)

for i := 0; i < nValidators; i++ {
stateDB := dbm.NewMemDB() // each state needs its own db
stateStore := sm.NewStore(stateDB)
Expand All @@ -725,6 +729,11 @@ func randConsensusNet(nValidators int, initialHeight int64, testName string, tic
}
ensureDir(filepath.Dir(thisConfig.Consensus.WalFile()), 0700) // dir for wal
app := appFunc()

if appCloser, ok := app.(io.Closer); ok {
closeFuncs = append(closeFuncs, appCloser.Close)
}

vals := types.TM2PB.ValidatorUpdates(state.Validators)
app.InitChain(abci.RequestInitChain{ValidatorSet: &vals})

Expand All @@ -733,6 +742,9 @@ func randConsensusNet(nValidators int, initialHeight int64, testName string, tic
css[i].SetLogger(logger.With("validator", i, "module", "consensus"))
}
return css, func() {
for _, closer := range closeFuncs {
_ = closer()
}
for _, dir := range configRootDirs {
os.RemoveAll(dir)
}
Expand Down Expand Up @@ -921,6 +933,7 @@ func randConsensusNetWithPeers(
css := make([]*State, nPeers)
logger := consensusLogger()
var peer0Config *cfg.Config
closeFuncs := make([]func() error, 0, nValidators)
configRootDirs := make([]string, 0, nPeers)
for i := 0; i < nPeers; i++ {
stateDB := dbm.NewMemDB() // each state needs its own db
Expand Down Expand Up @@ -953,6 +966,9 @@ func randConsensusNetWithPeers(
}

app := appFunc(path.Join(config.DBDir(), fmt.Sprintf("%s_%d", testName, i)))
if appCloser, ok := app.(io.Closer); ok {
closeFuncs = append(closeFuncs, appCloser.Close)
}
vals := types.TM2PB.ValidatorUpdates(state.Validators)
if _, ok := app.(*kvstore.PersistentKVStoreApplication); ok {
// simulate handshake, receive app version. If don't do this, replay test will fail
Expand All @@ -967,6 +983,9 @@ func randConsensusNetWithPeers(
css[i].SetLogger(logger.With("validator", i, "proTxHash", proTxHash.ShortString(), "module", "consensus"))
}
return css, genDoc, peer0Config, func() {
for _, closer := range closeFuncs {
_ = closer()
}
for _, dir := range configRootDirs {
os.RemoveAll(dir)
}
Expand Down
2 changes: 1 addition & 1 deletion consensus/replay_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
}

// Create proxyAppConn connection (consensus, mempool, query)
clientCreator := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
clientCreator, _ := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
proxyApp := proxy.NewAppConns(clientCreator)
err = proxyApp.Start()
if err != nil {
Expand Down
9 changes: 6 additions & 3 deletions consensus/replay_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ func testHandshakeReplay(
// make a new client creator
kvstoreApp := kvstore.NewPersistentKVStoreApplication(
filepath.Join(config.DBDir(), fmt.Sprintf("replay_test_%d_%d_a", nBlocks, mode)))
t.Cleanup(func() { require.NoError(t, kvstoreApp.Close()) })

clientCreator2 := proxy.NewLocalClientCreator(kvstoreApp)
if nBlocks > 0 {
Expand Down Expand Up @@ -1328,9 +1329,11 @@ func buildTMStateFromChain(
nBlocks int,
mode uint) sm.State {
// run the whole chain against this client to build up the tendermint state
clientCreator := proxy.NewLocalClientCreator(
kvstore.NewPersistentKVStoreApplication(
filepath.Join(config.DBDir(), fmt.Sprintf("replay_test_%d_%d_t", nBlocks, mode))))
kvstoreApp := kvstore.NewPersistentKVStoreApplication(
filepath.Join(config.DBDir(), fmt.Sprintf("replay_test_%d_%d_t", nBlocks, mode)))
defer kvstoreApp.Close()
clientCreator := proxy.NewLocalClientCreator(kvstoreApp)

proxyApp := proxy.NewAppConns(clientCreator)
if err := proxyApp.Start(); err != nil {
panic(err)
Expand Down
2 changes: 2 additions & 0 deletions consensus/wal_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/require"
db "github.com/tendermint/tm-db"

"github.com/tendermint/tendermint/abci/example/kvstore"
Expand All @@ -31,6 +32,7 @@ func WALGenerateNBlocks(t *testing.T, wr io.Writer, numBlocks int) (err error) {
config := getConfig(t)

app := kvstore.NewPersistentKVStoreApplication(filepath.Join(config.DBDir(), "wal_generator"))
t.Cleanup(func() { require.NoError(t, app.Close()) })

logger := log.TestingLogger().With("wal_generator", "wal_generator")
logger.Info("generating WAL (last height msg excluded)", "numBlocks", numBlocks)
Expand Down
3 changes: 2 additions & 1 deletion node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ func DefaultNewNode(config *cfg.Config, logger log.Logger) (*Node, error) {
return nil, fmt.Errorf("failed to load or gen node key %s: %w", config.NodeKeyFile(), err)
}

appClient, _ := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
return NewNode(config,
nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
appClient,
DefaultGenesisDocProviderFunc(config),
DefaultDBProvider,
DefaultMetricsProvider(config.Instrumentation),
Expand Down
4 changes: 3 additions & 1 deletion node/node_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,11 @@ func TestNodeNewNodeCustomReactors(t *testing.T) {
nodeKey, err := p2p.LoadOrGenNodeKey(config.NodeKeyFile())
require.NoError(t, err)

appClient, closer := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
t.Cleanup(func() { closer.Close() })
n, err := NewNode(config,
nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
appClient,
DefaultGenesisDocProviderFunc(config),
DefaultDBProvider,
DefaultMetricsProvider(config.Instrumentation),
Expand Down
23 changes: 16 additions & 7 deletions proxy/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package proxy

import (
"fmt"
"io"

abcicli "github.com/tendermint/tendermint/abci/client"
"github.com/tendermint/tendermint/abci/example/counter"
Expand Down Expand Up @@ -69,20 +70,28 @@ func (r *remoteClientCreator) NewABCIClient() (abcicli.Client, error) {
// DefaultClientCreator returns a default ClientCreator, which will create a
// local client if addr is one of: 'counter', 'counter_serial', 'kvstore',
// 'persistent_kvstore' or 'noop', otherwise - a remote client.
func DefaultClientCreator(addr, transport, dbDir string) ClientCreator {
//
// The Closer is a noop except for persistent_kvstore applications,
// which will clean up the store.
func DefaultClientCreator(addr, transport, dbDir string) (ClientCreator, io.Closer) {
switch addr {
case "counter":
return NewLocalClientCreator(counter.NewApplication(false))
return NewLocalClientCreator(counter.NewApplication(false)), noopCloser{}
case "counter_serial":
return NewLocalClientCreator(counter.NewApplication(true))
return NewLocalClientCreator(counter.NewApplication(true)), noopCloser{}
case "kvstore":
return NewLocalClientCreator(kvstore.NewApplication())
return NewLocalClientCreator(kvstore.NewApplication()), noopCloser{}
case "persistent_kvstore":
return NewLocalClientCreator(kvstore.NewPersistentKVStoreApplication(dbDir))
app := kvstore.NewPersistentKVStoreApplication(dbDir)
return NewLocalClientCreator(app), app
case "noop":
return NewLocalClientCreator(types.NewBaseApplication())
return NewLocalClientCreator(types.NewBaseApplication()), noopCloser{}
default:
mustConnect := false // loop retrying
return NewRemoteClientCreator(addr, transport, mustConnect)
return NewRemoteClientCreator(addr, transport, mustConnect), noopCloser{}
}
}

type noopCloser struct{}

func (noopCloser) Close() error { return nil }
1 change: 1 addition & 0 deletions rpc/client/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func TestMain(m *testing.M) {

// and shut down proper at the end
rpctest.StopTendermint(node)
app.Close()
_ = os.RemoveAll(dir)
os.Exit(code)
}
2 changes: 1 addition & 1 deletion test/maverick/consensus/replay_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func newConsensusStateForReplay(config cfg.BaseConfig, csConfig *cfg.ConsensusCo
}

// Create proxyAppConn connection (consensus, mempool, query)
clientCreator := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
clientCreator, _ := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
proxyApp := proxy.NewAppConns(clientCreator)
err = proxyApp.Start()
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion test/maverick/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,10 @@ func DefaultNewNode(
)
}

appClient, _ := proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir())
return NewNode(config,
nodeKey,
proxy.DefaultClientCreator(config.ProxyApp, config.ABCI, config.DBDir()),
appClient,
DefaultGenesisDocProviderFunc(config),
DefaultDBProvider,
DefaultMetricsProvider(config.Instrumentation),
Expand Down

0 comments on commit 1d92eac

Please sign in to comment.