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

Implement SIGN_MODE_DIRECT #6216

Closed
wants to merge 69 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
6a1a345
Add Tx, SignDoc from #6111 to types/types.proto, refactor Tx -> TxI a…
aaronc May 13, 2020
621282d
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 13, 2020
4308623
Add CHANGELOG entry
aaronc May 13, 2020
d8703ef
Add proto doc strings
aaronc May 13, 2020
4a889c8
Add proto doc strings
aaronc May 13, 2020
7f09389
ws
aaronc May 13, 2020
b695a24
ws
aaronc May 13, 2020
4818e1b
Implement SIGN_MODE_DIRECT for single signer mode
aaronc May 13, 2020
8e9de14
Merge branch 'master' into aaronc/6213-sign-mode
aaronc May 13, 2020
7fdec59
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 14, 2020
15de659
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 15, 2020
0d875e1
WIP
aaronc May 15, 2020
15bbcb5
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 20, 2020
6e6142c
Cleanup
aaronc May 20, 2020
c638659
WIP on proto ante handlers
aaronc May 20, 2020
93583a0
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 20, 2020
40911b8
WIP on proto signing handlers
aaronc May 21, 2020
bf5bbdc
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 21, 2020
75e9ad5
WIP on multisigs
aaronc May 21, 2020
33a9ff0
WIP on keys, simapp
aaronc May 21, 2020
b0c3071
implement multisig in ante handler
aaronc May 21, 2020
f21b823
Refactoring
aaronc May 21, 2020
c4b35df
Fix build errors
aaronc May 21, 2020
91f2b3d
Add split integration tests
aaronc May 21, 2020
ff80065
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 21, 2020
87409ac
Setup test_amino
aaronc May 21, 2020
2267516
WIP on proto tx generator
aaronc May 21, 2020
2d6955c
typo
aaronc May 21, 2020
c9ecb0e
Fix tests
aaronc May 22, 2020
77ad336
Split proto/amino unit tests
aaronc May 22, 2020
ca25ce8
Fix amino
aaronc May 22, 2020
3cf884c
Fix tests
aaronc May 22, 2020
9aa57d1
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 22, 2020
7af5d55
fix cli tests
aaronc May 22, 2020
f9f3124
Fix CLi test
aaronc May 22, 2020
d8f9d07
Fix some amino store errors
aaronc May 22, 2020
c12fefa
Switch to using HybridCodec with test_amino for now
aaronc May 22, 2020
ab4ea68
Switch to using HybridCodec with test_amino for now
aaronc May 22, 2020
66fc497
fix cli test
aaronc May 22, 2020
2a30b8c
WIP on proto signing
aaronc May 22, 2020
fe2ec41
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 26, 2020
8e442a9
Fix tests
aaronc May 26, 2020
1f2aee7
Make sdk.Msg implement proto.Message
aaronc May 26, 2020
f61c345
Fix tests
aaronc May 26, 2020
c59d51f
Fix amino tests
aaronc May 26, 2020
cf406a3
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 26, 2020
f089efb
Fix amino build
aaronc May 26, 2020
759dd35
Fix tests
aaronc May 27, 2020
bcada32
Switch proto cli tests to amino JSON
aaronc May 27, 2020
a996a71
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc May 27, 2020
e83ca5f
Fix tests
aaronc May 27, 2020
f8584ae
Fix sims
aaronc May 27, 2020
2e797a1
test fixes
aaronc May 27, 2020
bf1bb2a
WIP on making auth cli stuff proto compatible
aaronc May 28, 2020
dd682b5
Add SignatureV2
aaronc May 28, 2020
88e2ab2
Refactor signature, multisig
aaronc May 28, 2020
da98515
Fix build
aaronc May 28, 2020
bfb3ae6
fix validate sigs
aaronc May 28, 2020
e97b368
Refactor TxBuilder
aaronc May 29, 2020
b0e72fc
fixes
aaronc May 29, 2020
a9d9544
fix tests
aaronc Jun 1, 2020
45f0daf
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc Jun 1, 2020
a71dcc6
fixes
aaronc Jun 1, 2020
e0cb203
fix tests
aaronc Jun 1, 2020
bfc7e69
fix amino build
aaronc Jun 1, 2020
8598372
fix tests
aaronc Jun 1, 2020
7241768
WIP on implementing sign and multisign cmd's
aaronc Jun 2, 2020
f9ce60b
Merge branch 'master' of github.com:cosmos/cosmos-sdk into aaronc/621…
aaronc Jun 2, 2020
b314126
Merge branch 'master' of https://github.com/cosmos/cosmos-sdk into aa…
aaronc Jun 8, 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
54 changes: 54 additions & 0 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: CLI Tests
on:
pull_request:
push:
branches:
- master
jobs:
cleanup-runs:
runs-on: ubuntu-latest
steps:
- uses: rokroskar/workflow-run-cleanup-action@master
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"

