Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/cosmos/cosmos-sdk into am/1…
Browse files Browse the repository at this point in the history
…0610-txdecoder-middleware
  • Loading branch information
amaury1093 committed Dec 2, 2021
2 parents 66085ab + 5d86db3 commit d6b0884
Show file tree
Hide file tree
Showing 19 changed files with 202 additions and 44 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [\#9695](https://github.com/cosmos/cosmos-sdk/pull/9695) `<app> keys migrate` CLI command now takes no arguments
* [\#9246](https://github.com/cosmos/cosmos-sdk/pull/9246) Removed the CLI flag `--setup-config-only` from the `testnet` command and added the subcommand `init-files`.
* [\#9780](https://github.com/cosmos/cosmos-sdk/pull/9780) Use sigs.k8s.io for yaml, which might lead to minor YAML output changes
* [\#10625](https://github.com/cosmos/cosmos-sdk/pull/10625) Rename `--fee-account` CLI flag to `--fee-granter`

### Improvements

Expand All @@ -139,6 +140,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (genesis) [\#9697](https://github.com/cosmos/cosmos-sdk/pull/9697) Ensure `InitGenesis` returns with non-empty validator set.
* [\#10341](https://github.com/cosmos/cosmos-sdk/pull/10341) Move from `io/ioutil` to `io` and `os` packages.
* [\#10468](https://github.com/cosmos/cosmos-sdk/pull/10468) Allow futureOps to queue additional operations in simulations
* [\#10625](https://github.com/cosmos/cosmos-sdk/pull/10625) Add `--fee-payer` CLI flag

### Bug Fixes

Expand Down
28 changes: 22 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ ifeq (,$(findstring nostrip,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -trimpath
endif

# Check for debug option
ifeq (debug,$(findstring debug,$(COSMOS_BUILD_OPTIONS)))
BUILD_FLAGS += -gcflags "all=-N -l"
endif

all: tools build lint test

# The below include contains the tools and runsim targets.
Expand Down Expand Up @@ -472,17 +477,28 @@ proto-update-deps:
### Localnet ###
###############################################################################

# Run a 4-node testnet locally via docker compose
localnet-start: localnet-stop
$(if $(shell $(DOCKER) inspect -f '{{ .Id }}' cosmossdk/simd-env 2>/dev/null),$(info found image cosmossdk/simd-env),$(MAKE) -C contrib/images simd-env)
$(DOCKER) run --rm -v $(CURDIR)/localnet:/data cosmossdk/simd-env \
testnet init-files --v 4 -o /data --starting-ip-address 192.168.10.2 --keyring-backend=test
localnet-build-env:
$(MAKE) -C contrib/images simd-env
localnet-build-dlv:
$(MAKE) -C contrib/images simd-dlv

localnet-build-nodes:
$(DOCKER) run --rm -v $(CURDIR)/.testnets:/data cosmossdk/simd \
testnet init-files --v 4 --starting-ip-address 192.168.10.2 --keyring-backend=test
docker-compose up -d

localnet-stop:
docker-compose down

.PHONY: localnet-start localnet-stop
# localnet-start will run a 4-node testnet locally. The nodes are
# based off the docker images in: ./contrib/images/simd-env
localnet-start: localnet-stop localnet-build-env localnet-build-nodes

# localnet-debug will run a 4-node testnet locally in debug mode
# you can read more about the debug mode here: ./contrib/images/simd-dlv/README.md
localnet-debug: localnet-stop localnet-build-dlv localnet-build-nodes

.PHONY: localnet-start localnet-stop localnet-debug localnet-build-env localnet-build-dlv localnet-build-nodes

###############################################################################
### rosetta ###
Expand Down
4 changes: 2 additions & 2 deletions SECURITY.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Security

> **IMPORTANT**: If you find a security issue, you can contact our team directly at
[email protected], or report it to our [bug bounty program](https://hackerone.com/tendermint) on HackerOne. *DO NOT* open a public issue on the repository.
> **IMPORTANT**: If you find a security issue, you can
report it to our [bug bounty program](https://hackerone.com/cosmos) on HackerOne. *DO NOT* open a public issue on the repository.

## Bug Bounty

Expand Down
4 changes: 0 additions & 4 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,10 +257,6 @@ func (app *BaseApp) CheckTx(req abci.RequestCheckTx) abci.ResponseCheckTx {
}

abciRes, err := convertTxResponseToCheckTx(res, checkRes)
if err != nil {
return sdkerrors.ResponseCheckTx(err, uint64(res.GasUsed), uint64(res.GasWanted), app.trace)
}

return abciRes
}

Expand Down
17 changes: 15 additions & 2 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,21 @@ func readTxCommandFlags(clientCtx Context, flagSet *pflag.FlagSet) (Context, err
clientCtx = clientCtx.WithSignModeStr(signModeStr)
}

if clientCtx.FeeGranter == nil || flagSet.Changed(flags.FlagFeeAccount) {
granter, _ := flagSet.GetString(flags.FlagFeeAccount)
if clientCtx.FeePayer == nil || flagSet.Changed(flags.FlagFeePayer) {
payer, _ := flagSet.GetString(flags.FlagFeePayer)

if payer != "" {
payerAcc, err := sdk.AccAddressFromBech32(payer)
if err != nil {
return clientCtx, err
}

clientCtx = clientCtx.WithFeePayerAddress(payerAcc)
}
}

if clientCtx.FeeGranter == nil || flagSet.Changed(flags.FlagFeeGranter) {
granter, _ := flagSet.GetString(flags.FlagFeeGranter)

if granter != "" {
granterAcc, err := sdk.AccAddressFromBech32(granter)
Expand Down
8 changes: 8 additions & 0 deletions client/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type Context struct {
TxConfig TxConfig
AccountRetriever AccountRetriever
NodeURI string
FeePayer sdk.AccAddress
FeeGranter sdk.AccAddress
Viper *viper.Viper

Expand Down Expand Up @@ -181,6 +182,13 @@ func (ctx Context) WithFromAddress(addr sdk.AccAddress) Context {
return ctx
}

// WithFeePayerAddress returns a copy of the context with an updated fee payer account
// address.
func (ctx Context) WithFeePayerAddress(addr sdk.AccAddress) Context {
ctx.FeePayer = addr
return ctx
}

// WithFeeGranterAddress returns a copy of the context with an updated fee granter account
// address.
func (ctx Context) WithFeeGranterAddress(addr sdk.AccAddress) Context {
Expand Down
6 changes: 4 additions & 2 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ const (
FlagCountTotal = "count-total"
FlagTimeoutHeight = "timeout-height"
FlagKeyAlgorithm = "algo"
FlagFeeAccount = "fee-account"
FlagFeePayer = "fee-payer"
FlagFeeGranter = "fee-granter"
FlagReverse = "reverse"

// Tendermint logging flags
Expand Down Expand Up @@ -112,7 +113,8 @@ func AddTxFlagsToCmd(cmd *cobra.Command) {
cmd.Flags().String(FlagKeyringBackend, DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test|memory)")
cmd.Flags().String(FlagSignMode, "", "Choose sign mode (direct|amino-json), this is an advanced feature")
cmd.Flags().Uint64(FlagTimeoutHeight, 0, "Set a block timeout height to prevent the tx from being committed past a certain height")
cmd.Flags().String(FlagFeeAccount, "", "Fee account pays fees for the transaction instead of deducting from the signer")
cmd.Flags().String(FlagFeePayer, "", "Fee payer pays fees for the transaction instead of deducting from the signer")
cmd.Flags().String(FlagFeeGranter, "", "Fee granter grants fees for the transaction")

// --gas can accept integers and "auto"
cmd.Flags().String(FlagGas, "", fmt.Sprintf("gas limit to set per-transaction; set to %q to calculate sufficient gas automatically (default %d)", GasFlagAuto, DefaultGasLimit))
Expand Down
5 changes: 5 additions & 0 deletions client/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ func (ctx Context) GetFromAddress() sdk.AccAddress {
return ctx.FromAddress
}

// GetFeePayerAddress returns the fee granter address from the context
func (ctx Context) GetFeePayerAddress() sdk.AccAddress {
return ctx.FeePayer
}

// GetFeeGranterAddress returns the fee granter address from the context
func (ctx Context) GetFeeGranterAddress() sdk.AccAddress {
return ctx.FeeGranter
Expand Down
1 change: 1 addition & 0 deletions client/tx/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func BroadcastTx(clientCtx client.Context, txf Factory, msgs ...sdk.Msg) error {
}

tx.SetFeeGranter(clientCtx.GetFeeGranterAddress())
tx.SetFeePayer(clientCtx.GetFeePayerAddress())
err = Sign(txf, clientCtx.GetFromName(), tx, true)
if err != nil {
return err
Expand Down
15 changes: 11 additions & 4 deletions contrib/images/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
all: simd-env

simd-env:
docker build --tag cosmossdk/simd-env -f simd-env/Dockerfile \
$(shell git rev-parse --show-toplevel)
simd-env: simd-rmi
docker build --tag cosmossdk/simd -f simd-env/Dockerfile \
$(shell git rev-parse --show-toplevel)

.PHONY: all simd-env
simd-dlv: simd-rmi
docker build --tag cosmossdk/simd -f simd-dlv/Dockerfile \
$(shell git rev-parse --show-toplevel)

simd-rmi:
docker rmi cosmossdk/simd 2>/dev/null; true

.PHONY: all simd-env simd-dlv simd-rmi
23 changes: 23 additions & 0 deletions contrib/images/simd-dlv/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM golang:1.17-alpine AS build
RUN apk add build-base git linux-headers libc-dev
RUN go install github.com/go-delve/delve/cmd/dlv@latest
WORKDIR /work
COPY go.mod go.sum /work/
COPY db/go.mod db/go.sum /work/db/
RUN go mod download
COPY ./ /work
RUN LEDGER_ENABLED=false make COSMOS_BUILD_OPTIONS="debug,nostrip" clean build

FROM alpine:3.14 AS run
RUN apk add bash curl jq
COPY contrib/images/simd-dlv/wrapper.sh /usr/bin/wrapper.sh

VOLUME /simd
COPY --from=build /work/build/simd /simd/
COPY --from=build /go/bin/dlv /usr/local/bin
WORKDIR /simd

EXPOSE 26656 26657 2345
ENTRYPOINT ["/usr/bin/wrapper.sh"]
CMD ["start", "--log_format", "plain"]
STOPSIGNAL SIGTERM
34 changes: 34 additions & 0 deletions contrib/images/simd-dlv/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Remote Debugging with go-delve

[Delve](https://github.com/go-delve/delve) is a debugger for the Go programming language. The goal of the project is to provide a simple, full featured debugging tool for Go. Delve should be easy to invoke and easy to use. Chances are if you're using a debugger, things aren't going your way. With that in mind, Delve should stay out of your way as much as possible.

## Use-case

Cosmos-SDK provides you with a local network to bootstrap a chain in your machine, but how does one debug a node or module?

If we start a single node, we won't be able to debug transactions as the machine will be in bootstrapping phase trying to find peers to connect too, thats why we need to start a local network.

But the current `localnet-start` does not provide us with debugging tools so that's why there is a different image for debugging a local network, that is to avoid any issues in the future were debugging won't be needed.

Both `simd-env` and `simd-dlv` work and run the same, except that `simd-dlv` uses `go-delve` to run the binaries.

## How to use

The command to start a local network in debug mode is:
```shell
# make localnet-debug
```

The command to stop the local network and destroy its containers is:
```shell
# make localnet-stop
```
__note: this works the same for both `localnet-start` and `localnet-debug`__

Now, by default only `simdnode0` is run in debug mode, but you can run any of the other nodes in debug mode by changing the `DEBUG` environment variable to `1` in `docker-compose.yml`.

## How to connect

Delve will open a port on `2345` for `simdnode0` and it will increment for each of the other nodes that have `DEBUG` set to `1`.

You can connect to the debugging server either through [GoLand IDE](https://www.jetbrains.com/help/go/attach-to-running-go-processes-with-debugger.html) or you can use [delve cli](https://github.com/go-delve/delve/blob/master/Documentation/usage/dlv_connect.md) command.
25 changes: 25 additions & 0 deletions contrib/images/simd-dlv/wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env sh
set -euo pipefail
set -x

DEBUG=${DEBUG:-0}
BINARY=/simd/${BINARY:-simd}
ID=${ID:-0}
LOG=${LOG:-simd.log}

if ! [ -f "${BINARY}" ]; then
echo "The binary $(basename "${BINARY}") cannot be found. Please add the binary to the shared folder. Please use the BINARY environment variable if the name of the binary is not 'simd'"
exit 1
fi

export SIMDHOME="/data/node${ID}/simd"

if [ "$DEBUG" -eq 1 ]; then
dlv --listen=:2345 --continue --headless=true --api-version=2 --accept-multiclient exec "${BINARY}" -- --home "${SIMDHOME}" "$@"
elif [ "$DEBUG" -eq 1 ] && [ -d "$(dirname "${SIMDHOME}"/"${LOG}")" ]; then
dlv --listen=:2345 --continue --headless=true --api-version=2 --accept-multiclient exec "${BINARY}" -- --home "${SIMDHOME}" "$@" | tee "${SIMDHOME}/${LOG}"
elif [ -d "$(dirname "${SIMDHOME}"/"${LOG}")" ]; then
"${BINARY}" --home "${SIMDHOME}" "$@" | tee "${SIMDHOME}/${LOG}"
else
"${BINARY}" --home "${SIMDHOME}" "$@"
fi
52 changes: 38 additions & 14 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,88 @@ version: "3"
services:
simdnode0:
container_name: simdnode0
image: "cosmossdk/simd-env"
image: "cosmossdk/simd"
environment:
- DEBUG=1
- ID=0
- LOG=${LOG:-simd.log}
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
ports:
- "26656-26657:26656-26657"
- "1317:1317"
- "9090:9090"
environment:
- ID=0
- LOG=${LOG:-simd.log}
- "2345:2345"
volumes:
- ./localnet:/data:Z
- ./.testnets:/data:Z
networks:
localnet:
ipv4_address: 192.168.10.2

simdnode1:
container_name: simdnode1
image: "cosmossdk/simd-env"
image: "cosmossdk/simd"
environment:
- DEBUG=0
- ID=1
- LOG=${LOG:-simd.log}
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
ports:
- "26666-26667:26656-26657"
- "1318:1317"
- "9091:9090"
environment:
- ID=1
- LOG=${LOG:-simd.log}
- "2346:2345"
volumes:
- ./localnet:/data:Z
- ./.testnets:/data:Z
networks:
localnet:
ipv4_address: 192.168.10.3

simdnode2:
container_name: simdnode2
image: "cosmossdk/simd-env"
image: "cosmossdk/simd"
environment:
- DEBUG=0
- ID=2
- LOG=${LOG:-simd.log}
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
ports:
- "26676-26677:26656-26657"
- "1319:1317"
- "9092:9090"
- "2347:2345"
volumes:
- ./localnet:/data:Z
- ./.testnets:/data:Z
networks:
localnet:
ipv4_address: 192.168.10.4

simdnode3:
container_name: simdnode3
image: "cosmossdk/simd-env"
image: "cosmossdk/simd"
environment:
- DEBUG=0
- ID=3
- LOG=${LOG:-simd.log}
cap_add:
- SYS_PTRACE
security_opt:
- seccomp:unconfined
ports:
- "26686-26687:26656-26657"
- "1320:1317"
- "9093:9090"
- "2348:2345"
volumes:
- ./localnet:/data:Z
- ./.testnets:/data:Z
networks:
localnet:
ipv4_address: 192.168.10.5
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/cosmos/cosmos-proto v0.0.0-20211123144845-528f5002c9f8
github.com/cosmos/cosmos-sdk/db v0.0.0
github.com/cosmos/go-bip39 v1.0.0
github.com/cosmos/iavl v0.17.2
github.com/cosmos/iavl v0.17.3
github.com/cosmos/ledger-cosmos-go v0.11.1
github.com/gogo/gateway v1.1.0
github.com/gogo/protobuf v1.3.3
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ github.com/cosmos/cosmos-proto v0.0.0-20211123144845-528f5002c9f8/go.mod h1:msdD
github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y=
github.com/cosmos/go-bip39 v1.0.0 h1:pcomnQdrdH22njcAatO0yWojsUnCO3y2tNoV1cb6hHY=
github.com/cosmos/go-bip39 v1.0.0/go.mod h1:RNJv0H/pOIVgxw6KS7QeX2a0Uo0aKUlfhZ4xuwvCdJw=
github.com/cosmos/iavl v0.17.2 h1:BT2u7DUvLLB+RYz9RItn/8n7Bt5xe5rj8QRTkk/PQU0=
github.com/cosmos/iavl v0.17.2/go.mod h1:prJoErZFABYZGDHka1R6Oay4z9PrNeFFiMKHDAMOi4w=
github.com/cosmos/iavl v0.17.3 h1:s2N819a2olOmiauVa0WAhoIJq9EhSXE9HDBAoR9k+8Y=
github.com/cosmos/iavl v0.17.3/go.mod h1:prJoErZFABYZGDHka1R6Oay4z9PrNeFFiMKHDAMOi4w=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76 h1:DdzS1m6o/pCqeZ8VOAit/gyATedRgjvkVI+UCrLpyuU=
github.com/cosmos/keyring v1.1.7-0.20210622111912-ef00f8ac3d76/go.mod h1:0mkLWIoZuQ7uBoospo5Q9zIpqq6rYCPJDSUdeCJvPM8=
github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4=
Expand Down
Loading

0 comments on commit d6b0884

Please sign in to comment.