Skip to content

Commit

Permalink
Merge branch 'main' into dependabot/go_modules/log/github.com/bytedan…
Browse files Browse the repository at this point in the history
…ce/sonic-1.12.7
  • Loading branch information
mergify[bot] authored Jan 14, 2025
2 parents 065b451 + 64e8280 commit f86e2e0
Show file tree
Hide file tree
Showing 18 changed files with 124 additions and 45 deletions.
20 changes: 17 additions & 3 deletions UPGRADING.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,23 @@ Accounts's AccountNumber will be used as a global account number tracking replac
```go
import authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
...
err := authkeeper.MigrateAccountNumberUnsafe(ctx, &app.AuthKeeper)
if err != nil {
return nil, err
app.UpgradeKeeper.SetUpgradeHandler(planName,
func(ctx context.Context, _ upgradetypes.Plan, fromVM appmodule.VersionMap) (appmodule.VersionMap, error) {
if err := authkeeper.MigrateAccountNumberUnsafe(ctx, &app.AuthKeeper); err != nil {
return nil, err
}
return app.ModuleManager.RunMigrations(ctx, app.configurator, fromVM)
},
)
```

Add `x/accounts` store while upgrading to v0.52.x:

```go
storetypes.StoreUpgrades{
Added: []string{
accounts.StoreKey,
},
}
```

Expand Down
2 changes: 1 addition & 1 deletion baseapp/abci_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2204,7 +2204,7 @@ func TestABCI_ProcessProposal_PanicRecovery(t *testing.T) {
})
}

// TestABCI_Proposal_Reset_State ensures that state is reset between runs of
// TestABCI_Proposal_Reset_State_Between_Calls ensures that state is reset between runs of
// PrepareProposal and ProcessProposal in case they are called multiple times.
// This is only valid for heights > 1, given that on height 1 we always set the
// state to be deliverState.
Expand Down
2 changes: 1 addition & 1 deletion client/v2/tx/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func encodeTextTx(tx Tx) ([]byte, error) {
return textMarshalOptions.Marshal(wTx.Tx)
}

