Skip to content

Commit

Permalink
Merge branch 'main' into julian/gas-simulation-incorrect-key
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianToledano authored Nov 17, 2023
2 parents 8d3e693 + a27cfa0 commit 7681068
Show file tree
Hide file tree
Showing 84 changed files with 722 additions and 321 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/issues.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/cosmos/projects/26
# add all issues opened to the issue board for triage and assignment
github-token: ${{ secrets.PERSONAL_TOKEN }}
labeled: T:Sprint,needs-triage
44 changes: 18 additions & 26 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,40 +22,32 @@ jobs:
check-latest: true
- uses: technote-space/[email protected]
id: git_diff
with:
PATTERNS: |
Makefile
**/Makefile
.golangci.yml
- name: run linting (long)
if: env.GIT_DIFF
id: lint_long
run: |
nix develop -c make lint
env:
NIX: 1
- uses: technote-space/[email protected]
if: steps.lint_long.outcome == 'skipped'
with:
PATTERNS: |
**/*.go
go.mod
go.sum
**/go.mod
**/go.sum
# with:
# PATTERNS: |
# Makefile
# **/Makefile
# .golangci.yml
- name: run linting (long)
# if: env.GIT_DIFF
# id: lint_long
- name: run linting (short)
if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF
run: |
nix develop -c make lint
env:
GIT_DIFF: ${{ env.GIT_DIFF }}
LINT_DIFF: 1
NIX: 1
# - uses: technote-space/[email protected]
# if: steps.lint_long.outcome == 'skipped'
# id: git_diff_all
# with:
# PATTERNS: |
# **/*.go
# go.mod
# go.sum
# **/go.mod
# **/go.sum
# - name: run linting (short)
# if: steps.lint_long.outcome == 'skipped' && env.GIT_DIFF
# run: |
# nix develop -c make lint
# env:
# GIT_DIFF: ${{ env.GIT_DIFF }}
# LINT_DIFF: 1
# NIX: 1
26 changes: 0 additions & 26 deletions .github/workflows/pr-reviews.yml

This file was deleted.

