Skip to content

Commit

Permalink
v0.34.x: rename TMHOME to CMTHOME (backport #212) (#227)
Browse files Browse the repository at this point in the history
* main: rename TMHOME to CMTHOME (#212)

* Renames cmd/tendermint to cmd/cometbft

* Replacing TMHOME for CMTHOME. On reading the environment variable we still try TMHOME if CMTHOME is not found. TMHOME is deprecated and will be removed in the future releases.

* Include TMHOME deprecation in the changelog

* Updating the config

* updating uses of .tendermint to .cometbft

* Updating the Makefile

* Fix test of debug level flags.

* Update .changelog/unreleased/breaking-changes/211-deprecate-tmhome.md

Co-authored-by: Thane Thomson <connect@thanethomson.com>

---------

Co-authored-by: Thane Thomson <connect@thanethomson.com>
(cherry picked from commit 2f4a09a)

# Conflicts:
#	.gitignore
#	cmd/cometbft/commands/inspect.go
#	config/config.go

* Revert "main: rename TMHOME to CMTHOME (#212)"

This reverts commit 3f95ea1561bb59cd814fada599d72923ec4f77a9.

* main: rename TMHOME to CMTHOME (#212)

* Renames cmd/tendermint to cmd/cometbft

* Replacing TMHOME for CMTHOME. On reading the environment variable we still try TMHOME if CMTHOME is not found. TMHOME is deprecated and will be removed in the future releases.

* Include TMHOME deprecation in the changelog

* Updating the config

* updating uses of .tendermint to .cometbft

* Updating the Makefile

* Fix test of debug level flags.

* Update .changelog/unreleased/breaking-changes/211-deprecate-tmhome.md

Co-authored-by: Thane Thomson <connect@thanethomson.com>

---------

Co-authored-by: Thane Thomson <connect@thanethomson.com>

* added uncommited changes

* Removed inspect.go

* Added env variable fix

* Renamed tm command

* Renaming tmhome

* Fixed duplicates and extras in .gitignore and moved defaultdir back to vars

* removed non existing folder form .gitignore

* Corrected .gitignore

* Added newline at end of file

---------

Co-authored-by: Lasaro <lasaro@informal.systems>
Co-authored-by: Jasmina Malicevic <jasmina.dustinac@gmail.com>
Co-authored-by: Thane Thomson <connect@thanethomson.com>
  • Loading branch information
4 people committed Jan 31, 2023
1 parent f6dc33a commit d41a46e
Show file tree
Hide file tree
Showing 43 changed files with 125 additions and 91 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- The `TMHOME` environment variable was renamed to `CMTHOME`, and all environment variables starting with `TM_` are instead prefixed with `CMT_`
([\#211](https://github.com/cometbft/cometbft/issues/211))
8 changes: 3 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,15 @@
*.bak
.DS_Store
build/*
.cometbft
.cometbft-lite
rpc/test/.cometbft
rpc/test/.tendermint
.tendermint
remote_dump
.revision
vendor
.vagrant
test/e2e/build
test/maverick/maverick
test/e2e/networks/*/
test/p2p/data/
test/logs
coverage.txt
docs/_build
docs/dist
Expand Down
8 changes: 4 additions & 4 deletions DOCKER/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ LABEL maintainer="hello@informal.systems"
# private validator file into /cometbft/config.
#
# The /cometbft/data dir is used by CometBFT to store state.
ENV TMHOME /cometbft
ENV CMTHOME /cometbft

# OS environment setup
# Set user right away for determinism, create directory for persistence and give our user ownership
Expand All @@ -35,12 +35,12 @@ RUN apk update && \
apk upgrade && \
apk --no-cache add curl jq bash && \
addgroup tmuser && \
adduser -S -G tmuser tmuser -h "$TMHOME"
adduser -S -G tmuser tmuser -h "$CMTHOME"

# Run the container with tmuser by default. (UID=100, GID=1000)
USER tmuser

WORKDIR $TMHOME
WORKDIR $CMTHOME

# p2p, rpc and prometheus port
EXPOSE 26656 26657 26660
Expand All @@ -60,5 +60,5 @@ ENTRYPOINT ["docker-entrypoint.sh"]
CMD ["node"]

# Expose the data directory as a volume since there's mutable state in there
VOLUME [ "$TMHOME" ]
VOLUME [ "$CMTHOME" ]

8 changes: 4 additions & 4 deletions DOCKER/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -e

if [ ! -d "$TMHOME/config" ]; then
if [ ! -d "$CMTHOME/config" ]; then
echo "Running cometbft init to create (default) configuration for docker run."
cometbft init

Expand All @@ -13,11 +13,11 @@ if [ ! -d "$TMHOME/config" ]; then
-e 's/^index_all_tags\s*=.*/index_all_tags = true/' \
-e 's,^laddr = "tcp://127.0.0.1:26657",laddr = "tcp://0.0.0.0:26657",' \
-e 's/^prometheus\s*=.*/prometheus = true/' \
"$TMHOME/config/config.toml"
"$CMTHOME/config/config.toml"

jq ".chain_id = \"$CHAIN_ID\" | .consensus_params.block.time_iota_ms = \"500\"" \
"$TMHOME/config/genesis.json" > "$TMHOME/config/genesis.json.new"
mv "$TMHOME/config/genesis.json.new" "$TMHOME/config/genesis.json"
"$CMTHOME/config/genesis.json" > "$CMTHOME/config/genesis.json.new"
mv "$CMTHOME/config/genesis.json.new" "$CMTHOME/config/genesis.json"
fi

exec cometbft "$@"
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ include tests.mk
###############################################################################

build:
CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(OUTPUT) ./cmd/tendermint/
CGO_ENABLED=$(CGO_ENABLED) go build $(BUILD_FLAGS) -tags '$(BUILD_TAGS)' -o $(OUTPUT) ./cmd/cometbft/
.PHONY: build

install:
CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/tendermint
CGO_ENABLED=$(CGO_ENABLED) go install $(BUILD_FLAGS) -tags $(BUILD_TAGS) ./cmd/cometbft
.PHONY: install


Expand Down Expand Up @@ -154,12 +154,12 @@ go.sum: go.mod
draw_deps:
@# requires brew install graphviz or apt-get install graphviz
go get github.com/RobotsAndPencils/goviz
@goviz -i github.com/cometbft/cometbft/cmd/tendermint -d 3 | dot -Tpng -o dependency-graph.png
@goviz -i github.com/cometbft/cometbft/cmd/cometbft -d 3 | dot -Tpng -o dependency-graph.png
.PHONY: draw_deps

get_deps_bin_size:
@# Copy of build recipe with additional flags to perform binary size analysis
$(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/tendermint/ 2>&1))
$(eval $(shell go build -work -a $(BUILD_FLAGS) -tags $(BUILD_TAGS) -o $(OUTPUT) ./cmd/cometbft/ 2>&1))
@find $(WORK) -type f -name "*.a" | xargs -I{} du -hxs "{}" | sort -rh | sed -e s:${WORK}/::g > deps_bin_size.log
@echo "Results can be found here: $(CURDIR)/deps_bin_size.log"
.PHONY: get_deps_bin_size
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ func ParseConfig(cmd *cobra.Command) (*cfg.Config, error) {
}

var home string
if os.Getenv("TMHOME") != "" {
if os.Getenv("CMTHOME") != "" {
home = os.Getenv("CMTHOME")
} else if os.Getenv("TMHOME") != "" {
//XXX: Deprecated.
home = os.Getenv("TMHOME")
logger.Error("Deprecated environment variable TMHOME identified. CMTHOME should be used instead.")
} else {
home, err = cmd.Flags().GetString(cli.HomeFlag)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,18 @@ var defaultRoot = os.ExpandEnv("$HOME/.some/test/dir")

// clearConfig clears env vars, the given root dir, and resets viper.
func clearConfig(dir string) {
if err := os.Unsetenv("CMTHOME"); err != nil {
panic(err)
}
if err := os.Unsetenv("CMT_HOME"); err != nil {
panic(err)
}
if err := os.Unsetenv("TMHOME"); err != nil {
//XXX: Deprecated.
panic(err)
}
if err := os.Unsetenv("TM_HOME"); err != nil {
//XXX: Deprecated.
panic(err)
}

Expand Down Expand Up @@ -52,7 +60,7 @@ func testSetup(rootDir string, args []string, env map[string]string) error {
clearConfig(defaultRoot)

rootCmd := testRootCmd()
cmd := cli.PrepareBaseCmd(rootCmd, "TM", defaultRoot)
cmd := cli.PrepareBaseCmd(rootCmd, "CMT", defaultRoot)

// run with the args and env
args = append([]string{rootCmd.Use}, args...)
Expand All @@ -68,7 +76,8 @@ func TestRootHome(t *testing.T) {
}{
{nil, nil, defaultRoot},
{[]string{"--home", newRoot}, nil, newRoot},
{nil, map[string]string{"TMHOME": newRoot}, newRoot},
{nil, map[string]string{"TMHOME": newRoot}, newRoot}, //XXX: Deprecated.
{nil, map[string]string{"CMTHOME": newRoot}, newRoot},
}

for i, tc := range cases {
Expand All @@ -94,11 +103,14 @@ func TestRootFlagsEnv(t *testing.T) {
env map[string]string
logLevel string
}{
{[]string{"--log", "debug"}, nil, defaultLogLvl}, // wrong flag
{[]string{"--log_level", "debug"}, nil, "debug"}, // right flag
{nil, map[string]string{"TM_LOW": "debug"}, defaultLogLvl}, // wrong env flag
{nil, map[string]string{"MT_LOG_LEVEL": "debug"}, defaultLogLvl}, // wrong env prefix
{nil, map[string]string{"TM_LOG_LEVEL": "debug"}, "debug"}, // right env
{[]string{"--log", "debug"}, nil, defaultLogLvl}, // wrong flag
{[]string{"--log_level", "debug"}, nil, "debug"}, // right flag
{nil, map[string]string{"TM_LOW": "debug"}, defaultLogLvl}, // wrong env flag
{nil, map[string]string{"MT_LOG_LEVEL": "debug"}, defaultLogLvl}, // wrong env prefix
{nil, map[string]string{"TM_LOG_LEVEL": "debug"}, defaultLogLvl}, // right, but deprecated env
{nil, map[string]string{"CMT_LOW": "debug"}, defaultLogLvl}, // wrong env flag
{nil, map[string]string{"TMC_LOG_LEVEL": "debug"}, defaultLogLvl}, // wrong env prefix
{nil, map[string]string{"CMT_LOG_LEVEL": "debug"}, "debug"}, // right env
}

for i, tc := range cases {
Expand All @@ -124,9 +136,10 @@ func TestRootConfig(t *testing.T) {

logLvl string
}{
{nil, nil, nonDefaultLogLvl}, // should load config
{[]string{"--log_level=abc:info"}, nil, "abc:info"}, // flag over rides
{nil, map[string]string{"TM_LOG_LEVEL": "abc:info"}, "abc:info"}, // env over rides
{nil, nil, nonDefaultLogLvl}, // should load config
{[]string{"--log_level=abc:info"}, nil, "abc:info"}, // flag over rides
{nil, map[string]string{"TM_LOG_LEVEL": "abc:info"}, nonDefaultLogLvl}, // env over rides //XXX: Deprecated
{nil, map[string]string{"CMT_LOG_LEVEL": "abc:info"}, "abc:info"}, // env over rides
}

for i, tc := range cases {
Expand All @@ -144,7 +157,7 @@ func TestRootConfig(t *testing.T) {
require.Nil(t, err)

rootCmd := testRootCmd()
cmd := cli.PrepareBaseCmd(rootCmd, "TM", defaultRoot)
cmd := cli.PrepareBaseCmd(rootCmd, "CMT", defaultRoot)

// run with the args and env
tc.args = append([]string{rootCmd.Use}, tc.args...)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions cmd/tendermint/main.go → cmd/cometbft/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"os"
"path/filepath"

cmd "github.com/cometbft/cometbft/cmd/tendermint/commands"
"github.com/cometbft/cometbft/cmd/tendermint/commands/debug"
cmd "github.com/cometbft/cometbft/cmd/cometbft/commands"
"github.com/cometbft/cometbft/cmd/cometbft/commands/debug"
cfg "github.com/cometbft/cometbft/config"
"github.com/cometbft/cometbft/libs/cli"
nm "github.com/cometbft/cometbft/node"
Expand Down Expand Up @@ -48,7 +48,7 @@ func main() {
// Create & start node
rootCmd.AddCommand(cmd.NewRunNodeCmd(nodeFunc))

cmd := cli.PrepareBaseCmd(rootCmd, "TM", os.ExpandEnv(filepath.Join("$HOME", cfg.DefaultTendermintDir)))
cmd := cli.PrepareBaseCmd(rootCmd, "CMT", os.ExpandEnv(filepath.Join("$HOME", cfg.DefaultTendermintDir)))
if err := cmd.Execute(); err != nil {
panic(err)
}
Expand Down
29 changes: 23 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const (
// config/toml.go
// NOTE: libs/cli must know to look in the config dir!
var (
DefaultTendermintDir = ".tendermint"
DefaultTendermintDir = ".cometbft"
defaultConfigDir = "config"
defaultDataDir = "data"

Expand Down Expand Up @@ -687,11 +687,28 @@ type MempoolConfig struct {
// Mempool version to use:
// 1) "v0" - (default) FIFO mempool.
// 2) "v1" - prioritized mempool.
Version string `mapstructure:"version"`
RootDir string `mapstructure:"home"`
Recheck bool `mapstructure:"recheck"`
Broadcast bool `mapstructure:"broadcast"`
WalPath string `mapstructure:"wal_dir"`
Version string `mapstructure:"version"`
// RootDir is the root directory for all data. This should be configured via
// the $CMTHOME env variable or --home cmd flag rather than overriding this
// struct field.
RootDir string `mapstructure:"home"`
// Recheck (default: true) defines whether Tendermint should recheck the
// validity for all remaining transaction in the mempool after a block.
// Since a block affects the application state, some transactions in the
// mempool may become invalid. If this does not apply to your application,
// you can disable rechecking.
Recheck bool `mapstructure:"recheck"`
// Broadcast (default: true) defines whether the mempool should relay
// transactions to other peers. Setting this to false will stop the mempool
// from relaying transactions to other peers until they are included in a
// block. In other words, if Broadcast is disabled, only the peer you send
// the tx to will see it until it is included in a block.
Broadcast bool `mapstructure:"broadcast"`
// WalPath (default: "") configures the location of the Write Ahead Log
// (WAL) for the mempool. The WAL is disabled by default. To enable, set
// WalPath to where you want the WAL to be written (e.g.
// "data/mempool.wal").
WalPath string `mapstructure:"wal_dir"`
// Maximum number of transactions in the mempool
Size int `mapstructure:"size"`
// Limit the total size of all txs in the mempool.
Expand Down
4 changes: 2 additions & 2 deletions config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func EnsureRoot(rootDir string) {
}
}

// XXX: this func should probably be called by cmd/tendermint/commands/init.go
// XXX: this func should probably be called by cmd/cometbft/commands/init.go
// alongside the writing of the genesis.json and priv_validator.json
func writeDefaultConfigFile(configFilePath string) {
WriteConfigFile(configFilePath, DefaultConfig())
Expand All @@ -73,7 +73,7 @@ const defaultConfigTemplate = `# This is a TOML config file.
# NOTE: Any path below can be absolute (e.g. "/var/myawesomeapp/data") or
# relative to the home directory (e.g. "data"). The home directory is
# "$HOME/.tendermint" by default, but could be changed via $TMHOME env variable
# "$HOME/.cometbft" by default, but could be changed via $CMTHOME env variable
# or --home cmd flag.
#######################################################################
Expand Down
4 changes: 2 additions & 2 deletions docs/tendermint-core/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ order: 3
# Configuration

Tendermint Core can be configured via a TOML file in
`$TMHOME/config/config.toml`. Some of these parameters can be overridden by
`$CMTHOME/config/config.toml`. Some of these parameters can be overridden by
command-line flags. For most users, the options in the `##### main base configuration options #####` are intended to be modified while config options
further below are intended for advance power users.

Expand All @@ -22,7 +22,7 @@ like the file below, however, double check by inspecting the

# NOTE: Any path below can be absolute (e.g. "/var/myawesomeapp/data") or
# relative to the home directory (e.g. "data"). The home directory is
# "$HOME/.tendermint" by default, but could be changed via $TMHOME env variable
# "$HOME/.cometbft" by default, but could be changed via $CMTHOME env variable
# or --home cmd flag.

#######################################################################
Expand Down
6 changes: 3 additions & 3 deletions docs/tendermint-core/running-in-production.md
Original file line number Diff line number Diff line change
Expand Up @@ -211,13 +211,13 @@ Recovering from data corruption can be hard and time-consuming. Here are two app
1) Create a backup of the corrupted WAL file:

```sh
cp "$TMHOME/data/cs.wal/wal" > /tmp/corrupted_wal_backup
cp "$CMTHOME/data/cs.wal/wal" > /tmp/corrupted_wal_backup
```

2) Use `./scripts/wal2json` to create a human-readable version:

```sh
./scripts/wal2json/wal2json "$TMHOME/data/cs.wal/wal" > /tmp/corrupted_wal
./scripts/wal2json/wal2json "$CMTHOME/data/cs.wal/wal" > /tmp/corrupted_wal
```

3) Search for a "CORRUPTED MESSAGE" line.
Expand All @@ -235,7 +235,7 @@ Recovering from data corruption can be hard and time-consuming. Here are two app
5) After editing, convert this file back into binary form by running:

```sh
./scripts/json2wal/json2wal /tmp/corrupted_wal $TMHOME/data/cs.wal/wal
./scripts/json2wal/json2wal /tmp/corrupted_wal $CMTHOME/data/cs.wal/wal
```

## Hardware
Expand Down
8 changes: 4 additions & 4 deletions docs/tendermint-core/using-tendermint.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ number with `tendermint version`.
## Directory Root

The default directory for blockchain data is `~/.tendermint`. Override
this by setting the `TMHOME` environment variable.
this by setting the `CMTHOME` environment variable.

## Initialize

Expand All @@ -26,7 +26,7 @@ tendermint init

This will create a new private key (`priv_validator_key.json`), and a
genesis file (`genesis.json`) containing the associated public key, in
`$TMHOME/config`. This is all that's necessary to run a local testnet
`$CMTHOME/config`. This is all that's necessary to run a local testnet
with one validator.

For more elaborate initialization, see the testnet command:
Expand All @@ -37,7 +37,7 @@ tendermint testnet --help

### Genesis

The `genesis.json` file in `$TMHOME/config/` defines the initial
The `genesis.json` file in `$CMTHOME/config/` defines the initial
TendermintCore state upon genesis of the blockchain ([see
definition](https://github.com/tendermint/tendermint/blob/v0.34.x/types/genesis.go)).

Expand Down Expand Up @@ -439,7 +439,7 @@ have to use a seed node if you have a live persistent peer.
#### Connecting to Peers

To connect to peers on start-up, specify them in the
`$TMHOME/config/config.toml` or on the command line. Use `seeds` to
`$CMTHOME/config/config.toml` or on the command line. Use `seeds` to
specify seed nodes, and
`persistent_peers` to specify peers that your node will maintain
persistent connections with.
Expand Down
6 changes: 3 additions & 3 deletions networks/local/localnode/wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ fi
##
## Run binary with all parameters
##
export TMHOME="/cometbft/node${ID}"
export CMTHOME="/cometbft/node${ID}"

if [ -d "`dirname ${TMHOME}/${LOG}`" ]; then
"$BINARY" "$@" | tee "${TMHOME}/${LOG}"
if [ -d "`dirname ${CMTHOME}/${LOG}`" ]; then
"$BINARY" "$@" | tee "${CMTHOME}/${LOG}"
else
"$BINARY" "$@"
fi
Expand Down
2 changes: 1 addition & 1 deletion rpc/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ info:
## Configuration
RPC can be configured by tuning parameters under `[rpc]` table in the
`$TMHOME/config/config.toml` file or by using the `--rpc.X` command-line
`$CMTHOME/config/config.toml` file or by using the `--rpc.X` command-line
flags.
Default rpc listen address is `tcp://0.0.0.0:26657`.
Expand Down
4 changes: 2 additions & 2 deletions test/app/clean.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
killall tendermint
killall cometbft
killall abci-cli
rm -rf ~/.tendermint_app
rm -rf ~/.cometbft_app
Loading

0 comments on commit d41a46e

Please sign in to comment.