Skip to content

Commit d28fcf9

Browse files
Ganesha UpadhyayaGanesha Upadhyaya
authored andcommitted
Merge tag 'tags/v0.50.7' into release/v0.50.x
Release v0.50.7
2 parents b597e42 + 62212df commit d28fcf9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+475
-162
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,22 @@ Ref: https://keepachangelog.com/en/1.0.0/
3838

3939
## [Unreleased]
4040

41+
## [v0.50.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.7) - 2024-06-04
42+
43+
### Improvements
44+
45+
* (debug) [#20328](https://github.com/cosmos/cosmos-sdk/pull/20328) Add consensus address for debug cmd.
46+
* (runtime) [#20264](https://github.com/cosmos/cosmos-sdk/pull/20264) Expose grpc query router via depinject.
47+
* (x/consensus) [#20381](https://github.com/cosmos/cosmos-sdk/pull/20381) Use Comet utility for consensus module consensus param updates.
48+
* (client) [#20356](https://github.com/cosmos/cosmos-sdk/pull/20356) Overwrite client context when available in `SetCmdClientContext`.
49+
4150
### Bug Fixes
4251

52+
* (baseapp) [#20346](https://github.com/cosmos/cosmos-sdk/pull/20346) Correctly assign `execModeSimulate` to context for `simulateTx`.
53+
* (baseapp) [#20144](https://github.com/cosmos/cosmos-sdk/pull/20144) Remove txs from mempool when AnteHandler fails in recheck.
4354
* (baseapp) [#20107](https://github.com/cosmos/cosmos-sdk/pull/20107) Avoid header height overwrite block height.
4455
* (cli) [#20020](https://github.com/cosmos/cosmos-sdk/pull/20020) Make bootstrap-state command support both new and legacy genesis format.
56+
* (testutil/sims) [#20151](https://github.com/cosmos/cosmos-sdk/pull/20151) Set all signatures and don't overwrite the previous one in `GenSignedMockTx`.
4557

4658
## [v0.50.6](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.6) - 2024-04-22
4759

RELEASE_NOTES.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
# Cosmos SDK v0.50.6 Release Notes
1+
# Cosmos SDK v0.50.7 Release Notes
22

33
💬 [**Release Discussion**](https://github.com/orgs/cosmos/discussions/58)
44

55
## 🚀 Highlights
66

7-
For this month patch release of the v0.50.x line, a few features and improvements were added to the SDK.
7+
For this month patch release of the v0.50.x line, a few improvements were added to the SDK and some bugs were fixed.
88

99
Notably, we added and fixed the following:
1010

11-
* Add start customizability to start command options. Customize how an application starts with the new `StartCommandHandler` field in `server.StartCmdOptions` struct.
12-
* Fixing [GHSA-4j93-fm92-rp4m](https://github.com/cosmos/cosmos-sdk/security/advisories/GHSA-4j93-fm92-rp4m) in `x/feegrant` and `x/authz` modules. The upgrade instuctions were provided in the [v0.50.4 release notes](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.4).
11+
* Add extra checks in x/consensus `MsgUpdateParams` to prevent footguns when updating the consensus parameters.
12+
* Forgetting a field in a x/consensus parameter change gov proposal could lead to a chain halt.
13+
* The fix is in theory consensus breaking, but in practice, it is only a footgun prevention (the path only triggers if the proposal was executed and was invalid). Please ensure that all validators are on v0.50.7 before the execution of a `x/consensus` params update proposal.
14+
* Remove txs from the mempool when they fail in RecheckTX
1315

1416
## 📝 Changelog
1517

16-
Check out the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.50.6/CHANGELOG.md) for an exhaustive list of changes, or [compare changes](https://github.com/cosmos/cosmos-sdk/compare/release/v0.50.5...v0.50.6) from the last release.
18+
Check out the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.50.7/CHANGELOG.md) for an exhaustive list of changes, or [compare changes](https://github.com/cosmos/cosmos-sdk/compare/release/v0.50.6...v0.50.7) from the last release.
1719

1820
Refer to the [upgrading guide](https://github.com/cosmos/cosmos-sdk/blob/release/v0.50.x/UPGRADING.md) when migrating from `v0.47.x` to `v0.50.1`.
1921
Note, that the next SDK release, v0.51, will not include `x/params` migration, when migrating from < v0.47, v0.50.x **or** v0.47.x, is a mandatory migration.

baseapp/abci_test.go

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2388,3 +2388,104 @@ func TestOptimisticExecution(t *testing.T) {
23882388

23892389
require.Equal(t, int64(50), suite.baseApp.LastBlockHeight())
23902390
}
2391+
2392+
func TestABCI_Proposal_FailReCheckTx(t *testing.T) {
2393+
pool := mempool.NewPriorityMempool[int64](mempool.PriorityNonceMempoolConfig[int64]{
2394+
TxPriority: mempool.NewDefaultTxPriority(),
2395+
MaxTx: 0,
2396+
SignerExtractor: mempool.NewDefaultSignerExtractionAdapter(),
2397+
})
2398+
2399+
anteOpt := func(bapp *baseapp.BaseApp) {
2400+
bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (sdk.Context, error) {
2401+
// always fail on recheck, just to test the recheck logic
2402+
if ctx.IsReCheckTx() {
2403+
return ctx, errors.New("recheck failed in ante handler")
2404+
}
2405+
2406+
return ctx, nil
2407+
})
2408+
}
2409+
2410+
suite := NewBaseAppSuite(t, anteOpt, baseapp.SetMempool(pool))
2411+
baseapptestutil.RegisterKeyValueServer(suite.baseApp.MsgServiceRouter(), MsgKeyValueImpl{})
2412+
baseapptestutil.RegisterCounterServer(suite.baseApp.MsgServiceRouter(), NoopCounterServerImpl{})
2413+
2414+
_, err := suite.baseApp.InitChain(&abci.RequestInitChain{
2415+
ConsensusParams: &cmtproto.ConsensusParams{},
2416+
})
2417+
require.NoError(t, err)
2418+
2419+
tx := newTxCounter(t, suite.txConfig, 0, 1)
2420+
txBytes, err := suite.txConfig.TxEncoder()(tx)
2421+
require.NoError(t, err)
2422+
2423+
reqCheckTx := abci.RequestCheckTx{
2424+
Tx: txBytes,
2425+
Type: abci.CheckTxType_New,
2426+
}
2427+
_, err = suite.baseApp.CheckTx(&reqCheckTx)
2428+
require.NoError(t, err)
2429+
2430+
tx2 := newTxCounter(t, suite.txConfig, 1, 1)
2431+
2432+
tx2Bytes, err := suite.txConfig.TxEncoder()(tx2)
2433+
require.NoError(t, err)
2434+
2435+
err = pool.Insert(sdk.Context{}, tx2)
2436+
require.NoError(t, err)
2437+
2438+
require.Equal(t, 2, pool.CountTx())
2439+
2440+
// call prepareProposal before calling recheck tx, just as a sanity check
2441+
reqPrepareProposal := abci.RequestPrepareProposal{
2442+
MaxTxBytes: 1000,
2443+
Height: 1,
2444+
}
2445+
resPrepareProposal, err := suite.baseApp.PrepareProposal(&reqPrepareProposal)
2446+
require.NoError(t, err)
2447+
require.Equal(t, 2, len(resPrepareProposal.Txs))
2448+
2449+
// call recheck on the first tx, it MUST return an error
2450+
reqReCheckTx := abci.RequestCheckTx{
2451+
Tx: txBytes,
2452+
Type: abci.CheckTxType_Recheck,
2453+
}
2454+
resp, err := suite.baseApp.CheckTx(&reqReCheckTx)
2455+
require.NoError(t, err)
2456+
require.True(t, resp.IsErr())
2457+
require.Equal(t, "recheck failed in ante handler", resp.Log)
2458+
2459+
// call prepareProposal again, should return only the second tx
2460+
resPrepareProposal, err = suite.baseApp.PrepareProposal(&reqPrepareProposal)
2461+
require.NoError(t, err)
2462+
require.Equal(t, 1, len(resPrepareProposal.Txs))
2463+
require.Equal(t, tx2Bytes, resPrepareProposal.Txs[0])
2464+
2465+
// check the mempool, it should have only the second tx
2466+
require.Equal(t, 1, pool.CountTx())
2467+
2468+
reqProposalTxBytes := [][]byte{
2469+
tx2Bytes,
2470+
}
2471+
reqProcessProposal := abci.RequestProcessProposal{
2472+
Txs: reqProposalTxBytes,
2473+
Height: reqPrepareProposal.Height,
2474+
}
2475+
2476+
resProcessProposal, err := suite.baseApp.ProcessProposal(&reqProcessProposal)
2477+
require.NoError(t, err)
2478+
require.Equal(t, abci.ResponseProcessProposal_ACCEPT, resProcessProposal.Status)
2479+
2480+
// the same txs as in PrepareProposal
2481+
res, err := suite.baseApp.FinalizeBlock(&abci.RequestFinalizeBlock{
2482+
Height: suite.baseApp.LastBlockHeight() + 1,
2483+
Txs: reqProposalTxBytes,
2484+
})
2485+
require.NoError(t, err)
2486+
2487+
require.Equal(t, 0, pool.CountTx())
2488+
2489+
require.NotEmpty(t, res.TxResults[0].Events)
2490+
require.True(t, res.TxResults[0].IsOK(), fmt.Sprintf("%v", res))
2491+
}

baseapp/abci_utils.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@ import (
44
"bytes"
55
"context"
66
"fmt"
7-
"slices"
7+
"slices" //nolint: gci // ignore this line for this linter
88

99
"github.com/cockroachdb/errors"
1010
abci "github.com/cometbft/cometbft/abci/types"
1111
cryptoenc "github.com/cometbft/cometbft/crypto/encoding"
1212
cmtprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
1313
cmtproto "github.com/cometbft/cometbft/proto/tendermint/types"
1414
protoio "github.com/cosmos/gogoproto/io"
15-
"github.com/cosmos/gogoproto/proto"
15+
"github.com/cosmos/gogoproto/proto" //nolint: gci // ignore this line for this linter
1616

1717
"cosmossdk.io/core/comet"
1818

baseapp/baseapp.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,8 @@ func (app *BaseApp) Trace() bool {
277277
// MsgServiceRouter returns the MsgServiceRouter of a BaseApp.
278278
func (app *BaseApp) MsgServiceRouter() *MsgServiceRouter { return app.msgServiceRouter }
279279

280-
// SetMsgServiceRouter sets the MsgServiceRouter of a BaseApp.
281-
func (app *BaseApp) SetMsgServiceRouter(msgServiceRouter *MsgServiceRouter) {
282-
app.msgServiceRouter = msgServiceRouter
283-
}
280+
// GRPCQueryRouter returns the GRPCQueryRouter of a BaseApp.
281+
func (app *BaseApp) GRPCQueryRouter() *GRPCQueryRouter { return app.grpcQueryRouter }
284282

285283
// MountStores mounts all IAVL or DB stores to the provided keys in the BaseApp
286284
// multistore.
@@ -677,6 +675,7 @@ func (app *BaseApp) getContextForTx(mode execMode, txBytes []byte) sdk.Context {
677675

678676
if mode == execModeSimulate {
679677
ctx, _ = ctx.CacheContext()
678+
ctx = ctx.WithExecMode(sdk.ExecMode(execModeSimulate))
680679
}
681680

682681
return ctx
@@ -721,7 +720,7 @@ func (app *BaseApp) preBlock(req *abci.RequestFinalizeBlock) error {
721720
return nil
722721
}
723722

724-
func (app *BaseApp) beginBlock(req *abci.RequestFinalizeBlock) (sdk.BeginBlock, error) {
723+
func (app *BaseApp) beginBlock(_ *abci.RequestFinalizeBlock) (sdk.BeginBlock, error) {
725724
var (
726725
resp sdk.BeginBlock
727726
err error
@@ -786,7 +785,7 @@ func (app *BaseApp) deliverTx(tx []byte) *abci.ExecTxResult {
786785

787786
// endBlock is an application-defined function that is called after transactions
788787
// have been processed in FinalizeBlock.
789-
func (app *BaseApp) endBlock(ctx context.Context) (sdk.EndBlock, error) {
788+
func (app *BaseApp) endBlock(_ context.Context) (sdk.EndBlock, error) {
790789
var endblock sdk.EndBlock
791790

792791
if app.endBlocker != nil {
@@ -915,6 +914,12 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte) (gInfo sdk.GasInfo, res
915914
gasWanted = ctx.GasMeter().Limit()
916915

917916
if err != nil {
917+
if mode == execModeReCheck {
918+
// if the ante handler fails on recheck, we want to remove the tx from the mempool
919+
if mempoolErr := app.mempool.Remove(tx); mempoolErr != nil {
920+
return gInfo, nil, anteEvents, errors.Join(err, mempoolErr)
921+
}
922+
}
918923
return gInfo, nil, nil, err
919924
}
920925

baseapp/grpcserver.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@ import (
1919
grpctypes "github.com/cosmos/cosmos-sdk/types/grpc"
2020
)
2121

22-
// GRPCQueryRouter returns the GRPCQueryRouter of a BaseApp.
23-
func (app *BaseApp) GRPCQueryRouter() *GRPCQueryRouter { return app.grpcQueryRouter }
24-
2522
// RegisterGRPCServer registers gRPC services directly with the gRPC server.
2623
func (app *BaseApp) RegisterGRPCServer(server gogogrpc.Server) {
2724
// Define an interceptor for all gRPC queries: this interceptor will create

baseapp/options.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -372,3 +372,13 @@ func (app *BaseApp) SetStreamingManager(manager storetypes.StreamingManager) {
372372
func (app *BaseApp) SetDisableBlockGasMeter(disableBlockGasMeter bool) {
373373
app.disableBlockGasMeter = disableBlockGasMeter
374374
}
375+
376+
// SetMsgServiceRouter sets the MsgServiceRouter of a BaseApp.
377+
func (app *BaseApp) SetMsgServiceRouter(msgServiceRouter *MsgServiceRouter) {
378+
app.msgServiceRouter = msgServiceRouter
379+
}
380+
381+
// SetGRPCQueryRouter sets the GRPCQueryRouter of the BaseApp.
382+
func (app *BaseApp) SetGRPCQueryRouter(grpcQueryRouter *GRPCQueryRouter) {
383+
app.grpcQueryRouter = grpcQueryRouter
384+
}

client/cmd.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,14 +359,17 @@ func GetClientContextFromCmd(cmd *cobra.Command) Context {
359359
// SetCmdClientContext sets a command's Context value to the provided argument.
360360
// If the context has not been set, set the given context as the default.
361361
func SetCmdClientContext(cmd *cobra.Command, clientCtx Context) error {
362-
var cmdCtx context.Context
363-
364-
if cmd.Context() == nil {
362+
cmdCtx := cmd.Context()
363+
if cmdCtx == nil {
365364
cmdCtx = context.Background()
365+
}
366+
367+
v := cmd.Context().Value(ClientContextKey)
368+
if clientCtxPtr, ok := v.(*Context); ok {
369+
*clientCtxPtr = clientCtx
366370
} else {
367-
cmdCtx = cmd.Context()
371+
cmd.SetContext(context.WithValue(cmdCtx, ClientContextKey, &clientCtx))
368372
}
369373

370-
cmd.SetContext(context.WithValue(cmdCtx, ClientContextKey, &clientCtx))
371374
return nil
372375
}

client/cmd_test.go

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,21 @@ func TestSetCmdClientContextHandler(t *testing.T) {
7979
name string
8080
expectedContext client.Context
8181
args []string
82+
ctx context.Context
8283
}{
8384
{
8485
"no flags set",
8586
initClientCtx,
8687
[]string{},
88+
context.WithValue(context.Background(), client.ClientContextKey, &client.Context{}),
8789
},
8890
{
8991
"flags set",
9092
initClientCtx.WithChainID("new-chain-id"),
9193
[]string{
9294
fmt.Sprintf("--%s=new-chain-id", flags.FlagChainID),
9395
},
96+
context.WithValue(context.Background(), client.ClientContextKey, &client.Context{}),
9497
},
9598
{
9699
"flags set with space",
@@ -99,20 +102,37 @@ func TestSetCmdClientContextHandler(t *testing.T) {
99102
fmt.Sprintf("--%s", flags.FlagHome),
100103
"/tmp/dir",
101104
},
105+
context.Background(),
106+
},
107+
{
108+
"no context provided",
109+
initClientCtx.WithHomeDir("/tmp/noctx"),
110+
[]string{
111+
fmt.Sprintf("--%s", flags.FlagHome),
112+
"/tmp/noctx",
113+
},
114+
nil,
115+
},
116+
{
117+
"with invalid client value in the context",
118+
initClientCtx.WithHomeDir("/tmp/invalid"),
119+
[]string{
120+
fmt.Sprintf("--%s", flags.FlagHome),
121+
"/tmp/invalid",
122+
},
123+
context.WithValue(context.Background(), client.ClientContextKey, "invalid"),
102124
},
103125
}
104126

105127
for _, tc := range testCases {
106128
tc := tc
107129

108130
t.Run(tc.name, func(t *testing.T) {
109-
ctx := context.WithValue(context.Background(), client.ClientContextKey, &client.Context{})
110-
111131
cmd := newCmd()
112132
_ = testutil.ApplyMockIODiscardOutErr(cmd)
113133
cmd.SetArgs(tc.args)
114134

115-
require.NoError(t, cmd.ExecuteContext(ctx))
135+
require.NoError(t, cmd.ExecuteContext(tc.ctx))
116136

117137
clientCtx := client.GetClientContextFromCmd(cmd)
118138
require.Equal(t, tc.expectedContext, clientCtx)

client/debug/main.go

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -253,28 +253,43 @@ $ %s debug addr cosmos1e0jnq2sun3dzjh8p2xq95kk0expwmd7shwjpfg
253253
Args: cobra.ExactArgs(1),
254254
RunE: func(cmd *cobra.Command, args []string) error {
255255
addrString := args[0]
256-
var addr []byte
257-
258256
// try hex, then bech32
259-
var err error
260-
addr, err = hex.DecodeString(addrString)
261-
if err != nil {
262-
var err2 error
263-
addr, err2 = sdk.AccAddressFromBech32(addrString)
264-
if err2 != nil {
265-
var err3 error
266-
addr, err3 = sdk.ValAddressFromBech32(addrString)
267-
268-
if err3 != nil {
269-
return fmt.Errorf("expected hex or bech32. Got errors: hex: %v, bech32 acc: %v, bech32 val: %v", err, err2, err3)
257+
var (
258+
addr []byte
259+
err error
260+
)
261+
decodeFns := []func(text string) ([]byte, error){
262+
hex.DecodeString,
263+
func(text string) ([]byte, error) { return sdk.AccAddressFromBech32(text) },
264+
func(text string) ([]byte, error) { return sdk.ValAddressFromBech32(text) },
265+
func(text string) ([]byte, error) { return sdk.ConsAddressFromBech32(text) },
266+
}
267+
errs := make([]any, 0, len(decodeFns))
268+
for _, fn := range decodeFns {
269+
if addr, err = fn(addrString); err == nil {
270+
break
271+
}
272+
errs = append(errs, err)
273+
}
274+
if len(errs) == len(decodeFns) {
275+
errTags := []string{
276+
"hex", "bech32 acc", "bech32 val", "bech32 con",
277+
}
278+
format := ""
279+
for i := range errs {
280+
if format != "" {
281+
format += ", "
270282
}
283+
format += errTags[i] + ": %w"
271284
}
285+
return fmt.Errorf("expected hex or bech32. Got errors: "+format, errs...)
272286
}
273287

274288
cmd.Println("Address:", addr)
275289
cmd.Printf("Address (hex): %X\n", addr)
276290
cmd.Printf("Bech32 Acc: %s\n", sdk.AccAddress(addr))
277291
cmd.Printf("Bech32 Val: %s\n", sdk.ValAddress(addr))
292+
cmd.Printf("Bech32 Con: %s\n", sdk.ConsAddress(addr))
278293
return nil
279294
},
280295
}

0 commit comments

Comments
 (0)