2 changes: 1 addition & 1 deletion .github/workflows/proto-registry.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected].0
- uses: bufbuild/[email protected].1
- uses: bufbuild/buf-push-action@v1
with:
input: "proto"
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/proto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
timeout-minutes: 5
steps:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected].0
- uses: bufbuild/[email protected].1
- uses: bufbuild/buf-lint-action@v1
with:
input: "proto"
Expand All @@ -24,7 +24,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: bufbuild/[email protected].0
- uses: bufbuild/[email protected].1
- uses: bufbuild/buf-breaking-action@v1
with:
input: "proto"
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/bank) [#17569](https://github.com/cosmos/cosmos-sdk/pull/17569) Introduce a new message type, `MsgBurn`, to burn coins.
* (server) [#17094](https://github.com/cosmos/cosmos-sdk/pull/17094) Add duration `shutdown-grace` for resource clean up (closing database handles) before exit.
* (x/auth/vesting) [#17810](https://github.com/cosmos/cosmos-sdk/pull/17810) Add the ability to specify a start time for continuous vesting accounts.
* (runtime) [#18475](https://github.com/cosmos/cosmos-sdk/pull/18475) Adds an implementation for core.branch.Service.

### Improvements

Expand All @@ -66,6 +67,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Bug Fixes

* (client/tx) [#18472](https://github.com/cosmos/cosmos-sdk/pull/18472) Utilizes the correct Pubkey when simulating a transaction.
* (baseapp) [#18486](https://github.com/cosmos/cosmos-sdk/pull/18486) Fixed FinalizeBlock calls not being passed to ABCIListeners
* (baseapp) [#18383](https://github.com/cosmos/cosmos-sdk/pull/18383) Fixed a data race inside BaseApp.getContext, found by end-to-end (e2e) tests.
* (client/server) [#18345](https://github.com/cosmos/cosmos-sdk/pull/18345) Consistently set viper prefix in client and server. It defaults for the binary name for both client and server.
* (simulation) [#17911](https://github.com/cosmos/cosmos-sdk/pull/17911) Fix all problems with executing command `make test-sim-custom-genesis-fast` for simulation test.
Expand Down
8 changes: 8 additions & 0 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,14 @@ func (app *BaseApp) FinalizeBlock(req *abci.RequestFinalizeBlock) (*abci.Respons
if res != nil {
res.AppHash = app.workingHash()
}

// call the streaming service hooks with the FinalizeBlock messages
for _, streamingListener := range app.streamingManager.ABCIListeners {
if err := streamingListener.ListenFinalizeBlock(app.finalizeBlockState.ctx, *req, *res); err != nil {
app.logger.Error("ListenFinalizeBlock listening hook failed", "height", req.Height, "err", err)
}
}

return res, err
}

Expand Down
2 changes: 1 addition & 1 deletion client/prompt_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func ValidatePromptAddress(input string) error { // TODO(@julienrbrt) remove and
return fmt.Errorf("invalid address: %w", err)
}

// ValidatePromptYesNo validates that the input is valid sdk.COins
// ValidatePromptCoins validates that the input contains valid sdk.Coins
func ValidatePromptCoins(input string) error {
if _, err := sdk.ParseCoinsNormalized(input); err != nil {
return fmt.Errorf("invalid coins: %w", err)
Expand Down
4 changes: 4 additions & 0 deletions client/v2/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

<!-- ## [v2.1.0-beta.1] to be tagged after v0.51 final or in SDK agnostic version -->

### Features

* [#18461](https://github.com/cosmos/cosmos-sdk/pull/18461) Support governance proposals.

### API Breaking Changes

* [#17709](https://github.com/cosmos/cosmos-sdk/pull/17709) Address codecs have been removed from `autocli.AppOptions` and `flag.Builder`. Instead client/v2 uses the address codecs present in the context (introduced in [#17503](https://github.com/cosmos/cosmos-sdk/pull/17503)).
Expand Down
9 changes: 7 additions & 2 deletions client/v2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ This field is automatically filled when using the `--from` flag or defining the
AutoCLI currently supports only one signer per transaction.
:::

## Module Wiring & Customization
## Module wiring & Customization

The `AutoCLIOptions()` method on your module allows to specify custom commands, sub-commands or flags for each service, as it was a `cobra.Command` instance, within the `RpcCommandOptions` struct. Defining such options will customize the behavior of the `autocli` command generation, which by default generates a command for each method in your gRPC service.

Expand All @@ -137,6 +137,11 @@ The `AutoCLIOptions()` method on your module allows to specify custom commands,
}
```

:::tip
AutoCLI can create a gov proposal of any tx by simply setting the `GovProposal` field to `true` in the `autocli.RpcCommandOptions` struct.
Users can however use the `--no-proposal` flag to disable the proposal creation (which is useful if the authority isn't the gov module on a chain).
:::

### Specifying Subcommands

By default, `autocli` generates a command for each method in your gRPC service. However, you can specify subcommands to group related commands together. To specify subcommands, use the `autocliv1.ServiceCommandDescriptor` struct.
Expand Down Expand Up @@ -201,7 +206,7 @@ It is possible to use `AutoCLI` for non module commands. The trick is still to i
For example, here is how the SDK does it for `cometbft` gRPC commands:

```go reference
https://github.com/cosmos/cosmos-sdk/blob/julien/autocli-comet/client/grpc/cmtservice/autocli.go#L52-L71
https://github.com/cosmos/cosmos-sdk/blob/main/client/grpc/cmtservice/autocli.go#L52-L71
```

## Summary
Expand Down
2 changes: 1 addition & 1 deletion client/v2/autocli/flag/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,10 @@ func (b *Builder) addMessageFlags(ctx context.Context, flagSet *pflag.FlagSet, m

flagOpts := commandOptions.FlagOptions[string(field.Name())]
name, hasValue, err := b.addFieldFlag(ctx, flagSet, field, flagOpts, options)
flagOptsByFlagName[name] = flagOpts
if err != nil {
return nil, err
}
flagOptsByFlagName[name] = flagOpts

messageBinder.flagBindings = append(messageBinder.flagBindings, fieldBinding{
hasValue: hasValue,
Expand Down
78 changes: 72 additions & 6 deletions client/v2/autocli/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,26 @@ import (
"fmt"

"github.com/cockroachdb/errors"
gogoproto "github.com/cosmos/gogoproto/proto"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/reflect/protoreflect"
"google.golang.org/protobuf/types/dynamicpb"

autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
"cosmossdk.io/client/v2/autocli/flag"
"cosmossdk.io/client/v2/internal/flags"
"cosmossdk.io/client/v2/internal/util"
addresscodec "cosmossdk.io/core/address"
authtx "cosmossdk.io/x/auth/tx"
authtxconfig "cosmossdk.io/x/auth/tx/config"

// the following will be extracted to a separate module
// https://github.com/cosmos/cosmos-sdk/issues/14403
authtypes "cosmossdk.io/x/auth/types"
govcli "cosmossdk.io/x/gov/client/cli"
govtypes "cosmossdk.io/x/gov/types"

"github.com/cosmos/cosmos-sdk/client"
clienttx "github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/codec"
Expand Down Expand Up @@ -111,7 +120,7 @@ func (b *Builder) AddMsgServiceCommands(cmd *cobra.Command, cmdDescriptor *autoc

// BuildMsgMethodCommand returns a command that outputs the JSON representation of the message.
func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor, options *autocliv1.RpcCommandOptions) (*cobra.Command, error) {
cmd, err := b.buildMethodCommandCommon(descriptor, options, func(cmd *cobra.Command, input protoreflect.Message) error {
execFunc := func(cmd *cobra.Command, input protoreflect.Message) error {
cmd.SetContext(context.WithValue(context.Background(), client.ClientContextKey, &b.ClientCtx))

clientCtx, err := client.GetClientTxContext(cmd)
Expand Down Expand Up @@ -140,11 +149,17 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor
clientCtx = clientCtx.WithTxConfig(txConfig)
}

// set signer to signer field if empty
fd := input.Descriptor().Fields().ByName(protoreflect.Name(flag.GetSignerFieldName(input.Descriptor())))
if addr := input.Get(fd).String(); addr == "" {
addressCodec := b.Builder.AddressCodec
addressCodec := b.Builder.AddressCodec

// handle gov proposals commands
skipProposal, _ := cmd.Flags().GetBool(flags.FlagNoProposal)
if options.GovProposal && !skipProposal {
return b.handleGovProposal(options, cmd, input, clientCtx, addressCodec, fd)
}

// set signer to signer field if empty
if addr := input.Get(fd).String(); addr == "" {
scalarType, ok := flag.GetScalarType(fd)
if ok {
// override address codec if validator or consensus address
Expand Down Expand Up @@ -172,7 +187,12 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor
proto.Merge(msg, input.Interface())

return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
})
}

cmd, err := b.buildMethodCommandCommon(descriptor, options, execFunc)
if err != nil {
return nil, err
}

if b.AddTxConnFlags != nil {
b.AddTxConnFlags(cmd)
Expand All @@ -183,5 +203,51 @@ func (b *Builder) BuildMsgMethodCommand(descriptor protoreflect.MethodDescriptor
cmd.SilenceUsage = true
}

return cmd, err
// set gov proposal flags if command is a gov proposal
if options.GovProposal {
govcli.AddGovPropFlagsToCmd(cmd)
cmd.Flags().Bool(flags.FlagNoProposal, false, "Skip gov proposal and submit a normal transaction")
}

return cmd, nil
}

// handleGovProposal sets the authority field of the message to the gov module address and creates a gov proposal.
func (b *Builder) handleGovProposal(
options *autocliv1.RpcCommandOptions,
cmd *cobra.Command,
input protoreflect.Message,
clientCtx client.Context,
addressCodec addresscodec.Codec,
fd protoreflect.FieldDescriptor,
) error {
govAuthority := authtypes.NewModuleAddress(govtypes.ModuleName)
authority, err := addressCodec.BytesToString(govAuthority.Bytes())
if err != nil {
return fmt.Errorf("failed to convert gov authority: %w", err)
}
input.Set(fd, protoreflect.ValueOfString(authority))

signerFromFlag := clientCtx.GetFromAddress()
signer, err := addressCodec.BytesToString(signerFromFlag.Bytes())
if err != nil {
return fmt.Errorf("failed to set signer on message, got %q: %w", signerFromFlag, err)
}

proposal, err := govcli.ReadGovPropCmdFlags(signer, cmd.Flags())
if err != nil {
return err
}

// AutoCLI uses protov2 messages, while the SDK only supports proto v1 messages.
// Here we use dynamicpb, to create a proto v1 compatible message.
// The SDK codec will handle protov2 -> protov1 (marshal)
msg := dynamicpb.NewMessage(input.Descriptor())
proto.Merge(msg, input.Interface())

if err := proposal.SetMsgs([]gogoproto.Message{msg}); err != nil {
return fmt.Errorf("failed to set msg in proposal %w", err)
}

return clienttx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), proposal)
}
12 changes: 8 additions & 4 deletions client/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,17 @@ module cosmossdk.io/client/v2
go 1.21

require (
cosmossdk.io/api v0.7.3-0.20231029200940-6af7f30bfd54
cosmossdk.io/core v0.12.0
cosmossdk.io/api v0.7.3-0.20231113122742-912390d5fc4a
cosmossdk.io/core v0.12.1-0.20231114100755-569e3ff6a0d7
cosmossdk.io/depinject v1.0.0-alpha.4
cosmossdk.io/x/bank v0.0.0-00010101000000-000000000000
cosmossdk.io/x/gov v0.0.0-20231113122742-912390d5fc4a
cosmossdk.io/x/tx v0.12.0
github.com/chzyer/readline v1.5.1 // indirect
github.com/cockroachdb/errors v1.11.1
github.com/cosmos/cosmos-proto v1.0.0-beta.3
github.com/cosmos/cosmos-sdk v0.51.0
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/spf13/cobra v1.8.0
github.com/spf13/pflag v1.0.5
google.golang.org/grpc v1.59.0
Expand Down Expand Up @@ -47,7 +50,7 @@ require (
github.com/cosmos/cosmos-db v1.0.0 // indirect
github.com/cosmos/go-bip39 v1.0.0 // indirect
github.com/cosmos/gogogateway v1.2.0 // indirect
github.com/cosmos/gogoproto v1.4.11 // indirect
github.com/cosmos/gogoproto v1.4.11
github.com/cosmos/iavl v1.0.0 // indirect
github.com/cosmos/ics23/go v0.10.0 // indirect
github.com/cosmos/ledger-cosmos-go v0.13.3 // indirect
Expand Down Expand Up @@ -132,7 +135,7 @@ require (
github.com/spf13/afero v1.10.0 // indirect
github.com/spf13/cast v1.5.1 // indirect
github.com/spf13/viper v1.17.0 // indirect
github.com/stretchr/testify v1.8.4 // indirect
github.com/stretchr/testify v1.8.4
github.com/subosito/gotenv v1.6.0 // indirect
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d // indirect
github.com/tendermint/go-amino v0.16.0 // indirect
Expand Down Expand Up @@ -163,6 +166,7 @@ replace (
cosmossdk.io/x/auth => ./../../x/auth
cosmossdk.io/x/bank => ./../../x/bank
cosmossdk.io/x/distribution => ./../../x/distribution
cosmossdk.io/x/gov => ./../../x/gov
cosmossdk.io/x/mint => ./../../x/mint
cosmossdk.io/x/protocolpool => ./../../x/protocolpool
cosmossdk.io/x/slashing => ./../../x/slashing
Expand Down
Loading

0 comments on commit 7681068

Please sign in to comment.