From a1c4cf73669d62b24fb48da2d4daa256e7ffe2d3 Mon Sep 17 00:00:00 2001 From: Rootul P Date: Mon, 2 Dec 2024 16:24:10 -0500 Subject: [PATCH] chore: improve single-node.sh (#4041) Closes https://github.com/celestiaorg/celestia-app/issues/3975 Fixes a few issues I discovered with single-node.sh 1. `single-node.sh` previously created a genesis file with `appVersion: 3` so even though it attempted to upgrade from v1 -> v2, that step doesn't make any sense because the node was already on v3. This PR fixes the issue by removing the `--v2-upgrade-height` flag from the script 2. Add a few more logs 3. Add a new script: `single-node-upgrades.sh` that can be invoked to start a single node on v1 and upgrade it: v1 -> v2 -> v3. After running the command, the user will see ``` An upgrade is pending to app version 3 at height 50406. ``` ## FLUPs 1. Modify single-node.sh to override the upgrade height delay and instead upgrade from v2 -> v3 instantly: https://github.com/celestiaorg/celestia-app/issues/4053 --------- Co-authored-by: CHAMI Rachid Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- app/app.go | 1 + scripts/single-node-upgrades.sh | 157 ++++++++++++++++++++++++++++++++ scripts/single-node.sh | 63 ++++++------- 3 files changed, 188 insertions(+), 33 deletions(-) create mode 100755 scripts/single-node-upgrades.sh diff --git a/app/app.go b/app/app.go index b13e8f7f3f..eadd034ea1 100644 --- a/app/app.go +++ b/app/app.go @@ -476,6 +476,7 @@ func (app *App) EndBlocker(ctx sdk.Context, req abci.RequestEndBlock) abci.Respo } else if shouldUpgrade, newVersion := app.SignalKeeper.ShouldUpgrade(ctx); shouldUpgrade { // Version changes must be increasing. Downgrades are not permitted if newVersion > currentVersion { + app.BaseApp.Logger().Info("upgrading app version", "current version", currentVersion, "new version", newVersion) app.SetAppVersion(ctx, newVersion) app.SignalKeeper.ResetTally(ctx) } diff --git a/scripts/single-node-upgrades.sh b/scripts/single-node-upgrades.sh new file mode 100755 index 0000000000..32dd577fb8 --- /dev/null +++ b/scripts/single-node-upgrades.sh @@ -0,0 +1,157 @@ +#!/bin/sh + +# This script starts a single node testnet on app version 1. Then it upgrades +# from v1 -> v2 -> v3. + +# Stop script execution if an error is encountered +set -o errexit +# Stop script execution if an undefined variable is used +set -o nounset + +if ! [ -x "$(command -v celestia-appd)" ] +then + echo "celestia-appd could not be found. Please install the celestia-appd binary using 'make install' and make sure the PATH contains the directory where the binary exists. By default, go will install the binary under '~/go/bin'" + exit 1 +fi + +# Constants +CHAIN_ID="test" +KEY_NAME="validator" +KEYRING_BACKEND="test" +FEES="500utia" +BROADCAST_MODE="block" + +VERSION=$(celestia-appd version 2>&1) +APP_HOME="${HOME}/.celestia-app" +GENESIS_FILE="${APP_HOME}/config/genesis.json" + +echo "celestia-app version: ${VERSION}" +echo "celestia-app home: ${APP_HOME}" +echo "celestia-app genesis file: ${GENESIS_FILE}" +echo "" + +createGenesis() { + echo "Initializing validator and node config files..." + celestia-appd init ${CHAIN_ID} \ + --chain-id ${CHAIN_ID} \ + --home "${APP_HOME}" \ + > /dev/null 2>&1 # Hide output to reduce terminal noise + + echo "Adding a new key to the keyring..." + celestia-appd keys add ${KEY_NAME} \ + --keyring-backend=${KEYRING_BACKEND} \ + --home "${APP_HOME}" \ + > /dev/null 2>&1 # Hide output to reduce terminal noise + + echo "Adding genesis account..." + celestia-appd add-genesis-account \ + "$(celestia-appd keys show ${KEY_NAME} -a --keyring-backend=${KEYRING_BACKEND} --home "${APP_HOME}")" \ + "1000000000000000utia" \ + --home "${APP_HOME}" + + echo "Creating a genesis tx..." + celestia-appd gentx ${KEY_NAME} 5000000000utia \ + --fees ${FEES} \ + --keyring-backend=${KEYRING_BACKEND} \ + --chain-id ${CHAIN_ID} \ + --home "${APP_HOME}" \ + > /dev/null 2>&1 # Hide output to reduce terminal noise + + echo "Collecting genesis txs..." + celestia-appd collect-gentxs \ + --home "${APP_HOME}" \ + > /dev/null 2>&1 # Hide output to reduce terminal noise + + # If you encounter: `sed: -I or -i may not be used with stdin` on MacOS you can mitigate by installing gnu-sed + # https://gist.github.com/andre3k1/e3a1a7133fded5de5a9ee99c87c6fa0d?permalink_comment_id=3082272#gistcomment-3082272 + + # Override the default RPC server listening address + sed -i'.bak' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' "${APP_HOME}"/config/config.toml + + # Enable transaction indexing + sed -i'.bak' 's#"null"#"kv"#g' "${APP_HOME}"/config/config.toml + + # Persist ABCI responses + sed -i'.bak' 's#discard_abci_responses = true#discard_abci_responses = false#g' "${APP_HOME}"/config/config.toml + + # Override the genesis to use app version 1 and then upgrade to app version 2 later. + sed -i'.bak' 's/"app_version": *"[^"]*"/"app_version": "1"/' ${APP_HOME}/config/genesis.json + + # Override the log level to debug + # sed -i'.bak' 's#log_level = "info"#log_level = "debug"#g' "${APP_HOME}"/config/config.toml + + # Override the VotingPeriod from 1 week to 1 minute + sed -i'.bak' 's#"604800s"#"60s"#g' "${APP_HOME}"/config/genesis.json + + trace_type="local" + sed -i.bak -e "s/^trace_type *=.*/trace_type = \"$trace_type\"/" ${APP_HOME}/config/config.toml + + trace_pull_address=":26661" + sed -i.bak -e "s/^trace_pull_address *=.*/trace_pull_address = \"$trace_pull_address\"/" ${APP_HOME}/config/config.toml + + trace_push_batch_size=1000 + sed -i.bak -e "s/^trace_push_batch_size *=.*/trace_push_batch_size = \"$trace_push_batch_size\"/" ${APP_HOME}/config/config.toml + + echo "Tracing is set up with the ability to pull traced data from the node on the address http://127.0.0.1${trace_pull_address}" +} + +deleteCelestiaAppHome() { + echo "Deleting $APP_HOME..." + rm -r "$APP_HOME" +} + +startCelestiaApp() { + echo "Starting celestia-app..." + celestia-appd start \ + --home "${APP_HOME}" \ + --api.enable \ + --grpc.enable \ + --grpc-web.enable \ + --v2-upgrade-height 3 \ + --force-no-bbr # no need to require BBR usage on a local node. +} + +upgradeToV3() { + sleep 45 + echo "Submitting signal for v3..." + celestia-appd tx signal signal 3 \ + --keyring-backend=${KEYRING_BACKEND} \ + --home ${APP_HOME} \ + --from ${KEY_NAME} \ + --fees ${FEES} \ + --chain-id ${CHAIN_ID} \ + --broadcast-mode ${BROADCAST_MODE} \ + --yes \ + > /dev/null 2>&1 # Hide output to reduce terminal noise + + echo "Querying the tally for v3..." + celestia-appd query signal tally 3 + + echo "Submitting msg try upgrade..." + celestia-appd tx signal try-upgrade \ + --keyring-backend=${KEYRING_BACKEND} \ + --home ${APP_HOME} \ + --from ${KEY_NAME} \ + --fees ${FEES} \ + --chain-id ${CHAIN_ID} \ + --broadcast-mode ${BROADCAST_MODE} \ + --yes \ + > /dev/null 2>&1 # Hide output to reduce terminal noise + + echo "Querying for pending upgrade..." + celestia-appd query signal upgrade +} + +if [ -f $GENESIS_FILE ]; then + echo "Do you want to delete existing ${APP_HOME} and start a new local testnet? [y/n]" + read -r response + if [ "$response" = "y" ]; then + deleteCelestiaAppHome + createGenesis + fi +else + createGenesis +fi + +upgradeToV3 & # Start the upgrade process from v2 -> v3 in the background. +startCelestiaApp # Start celestia-app in the foreground. diff --git a/scripts/single-node.sh b/scripts/single-node.sh index b6a6e6486a..14c24e9eb8 100755 --- a/scripts/single-node.sh +++ b/scripts/single-node.sh @@ -1,6 +1,6 @@ #!/bin/sh -# This script starts a single node testnet. +# This script starts a single node testnet on app version 3. # Stop script execution if an error is encountered set -o errexit @@ -13,103 +13,100 @@ then exit 1 fi +# Constants CHAIN_ID="test" KEY_NAME="validator" KEYRING_BACKEND="test" -COINS="1000000000000000utia" -DELEGATION_AMOUNT="5000000000utia" -CELESTIA_APP_HOME="${HOME}/.celestia-app" -CELESTIA_APP_VERSION=$(celestia-appd version 2>&1) -GENESIS_FILE="${CELESTIA_APP_HOME}/config/genesis.json" FEES="500utia" -echo "celestia-app home: ${CELESTIA_APP_HOME}" -echo "celestia-app version: ${CELESTIA_APP_VERSION}" +VERSION=$(celestia-appd version 2>&1) +APP_HOME="${HOME}/.celestia-app" +GENESIS_FILE="${APP_HOME}/config/genesis.json" + +echo "celestia-app version: ${VERSION}" +echo "celestia-app home: ${APP_HOME}" +echo "celestia-app genesis file: ${GENESIS_FILE}" echo "" createGenesis() { echo "Initializing validator and node config files..." celestia-appd init ${CHAIN_ID} \ --chain-id ${CHAIN_ID} \ - --home "${CELESTIA_APP_HOME}" \ + --home "${APP_HOME}" \ > /dev/null 2>&1 # Hide output to reduce terminal noise echo "Adding a new key to the keyring..." celestia-appd keys add ${KEY_NAME} \ --keyring-backend=${KEYRING_BACKEND} \ - --home "${CELESTIA_APP_HOME}" \ + --home "${APP_HOME}" \ > /dev/null 2>&1 # Hide output to reduce terminal noise echo "Adding genesis account..." celestia-appd add-genesis-account \ - "$(celestia-appd keys show ${KEY_NAME} -a --keyring-backend=${KEYRING_BACKEND} --home "${CELESTIA_APP_HOME}")" \ - $COINS \ - --home "${CELESTIA_APP_HOME}" + "$(celestia-appd keys show ${KEY_NAME} -a --keyring-backend=${KEYRING_BACKEND} --home "${APP_HOME}")" \ + "1000000000000000utia" \ + --home "${APP_HOME}" echo "Creating a genesis tx..." - celestia-appd gentx ${KEY_NAME} ${DELEGATION_AMOUNT} \ + celestia-appd gentx ${KEY_NAME} 5000000000utia \ --fees ${FEES} \ --keyring-backend=${KEYRING_BACKEND} \ --chain-id ${CHAIN_ID} \ - --home "${CELESTIA_APP_HOME}" \ + --home "${APP_HOME}" \ > /dev/null 2>&1 # Hide output to reduce terminal noise echo "Collecting genesis txs..." celestia-appd collect-gentxs \ - --home "${CELESTIA_APP_HOME}" \ + --home "${APP_HOME}" \ > /dev/null 2>&1 # Hide output to reduce terminal noise # If you encounter: `sed: -I or -i may not be used with stdin` on MacOS you can mitigate by installing gnu-sed # https://gist.github.com/andre3k1/e3a1a7133fded5de5a9ee99c87c6fa0d?permalink_comment_id=3082272#gistcomment-3082272 # Override the default RPC server listening address - sed -i'.bak' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' "${CELESTIA_APP_HOME}"/config/config.toml + sed -i'.bak' 's#"tcp://127.0.0.1:26657"#"tcp://0.0.0.0:26657"#g' "${APP_HOME}"/config/config.toml # Enable transaction indexing - sed -i'.bak' 's#"null"#"kv"#g' "${CELESTIA_APP_HOME}"/config/config.toml + sed -i'.bak' 's#"null"#"kv"#g' "${APP_HOME}"/config/config.toml # Persist ABCI responses - sed -i'.bak' 's#discard_abci_responses = true#discard_abci_responses = false#g' "${CELESTIA_APP_HOME}"/config/config.toml + sed -i'.bak' 's#discard_abci_responses = true#discard_abci_responses = false#g' "${APP_HOME}"/config/config.toml # Override the log level to debug - # sed -i'.bak' 's#log_level = "info"#log_level = "debug"#g' "${CELESTIA_APP_HOME}"/config/config.toml + # sed -i'.bak' 's#log_level = "info"#log_level = "debug"#g' "${APP_HOME}"/config/config.toml # Override the VotingPeriod from 1 week to 1 minute - sed -i'.bak' 's#"604800s"#"60s"#g' "${CELESTIA_APP_HOME}"/config/genesis.json - - # Override the genesis to use app version 1 and then upgrade to app version 2 later. - sed -i'.bak' 's#"app_version": "2"#"app_version": "1"#g' "${CELESTIA_APP_HOME}"/config/genesis.json + sed -i'.bak' 's#"604800s"#"60s"#g' "${APP_HOME}"/config/genesis.json trace_type="local" - sed -i.bak -e "s/^trace_type *=.*/trace_type = \"$trace_type\"/" ${CELESTIA_APP_HOME}/config/config.toml + sed -i.bak -e "s/^trace_type *=.*/trace_type = \"$trace_type\"/" ${APP_HOME}/config/config.toml trace_pull_address=":26661" - sed -i.bak -e "s/^trace_pull_address *=.*/trace_pull_address = \"$trace_pull_address\"/" ${CELESTIA_APP_HOME}/config/config.toml + sed -i.bak -e "s/^trace_pull_address *=.*/trace_pull_address = \"$trace_pull_address\"/" ${APP_HOME}/config/config.toml trace_push_batch_size=1000 - sed -i.bak -e "s/^trace_push_batch_size *=.*/trace_push_batch_size = \"$trace_push_batch_size\"/" ${CELESTIA_APP_HOME}/config/config.toml + sed -i.bak -e "s/^trace_push_batch_size *=.*/trace_push_batch_size = \"$trace_push_batch_size\"/" ${APP_HOME}/config/config.toml echo "Tracing is set up with the ability to pull traced data from the node on the address http://127.0.0.1${trace_pull_address}" } deleteCelestiaAppHome() { - echo "Deleting $CELESTIA_APP_HOME..." - rm -r "$CELESTIA_APP_HOME" + echo "Deleting $APP_HOME..." + rm -r "$APP_HOME" } startCelestiaApp() { echo "Starting celestia-app..." celestia-appd start \ - --home "${CELESTIA_APP_HOME}" \ + --home "${APP_HOME}" \ --api.enable \ --grpc.enable \ --grpc-web.enable \ - --v2-upgrade-height 3 \ - --force-no-bbr // no need to require BBR usage on a local node + --force-no-bbr # no need to require BBR usage on a local node } if [ -f $GENESIS_FILE ]; then - echo "Do you want to delete existing ${CELESTIA_APP_HOME} and start a new local testnet? [y/n]" + echo "Do you want to delete existing ${APP_HOME} and start a new local testnet? [y/n]" read -r response if [ "$response" = "y" ]; then deleteCelestiaAppHome