Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade handler flag #706

Merged
merged 26 commits into from
Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
f2c7ec0
Update root.go
faddat Aug 1, 2022
56b55be
Update root.go
faddat Aug 1, 2022
292aee8
add flags to start cmd. next: handle logic
hieuvubk Aug 1, 2022
d97f5cc
remove println
hieuvubk Aug 1, 2022
7091b8f
fix
hieuvubk Aug 1, 2022
a91a273
add logic
hieuvubk Aug 1, 2022
50d82ec
update add flag
Aug 1, 2022
0e397f6
resolve conflict
hieuvubk Aug 1, 2022
d9e4677
Merge branch 'upgrade-handler-flag' of https://github.com/Pylons-tech…
hieuvubk Aug 1, 2022
290aae2
remove duplicate
hieuvubk Aug 1, 2022
ffc5127
fumpt
faddat Aug 2, 2022
a160ef2
Merge branch 'main' of github.com:Pylons-tech/pylons into upgrade-han…
nghuyenthevinh2000 Aug 2, 2022
64e54da
add docker node deployment for old node. docker-compose up -d for sta…
nghuyenthevinh2000 Aug 2, 2022
1d8e0d8
set plan for upgrade
hieuvubk Aug 2, 2022
66f9424
Merge branch 'upgrade-handler-flag' of https://github.com/Pylons-tech…
hieuvubk Aug 2, 2022
c6f5c1c
format
hieuvubk Aug 2, 2022
ad55792
flexible version
nghuyenthevinh2000 Aug 2, 2022
315b11a
Merge branch 'upgrade-handler-flag' of github.com:Pylons-tech/pylons …
nghuyenthevinh2000 Aug 2, 2022
2a60674
add comment
hieuvubk Aug 2, 2022
f8763fb
minor change to docker
nghuyenthevinh2000 Aug 2, 2022
3ff8f50
Merge branch 'upgrade-handler-flag' of github.com:Pylons-tech/pylons …
nghuyenthevinh2000 Aug 2, 2022
04d17a6
check err
hieuvubk Aug 2, 2022
d599476
Merge branch 'upgrade-handler-flag' of https://github.com/Pylons-tech…
hieuvubk Aug 2, 2022
842d40a
gofumpt
nghuyenthevinh2000 Aug 3, 2022
0f1faf8
Merge branch 'upgrade-handler-flag' of github.com:Pylons-tech/pylons …
nghuyenthevinh2000 Aug 3, 2022
53a9bcb
add CHANGELOG
nghuyenthevinh2000 Aug 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ genesis/pylonsd
artifacts