protobuf:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- name: build-sim
run: |
make build-sim
if: "env.GIT_DIFF != ''"
- name: cli-test
run: |
make test-integration
if: "env.GIT_DIFF != ''"

amino:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
with:
SUFFIX_FILTER: |
.go
.mod
.sum
- name: build-sim
run: |
make build-sim-amino
if: "env.GIT_DIFF != ''"
- name: cli-test
run: |
make test-integration-amino
if: "env.GIT_DIFF != ''"
45 changes: 23 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ jobs:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
if: "!startsWith(github.ref, 'refs/tags/') && github.ref != 'refs/heads/master'"

split-test-files:
split-test-files:
runs-on: ubuntu-latest
steps:
steps:
- uses: actions/checkout@v2
- name: Create a file with all the pkgs
run: go list ./... > pkgs.txt
Expand All @@ -29,15 +29,15 @@ jobs:
name: '${{ github.sha }}-aa'
path: ./xaa.txt
- uses: actions/upload-artifact@v2
with:
with:
name: '${{ github.sha }}-ab'
path: ./xab.txt
- uses: actions/upload-artifact@v2
with:
with:
name: '${{ github.sha }}-ac'
path: ./xac.txt
- uses: actions/upload-artifact@v2
with:
with:
name: '${{ github.sha }}-ad'
path: ./xad.txt

Expand All @@ -53,7 +53,7 @@ jobs:
SUFFIX_FILTER: |
.go
.mod
.sum
.sum
- uses: actions/download-artifact@v2
with:
name: '${{ github.sha }}-aa'
Expand All @@ -76,8 +76,8 @@ jobs:
- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"

test-coverage-run-2:
runs-on: ubuntu-latest
Expand All @@ -91,7 +91,7 @@ jobs:
SUFFIX_FILTER: |
.go
.mod
.sum
.sum
- uses: actions/download-artifact@v2
with:
name: '${{ github.sha }}-ab'
Expand All @@ -114,8 +114,8 @@ jobs:
- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"

test-coverage-run-3:
runs-on: ubuntu-latest
Expand All @@ -129,7 +129,7 @@ jobs:
SUFFIX_FILTER: |
.go
.mod
.sum
.sum
- uses: actions/download-artifact@v2
with:
name: '${{ github.sha }}-ac'
Expand All @@ -152,8 +152,8 @@ jobs:
- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"

test-coverage-run-4:
runs-on: ubuntu-latest
Expand All @@ -167,7 +167,7 @@ jobs:
SUFFIX_FILTER: |
.go
.mod
.sum
.sum
- uses: actions/download-artifact@v2
with:
name: '${{ github.sha }}-ad'
Expand All @@ -190,13 +190,14 @@ jobs:
- uses: codecov/codecov-action@v1
with:
file: ./coverage.txt
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"
fail_ci_if_error: true
if: "env.GIT_DIFF != ''"

integration-tests:
amino:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/setup-go@v2-beta
- uses: actions/checkout@v2
- uses: technote-space/get-diff-action@v1
id: git_diff
Expand All @@ -205,11 +206,11 @@ jobs:
.go
.mod
.sum
- name: build-sim
- name: build
run: |
make build-sim
make build
if: "env.GIT_DIFF != ''"
- name: cli-test
- name: unit tests
run: |
make test-integration
go test ./... -mod=readonly -timeout 12m -race -coverprofile=coverage.txt -covermode=atomic -tags='ledger test_ledger_mock test_amino'
if: "env.GIT_DIFF != ''"
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ build-sim: go.sum
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/cmd/simd
go build -mod=readonly $(BUILD_FLAGS) -o $(BUILDDIR) ./simapp/cmd/simcli

