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

Single Binary & Command Refactor #6595

Merged
merged 52 commits into from
Jul 7, 2020
Merged
Show file tree
Hide file tree
Changes from 50 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
4a1fb27
Merge simcli into simd
dauTT Jun 28, 2020
26aea15
Get rid of the unused variable config
dauTT Jun 28, 2020
b7fee05
Rename SimcliBinary to SimdBinary
dauTT Jun 28, 2020
84ef4c6
Resolve flag -o shorthand ambiguity. (It is used both to indicate <ou…
dauTT Jun 28, 2020
103e884
Resolve flags conflict with genTx cmd in x/genutil/client/cli/gentx.go
dauTT Jun 28, 2020
27fdd02
Merge branch 'master' into single-binary-6419
alexanderbez Jun 29, 2020
8859370
Merge branch 'master' into single-binary-6419
Jun 29, 2020
fd964da
Move ./simapp/cmd/simd to ./cmd/simd
dauTT Jun 29, 2020
fccd048
Merge branch 'master' into single-binary-6419
alexanderbez Jun 29, 2020
01da4cf
Sort available commands
dauTT Jun 29, 2020
7a84bcb
Simplify code
dauTT Jun 29, 2020
4bc67f4
Uncomment line. Issue got reolved automatically. :)
dauTT Jun 29, 2020
66eba9d
Merge branch 'single-binary-6419' of https://github.com/dauTT/cosmos-…
dauTT Jun 29, 2020
17e9e5f
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into si…
dauTT Jun 29, 2020
24fc533
Adjust version module to use only one binary and refactor accordingly
dauTT Jun 30, 2020
3b346ae
1) Remove global variables
dauTT Jun 30, 2020
e80e1b3
Fix lint error message (Remove unused flags: fsShares, fsValidator, f…
dauTT Jun 30, 2020
39e34e5
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into si…
dauTT Jul 1, 2020
0f99749
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into si…
dauTT Jul 1, 2020
2b58e8d
Delete TODO during the merge. Added it back
dauTT Jul 1, 2020
171064c
Merge branch 'master' into single-binary-6419
tac0turtle Jul 2, 2020
e64e4f8
Merge branch 'master' into single-binary-6419
alexanderbez Jul 2, 2020
052db8c
Apply suggestions from code review
alexanderbez Jul 2, 2020
c862dbf
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into si…
dauTT Jul 2, 2020
160a0ae
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into si…
dauTT Jul 2, 2020
9242385
Merge branch 'master' into single-binary-6419
Jul 2, 2020
e49d18a
Merge branch 'master' into single-binary-6419
Jul 2, 2020
80de6d9
Merge branch 'master' into single-binary-6419
alexanderbez Jul 3, 2020
bc30fd2
Init commit
alexanderbez Jul 3, 2020
73f22f5
remove viper start
alexanderbez Jul 3, 2020
f77e831
Makefile updates
alexanderbez Jul 3, 2020
f5bc1f0
Updates
alexanderbez Jul 3, 2020
fdf6142
Updates
alexanderbez Jul 3, 2020
6b966c4
Merge branch 'master' into bez/6419-attempt-fix
alexanderbez Jul 3, 2020
2fcf3a0
update keys pkg
alexanderbez Jul 7, 2020
bd05bb3
Merge branch 'master' into bez/6419-attempt-fix
alexanderbez Jul 7, 2020
546aadb
server: add missing flag
alexanderbez Jul 7, 2020
cc691ab
Merge branch 'master' into bez/6419-attempt-fix
alexanderbez Jul 7, 2020
055f598
refactor
alexanderbez Jul 7, 2020
16442d9
fix start cmd
alexanderbez Jul 7, 2020
ebbde64
fix start cmd
alexanderbez Jul 7, 2020
2857d74
Update godoc
alexanderbez Jul 7, 2020
6208fce
remove comment
alexanderbez Jul 7, 2020
9e48e3f
Fix TestExportCmd_ConsensusParams
alexanderbez Jul 7, 2020
5dc8c51
genutil: Fix TestMigrateGenesis
alexanderbez Jul 7, 2020
7c08736
genutil: fix tests
alexanderbez Jul 7, 2020
e4f283a
build: update make targets
alexanderbez Jul 7, 2020
ac05e9d
Merge branch 'master' into bez/6419-attempt-fix
Jul 7, 2020
c7593da
revert client/flags/flags.go
alexanderbez Jul 7, 2020
ccb068d
Merge branch 'bez/6419-attempt-fix' of github.com:cosmos/cosmos-sdk i…
alexanderbez Jul 7, 2020
277e192
Update simapp/simd/cmd/root.go
alexanderbez Jul 7, 2020
15e3673
genutil: add get commands
alexanderbez Jul 7, 2020
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: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ jobs:
.go
.mod
.sum
- name: build-sim
- name: build-simd
run: |
make build-sim
make build-simd
if: "env.GIT_DIFF != ''"
- name: cli-test
run: |
Expand Down
7 changes: 3 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simapp:/root/.simapp simapp simd start
#
# Client: (Note the simapp binary always looks at ~/.simapp we can bind to different local storage)
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simcli keys add foo
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simcli keys list
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys add foo
# > docker run -it -p 26657:26657 -p 26656:26656 -v ~/.simappcli:/root/.simapp simapp simd keys list
# TODO: demo connecting rest-server (or is this in server now?)
FROM golang:alpine AS build-env

Expand All @@ -24,7 +24,7 @@ COPY . .

# build Cosmos SDK, remove packages
RUN make tools && \
make build-sim && \
make build-simd && \
cp ./build/sim* /go/bin
# make build-sim-linux ??

Expand All @@ -38,7 +38,6 @@ WORKDIR /root

# Copy over binaries from the build-env
COPY --from=build-env /go/bin/simd /usr/bin/simd
COPY --from=build-env /go/bin/simcli /usr/bin/simcli

EXPOSE 26656 26657 1317

Expand Down
15 changes: 7 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,14 @@ include contrib/devtools/Makefile
build: go.sum
go build -mod=readonly ./...

build-sim: go.sum
build-simd: go.sum
alexanderbez marked this conversation as resolved.
Show resolved Hide resolved
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/cmd/simd
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/cmd/simcli
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/simd

build-sim-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build-sim
build-simd-linux: go.sum
LEDGER_ENABLED=false GOOS=linux GOARCH=amd64 $(MAKE) build-simd

.PHONY: build build-sim build-sim-linux
.PHONY: build build-simd build-simd-linux

mocks: $(MOCKS_DIR)
mockgen -source=client/account_retriever.go -package mocks -destination tests/mocks/account_retriever.go
Expand Down Expand Up @@ -129,7 +128,7 @@ test-unit:
test-race:
@VERSION=$(VERSION) go test -mod=readonly -race $(PACKAGES_NOSIMULATION)

test-integration: build-sim
test-integration: build-simd
BUILDDIR=$(BUILDDIR) go test -mod=readonly -p 4 -tags='ledger test_ledger_mock cli_test' -run ^TestCLI `go list ./.../cli/...`

.PHONY: test test-all test-ledger-mock test-ledger test-unit test-race
Expand Down Expand Up @@ -321,7 +320,7 @@ build-docker-local-simapp:
@$(MAKE) -C networks/local

# Run a 4-node testnet locally
localnet-start: build-sim-linux localnet-stop
localnet-start: build-simd-linux localnet-stop
@if ! [ -f build/node0/simd/config/genesis.json ]; then docker run --rm -v $(CURDIR)/build:/simd:Z cosmos-sdk/simappnode testnet --v 4 -o . --starting-ip-address 192.168.10.2 --keyring-backend=test ; fi
docker-compose up -d

Expand Down
5 changes: 2 additions & 3 deletions client/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ import (
"github.com/spf13/pflag"

"github.com/cosmos/cosmos-sdk/client/flags"
sdk "github.com/cosmos/cosmos-sdk/types"
)

type contextKey string

// ClientContextKey defines the context key used to retrieve a client.Context from
// a command's Context.
const ClientContextKey = contextKey("client.context")
const ClientContextKey = sdk.ContextKey("client.context")

// SetCmdClientContextHandler is to be used in a command pre-hook execution to
// read flags that populate a Context and sets that to the command's Context.
Expand Down
18 changes: 9 additions & 9 deletions client/debug/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@ import (
"strings"

"github.com/spf13/cobra"

"github.com/tendermint/tendermint/crypto"
"github.com/tendermint/tendermint/crypto/ed25519"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/version"
)

func Cmd(cdc *codec.Codec) *cobra.Command {
func Cmd() *cobra.Command {
cmd := &cobra.Command{
Use: "debug",
Short: "Tool for helping with debugging your application",
RunE: client.ValidateCmd,
}

cmd.AddCommand(PubkeyCmd(cdc))
cmd.AddCommand(PubkeyCmd())
cmd.AddCommand(AddrCmd())
cmd.AddCommand(RawBytesCmd())

Expand Down Expand Up @@ -68,7 +66,7 @@ func getPubKeyFromString(pkstr string) (crypto.PubKey, error) {
return nil, fmt.Errorf("pubkey '%s' invalid; expected hex, base64, or bech32", pubKey)
}

func PubkeyCmd(cdc *codec.Codec) *cobra.Command {
func PubkeyCmd() *cobra.Command {
return &cobra.Command{
Use: "pubkey [pubkey]",
Short: "Decode a ED25519 pubkey from hex, base64, or bech32",
Expand All @@ -77,9 +75,11 @@ func PubkeyCmd(cdc *codec.Codec) *cobra.Command {
Example:
$ %s debug pubkey TWFuIGlzIGRpc3Rpbmd1aXNoZWQsIG5vdCBvbmx5IGJ5IGhpcyByZWFzb24sIGJ1dCBieSB0aGlz
$ %s debug pubkey cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
`, version.ClientName, version.ClientName),
`, version.AppName, version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

pk, err := getPubKeyFromString(args[0])
if err != nil {
return err
Expand All @@ -90,7 +90,7 @@ $ %s debug pubkey cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
return fmt.Errorf("invalid pubkey type; expected ED25519")
}

pubKeyJSONBytes, err := cdc.MarshalJSON(edPK)
pubKeyJSONBytes, err := clientCtx.JSONMarshaler.MarshalJSON(edPK)
if err != nil {
return err
}
Expand Down Expand Up @@ -127,7 +127,7 @@ func AddrCmd() *cobra.Command {

Example:
$ %s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
`, version.ClientName),
`, version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {

Expand Down Expand Up @@ -171,7 +171,7 @@ func RawBytesCmd() *cobra.Command {

Example:
$ %s debug raw-bytes [72 101 108 108 111 44 32 112 108 97 121 103 114 111 117 110 100]
`, version.ClientName),
`, version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
stringBytes := args[0]
Expand Down
13 changes: 9 additions & 4 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/spf13/cobra"
tmtypes "github.com/tendermint/tendermint/types"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -22,12 +23,16 @@ const (
)

// ExportCmd dumps app state to JSON.
func ExportCmd(ctx *Context, cdc codec.JSONMarshaler, appExporter AppExporter) *cobra.Command {
func ExportCmd(appExporter AppExporter) *cobra.Command {
cmd := &cobra.Command{
Use: "export",
Short: "Export state to JSON",
RunE: func(cmd *cobra.Command, args []string) error {
config := ctx.Config
clientCtx := client.GetClientContextFromCmd(cmd)
cdc := clientCtx.JSONMarshaler

serverCtx := GetServerContextFromCmd(cmd)
config := serverCtx.Config

homeDir, _ := cmd.Flags().GetString(flags.FlagHome)
config.SetRoot(homeDir)
Expand Down Expand Up @@ -61,12 +66,12 @@ func ExportCmd(ctx *Context, cdc codec.JSONMarshaler, appExporter AppExporter) *
forZeroHeight, _ := cmd.Flags().GetBool(flagForZeroHeight)
jailWhiteList, _ := cmd.Flags().GetStringSlice(flagJailWhitelist)

appState, validators, cp, err := appExporter(ctx.Logger, db, traceWriter, height, forZeroHeight, jailWhiteList)
appState, validators, cp, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailWhiteList)
if err != nil {
return fmt.Errorf("error exporting state: %v", err)
}

doc, err := tmtypes.GenesisDocFromFile(ctx.Config.GenesisFile())
doc, err := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile())
if err != nil {
return err
}
Expand Down
18 changes: 12 additions & 6 deletions server/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
Expand All @@ -16,6 +17,7 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
dbm "github.com/tendermint/tm-db"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/simapp"
Expand All @@ -36,11 +38,13 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
db := dbm.NewMemDB()
app := simapp.NewSimApp(log.NewTMLogger(log.NewSyncWriter(os.Stdout)), db, nil, true, map[int64]bool{}, tempDir, 0)

ctx := NewDefaultContext()
ctx.Config.RootDir = tempDir
serverCtx := NewDefaultContext()
serverCtx.Config.RootDir = tempDir

clientCtx := client.Context{}.WithJSONMarshaler(app.Codec())

genDoc := newDefaultGenesisDoc(app.Codec())
err = saveGenesisFile(genDoc, ctx.Config.GenesisFile())
err = saveGenesisFile(genDoc, serverCtx.Config.GenesisFile())

app.InitChain(
abci.RequestInitChain{
Expand All @@ -53,16 +57,18 @@ func TestExportCmd_ConsensusParams(t *testing.T) {
app.Commit()

cmd := ExportCmd(
ctx,
app.Codec(),
func(logger log.Logger, db dbm.DB, writer io.Writer, i int64, b bool, strings []string) (json.RawMessage, []tmtypes.GenesisValidator, *abci.ConsensusParams, error) {
return app.ExportAppStateAndValidators(true, []string{})
})

ctx := context.Background()
ctx = context.WithValue(ctx, client.ClientContextKey, &clientCtx)
ctx = context.WithValue(ctx, ServerContextKey, serverCtx)

output := &bytes.Buffer{}
cmd.SetOut(output)
cmd.SetArgs([]string{fmt.Sprintf("--%s=%s", flags.FlagHome, tempDir)})
require.NoError(t, cmd.Execute())
require.NoError(t, cmd.ExecuteContext(ctx))

var exportedGenDoc tmtypes.GenesisDoc
err = app.Codec().UnmarshalJSON(output.Bytes(), &exportedGenDoc)
Expand Down
34 changes: 19 additions & 15 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const (

// StartCmd runs the service passed in, either stand-alone or in-process with
// Tendermint.
func StartCmd(ctx *Context, cdc codec.JSONMarshaler, appCreator AppCreator) *cobra.Command {
func StartCmd(appCreator AppCreator) *cobra.Command {
cmd := &cobra.Command{
Use: "start",
Short: "Run the full node",
Expand All @@ -74,20 +74,29 @@ will not be able to commit subsequent blocks.
For profiling and benchmarking purposes, CPU profiling can be enabled via the '--cpu-profile' flag
which accepts a path for the resulting pprof file.
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
_, err := GetPruningOptionsFromFlags(ctx.Viper)
PreRunE: func(cmd *cobra.Command, _ []string) error {
serverCtx := GetServerContextFromCmd(cmd)

// Bind flags to the Context's Viper so the app construction can set
// options accordingly.
serverCtx.Viper.BindPFlags(cmd.Flags())

_, err := GetPruningOptionsFromFlags(serverCtx.Viper)
return err
},
RunE: func(cmd *cobra.Command, args []string) error {
RunE: func(cmd *cobra.Command, _ []string) error {
serverCtx := GetServerContextFromCmd(cmd)
clientCtx := client.GetClientContextFromCmd(cmd)

withTM, _ := cmd.Flags().GetBool(flagWithTendermint)
if !withTM {
ctx.Logger.Info("starting ABCI without Tendermint")
return startStandAlone(ctx, appCreator)
serverCtx.Logger.Info("starting ABCI without Tendermint")
return startStandAlone(serverCtx, appCreator)
}

ctx.Logger.Info("starting ABCI with Tendermint")
serverCtx.Logger.Info("starting ABCI with Tendermint")

err := startInProcess(ctx, cdc, appCreator)
err := startInProcess(serverCtx, clientCtx.JSONMarshaler, appCreator)
return err
},
}
Expand All @@ -109,10 +118,6 @@ which accepts a path for the resulting pprof file.
cmd.Flags().Uint64(FlagPruningInterval, 0, "Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom')")
cmd.Flags().Uint(FlagInvCheckPeriod, 0, "Assert registered invariants every N blocks")

// Bind flags to the Context's Viper so the app construction can set options
// accordingly.
ctx.Viper.BindPFlags(cmd.Flags())

// add support for all Tendermint-specific command line options
tcmd.AddNodeFlags(cmd)
return cmd
Expand Down Expand Up @@ -147,9 +152,8 @@ func startStandAlone(ctx *Context, appCreator AppCreator) error {
tmos.Exit(err.Error())
}

tmos.TrapSignal(ctx.Logger, func() {
err = svr.Stop()
if err != nil {
TrapSignal(func() {
if err = svr.Stop(); err != nil {
tmos.Exit(err.Error())
}
})
Expand Down
Loading