cmd/pylonsd/__debug_bin
proto/dart/*
proto/dart/*

debug
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
- [#591](https://github.com/Pylons-tech/pylons/pull/591) Change CamelCase field name to snake_case in proto

### Changes:

- [#706](https://github.com/Pylons-tech/pylons/pull/706) Add flag "--run-upgrade-handlers" and "--upgrade-height" to "pylonsd start" cmd for immediate upgrade
- [#710](https://github.com/Pylons-tech/pylons/pull/710) Bump IBC-Go to v5.
- [#691](https://github.com/Pylons-tech/pylons/pull/691) Bump Cosmos SDK to v0.46.0.
- [#537](https://github.com/Pylons-tech/pylons/pull/537) CEL execution environment cleanup.
Expand Down
42 changes: 37 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,37 @@
FROM starport/cli
COPY . /app
USER root
EXPOSE $PORT
ENTRYPOINT [ "starport", "chain", "serve", "-p", "/app" ]
FROM golang:1.18-alpine3.16 AS go-builder
ARG BINARY_VERSION=v0.4.2

RUN set -eux

WORKDIR /code

# Install babyd binary
RUN echo "Installing pylonsd binary"
ADD https://github.com/Pylons-tech/pylons/archive/refs/tags/${BINARY_VERSION}.tar.gz /code/
RUN tar -xf ${BINARY_VERSION}.tar.gz -C /code/ --strip-components=1
RUN go build -o bin/pylonsd -mod=readonly ./cmd/pylonsd

#-------------------------------------------
FROM golang:1.18-alpine3.16

RUN apk add --no-cache git bash py3-pip jq curl
RUN pip install toml-cli

WORKDIR /

COPY --from=go-builder /code/bin/pylonsd /usr/bin/pylonsd
COPY --from=go-builder /code/bin/pylonsd /
COPY scripts/* /
RUN chmod +x /*.sh

# rest server
EXPOSE 1317
# tendermint rpc
EXPOSE 26657
# p2p address
EXPOSE 26656
# gRPC address
EXPOSE 9090

# wrong ENTRYPOINT can lead to executable not running
ENTRYPOINT ["/bin/bash"]
69 changes: 39 additions & 30 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,30 @@ export GO111MODULE = on

build_tags = netgo
ifeq ($(LEDGER_ENABLED),true)
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
ifeq ($(OS),Windows_NT)
GCCEXE = $(shell where gcc.exe 2> NUL)
ifeq ($(GCCEXE),)
$(error gcc.exe not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
else
UNAME_S = $(shell uname -s)
ifeq ($(UNAME_S),OpenBSD)
$(warning OpenBSD detected, disabling ledger support (https://github.com/cosmos/cosmos-sdk/issues/1988))
else
GCC = $(shell command -v gcc 2> /dev/null)
ifeq ($(GCC),)
$(error gcc not installed for ledger support, please install or set LEDGER_ENABLED=false)
else
build_tags += ledger
endif
endif
endif
endif

ifeq (cleveldb,$(findstring cleveldb,$(PYLONS_BUILD_OPTIONS)))
build_tags += gcc
build_tags += gcc
endif
build_tags += $(BUILD_TAGS)
build_tags := $(strip $(build_tags))
Expand All @@ -59,18 +59,18 @@ ldflags = -X github.com/cosmos/cosmos-sdk/version.Name=pylons \


ifeq (cleveldb,$(findstring cleveldb,$(PYLONS_BUILD_OPTIONS)))
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
ldflags += -X github.com/cosmos/cosmos-sdk/types.DBBackend=cleveldb
endif
ifeq (,$(findstring nostrip,$(PYLONS_BUILD_OPTIONS)))
ldflags += -w -s
ldflags += -w -s
endif
ldflags += $(LDFLAGS)
ldflags := $(strip $(ldflags))

BUILD_FLAGS := -tags "$(build_tags)" -ldflags '$(ldflags)'
# check for nostrip option
ifeq (,$(findstring nostrip,$(PYLONS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
BUILD_FLAGS += -trimpath
endif

# The below include contains the tools target.
Expand All @@ -96,12 +96,12 @@ build-linux: go.sum
build-reproducible: go.sum
$(DOCKER) rm latest-build || true
$(DOCKER) run --volume=$(CURDIR):/sources:ro \
--env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm6' \
--env APP=pylonsd \
--env VERSION=$(VERSION) \
--env COMMIT=$(COMMIT) \
--env LEDGER_ENABLED=$(LEDGER_ENABLED) \
--name latest-build cosmossdk/rbuilder:latest
--env TARGET_PLATFORMS='linux/amd64 darwin/amd64 linux/arm6' \
--env APP=pylonsd \
--env VERSION=$(VERSION) \
--env COMMIT=$(COMMIT) \
--env LEDGER_ENABLED=$(LEDGER_ENABLED) \
--name latest-build cosmossdk/rbuilder:latest
$(DOCKER) cp -a latest-build:/home/builder/artifacts/ $(CURDIR)/

clean:
Expand Down Expand Up @@ -249,3 +249,12 @@ proto-lint:


.PHONY: lint format proto-lint


###############################################################################
### Localnet ###
###############################################################################

# Build image for a local testnet
localnet-build:
docker build -f Dockerfile -t pylons-node .
31 changes: 27 additions & 4 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import (
"os"
"path/filepath"

upgradev46 "github.com/Pylons-tech/pylons/app/upgrade"
evidencekeeper "github.com/cosmos/cosmos-sdk/x/evidence/keeper"

upgradev46 "github.com/Pylons-tech/pylons/app/upgrade"

storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/version"

Expand Down Expand Up @@ -111,6 +112,12 @@ const (
Name = "pylons"
)

// flag Upgrade Handler
const (
FlagUpgradeHandler = "run-upgrade-handlers"
FlagUpgradeHeight = "upgrade-height"
)

var AccountTrack = make(map[string]uint64)

// These constants are derived from the above variables.
Expand Down Expand Up @@ -254,6 +261,9 @@ type PylonsApp struct {

// module migration manager
configurator module.Configurator

// upgrade height
upgradeHeight int64
}

// New returns a reference to an initialized Pylons.
Expand Down Expand Up @@ -449,10 +459,14 @@ func New(
// NOTE: we may consider parsing `appOpts` inside module constructors. For the moment
// we prefer to be more strict in what arguments the modules expect.
skipGenesisInvariants := cast.ToBool(appOpts.Get(crisis.FlagSkipGenesisInvariants))
isUpgrade := cast.ToBool(appOpts.Get(FlagUpgradeHandler))
app.upgradeHeight = cast.ToInt64(appOpts.Get(FlagUpgradeHeight))

// NOTE: Any module instantiated in the module manager that is later modified
// must be passed by reference here.
app.setupUpgradeStoreLoaders()
if isUpgrade {
app.setupUpgradeStoreLoaders()
}

app.mm = module.NewManager(
genutil.NewAppModule(
Expand Down Expand Up @@ -583,7 +597,9 @@ func New(
app.sm.RegisterStoreDecoders()

// register upgrade
app.RegisterUpgradeHandlers(cfg)
if isUpgrade {
app.RegisterUpgradeHandlers(cfg)
}

// initialize stores
app.MountKVStores(keys)
Expand All @@ -609,7 +625,6 @@ func New(

app.ScopedIBCKeeper = scopedIBCKeeper
app.ScopedTransferKeeper = scopedTransferKeeper

return app
}

Expand All @@ -618,6 +633,14 @@ func (app *PylonsApp) Name() string { return app.BaseApp.Name() }

// BeginBlocker application updates every begin block
func (app *PylonsApp) BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
// Because we upgrade directly on the node without the proposal.
// So create an upgrade plan at the block that needs to be upgraded
if app.upgradeHeight != 0 && app.upgradeHeight == ctx.BlockHeight() {
err := app.UpgradeKeeper.ScheduleUpgrade(ctx, upgradetypes.Plan{Name: upgradev46.UpgradeName, Height: ctx.BlockHeight()})

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if err != nil {
panic(err)

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}
}
return app.mm.BeginBlock(ctx, req)
}

Expand Down
12 changes: 10 additions & 2 deletions cmd/pylonsd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"io"
"os"

"github.com/Pylons-tech/pylons/app/params"
"github.com/cosmos/cosmos-sdk/x/crisis"

"github.com/Pylons-tech/pylons/app"
"github.com/Pylons-tech/pylons/app/params"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/config"
Expand All @@ -32,6 +32,8 @@ import (
tmcli "github.com/tendermint/tendermint/libs/cli"
"github.com/tendermint/tendermint/libs/log"
dbm "github.com/tendermint/tm-db"

"github.com/Pylons-tech/pylons/app"
)

// NewRootCmd creates a new root command for simd. It is called once in the
Expand Down Expand Up @@ -139,8 +141,14 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
rootCmd.AddCommand(server.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec))
}

func addUpgradeHandlerFlags(startCmd *cobra.Command) {
startCmd.Flags().Bool(app.FlagUpgradeHandler, false, "For upgrade handler")
startCmd.Flags().Int64(app.FlagUpgradeHeight, 0, "Upgrade execution block")
}

func addModuleInitFlags(startCmd *cobra.Command) {
crisis.AddModuleInitFlags(startCmd)
addUpgradeHandlerFlags(startCmd)
}

// initTendermintConfig helps to override default Tendermint Config values.
Expand Down
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: '3'

services:
node0:
container_name: pylonsnode
build:
context: .
args:
- BINARY_VERSION=v0.4.2
command: test_node_deploy.sh
ports:
- "26657:26657"
- "1317:1317"
volumes:
- ./debug:/debug
26 changes: 22 additions & 4 deletions scripts/test_node_deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ LOGLEVEL="info"

rm -rf ~/.pylon*
# retrieve all args
WILL_START_FRESH=0
WILL_RECOVER=0
WILL_INSTALL=0
WILL_CONTINUE=0
Expand All @@ -18,6 +19,10 @@ then
# $@ is for getting list of arguments
for arg in "$@"; do
case $arg in
--fresh)
WILL_START_FRESH=1
shift
;;
--recover)
WILL_RECOVER=1
shift
Expand Down Expand Up @@ -48,25 +53,34 @@ fi
# validate dependencies are installed
command -v jq > /dev/null 2>&1 || { echo >&2 "jq not installed. More info: https://stedolan.github.io/jq/download/"; exit 1; }

if [ $WILL_START_FRESH -eq 1 ];
then
rm -rf $HOME/.pylons*
fi

# install pylonsd if not exist
if [ $WILL_INSTALL -eq 0 ];
then
command -v pylonsd > /dev/null 2>&1 || { echo >&1 "installing pylonsd"; make install; }
else
echo >&1 "installing pylonsd"
rm -rf $HOME/.pylons*
make install
go install ./...
fi

pylonsd config keyring-backend $KEYRING
pylonsd config chain-id $CHAINID

# determine if user wants to recorver or create new
rm debug/keys.txt

if [ $WILL_RECOVER -eq 0 ];
then
pylonsd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO
KEY_INFO=$(pylonsd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO)
echo $KEY_INFO >> debug/keys.txt
else
pylonsd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover
KEY_INFO=$(pylonsd keys add $KEY --keyring-backend $KEYRING --algo $KEYALGO --recover)
echo $KEY_INFO >> debug/keys.txt
fi

echo >&1 "\n"
Expand All @@ -83,6 +97,10 @@ cat $HOME/.pylons/config/genesis.json | jq '.app_state["mint"]["params"]["mint_d
# Set gas limit in genesis
# cat $HOME/.pylons/config/genesis.json | jq '.consensus_params["block"]["max_gas"]="10000000"' > $HOME/.pylons/config/tmp_genesis.json && mv $HOME/.pylons/config/tmp_genesis.json $HOME/.pylons/config/genesis.json

# enable rest server and swagger
toml set --toml-path $HOME/.pylons/config/app.toml api.swagger true
toml set --toml-path $HOME/.pylons/config/app.toml api.enable true

# Allocate genesis accounts (cosmos formatted addresses)
pylonsd add-genesis-account $KEY 1000000000000upylon --keyring-backend $KEYRING

Expand All @@ -96,4 +114,4 @@ pylonsd collect-gentxs
pylonsd validate-genesis

# Start the node (remove the --pruning=nothing flag if historical queries are not needed)
pylonsd start --pruning=nothing --log_level $LOGLEVEL --minimum-gas-prices=0.0001upylon
pylonsd start --pruning=nothing --log_level $LOGLEVEL --minimum-gas-prices=0.0001upylon --rpc.laddr tcp://0.0.0.0:26657
2 changes: 1 addition & 1 deletion scripts/upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ cat $HOME/.pylonsd/config/genesis.json | jq '.app_state["staking"]["params"]["mi
pylonsd start
# Create proposals

pylonsd tx gov submit-proposal --title="existing passing prop" --description="passing prop" --from=validator --deposit=1000valtoken --chain-id=testing --keyring-backend=test --broadcast-mode=block --type="Text"
pylonsd tx gov submit-proposal --title="existing passing prop" --description="passing prop" --from=test --deposit=1000valtoken --chain-id=testing --keyring-backend=test --broadcast-mode=block --type="Text"
pylonsd tx gov vote 1 yes --from=validator --keyring-backend=test --chain-id=testing --yes
pylonsd tx gov submit-proposal --title="prop with enough osmo deposit" --description="prop w/ enough deposit" --from=validator --deposit=500000000upylon --chain-id=testing --keyring-backend=test --broadcast-mode=block --type="Text"
# Check that we have proposal 1 passed, and proposal 2 in deposit period
Expand Down