build-sim-amino: go.sum
mkdir -p $(BUILDDIR)
go build -mod=readonly $(BUILD_FLAGS) -tags test_amino -o $(BUILDDIR) ./simapp/cmd/simd
go build -mod=readonly $(BUILD_FLAGS) -tags test_amino -o $(BUILDDIR) ./simapp/cmd/simcli

.PHONY: \
build \
build-sim
Expand Down Expand Up @@ -131,6 +136,9 @@ test-race:
test-integration: build-sim
BUILDDIR=$(BUILDDIR) go test -mod=readonly -p 4 -tags='ledger test_ledger_mock cli_test' -run ^TestCLI `go list ./.../cli/...`

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

.PHONY: test test-all test-ledger-mock test-ledger test-unit test-race

test-sim-nondeterminism:
Expand Down
7 changes: 1 addition & 6 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,12 +376,7 @@ func handleQueryApp(app *BaseApp, path []string, req abci.RequestQuery) abci.Res
case "simulate":
txBytes := req.Data

tx, err := app.txDecoder(txBytes)
if err != nil {
return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to decode tx"))
}

gInfo, res, err := app.Simulate(txBytes, tx)
gInfo, res, _, err := app.Simulate(txBytes)
if err != nil {
return sdkerrors.QueryResult(sdkerrors.Wrap(err, "failed to simulate tx"))
}
Expand Down
4 changes: 2 additions & 2 deletions baseapp/baseapp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -985,13 +985,13 @@ func TestSimulateTx(t *testing.T) {
require.Nil(t, err)

// simulate a message, check gas reported
gInfo, result, err := app.Simulate(txBytes, tx)
gInfo, result, _, err := app.Simulate(txBytes)
require.NoError(t, err)
require.NotNil(t, result)
require.Equal(t, gasConsumed, gInfo.GasUsed)

// simulate again, same result
gInfo, result, err = app.Simulate(txBytes, tx)
gInfo, result, _, err = app.Simulate(txBytes)
require.NoError(t, err)
require.NotNil(t, result)
require.Equal(t, gasConsumed, gInfo.GasUsed)
Expand Down
11 changes: 9 additions & 2 deletions baseapp/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,22 @@ package baseapp
import (
abci "github.com/tendermint/tendermint/abci/types"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"

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

func (app *BaseApp) Check(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) {
return app.runTx(runTxModeCheck, nil, tx)
}

func (app *BaseApp) Simulate(txBytes []byte, tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) {
return app.runTx(runTxModeSimulate, txBytes, tx)
func (app *BaseApp) Simulate(txBytes []byte) (sdk.GasInfo, *sdk.Result, sdk.Tx, error) {
tx, err := app.txDecoder(txBytes)
if err != nil {
return sdk.GasInfo{}, nil, nil, sdkerrors.Wrap(err, "failed to decode tx")
}
gi, r, err := app.runTx(runTxModeSimulate, txBytes, tx)
return gi, r, tx, err
}

func (app *BaseApp) Deliver(tx sdk.Tx) (sdk.GasInfo, *sdk.Result, error) {
Expand Down
22 changes: 11 additions & 11 deletions client/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// based on the context parameters. The result of the broadcast is parsed into
// an intermediate structure which is logged if the context has a logger
// defined.
func (ctx Context) BroadcastTx(txBytes []byte) (res sdk.TxResponse, err error) {
func (ctx Context) BroadcastTx(txBytes []byte) (res *sdk.TxResponse, err error) {
switch ctx.BroadcastMode {
case flags.BroadcastSync:
res, err = ctx.BroadcastTxSync(txBytes)
Expand All @@ -28,7 +28,7 @@ func (ctx Context) BroadcastTx(txBytes []byte) (res sdk.TxResponse, err error) {
res, err = ctx.BroadcastTxCommit(txBytes)

default:
return sdk.TxResponse{}, fmt.Errorf("unsupported return type %s; supported types: sync, async, block", ctx.BroadcastMode)
return nil, fmt.Errorf("unsupported return type %s; supported types: sync, async, block", ctx.BroadcastMode)
}

return res, err
Expand Down Expand Up @@ -84,16 +84,16 @@ func CheckTendermintError(err error, txBytes []byte) *sdk.TxResponse {
// NOTE: This should ideally not be used as the request may timeout but the tx
// may still be included in a block. Use BroadcastTxAsync or BroadcastTxSync
// instead.
func (ctx Context) BroadcastTxCommit(txBytes []byte) (sdk.TxResponse, error) {
func (ctx Context) BroadcastTxCommit(txBytes []byte) (*sdk.TxResponse, error) {
node, err := ctx.GetNode()
if err != nil {
return sdk.TxResponse{}, err
return nil, err
}

res, err := node.BroadcastTxCommit(txBytes)
if err != nil {
if errRes := CheckTendermintError(err, txBytes); errRes != nil {
return *errRes, nil
return errRes, nil
}

return sdk.NewResponseFormatBroadcastTxCommit(res), err
Expand All @@ -112,31 +112,31 @@ func (ctx Context) BroadcastTxCommit(txBytes []byte) (sdk.TxResponse, error) {

// BroadcastTxSync broadcasts transaction bytes to a Tendermint node
// synchronously (i.e. returns after CheckTx execution).
func (ctx Context) BroadcastTxSync(txBytes []byte) (sdk.TxResponse, error) {
func (ctx Context) BroadcastTxSync(txBytes []byte) (*sdk.TxResponse, error) {
node, err := ctx.GetNode()
if err != nil {
return sdk.TxResponse{}, err
return nil, err
}

res, err := node.BroadcastTxSync(txBytes)
if errRes := CheckTendermintError(err, txBytes); errRes != nil {
return *errRes, nil
return errRes, nil
}

return sdk.NewResponseFormatBroadcastTx(res), err
}

// BroadcastTxAsync broadcasts transaction bytes to a Tendermint node
// asynchronously (i.e. returns immediately).
func (ctx Context) BroadcastTxAsync(txBytes []byte) (sdk.TxResponse, error) {
func (ctx Context) BroadcastTxAsync(txBytes []byte) (*sdk.TxResponse, error) {
node, err := ctx.GetNode()
if err != nil {
return sdk.TxResponse{}, err
return nil, err
}

res, err := node.BroadcastTxAsync(txBytes)
if errRes := CheckTendermintError(err, txBytes); errRes != nil {
return *errRes, nil
return errRes, nil
}

return sdk.NewResponseFormatBroadcastTx(res), err
Expand Down
2 changes: 2 additions & 0 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const (
FlagPage = "page"
FlagLimit = "limit"
FlagUnsafeCORS = "unsafe-cors"
FlagSignMode = "sign-mode"
)

// LineBreak can be included in a command list to provide a blank line
Expand Down Expand Up @@ -122,6 +123,7 @@ func PostCommands(cmds ...*cobra.Command) []*cobra.Command {
c.Flags().Bool(FlagOffline, false, "Offline mode (does not allow any online functionality")
c.Flags().BoolP(FlagSkipConfirmation, "y", false, "Skip tx broadcasting prompt confirmation")
c.Flags().String(FlagKeyringBackend, DefaultKeyringBackend, "Select keyring's backend (os|file|kwallet|pass|test)")
c.Flags().String(FlagSignMode, "", "Choose sign mode (direct|amino-json), this is an advanced feature")

// --gas can accept integers and "simulate"
c.Flags().Var(&GasFlagVar, "gas", fmt.Sprintf(
Expand Down
6 changes: 4 additions & 2 deletions client/rpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"net/http"
"strconv"

"github.com/cosmos/cosmos-sdk/codec"

"github.com/gorilla/mux"
"github.com/spf13/cobra"
"github.com/spf13/viper"
Expand Down Expand Up @@ -65,10 +67,10 @@ func getBlock(clientCtx client.Context, height *int64) ([]byte, error) {
}

if clientCtx.Indent {
return legacy.Cdc.MarshalJSONIndent(res, "", " ")
return legacy.MarshalJSONIndent(clientCtx.JSONMarshaler, res)
}

return legacy.Cdc.MarshalJSON(res)
return clientCtx.JSONMarshaler.MarshalJSON(res)
}

// get the current blockchain height
Expand Down
2 changes: 2 additions & 0 deletions client/rpc/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import (
"fmt"
"net/http"

"github.com/cosmos/cosmos-sdk/codec/legacy_global"

"github.com/spf13/cobra"
"github.com/spf13/viper"

Expand Down
Loading