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

refactor!: remove broadcast mode block #12659

Merged
merged 25 commits into from
Sep 23, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
* [#12596](https://github.com/cosmos/cosmos-sdk/pull/12596) Remove all imports of the non-existent gogo/protobuf v1.3.3 to ease downstream use and go workspaces.
* [#12187](https://github.com/cosmos/cosmos-sdk/pull/12187) Add batch operation for x/nft module.
* [#12693](https://github.com/cosmos/cosmos-sdk/pull/12693) Make sure the order of each node is consistent when emitting proto events.
* [#12455](https://github.com/cosmos/cosmos-sdk/pull/12455) Show attempts count in error for signing.
* [#12886](https://github.com/cosmos/cosmos-sdk/pull/12886) Amortize cost of processing cache KV store
* [#12455](https://github.com/cosmos/cosmos-sdk/pull/12455) Show attempts count in error for signing.
* [#12885](https://github.com/cosmos/cosmos-sdk/pull/12885) Amortize cost of processing cache KV store
* [#12953](https://github.com/cosmos/cosmos-sdk/pull/12953) Change the default priority mechanism to be based on gas price.
* [#13048](https://github.com/cosmos/cosmos-sdk/pull/13048) Add handling of AccountNumberStoreKeyPrefix to the x/auth simulation decoder.
* [#13101](https://github.com/cosmos/cosmos-sdk/pull/13101) Remove weights from `simapp/params` and `testutil/sims`. They are now in their respective modules.
Expand Down Expand Up @@ -111,6 +111,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

### API Breaking Changes

* (tx) [#12659](https://github.com/cosmos/cosmos-sdk/pull/12659) Remove broadcast mode `block`.
julienrbrt marked this conversation as resolved.
Show resolved Hide resolved
* (context) [#13063](https://github.com/cosmos/cosmos-sdk/pull/13063) Update `Context#CacheContext` to automatically emit all events on the parent context's `EventManager`.
* (x/bank) [#12706](https://github.com/cosmos/cosmos-sdk/pull/12706) Removed the `testutil` package from the `x/bank/client` package.
* (simapp) [#12747](https://github.com/cosmos/cosmos-sdk/pull/12747) Remove `simapp.MakeTestEncodingConfig`. Please use `moduletestutil.MakeTestEncodingConfig` (`types/module/testutil`) in tests instead.
Expand Down
127 changes: 65 additions & 62 deletions api/cosmos/tx/v1beta1/service.pulsar.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 1 addition & 39 deletions client/broadcast.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ func (ctx Context) BroadcastTx(txBytes []byte) (res *sdk.TxResponse, err error)
case flags.BroadcastAsync:
res, err = ctx.BroadcastTxAsync(txBytes)

case flags.BroadcastBlock:
res, err = ctx.BroadcastTxCommit(txBytes)

default:
return nil, 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", ctx.BroadcastMode)
}

return res, err
Expand Down Expand Up @@ -81,39 +78,6 @@ func CheckTendermintError(err error, tx tmtypes.Tx) *sdk.TxResponse {
}
}

// BroadcastTxCommit broadcasts transaction bytes to a Tendermint node and
// waits for a commit. An error is only returned if there is no RPC node
// connection or if broadcasting fails.
//
// 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) {
node, err := ctx.GetNode()
if err != nil {
return nil, err
}

res, err := node.BroadcastTxCommit(context.Background(), txBytes)
if err == nil {
return sdk.NewResponseFormatBroadcastTxCommit(res), nil
}

// with these changes(https://github.com/tendermint/tendermint/pull/7683)
// in tendermint, we receive both an error and a non-empty res from TM. Here
// we handle the case where both are relevant. Note: without this edge-case handling,
// CLI is breaking (for few transactions ex: executing unathorized messages in feegrant)
// this check is added to tackle the particular case.
if strings.Contains(err.Error(), "transaction encountered error") {
return sdk.NewResponseFormatBroadcastTxCommit(res), nil
}

if errRes := CheckTendermintError(err, txBytes); errRes != nil {
return errRes, nil
}
return sdk.NewResponseFormatBroadcastTxCommit(res), err
}

// BroadcastTxSync broadcasts transaction bytes to a Tendermint node
// synchronously (i.e. returns after CheckTx execution).
func (ctx Context) BroadcastTxSync(txBytes []byte) (*sdk.TxResponse, error) {
Expand Down Expand Up @@ -170,8 +134,6 @@ func normalizeBroadcastMode(mode tx.BroadcastMode) string {
switch mode {
case tx.BroadcastMode_BROADCAST_MODE_ASYNC:
return "async"
case tx.BroadcastMode_BROADCAST_MODE_BLOCK:
return "block"
case tx.BroadcastMode_BROADCAST_MODE_SYNC:
return "sync"
default:
Expand Down
5 changes: 0 additions & 5 deletions client/broadcast_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ type MockClient struct {
err error
}

func (c MockClient) BroadcastTxCommit(ctx context.Context, tx tmtypes.Tx) (*coretypes.ResultBroadcastTxCommit, error) {
return nil, c.err
}

func (c MockClient) BroadcastTxAsync(ctx context.Context, tx tmtypes.Tx) (*coretypes.ResultBroadcastTx, error) {
return nil, c.err
}
Expand All @@ -50,7 +46,6 @@ func TestBroadcastError(t *testing.T) {

modes := []string{
flags.BroadcastAsync,
flags.BroadcastBlock,
flags.BroadcastSync,
}

Expand Down
2 changes: 1 addition & 1 deletion client/config/toml.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ keyring-backend = "{{ .KeyringBackend }}"
output = "{{ .Output }}"
# <host>:<port> to Tendermint RPC interface for this chain
node = "{{ .Node }}"
# Transaction broadcasting mode (sync|async|block)
# Transaction broadcasting mode (sync|async)
broadcast-mode = "{{ .BroadcastMode }}"
`

Expand Down
5 changes: 1 addition & 4 deletions client/flags/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ const (
// DefaultKeyringBackend
DefaultKeyringBackend = keyring.BackendOS

// BroadcastBlock defines a tx broadcasting mode where the client waits for
// the tx to be committed in a block.
BroadcastBlock = "block"
// BroadcastSync defines a tx broadcasting mode where the client waits for
// a CheckTx execution response only.
BroadcastSync = "sync"
Expand Down Expand Up @@ -114,7 +111,7 @@ func AddTxFlagsToCmd(cmd *cobra.Command) {
cmd.Flags().String(FlagNode, "tcp://localhost:26657", "<host>:<port> to tendermint rpc interface for this chain")
cmd.Flags().Bool(FlagUseLedger, false, "Use a connected Ledger device")
cmd.Flags().Float64(FlagGasAdjustment, DefaultGasAdjustment, "adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored ")
cmd.Flags().StringP(FlagBroadcastMode, "b", BroadcastSync, "Transaction broadcasting mode (sync|async|block)")
cmd.Flags().StringP(FlagBroadcastMode, "b", BroadcastSync, "Transaction broadcasting mode (sync|async)")
cmd.Flags().Bool(FlagDryRun, false, "ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible)")
cmd.Flags().Bool(FlagGenerateOnly, false, "Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name)")
cmd.Flags().Bool(FlagOffline, false, "Offline mode (does not allow any online functionality)")
Expand Down
3 changes: 2 additions & 1 deletion codec/amino_codec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"github.com/stretchr/testify/require"

"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/cosmos-sdk/testutil/testdata"
Expand Down Expand Up @@ -135,7 +136,7 @@ func TestAminoCodecFullDecodeAndEncode(t *testing.T) {

// Marshalling/unmarshalling the tx wrapped in a struct should work.
txRequest := &cli.BroadcastReq{
Mode: "block",
Mode: flags.BroadcastSync,
Tx: tx,
}
_, err = legacyCdc.MarshalJSON(txRequest)
Expand Down
Loading