From b2caa8fd20bf1ff00ea4bd76d7a167a09d6417d2 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Fri, 7 Aug 2020 12:02:12 +0200 Subject: [PATCH 1/5] Add client context to cli --- cmd/wasmcli/main.go | 18 ++++++++++++++---- cmd/wasmd/main.go | 13 ++++++++++++- 2 files changed, 26 insertions(+), 5 deletions(-) diff --git a/cmd/wasmcli/main.go b/cmd/wasmcli/main.go index 9067ed5b59..2738e3f18c 100644 --- a/cmd/wasmcli/main.go +++ b/cmd/wasmcli/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "fmt" "os" @@ -43,7 +44,7 @@ func main() { WithInput(os.Stdin). WithAccountRetriever(authtypes.NewAccountRetriever(encodingConfig.Marshaler)). WithBroadcastMode(flags.BroadcastBlock). - WithHomeDir(app.DefaultNodeHome) + WithHomeDir(app.DefaultCLIHome) rootCmd := &cobra.Command{ Use: "wasmcli", @@ -70,10 +71,19 @@ func main() { cli.NewCompletionCmd(rootCmd, true), ) - // Add flags and prefix all env exposed with WM - executor := cli.PrepareMainCmd(rootCmd, "WM", app.DefaultCLIHome) + // Create and set a client.Context on the command's Context. During the pre-run + // of the root command, a default initialized client.Context is provided to + // seed child command execution with values such as AccountRetriver, Keyring, + // and a Tendermint RPC. This requires the use of a pointer reference when + // getting and setting the client.Context. Ideally, we utilize + // https://github.com/spf13/cobra/pull/1118. + ctx := context.Background() + ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{}) + ctx = context.WithValue(ctx, server.ServerContextKey, server.NewDefaultContext()) + + executor := cli.PrepareBaseCmd(rootCmd, "WM", app.DefaultCLIHome) + err := executor.ExecuteContext(ctx) - err := executor.Execute() if err != nil { fmt.Printf("Failed executing CLI command: %s, exiting...\n", err) os.Exit(1) diff --git a/cmd/wasmd/main.go b/cmd/wasmd/main.go index 0f4f4077b6..6a6622b1d9 100644 --- a/cmd/wasmd/main.go +++ b/cmd/wasmd/main.go @@ -1,6 +1,7 @@ package main import ( + "context" "encoding/json" "io" "os" @@ -76,11 +77,21 @@ func main() { server.AddCommands(rootCmd, newApp, exportAppStateAndTMValidators) + // Create and set a client.Context on the command's Context. During the pre-run + // of the root command, a default initialized client.Context is provided to + // seed child command execution with values such as AccountRetriver, Keyring, + // and a Tendermint RPC. This requires the use of a pointer reference when + // getting and setting the client.Context. Ideally, we utilize + // https://github.com/spf13/cobra/pull/1118. + ctx := context.Background() + ctx = context.WithValue(ctx, client.ClientContextKey, &client.Context{}) + ctx = context.WithValue(ctx, server.ServerContextKey, server.NewDefaultContext()) + // prepare and add flags executor := cli.PrepareBaseCmd(rootCmd, "WM", app.DefaultNodeHome) rootCmd.PersistentFlags().UintVar(&invCheckPeriod, flagInvCheckPeriod, 0, "Assert registered invariants every N blocks") - err := executor.Execute() + err := executor.ExecuteContext(ctx) if err != nil { panic(err) } From 4ac4c6281b1611a25a8f681dfb88afc009db2db2 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Fri, 7 Aug 2020 14:20:57 +0200 Subject: [PATCH 2/5] Upgrade sdk to 3322e26 to fix home dir issue --- app/app.go | 2 +- cmd/wasmd/main.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/app.go b/app/app.go index d52444c386..0a69388ceb 100644 --- a/app/app.go +++ b/app/app.go @@ -265,7 +265,7 @@ func NewWasmApp( // TODO: remove amino codec dependency once Tendermint version is upgraded with // protobuf changes app.ibcKeeper = ibckeeper.NewKeeper( - app.cdc, appCodec, keys[ibchost.StoreKey], app.stakingKeeper, scopedIBCKeeper, + appCodec, keys[ibchost.StoreKey], app.stakingKeeper, scopedIBCKeeper, ) // Create Transfer Keepers diff --git a/cmd/wasmd/main.go b/cmd/wasmd/main.go index 6a6622b1d9..b92903384a 100644 --- a/cmd/wasmd/main.go +++ b/cmd/wasmd/main.go @@ -75,7 +75,7 @@ func main() { debug.Cmd(), ) - server.AddCommands(rootCmd, newApp, exportAppStateAndTMValidators) + server.AddCommands(rootCmd, app.DefaultNodeHome, newApp, exportAppStateAndTMValidators) // Create and set a client.Context on the command's Context. During the pre-run // of the root command, a default initialized client.Context is provided to diff --git a/go.mod b/go.mod index 0f74d63ae4..089a08c82c 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.14 require ( // Note: update ENV GO_COSMWASM in Dockerfile when updating this github.com/CosmWasm/go-cosmwasm v0.9.1 - github.com/cosmos/cosmos-sdk v0.34.4-0.20200806092156-3076a8b12ec3 + github.com/cosmos/cosmos-sdk v0.34.4-0.20200807102022-3322e269a184 github.com/dvsekhvalnov/jose2go v0.0.0-20180829124132-7f401d37b68a github.com/gogo/protobuf v1.3.1 github.com/google/gofuzz v1.0.0 diff --git a/go.sum b/go.sum index a66e0b1a7f..3798fdcfc1 100644 --- a/go.sum +++ b/go.sum @@ -100,8 +100,8 @@ github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7 github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/pkg v0.0.0-20160727233714-3ac0863d7acf/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= github.com/coreos/pkg v0.0.0-20180928190104-399ea9e2e55f/go.mod h1:E3G3o1h8I7cfcXa63jLwjI0eiQQMgzzUDFVpN/nH/eA= -github.com/cosmos/cosmos-sdk v0.34.4-0.20200806092156-3076a8b12ec3 h1:22rm9uHzeJtlGjVMRIqTUkRFapFU3nwN9xy8KLvLStg= -github.com/cosmos/cosmos-sdk v0.34.4-0.20200806092156-3076a8b12ec3/go.mod h1:7fv4+b5E8Iq9m0MKzR/v/QOLDKcpp+rBZW2JiNRtqMY= +github.com/cosmos/cosmos-sdk v0.34.4-0.20200807102022-3322e269a184 h1:Ogtqklf+8k2mdVl5JVwPVaBIk1Io9KyKdMzoxhq1cw8= +github.com/cosmos/cosmos-sdk v0.34.4-0.20200807102022-3322e269a184/go.mod h1:7fv4+b5E8Iq9m0MKzR/v/QOLDKcpp+rBZW2JiNRtqMY= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d h1:49RLWk1j44Xu4fjHb6JFYmeUnDORVwHNkDxaQ0ctCVU= github.com/cosmos/go-bip39 v0.0.0-20180819234021-555e2067c45d/go.mod h1:tSxLoYXyBmiFeKpvmq4dzayMdCjCnu8uqmCysIGBT2Y= github.com/cosmos/ledger-cosmos-go v0.11.1 h1:9JIYsGnXP613pb2vPjFeMMjBI5lEDsEaF6oYorTy6J4= From 4951b2f7af8aa4275c3d9af1f277b1393b4cad08 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Fri, 7 Aug 2020 14:45:51 +0200 Subject: [PATCH 3/5] Adjust docker scripts --- docker/run_all.sh | 11 ----------- docker/run_rest_server.sh | 4 ---- docker/setup.sh | 2 +- 3 files changed, 1 insertion(+), 16 deletions(-) delete mode 100755 docker/run_all.sh delete mode 100755 docker/run_rest_server.sh diff --git a/docker/run_all.sh b/docker/run_all.sh deleted file mode 100755 index f183d532e2..0000000000 --- a/docker/run_all.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh -#set -euo pipefail - -mkdir -p /root/log -touch /root/log/wasmd.log -./run_wasmd.sh $1 >> /root/log/wasmd.log & - -sleep 4 -echo Starting Rest Server... - -./run_rest_server.sh diff --git a/docker/run_rest_server.sh b/docker/run_rest_server.sh deleted file mode 100755 index 368a90d341..0000000000 --- a/docker/run_rest_server.sh +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -#set -euo pipefail - -wasmcli rest-server --laddr tcp://0.0.0.0:1317 --trust-node --cors diff --git a/docker/setup.sh b/docker/setup.sh index d6829a1f6a..f5a67b1d1a 100755 --- a/docker/setup.sh +++ b/docker/setup.sh @@ -19,5 +19,5 @@ for addr in "$@"; do wasmd add-genesis-account "$addr" "1000000000$STAKE,1000000000$FEE" done # submit a genesis validator tx -(echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | wasmd gentx --name validator --amount "250000000$STAKE" +(echo "$PASSWORD"; echo "$PASSWORD"; echo "$PASSWORD") | wasmd gentx validator --chain-id=testing --amount "250000000$STAKE" wasmd collect-gentxs From c06327aace4c7100443732be916f3c7bdbe851c5 Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Mon, 10 Aug 2020 09:30:07 +0200 Subject: [PATCH 4/5] Use our ModuleBasic var for encoding --- app/encoding.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/app/encoding.go b/app/encoding.go index fe229330d7..5116eb2aad 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -1,14 +1,15 @@ package app import ( - "github.com/CosmWasm/wasmd/x/wasm" - "github.com/cosmos/cosmos-sdk/simapp" simparams "github.com/cosmos/cosmos-sdk/simapp/params" + "github.com/cosmos/cosmos-sdk/std" ) func MakeEncodingConfig() simparams.EncodingConfig { - encodingConfig := simapp.MakeEncodingConfig() // todo: this is the simapp !!! - wasm.RegisterCodec(encodingConfig.Amino) - wasm.RegisterInterfaces(encodingConfig.InterfaceRegistry) + encodingConfig := simparams.MakeEncodingConfig() // todo: this is the simapp !!! + std.RegisterCodec(encodingConfig.Amino) + std.RegisterInterfaces(encodingConfig.InterfaceRegistry) + ModuleBasics.RegisterCodec(encodingConfig.Amino) + ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) return encodingConfig } From c91b526104004ba1ce68a9cae817533a622121da Mon Sep 17 00:00:00 2001 From: Alex Peters Date: Wed, 12 Aug 2020 09:54:24 +0200 Subject: [PATCH 5/5] Review comments --- app/app.go | 2 -- app/encoding.go | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/app/app.go b/app/app.go index 0a69388ceb..9ea3964647 100644 --- a/app/app.go +++ b/app/app.go @@ -262,8 +262,6 @@ func NewWasmApp( ) // Create IBC Keeper - // TODO: remove amino codec dependency once Tendermint version is upgraded with - // protobuf changes app.ibcKeeper = ibckeeper.NewKeeper( appCodec, keys[ibchost.StoreKey], app.stakingKeeper, scopedIBCKeeper, ) diff --git a/app/encoding.go b/app/encoding.go index 5116eb2aad..7dc454fa77 100644 --- a/app/encoding.go +++ b/app/encoding.go @@ -1,15 +1,36 @@ package app import ( - simparams "github.com/cosmos/cosmos-sdk/simapp/params" + "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/codec" + "github.com/cosmos/cosmos-sdk/codec/types" "github.com/cosmos/cosmos-sdk/std" + "github.com/cosmos/cosmos-sdk/x/auth/tx" ) -func MakeEncodingConfig() simparams.EncodingConfig { - encodingConfig := simparams.MakeEncodingConfig() // todo: this is the simapp !!! - std.RegisterCodec(encodingConfig.Amino) - std.RegisterInterfaces(encodingConfig.InterfaceRegistry) - ModuleBasics.RegisterCodec(encodingConfig.Amino) - ModuleBasics.RegisterInterfaces(encodingConfig.InterfaceRegistry) - return encodingConfig +// EncodingConfig specifies the concrete encoding types to use for a given app. +// This is provided for compatibility between protobuf and amino implementations. +type EncodingConfig struct { + InterfaceRegistry types.InterfaceRegistry + Marshaler codec.Marshaler + TxConfig client.TxConfig + Amino *codec.Codec +} + +func MakeEncodingConfig() EncodingConfig { + amino := codec.New() + interfaceRegistry := types.NewInterfaceRegistry() + marshaler := codec.NewHybridCodec(amino, interfaceRegistry) + txGen := tx.NewTxConfig(codec.NewProtoCodec(interfaceRegistry), std.DefaultPublicKeyCodec{}, tx.DefaultSignModes) + + std.RegisterCodec(amino) + std.RegisterInterfaces(interfaceRegistry) + ModuleBasics.RegisterCodec(amino) + ModuleBasics.RegisterInterfaces(interfaceRegistry) + return EncodingConfig{ + InterfaceRegistry: interfaceRegistry, + Marshaler: marshaler, + TxConfig: txGen, + Amino: amino, + } }