Skip to content

Commit f59fb99

Browse files
committed
Merge tag 'v0.47.7' into release/v0.47.x-neutron
Release v0.47.7
2 parents 28f3db4 + d09f40d commit f59fb99

33 files changed

+470
-158
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,19 @@ Ref: https://keepachangelog.com/en/1.0.0/
3737

3838
## [Unreleased]
3939

40+
## [v0.47.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.7) - 2023-12-20
41+
42+
### Improvements
43+
44+
* (x/gov) [#18707](https://github.com/cosmos/cosmos-sdk/pull/18707) Improve genesis validation.
45+
* (server) [#18478](https://github.com/cosmos/cosmos-sdk/pull/18478) Add command flag to disable colored logs.
46+
47+
### Bug Fixes
48+
49+
* (baseapp) [#18609](https://github.com/cosmos/cosmos-sdk/issues/18609) Fixed accounting in the block gas meter after BeginBlock and before DeliverTx, ensuring transaction processing always starts with the expected zeroed out block gas meter.
50+
* (server) [#18537](https://github.com/cosmos/cosmos-sdk/pull/18537) Fix panic when defining minimum gas config as `100stake;100uatom`. Use a `,` delimiter instead of `;`. Fixes the server config getter to use the correct delimiter.
51+
* (client/tx) [#18472](https://github.com/cosmos/cosmos-sdk/pull/18472) Utilizes the correct Pubkey when simulating a transaction.
52+
4053
## [v0.47.6](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.6) - 2023-11-14
4154

4255
### Features

RELEASE_NOTES.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
# Cosmos SDK v0.47.6 Release Notes
1+
# Cosmos SDK v0.47.7 Release Notes
22

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

55
## 🚀 Highlights
66

77
v0.50 is there, the v0.47.x line is now supported for bug fixes only, as per our release policy.
8-
Start integrating with [Cosmos SDK Eden (v0.50)](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.1) and enjoy and the new features and performance improvements.
8+
Start integrating with [Cosmos SDK Eden (v0.50)](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.2) and enjoy and the new features and performance improvements.
99

10-
For this 6th patch release of the `v0.47.x` line, some of the notable changes include:
10+
For this 7th patch release of the `v0.47.x` line, some of the notable changes include:
1111

12-
* The gRPC and API server are both started in standalone mode (CometBFT out of process)
13-
* Fix the default prepare proposal handler to better match CometBFT ABCI specification
12+
* A bug fix in the `app.toml` parsing for the `minimum-gas-prices` parameter.
13+
* A bug fix to properly simulate a transaction when using a multisig.
1414

15-
Check out the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.47.5/CHANGELOG.md) for an exhaustive list of changes or [compare changes](https://github.com/cosmos/cosmos-sdk/compare/v0.47.5...v0.47.6) from last release.
15+
Check out the [changelog](https://github.com/cosmos/cosmos-sdk/blob/v0.47.5/CHANGELOG.md) for an exhaustive list of changes or [compare changes](https://github.com/cosmos/cosmos-sdk/compare/v0.47.6...v0.47.7) from last release.
1616

17-
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`.
17+
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.x`.

baseapp/abci.go

+4
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,10 @@ func (app *BaseApp) BeginBlock(req abci.RequestBeginBlock) (res abci.ResponseBeg
206206
}
207207
}
208208

209+
// Reset the gas meter so that the AnteHandlers aren't required to
210+
gasMeter = app.getBlockGasMeter(app.deliverState.ctx)
211+
app.deliverState.ctx = app.deliverState.ctx.WithBlockGasMeter(gasMeter)
212+
209213
return res
210214
}
211215

baseapp/baseapp_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,41 @@ func NewBaseAppSuiteWithSnapshots(t *testing.T, cfg SnapshotsConfig, opts ...fun
158158
return suite
159159
}
160160

161+
func TestAnteHandlerGasMeter(t *testing.T) {
162+
// run BeginBlock and assert that the gas meter passed into the first Txn's AnteHandlers is zeroed out
163+
anteOpt := func(bapp *baseapp.BaseApp) {
164+
bapp.SetAnteHandler(func(ctx sdk.Context, tx sdk.Tx, simulate bool) (newCtx sdk.Context, err error) {
165+
gasMeter := ctx.BlockGasMeter()
166+
require.NotNil(t, gasMeter)
167+
require.Equal(t, sdk.Gas(0), gasMeter.GasConsumed())
168+
return ctx, nil
169+
})
170+
}
171+
// set the beginBlocker to use some gas
172+
beginBlockerOpt := func(bapp *baseapp.BaseApp) {
173+
bapp.SetBeginBlocker(func(ctx sdk.Context, req abci.RequestBeginBlock) abci.ResponseBeginBlock {
174+
ctx.BlockGasMeter().ConsumeGas(1, "beginBlocker gas consumption")
175+
return abci.ResponseBeginBlock{}
176+
})
177+
}
178+
179+
suite := NewBaseAppSuite(t, anteOpt, beginBlockerOpt)
180+
181+
_ = suite.baseApp.InitChain(abci.RequestInitChain{
182+
ConsensusParams: &tmproto.ConsensusParams{},
183+
})
184+
185+
// Run BeginBlock to consume some gas
186+
header := tmproto.Header{Height: 1}
187+
suite.baseApp.BeginBlock(abci.RequestBeginBlock{Header: header})
188+
189+
// Run our first Tx (make sure the AnteHandler doesn't see gas consumed in BeginBlock
190+
tx := newTxCounter(t, suite.txConfig, 0, 0)
191+
txBytes, err := suite.txConfig.TxEncoder()(tx)
192+
require.NoError(t, err)
193+
suite.baseApp.DeliverTx(abci.RequestDeliverTx{Tx: txBytes})
194+
}
195+
161196
func TestLoadVersion(t *testing.T) {
162197
logger := defaultLogger()
163198
pruningOpt := baseapp.SetPruning(pruningtypes.NewPruningOptions(pruningtypes.PruningNothing))

client/flags/flags.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -85,8 +85,9 @@ const (
8585
FlagOutput = tmcli.OutputFlag
8686

8787
// Tendermint logging flags
88-
FlagLogLevel = "log_level"
89-
FlagLogFormat = "log_format"
88+
FlagLogLevel = "log_level"
89+
FlagLogFormat = "log_format"
90+
FlagLogNoColor = "log_no_color"
9091
)
9192

9293
// LineBreak can be included in a command list to provide a blank line

client/tx/factory.go

+29-11
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/cosmos/cosmos-sdk/client/flags"
1616
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
1717
"github.com/cosmos/cosmos-sdk/crypto/keyring"
18+
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
1819
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
1920
cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
2021
sdk "github.com/cosmos/cosmos-sdk/types"
@@ -34,6 +35,7 @@ type Factory struct {
3435
timeoutHeight uint64
3536
gasAdjustment float64
3637
chainID string
38+
fromName string
3739
offline bool
3840
generateOnly bool
3941
memo string
@@ -86,6 +88,7 @@ func NewFactoryCLI(clientCtx client.Context, flagSet *pflag.FlagSet) (Factory, e
8688
accountRetriever: clientCtx.AccountRetriever,
8789
keybase: clientCtx.Keyring,
8890
chainID: clientCtx.ChainID,
91+
fromName: clientCtx.FromName,
8992
offline: clientCtx.Offline,
9093
generateOnly: clientCtx.GenerateOnly,
9194
gas: gasSetting.Gas,
@@ -414,10 +417,8 @@ func (f Factory) BuildSimTx(msgs ...sdk.Msg) ([]byte, error) {
414417
// Create an empty signature literal as the ante handler will populate with a
415418
// sentinel pubkey.
416419
sig := signing.SignatureV2{
417-
PubKey: pk,
418-
Data: &signing.SingleSignatureData{
419-
SignMode: f.signMode,
420-
},
420+
PubKey: pk,
421+
Data: f.getSimSignatureData(pk),
421422
Sequence: f.Sequence(),
422423
}
423424
if err := txb.SetSignatures(sig); err != nil {
@@ -438,16 +439,13 @@ func (f Factory) getSimPK() (cryptotypes.PubKey, error) {
438439
pk cryptotypes.PubKey = &secp256k1.PubKey{} // use default public key type
439440
)
440441

441-
// Use the first element from the list of keys in order to generate a valid
442-
// pubkey that supports multiple algorithms.
443442
if f.simulateAndExecute && f.keybase != nil {
444-
records, _ := f.keybase.List()
445-
if len(records) == 0 {
446-
return nil, errors.New("cannot build signature for simulation, key records slice is empty")
443+
record, err := f.keybase.Key(f.fromName)
444+
if err != nil {
445+
return nil, err
447446
}
448447

449-
// take the first record just for simulation purposes
450-
pk, ok = records[0].PubKey.GetCachedValue().(cryptotypes.PubKey)
448+
pk, ok = record.PubKey.GetCachedValue().(cryptotypes.PubKey)
451449
if !ok {
452450
return nil, errors.New("cannot build signature for simulation, failed to convert proto Any to public key")
453451
}
@@ -456,6 +454,26 @@ func (f Factory) getSimPK() (cryptotypes.PubKey, error) {
456454
return pk, nil
457455
}
458456

457+
// getSimSignatureData based on the pubKey type gets the correct SignatureData type
458+
// to use for building a simulation tx.
459+
func (f Factory) getSimSignatureData(pk cryptotypes.PubKey) signing.SignatureData {
460+
multisigPubKey, ok := pk.(*multisig.LegacyAminoPubKey)
461+
if !ok {
462+
return &signing.SingleSignatureData{SignMode: f.signMode}
463+
}
464+
465+
multiSignatureData := make([]signing.SignatureData, 0, multisigPubKey.Threshold)
466+
for i := uint32(0); i < multisigPubKey.Threshold; i++ {
467+
multiSignatureData = append(multiSignatureData, &signing.SingleSignatureData{
468+
SignMode: f.SignMode(),
469+
})
470+
}
471+
472+
return &signing.MultiSignatureData{
473+
Signatures: multiSignatureData,
474+
}
475+
}
476+
459477
// Prepare ensures the account defined by ctx.GetFromAddress() exists and
460478
// if the account number and/or the account sequence number are zero (not set),
461479
// they will be queried for and set on the provided Factory.

client/tx/factory_test.go

+93-7
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,120 @@
1-
package tx_test
1+
package tx
22

33
import (
44
"testing"
55

6-
"github.com/cosmos/cosmos-sdk/client"
7-
"github.com/cosmos/cosmos-sdk/client/tx"
86
"github.com/stretchr/testify/require"
7+
8+
"github.com/cosmos/cosmos-sdk/client"
9+
"github.com/cosmos/cosmos-sdk/codec"
10+
"github.com/cosmos/cosmos-sdk/crypto/hd"
11+
"github.com/cosmos/cosmos-sdk/crypto/keyring"
12+
"github.com/cosmos/cosmos-sdk/crypto/keys/multisig"
13+
"github.com/cosmos/cosmos-sdk/crypto/keys/secp256k1"
14+
"github.com/cosmos/cosmos-sdk/crypto/types"
15+
"github.com/cosmos/cosmos-sdk/testutil/testdata"
16+
"github.com/cosmos/cosmos-sdk/types/tx/signing"
17+
18+
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
19+
cryptocodec "github.com/cosmos/cosmos-sdk/crypto/codec"
920
)
1021

11-
func TestFactoryPrepate(t *testing.T) {
22+
func TestFactoryPrepare(t *testing.T) {
1223
t.Parallel()
1324

14-
factory := tx.Factory{}
25+
factory := Factory{}
1526
clientCtx := client.Context{}
1627

1728
output, err := factory.Prepare(clientCtx.WithOffline(true))
1829
require.NoError(t, err)
1930
require.Equal(t, output, factory)
2031

21-
factory = tx.Factory{}.WithAccountRetriever(client.MockAccountRetriever{ReturnAccNum: 10, ReturnAccSeq: 1}).WithAccountNumber(5)
32+
factory = Factory{}.WithAccountRetriever(client.MockAccountRetriever{ReturnAccNum: 10, ReturnAccSeq: 1}).WithAccountNumber(5)
2233
output, err = factory.Prepare(clientCtx.WithFrom("foo"))
2334
require.NoError(t, err)
2435
require.NotEqual(t, output, factory)
2536
require.Equal(t, output.AccountNumber(), uint64(5))
2637
require.Equal(t, output.Sequence(), uint64(1))
2738

28-
factory = tx.Factory{}.WithAccountRetriever(client.MockAccountRetriever{ReturnAccNum: 10, ReturnAccSeq: 1})
39+
factory = Factory{}.WithAccountRetriever(client.MockAccountRetriever{ReturnAccNum: 10, ReturnAccSeq: 1})
2940
output, err = factory.Prepare(clientCtx.WithFrom("foo"))
3041
require.NoError(t, err)
3142
require.NotEqual(t, output, factory)
3243
require.Equal(t, output.AccountNumber(), uint64(10))
3344
require.Equal(t, output.Sequence(), uint64(1))
3445
}
46+
47+
func TestFactory_getSimPKType(t *testing.T) {
48+
// setup keyring
49+
registry := codectypes.NewInterfaceRegistry()
50+
cryptocodec.RegisterInterfaces(registry)
51+
k := keyring.NewInMemory(codec.NewProtoCodec(registry))
52+
53+
tests := []struct {
54+
name string
55+
fromName string
56+
genKey func(fromName string, k keyring.Keyring) error
57+
wantType types.PubKey
58+
}{
59+
{
60+
name: "simple key",
61+
fromName: "testKey",
62+
genKey: func(fromName string, k keyring.Keyring) error {
63+
_, err := k.NewAccount(fromName, testdata.TestMnemonic, "", "", hd.Secp256k1)
64+
return err
65+
},
66+
wantType: (*secp256k1.PubKey)(nil),
67+
},
68+
{
69+
name: "multisig key",
70+
fromName: "multiKey",
71+
genKey: func(fromName string, k keyring.Keyring) error {
72+
pk := multisig.NewLegacyAminoPubKey(1, []types.PubKey{&multisig.LegacyAminoPubKey{}})
73+
_, err := k.SaveMultisig(fromName, pk)
74+
return err
75+
},
76+
wantType: (*multisig.LegacyAminoPubKey)(nil),
77+
},
78+
}
79+
80+
for _, tt := range tests {
81+
t.Run(tt.name, func(t *testing.T) {
82+
err := tt.genKey(tt.fromName, k)
83+
require.NoError(t, err)
84+
f := Factory{
85+
keybase: k,
86+
fromName: tt.fromName,
87+
simulateAndExecute: true,
88+
}
89+
got, err := f.getSimPK()
90+
require.NoError(t, err)
91+
require.IsType(t, tt.wantType, got)
92+
})
93+
}
94+
}
95+
96+
func TestFactory_getSimSignatureData(t *testing.T) {
97+
tests := []struct {
98+
name string
99+
pk types.PubKey
100+
wantType any
101+
}{
102+
{
103+
name: "simple pubkey",
104+
pk: &secp256k1.PubKey{},
105+
wantType: (*signing.SingleSignatureData)(nil),
106+
},
107+
{
108+
name: "multisig pubkey",
109+
pk: &multisig.LegacyAminoPubKey{},
110+
wantType: (*signing.MultiSignatureData)(nil),
111+
},
112+
}
113+
114+
for _, tt := range tests {
115+
t.Run(tt.name, func(t *testing.T) {
116+
got := Factory{}.getSimSignatureData(tt.pk)
117+
require.IsType(t, tt.wantType, got)
118+
})
119+
}
120+
}

0 commit comments

Comments
 (0)