// decodeJsonTx decodes transaction bytes into an apitx.Tx structure using JSON format.
// decodeTextTx decodes transaction bytes into an apitx.Tx structure using TEXT format.
func decodeTextTx(cdc codec.BinaryCodec, decoder Decoder) txDecoder {
return func(txBytes []byte) (Tx, error) {
jsonTx := new(txv1beta1.Tx)
Expand Down
19 changes: 4 additions & 15 deletions core/header/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package header

import (
"crypto/sha256"
"slices"
"testing"
"time"
)
Expand Down Expand Up @@ -29,7 +30,7 @@ func TestInfo_Bytes(t *testing.T) {
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if !bytesEqual(expectedBytes, bytes) {
if !slices.Equal(expectedBytes, bytes) {
t.Errorf("expected bytes %v, got %v", expectedBytes, bytes)
}
}
Expand All @@ -54,28 +55,16 @@ func TestInfo_FromBytes(t *testing.T) {
if info.Height != 12345 {
t.Errorf("expected Height %d, got %d", 12345, info.Height)
}
if !bytesEqual([]byte{0x26, 0xb0, 0xb8, 0x3e, 0x72, 0x81, 0xbe, 0x3b, 0x11, 0x76, 0x58, 0xb6, 0xf2, 0x63, 0x6d, 0x3, 0x68, 0xca, 0xd3, 0xd7, 0x4f, 0x22, 0x24, 0x34, 0x28, 0xf5, 0x40, 0x1a, 0x4b, 0x70, 0x89, 0x7e}, info.Hash) {
if !slices.Equal([]byte{0x26, 0xb0, 0xb8, 0x3e, 0x72, 0x81, 0xbe, 0x3b, 0x11, 0x76, 0x58, 0xb6, 0xf2, 0x63, 0x6d, 0x3, 0x68, 0xca, 0xd3, 0xd7, 0x4f, 0x22, 0x24, 0x34, 0x28, 0xf5, 0x40, 0x1a, 0x4b, 0x70, 0x89, 0x7e}, info.Hash) {
t.Errorf("expected Hash %v, got %v", []byte{0x26, 0xb0, 0xb8, 0x3e, 0x72, 0x81, 0xbe, 0x3b, 0x11, 0x76, 0x58, 0xb6, 0xf2, 0x63, 0x6d, 0x3, 0x68, 0xca, 0xd3, 0xd7, 0x4f, 0x22, 0x24, 0x34, 0x28, 0xf5, 0x40, 0x1a, 0x4b, 0x70, 0x89, 0x7e}, info.Hash)
}
if info.Time != time.Date(2024, time.January, 1, 0, 0, 0, 0, time.UTC) {
t.Errorf("expected Time %v, got %v", time.Date(2024, time.January, 1, 0, 0, 0, 0, time.UTC), info.Time)
}
if !bytesEqual([]byte{0x26, 0xb0, 0xb8, 0x3e, 0x72, 0x81, 0xbe, 0x3b, 0x11, 0x76, 0x58, 0xb6, 0xf2, 0x63, 0x6d, 0x3, 0x68, 0xca, 0xd3, 0xd7, 0x4f, 0x22, 0x24, 0x34, 0x28, 0xf5, 0x40, 0x1a, 0x4b, 0x70, 0x89, 0x7e}, info.AppHash) {
if !slices.Equal([]byte{0x26, 0xb0, 0xb8, 0x3e, 0x72, 0x81, 0xbe, 0x3b, 0x11, 0x76, 0x58, 0xb6, 0xf2, 0x63, 0x6d, 0x3, 0x68, 0xca, 0xd3, 0xd7, 0x4f, 0x22, 0x24, 0x34, 0x28, 0xf5, 0x40, 0x1a, 0x4b, 0x70, 0x89, 0x7e}, info.AppHash) {
t.Errorf("expected AppHash %v, got %v", []byte{0x26, 0xb0, 0xb8, 0x3e, 0x72, 0x81, 0xbe, 0x3b, 0x11, 0x76, 0x58, 0xb6, 0xf2, 0x63, 0x6d, 0x3, 0x68, 0xca, 0xd3, 0xd7, 0x4f, 0x22, 0x24, 0x34, 0x28, 0xf5, 0x40, 0x1a, 0x4b, 0x70, 0x89, 0x7e}, info.AppHash)
}
if info.ChainID != "test-chain" {
t.Errorf("expected ChainID %s, got %s", "test-chain", info.ChainID)
}
}

func bytesEqual(a, b []byte) bool {
if len(a) != len(b) {
return false
}
for i := range a {
if a[i] != b[i] {
return false
}
}
return true
}
2 changes: 1 addition & 1 deletion crypto/ledger/ledger_secp256k1.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ func getPubKeyUnsafe(device SECP256K1, path hd.BIP44Params) (types.PubKey, error
return options.createPubkey(compressedPublicKey), nil
}

// getPubKeyAddr reads the pubkey and the address from a ledger device.
// getPubKeyAddrSafe reads the pubkey and the address from a ledger device.
// This function is marked as Safe as it will require user confirmation and
// account and index will be shown in the device.
//
Expand Down
4 changes: 4 additions & 0 deletions depinject/appconfig/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ var Register = RegisterModule
// will be injected into the container and can be requested by a provider
// function. All module initialization should be handled by the provided options.
//
// In some cases, a module may need to be manually overwritten from the global module
// registry. This can be done by calling RegisterModule again with the same config,
// but different options. This is useful when wrapping or overriding default modules.
//
// Protobuf message types used for module configuration should define the
// cosmos.app.v1alpha.module option and must explicitly specify go_package
// to make debugging easier for users.
Expand Down
4 changes: 2 additions & 2 deletions schema/appdata/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ func ListenerMux(listeners ...Listener) Listener {
}

mux.onBatch = func(batch PacketBatch) error {
for _, listener := range listeners {
err := batch.apply(&listener)
for i := range listeners {
err := batch.apply(&listeners[i])
if err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions server/v2/cometbft/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (c *consensus[T]) handleQueryP2P(path []string) (*abci.QueryResponse, error
return c.idPeerFilter(arg)
}
}
return &abci.QueryResponse{}, nil
}

return nil, errorsmod.Wrap(cometerrors.ErrUnknownRequest, "expected second parameter to be 'filter'")
Expand Down
7 changes: 0 additions & 7 deletions simapp/v2/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@ import (
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/store"
"cosmossdk.io/runtime/v2"
"cosmossdk.io/x/accounts"
bankv2types "cosmossdk.io/x/bank/v2/types"
epochstypes "cosmossdk.io/x/epochs/types"
protocolpooltypes "cosmossdk.io/x/protocolpool/types"
upgradetypes "cosmossdk.io/x/upgrade/types"
)

Expand Down Expand Up @@ -37,12 +34,8 @@ func (app *SimApp[T]) RegisterUpgradeHandlers() {
if upgradeInfo.Name == UpgradeName && !app.UpgradeKeeper.IsSkipHeight(upgradeInfo.Height) {
storeUpgrades := store.StoreUpgrades{
Added: []string{
accounts.StoreKey,
protocolpooltypes.StoreKey,
epochstypes.StoreKey,
bankv2types.ModuleName,
},
Deleted: []string{"crisis"}, // The SDK discontinued the crisis module in v0.52.0
}

app.SetStoreLoader(runtime.UpgradeStoreLoader(upgradeInfo.Height, &storeUpgrades))
Expand Down
4 changes: 1 addition & 3 deletions store/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,7 @@ func (cmgr *CommitKVStoreCacheManager) Reset() {
// Clear the map.
// Please note that we are purposefully using the map clearing idiom.
// See https://github.com/cosmos/cosmos-sdk/issues/6681.
for key := range cmgr.caches {
delete(cmgr.caches, key)
}
clear(cmgr.caches)
}

// CacheWrap implements the CacheWrapper interface
Expand Down
12 changes: 3 additions & 9 deletions store/cachekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,8 @@ func (store *Store) resetCaches() {
// Clear the cache using the map clearing idiom
// and not allocating fresh objects.
// Please see https://bencher.orijtech.com/perfclinic/mapclearing/
for key := range store.cache {
delete(store.cache, key)
}
for key := range store.unsortedCache {
delete(store.unsortedCache, key)
}
clear(store.cache)
clear(store.unsortedCache)
}
store.sortedCache = internal.NewBTree()
}
Expand Down Expand Up @@ -369,9 +365,7 @@ func (store *Store) dirtyItems(start, end []byte) {
func (store *Store) clearUnsortedCacheSubset(unsorted []*kv.Pair, sortState sortState) { //nolint:staticcheck // We are in store v1.
n := len(store.unsortedCache)
if len(unsorted) == n { // This pattern allows the Go compiler to emit the map clearing idiom for the entire map.
for key := range store.unsortedCache {
delete(store.unsortedCache, key)
}
clear(store.unsortedCache)
} else { // Otherwise, normally delete the unsorted keys from the map.
for _, kv := range unsorted {
delete(store.unsortedCache, conv.UnsafeBytesToStr(kv.Key))
Expand Down
2 changes: 1 addition & 1 deletion tests/systemtests/upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestChainUpgrade(t *testing.T) {

const (
upgradeHeight int64 = 22
upgradeName = "v052-to-v054" // must match UpgradeName in simapp/upgrades.go
upgradeName = "v052-to-v2" // must match UpgradeName in simapp/upgrades.go
)

systest.Sut.StartChain(t, fmt.Sprintf("--comet.halt-height=%d", upgradeHeight+1))
Expand Down
25 changes: 25 additions & 0 deletions testutil/sims/state_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,23 @@ func AppStateFn(
addressCodec, validatorCodec address.Codec,
modules []module.AppModuleSimulation,
genesisState map[string]json.RawMessage,
) simtypes.AppStateFn {
return AppStateFnWithExtendedCbs(cdc, addressCodec, validatorCodec, modules, genesisState, nil, nil)
}

// AppStateFnWithExtendedCbs returns the initial application state using a genesis or the simulation parameters.
// It panics if the user provides files for both of them.
// If a file is not given for the genesis or the sim params, it creates a randomized one.
// genesisState is the default genesis state of the whole app.
// moduleStateCb is the callback function to access moduleState.
// postRawStateCb is the callback function to extend rawState.
func AppStateFnWithExtendedCbs(
cdc codec.JSONCodec,
addressCodec, validatorCodec address.Codec,
modules []module.AppModuleSimulation,
genesisState map[string]json.RawMessage,
moduleStateCb func(moduleName string, genesisState interface{}),
postRawStateCb func(rawState map[string]json.RawMessage),
) simtypes.AppStateFn {
return func(
r *rand.Rand,
Expand Down Expand Up @@ -143,9 +160,17 @@ func AppStateFn(
stakingtypes.ModuleName: stakingState,
testutil.BankModuleName: bankState,
} {
if moduleStateCb != nil {
moduleStateCb(name, state)
}
rawState[name] = cdc.MustMarshalJSON(state)
}

// extend state from callback function
if postRawStateCb != nil {
postRawStateCb(rawState)
}

// replace appstate
appState, err = json.Marshal(rawState)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions x/upgrade/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ Ref: https://keepachangelog.com/en/1.0.0/

## [Unreleased]

### Bug Fixes
* (x/upgrade) [#23179](https://github.com/cosmos/cosmos-sdk/pull/23179) Register missing implementation for SoftwareUpgradeProposal to avoid no concrete type registered for type URL /cosmos.upgrade.v1beta1.SoftwareUpgradeProposal against interface *v1beta1.Content error.

## [v0.2.0-rc.1](https://github.com/cosmos/cosmos-sdk/releases/tag/x/upgrade/v0.2.0-rc.1) - 2024-12-18

### Improvements
Expand Down
2 changes: 1 addition & 1 deletion x/upgrade/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ require (
cosmossdk.io/log v1.5.0
cosmossdk.io/store v1.10.0-rc.1
cosmossdk.io/x/gov v0.0.0-20231113122742-912390d5fc4a
cosmossdk.io/x/tx v1.0.0
github.com/cometbft/cometbft v1.0.0
github.com/cometbft/cometbft/api v1.0.0
github.com/cosmos/cosmos-proto v1.0.0-beta.5
Expand Down Expand Up @@ -46,7 +47,6 @@ require (
cosmossdk.io/schema v1.0.0 // indirect
cosmossdk.io/x/bank v0.0.0-20240226161501-23359a0b6d91 // indirect
cosmossdk.io/x/staking v0.0.0-00010101000000-000000000000 // indirect
cosmossdk.io/x/tx v1.0.0 // indirect
filippo.io/edwards25519 v1.1.0 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.2 // indirect
Expand Down
6 changes: 5 additions & 1 deletion x/upgrade/types/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package types
import (
"cosmossdk.io/core/registry"
coretransaction "cosmossdk.io/core/transaction"
"cosmossdk.io/x/gov/types/v1beta1"

"github.com/cosmos/cosmos-sdk/codec/legacy"
"github.com/cosmos/cosmos-sdk/types/msgservice"
Expand All @@ -23,6 +24,9 @@ func RegisterInterfaces(registrar registry.InterfaceRegistrar) {
&MsgSoftwareUpgrade{},
&MsgCancelUpgrade{},
)

registrar.RegisterImplementations(
(*v1beta1.Content)(nil),
&SoftwareUpgradeProposal{},
)
msgservice.RegisterMsgServiceDesc(registrar, &_Msg_serviceDesc)
}
33 changes: 33 additions & 0 deletions x/upgrade/types/codec_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package types

import (
"testing"

proto "github.com/cosmos/gogoproto/proto"
gogoprotoany "github.com/cosmos/gogoproto/types/any"
"github.com/stretchr/testify/require"

"cosmossdk.io/x/gov/types/v1beta1"
"cosmossdk.io/x/tx/signing"

codectestutil "github.com/cosmos/cosmos-sdk/codec/testutil"
"github.com/cosmos/cosmos-sdk/codec/types"
)

func TestInterfaceRegistrationOfContent(t *testing.T) {
opts := codectestutil.CodecOptions{}
registrar, err := types.NewInterfaceRegistryWithOptions(types.InterfaceRegistryOptions{
ProtoFiles: proto.HybridResolver,
SigningOptions: signing.Options{
AddressCodec: opts.GetAddressCodec(),
ValidatorAddressCodec: opts.GetValidatorCodec(),
},
})
require.NoError(t, err)
RegisterInterfaces(registrar)
val := &gogoprotoany.Any{
TypeUrl: "/cosmos.upgrade.v1beta1.SoftwareUpgradeProposal",
Value: []byte{},
}
require.NoError(t, registrar.UnpackAny(val, new(v1beta1.Content)))
}
21 changes: 21 additions & 0 deletions x/upgrade/types/proposal.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package types

import (
"cosmossdk.io/x/gov/types"
"cosmossdk.io/x/gov/types/v1beta1"
)

// GetTitle returns the proposal title
func (sp *SoftwareUpgradeProposal) GetTitle() string { return sp.Title }

// GetDescription returns the proposal description
func (sp *SoftwareUpgradeProposal) GetDescription() string { return sp.Description }

// ProposalRoute returns the proposal router key
func (sp *SoftwareUpgradeProposal) ProposalRoute() string { return types.RouterKey }

// ProposalType is "Text"
func (sp *SoftwareUpgradeProposal) ProposalType() string { return v1beta1.ProposalTypeText }

// ValidateBasic validates the content's title and description of the proposal
func (sp *SoftwareUpgradeProposal) ValidateBasic() error { return v1beta1.ValidateAbstract(sp) }

0 comments on commit f86e2e0

Please sign in to comment.