From 9f68fc57591e7e5cbef1413aa759e784da932b67 Mon Sep 17 00:00:00 2001 From: TinyFoxy Date: Mon, 10 Jun 2024 03:41:56 +0800 Subject: [PATCH 1/4] refactor(hubl): handle the case when grpc endpoints is nil (#20603) --- tools/hubl/internal/registry.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/tools/hubl/internal/registry.go b/tools/hubl/internal/registry.go index acbf1ef0c60c..a3eea12391e4 100644 --- a/tools/hubl/internal/registry.go +++ b/tools/hubl/internal/registry.go @@ -41,10 +41,8 @@ func GetChainRegistryEntry(chain string) (*ChainRegistryEntry, error) { cleanEntries := make([]*APIEntry, 0) for i, apiEntry := range data.APIs.GRPC { // clean-up the http(s):// prefix - if strings.Contains(apiEntry.Address, "https://") { - data.APIs.GRPC[i].Address = strings.Replace(apiEntry.Address, "https://", "", 1) - } else if strings.Contains(apiEntry.Address, "http://") { - data.APIs.GRPC[i].Address = strings.Replace(apiEntry.Address, "http://", "", 1) + if idx := strings.Index(apiEntry.Address, "://"); idx != -1 { + data.APIs.GRPC[i].Address = apiEntry.Address[idx+3:] } // remove trailing slashes @@ -59,25 +57,29 @@ func GetChainRegistryEntry(chain string) (*ChainRegistryEntry, error) { } data.APIs.GRPC = cleanEntries - fmt.Printf("Found data for %s in the chain registry\n", chain) return data, nil } func SelectGRPCEndpoints(chain string) (string, error) { entry, err := GetChainRegistryEntry(chain) - if err != nil { - fmt.Printf("Unable to load data for %s in the chain registry. Specify a custom gRPC endpoint manually.\n", chain) + if err != nil || len(entry.APIs.GRPC) == 0 { + if err != nil { + // print error here so that user can know what happened and decide what to do next + fmt.Printf("Failed to load data for %s in the chain registry: %v\n", chain, err) + } else { + fmt.Printf("Found empty gRPC endpoint of %s in the chain registry.\n", chain) + } + fmt.Println("Specify a custom gRPC endpoint manually.") prompt := &promptui.Prompt{ Label: "Enter a gRPC endpoint that you trust", } return prompt.Run() } + fmt.Printf("Found data for %s in the chain registry\n", chain) var items []string - if entry != nil { - for _, apiEntry := range entry.APIs.GRPC { - items = append(items, fmt.Sprintf("%s: %s", apiEntry.Provider, apiEntry.Address)) - } + for _, apiEntry := range entry.APIs.GRPC { + items = append(items, fmt.Sprintf("%s: %s", apiEntry.Provider, apiEntry.Address)) } prompt := promptui.SelectWithAdd{ Label: fmt.Sprintf("Select a gRPC endpoint that you trust for the %s network", chain), From efea5db29b71770282343842337cf02e2879b088 Mon Sep 17 00:00:00 2001 From: Marko Date: Sun, 9 Jun 2024 22:13:25 +0200 Subject: [PATCH 2/4] refactor(distribution)!: add cometinfo (#20588) --- simapp/app.go | 2 +- .../distribution/keeper/msg_server_test.go | 3 ++- x/distribution/CHANGELOG.md | 4 +++- x/distribution/depinject.go | 9 ++++++--- x/distribution/keeper/abci.go | 16 ++++++++++------ x/distribution/keeper/allocation_test.go | 15 +++++++++++++++ x/distribution/keeper/delegation_test.go | 9 +++++++++ x/distribution/keeper/keeper.go | 13 +++++++++++-- x/distribution/keeper/keeper_test.go | 1 + .../migrations/v4/migrate_funds_test.go | 9 +++++++++ 10 files changed, 67 insertions(+), 14 deletions(-) diff --git a/simapp/app.go b/simapp/app.go index 2c9340db04bf..2f3046cefce5 100644 --- a/simapp/app.go +++ b/simapp/app.go @@ -357,7 +357,7 @@ func NewSimApp( app.PoolKeeper = poolkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), logger.With(log.ModuleKey, "x/protocolpool")), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String()) - app.DistrKeeper = distrkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[distrtypes.StoreKey]), logger.With(log.ModuleKey, "x/distribution")), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) + app.DistrKeeper = distrkeeper.NewKeeper(appCodec, runtime.NewEnvironment(runtime.NewKVStoreService(keys[distrtypes.StoreKey]), logger.With(log.ModuleKey, "x/distribution")), app.AuthKeeper, app.BankKeeper, app.StakingKeeper, app.PoolKeeper, cometService, authtypes.FeeCollectorName, authtypes.NewModuleAddress(govtypes.ModuleName).String()) app.SlashingKeeper = slashingkeeper.NewKeeper(runtime.NewEnvironment(runtime.NewKVStoreService(keys[slashingtypes.StoreKey]), logger.With(log.ModuleKey, "x/slashing")), appCodec, legacyAmino, app.StakingKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), diff --git a/tests/integration/distribution/keeper/msg_server_test.go b/tests/integration/distribution/keeper/msg_server_test.go index 4bf6d47e6c77..89d31409ac11 100644 --- a/tests/integration/distribution/keeper/msg_server_test.go +++ b/tests/integration/distribution/keeper/msg_server_test.go @@ -137,7 +137,7 @@ func initFixture(t *testing.T) *fixture { poolKeeper := poolkeeper.NewKeeper(cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[pooltypes.StoreKey]), log.NewNopLogger()), accountKeeper, bankKeeper, stakingKeeper, authority.String()) distrKeeper := distrkeeper.NewKeeper( - cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[distrtypes.StoreKey]), logger), accountKeeper, bankKeeper, stakingKeeper, poolKeeper, distrtypes.ModuleName, authority.String(), + cdc, runtime.NewEnvironment(runtime.NewKVStoreService(keys[distrtypes.StoreKey]), logger), accountKeeper, bankKeeper, stakingKeeper, poolKeeper, cometService, distrtypes.ModuleName, authority.String(), ) authModule := auth.NewAppModule(cdc, accountKeeper, acctsModKeeper, authsims.RandomGenesisAccounts) @@ -163,6 +163,7 @@ func initFixture(t *testing.T) *fixture { }, }, }, + ProposerAddress: valConsAddr, }) integrationApp := integration.NewIntegrationApp(ctx, logger, keys, cdc, diff --git a/x/distribution/CHANGELOG.md b/x/distribution/CHANGELOG.md index d48ad2a679ef..ad37c21997b0 100644 --- a/x/distribution/CHANGELOG.md +++ b/x/distribution/CHANGELOG.md @@ -31,6 +31,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### API Breaking Changes + +* [#20588](https://github.com/cosmos/cosmos-sdk/pull/20588) `x/distribution` now takes cometService in order to get consensus related information. * [#19868](https://github.com/cosmos/cosmos-sdk/pull/19868) Removes Accounts String method * `NewMsgSetWithdrawAddress` now takes strings as argument instead of `sdk.AccAddress`. * `NewGenesisState` now takes a string as argument instead of `sdk.ConsAddress`. @@ -74,4 +76,4 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes -* [#19301](https://github.com/cosmos/cosmos-sdk/pull/19301) Fix vulnerability in `incrementReferenceCount` in distribution. \ No newline at end of file +* [#19301](https://github.com/cosmos/cosmos-sdk/pull/19301) Fix vulnerability in `incrementReferenceCount` in distribution. diff --git a/x/distribution/depinject.go b/x/distribution/depinject.go index 299f750c60c7..ddd6c64b33b3 100644 --- a/x/distribution/depinject.go +++ b/x/distribution/depinject.go @@ -3,6 +3,7 @@ package distribution import ( modulev1 "cosmossdk.io/api/cosmos/distribution/module/v1" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/comet" "cosmossdk.io/depinject" "cosmossdk.io/depinject/appconfig" authtypes "cosmossdk.io/x/auth/types" @@ -27,9 +28,10 @@ func init() { type ModuleInputs struct { depinject.In - Config *modulev1.Module - Environment appmodule.Environment - Cdc codec.Codec + Config *modulev1.Module + Environment appmodule.Environment + Cdc codec.Codec + CometService comet.Service AccountKeeper types.AccountKeeper BankKeeper types.BankKeeper @@ -69,6 +71,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs { in.BankKeeper, in.StakingKeeper, in.PoolKeeper, + in.CometService, feeCollectorName, authorityAddr, ) diff --git a/x/distribution/keeper/abci.go b/x/distribution/keeper/abci.go index 60d1aea984a9..46ee8561a6a9 100644 --- a/x/distribution/keeper/abci.go +++ b/x/distribution/keeper/abci.go @@ -1,6 +1,8 @@ package keeper import ( + "context" + "cosmossdk.io/x/distribution/types" "github.com/cosmos/cosmos-sdk/telemetry" @@ -10,24 +12,26 @@ import ( // BeginBlocker sets the proposer for determining distribution during endblock // and distribute rewards for the previous block. // TODO: use context.Context after including the comet service -func (k Keeper) BeginBlocker(ctx sdk.Context) error { +func (k Keeper) BeginBlocker(ctx context.Context) error { defer telemetry.ModuleMeasureSince(types.ModuleName, telemetry.Now(), telemetry.MetricKeyBeginBlocker) // determine the total power signing the block var previousTotalPower int64 - for _, vote := range ctx.CometInfo().LastCommit.Votes { + header := k.HeaderService.HeaderInfo(ctx) + ci := k.cometService.CometInfo(ctx) + for _, vote := range ci.LastCommit.Votes { previousTotalPower += vote.Validator.Power } // TODO this is Tendermint-dependent // ref https://github.com/cosmos/cosmos-sdk/issues/3095 - if ctx.BlockHeight() > 1 { - if err := k.AllocateTokens(ctx, previousTotalPower, ctx.CometInfo().LastCommit.Votes); err != nil { + if header.Height > 1 { + if err := k.AllocateTokens(ctx, previousTotalPower, ci.LastCommit.Votes); err != nil { return err } // every 1000 blocks send whole coins from decimal pool to community pool - if ctx.BlockHeight()%1000 == 0 { + if header.Height%1000 == 0 { if err := k.sendDecimalPoolToCommunityPool(ctx); err != nil { return err } @@ -35,6 +39,6 @@ func (k Keeper) BeginBlocker(ctx sdk.Context) error { } // record the proposer for when we payout on the next block - consAddr := sdk.ConsAddress(ctx.BlockHeader().ProposerAddress) + consAddr := sdk.ConsAddress(ci.ProposerAddress) return k.PreviousProposer.Set(ctx, consAddr) } diff --git a/x/distribution/keeper/allocation_test.go b/x/distribution/keeper/allocation_test.go index d22341717a33..1729a3982010 100644 --- a/x/distribution/keeper/allocation_test.go +++ b/x/distribution/keeper/allocation_test.go @@ -1,6 +1,7 @@ package keeper_test import ( + "context" "testing" "time" @@ -28,6 +29,17 @@ import ( moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) +var _ comet.Service = (*emptyCometService)(nil) + +type emptyCometService struct{} + +// CometInfo implements comet.Service. +func (e *emptyCometService) CometInfo(context.Context) comet.Info { + return comet.Info{} +} + +var testCometService = &emptyCometService{} + func TestAllocateTokensToValidatorWithCommission(t *testing.T) { ctrl := gomock.NewController(t) key := storetypes.NewKVStoreKey(disttypes.StoreKey) @@ -58,6 +70,7 @@ func TestAllocateTokensToValidatorWithCommission(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) @@ -124,6 +137,7 @@ func TestAllocateTokensToManyValidators(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) @@ -264,6 +278,7 @@ func TestAllocateTokensTruncation(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) diff --git a/x/distribution/keeper/delegation_test.go b/x/distribution/keeper/delegation_test.go index e3d8c0547b07..f1bae825e36d 100644 --- a/x/distribution/keeper/delegation_test.go +++ b/x/distribution/keeper/delegation_test.go @@ -54,6 +54,7 @@ func TestCalculateRewardsBasic(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) @@ -167,6 +168,7 @@ func TestCalculateRewardsAfterSlash(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) @@ -283,6 +285,7 @@ func TestCalculateRewardsAfterManySlashes(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) @@ -420,6 +423,7 @@ func TestCalculateRewardsMultiDelegator(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) @@ -530,6 +534,7 @@ func TestWithdrawDelegationRewardsBasic(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) @@ -618,6 +623,7 @@ func TestCalculateRewardsAfterManySlashesInSameBlock(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) @@ -747,6 +753,7 @@ func TestCalculateRewardsMultiDelegatorMultiSlash(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) @@ -900,6 +907,7 @@ func TestCalculateRewardsMultiDelegatorMultWithdraw(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) @@ -1114,6 +1122,7 @@ func Test100PercentCommissionReward(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) diff --git a/x/distribution/keeper/keeper.go b/x/distribution/keeper/keeper.go index 58f141ca0e33..e2bada2b9d8e 100644 --- a/x/distribution/keeper/keeper.go +++ b/x/distribution/keeper/keeper.go @@ -8,6 +8,7 @@ import ( "cosmossdk.io/collections" collcodec "cosmossdk.io/collections/codec" "cosmossdk.io/core/appmodule" + "cosmossdk.io/core/comet" "cosmossdk.io/core/event" errorsmod "cosmossdk.io/errors" "cosmossdk.io/x/distribution/types" @@ -21,6 +22,8 @@ import ( type Keeper struct { appmodule.Environment + cometService comet.Service + cdc codec.BinaryCodec authKeeper types.AccountKeeper bankKeeper types.BankKeeper @@ -57,8 +60,13 @@ type Keeper struct { // NewKeeper creates a new distribution Keeper instance func NewKeeper( - cdc codec.BinaryCodec, env appmodule.Environment, - ak types.AccountKeeper, bk types.BankKeeper, sk types.StakingKeeper, pk types.PoolKeeper, + cdc codec.BinaryCodec, + env appmodule.Environment, + ak types.AccountKeeper, + bk types.BankKeeper, + sk types.StakingKeeper, + pk types.PoolKeeper, + cometService comet.Service, feeCollectorName, authority string, ) Keeper { // ensure distribution module account is set @@ -69,6 +77,7 @@ func NewKeeper( sb := collections.NewSchemaBuilder(env.KVStoreService) k := Keeper{ Environment: env, + cometService: cometService, cdc: cdc, authKeeper: ak, bankKeeper: bk, diff --git a/x/distribution/keeper/keeper_test.go b/x/distribution/keeper/keeper_test.go index 074ca1c3fc1e..7833762a3b0e 100644 --- a/x/distribution/keeper/keeper_test.go +++ b/x/distribution/keeper/keeper_test.go @@ -70,6 +70,7 @@ func initFixture(t *testing.T) (sdk.Context, []sdk.AccAddress, keeper.Keeper, de bankKeeper, stakingKeeper, poolKeeper, + testCometService, "fee_collector", authorityAddr, ) diff --git a/x/distribution/migrations/v4/migrate_funds_test.go b/x/distribution/migrations/v4/migrate_funds_test.go index d8b61c6cb1e3..e801040009a2 100644 --- a/x/distribution/migrations/v4/migrate_funds_test.go +++ b/x/distribution/migrations/v4/migrate_funds_test.go @@ -7,6 +7,7 @@ import ( "github.com/golang/mock/gomock" "github.com/stretchr/testify/require" + "cosmossdk.io/core/comet" "cosmossdk.io/log" storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/auth" @@ -31,6 +32,13 @@ import ( moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" ) +type emptyCometService struct{} + +// CometInfo implements comet.Service. +func (e *emptyCometService) CometInfo(context.Context) comet.Info { + return comet.Info{} +} + func TestFundsMigration(t *testing.T) { keys := storetypes.NewKVStoreKeys( authtypes.StoreKey, banktypes.StoreKey, disttypes.StoreKey, @@ -90,6 +98,7 @@ func TestFundsMigration(t *testing.T) { bankKeeper, stakingKeeper, poolKeeper, + &emptyCometService{}, disttypes.ModuleName, authority, ) From 7d68ba2cb8662d881a8c4846a793137fc78cb281 Mon Sep 17 00:00:00 2001 From: Julien Robert Date: Mon, 10 Jun 2024 09:29:28 +0200 Subject: [PATCH 3/4] chore: bring patch changelogs to main (#20599) --- CHANGELOG.md | 32 +++++++++++++++++++++++++++++--- x/upgrade/CHANGELOG.md | 5 +++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3773d6e78ab1..21784defaa04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,9 +61,9 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (client) [#19870](https://github.com/cosmos/cosmos-sdk/pull/19870) Add new query command `wait-tx`. Alias `event-query-tx-for` to `wait-tx` for backward compatibility. * (crypto/keyring) [#20212](https://github.com/cosmos/cosmos-sdk/pull/20212) Expose the db keyring used in the keystore. * (genutil) [#19971](https://github.com/cosmos/cosmos-sdk/pull/19971) Allow manually setting the consensus key type in genesis -* (debug) [#20328](https://github.com/cosmos/cosmos-sdk/pull/20328) Add consensus address for debug cmd. ### Improvements + * (bank) [#20354](https://github.com/cosmos/cosmos-sdk/pull/20354) Reduce the number of `ValidateDenom` calls in `bank.SendCoins`. * (types) [#19869](https://github.com/cosmos/cosmos-sdk/pull/19869) Removed `Any` type from `codec/types` and replaced it with an alias for `cosmos/gogoproto/types/any`. * (server) [#19854](https://github.com/cosmos/cosmos-sdk/pull/19854) Add customizability to start command. @@ -114,8 +114,6 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (server) [#18994](https://github.com/cosmos/cosmos-sdk/pull/18994) Update server context directly rather than a reference to a sub-object * [#19833](https://github.com/cosmos/cosmos-sdk/pull/19833) Fix some places in which we call Remove inside a Walk. * [#19851](https://github.com/cosmos/cosmos-sdk/pull/19851) Fix some places in which we call Remove inside a Walk (x/staking and x/gov). -* (cli) [#20020](https://github.com/cosmos/cosmos-sdk/pull/20020) Make bootstrap-state command support both new and legacy genesis format. -* (baseapp) [#20107](https://github.com/cosmos/cosmos-sdk/pull/20107) Allow height overwrite BlockHeight in header. ### API Breaking Changes @@ -202,6 +200,23 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (simapp) [#19146](https://github.com/cosmos/cosmos-sdk/pull/19146) Replace `--v` CLI option with `--validator-count`/`-n`. * (module) [#19370](https://github.com/cosmos/cosmos-sdk/pull/19370) Deprecate `module.Configurator`, use `appmodule.HasMigrations` and `appmodule.HasServices` instead from Core API. +## [v0.50.7](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.7) - 2024-06-04 + +### Improvements + +* (debug) [#20328](https://github.com/cosmos/cosmos-sdk/pull/20328) Add consensus address for debug cmd. +* (runtime) [#20264](https://github.com/cosmos/cosmos-sdk/pull/20264) Expose grpc query router via depinject. +* (x/consensus) [#20381](https://github.com/cosmos/cosmos-sdk/pull/20381) Use Comet utility for consensus module consensus param updates. +* (client) [#20356](https://github.com/cosmos/cosmos-sdk/pull/20356) Overwrite client context when available in `SetCmdClientContext`. + +### Bug Fixes + +* (baseapp) [#20346](https://github.com/cosmos/cosmos-sdk/pull/20346) Correctly assign `execModeSimulate` to context for `simulateTx`. +* (baseapp) [#20144](https://github.com/cosmos/cosmos-sdk/pull/20144) Remove txs from mempool when AnteHandler fails in recheck. +* (baseapp) [#20107](https://github.com/cosmos/cosmos-sdk/pull/20107) Avoid header height overwrite block height. +* (cli) [#20020](https://github.com/cosmos/cosmos-sdk/pull/20020) Make bootstrap-state command support both new and legacy genesis format. +* (testutil/sims) [#20151](https://github.com/cosmos/cosmos-sdk/pull/20151) Set all signatures and don't overwrite the previous one in `GenSignedMockTx`. + ## [v0.50.6](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.6) - 2024-04-22 ### Features @@ -666,6 +681,17 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (x/staking) [#14567](https://github.com/cosmos/cosmos-sdk/pull/14567) The `delegator_address` field of `MsgCreateValidator` has been deprecated. The validator address bytes and delegator address bytes refer to the same account while creating validator (defer only in bech32 notation). +## [v0.47.12](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.12) - 2024-06-10 + +## Improvements + +* (x/authz,x/feegrant) [#20590](https://github.com/cosmos/cosmos-sdk/pull/20590) Provide updated keeper in depinject for authz and feegrant modules. + +### Bug Fixes + +* (baseapp) [#20144](https://github.com/cosmos/cosmos-sdk/pull/20144) Remove txs from mempool when AnteHandler fails in recheck. +* (testutil/sims) [#20151](https://github.com/cosmos/cosmos-sdk/pull/20151) Set all signatures and don't overwrite the previous one in `GenSignedMockTx`. + ## [v0.47.11](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.47.11) - 2024-04-22 ### Bug Fixes diff --git a/x/upgrade/CHANGELOG.md b/x/upgrade/CHANGELOG.md index 35113c3611b7..c098e5a24827 100644 --- a/x/upgrade/CHANGELOG.md +++ b/x/upgrade/CHANGELOG.md @@ -37,6 +37,11 @@ Ref: https://keepachangelog.com/en/1.0.0/ * (x/upgrade) [#16244](https://github.com/cosmos/cosmos-sdk/pull/16244) Upgrade module no longer stores the app version but gets and sets the app version stored in the `ParamStore` of baseapp. +## [v0.1.3](https://github.com/cosmos/cosmos-sdk/releases/tag/x/upgrade/v0.1.3) - 2024-06-04 + +* (deps) [#20530](https://github.com/cosmos/cosmos-sdk/pull/20530) Bump vulnerable `github.com/hashicorp/go-getter` to v1.7.4. + * In theory, we do not need a new release for this, but we are doing it as `x/upgrade` is used in Cosmovisor. + ## [v0.1.2](https://github.com/cosmos/cosmos-sdk/releases/tag/x/upgrade/v0.1.2) - 2024-04-22 ### Improvements From e799965ec88532799868a62c5a8bbaeb7caba645 Mon Sep 17 00:00:00 2001 From: testinginprod <98415576+testinginprod@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:55:23 +0200 Subject: [PATCH 4/4] feat(stf): port simappv2 changes (#20587) Co-authored-by: unknown unknown --- server/v2/stf/branch/writer_map.go | 40 +++++++++++++++++++++++----- server/v2/stf/core_router_service.go | 24 +++++++++++------ server/v2/stf/stf.go | 26 +++++++++++++----- 3 files changed, 68 insertions(+), 22 deletions(-) diff --git a/server/v2/stf/branch/writer_map.go b/server/v2/stf/branch/writer_map.go index b624a4d2532c..8e7edf0e4104 100644 --- a/server/v2/stf/branch/writer_map.go +++ b/server/v2/stf/branch/writer_map.go @@ -53,21 +53,47 @@ func (b WriterMap) ApplyStateChanges(stateChanges []store.StateChanges) error { return nil } +// GetStateChanges returns the state changes for all actors in the WriterMap, including all direct +// ancesotors from which this WriterMap was derived. +// See WriterMap.recurseStateChanges for more details. +// Subject to possible renaming to ensure a developer can retrieve only changes in *this* branch +// context (not ancestors) if that is desired. +// see: https://github.com/cosmos/cosmos-sdk/pull/20412#discussion_r1618771230 func (b WriterMap) GetStateChanges() ([]store.StateChanges, error) { - sc := make([]store.StateChanges, len(b.branchedWriterState)) - for account, stateChange := range b.branchedWriterState { - kvChanges, err := stateChange.ChangeSets() - if err != nil { - return nil, err - } + var ( + changes = make(map[string][]store.KVPair) + sc []store.StateChanges + ) + if err := b.recurseStateChanges(changes); err != nil { + return nil, err + } + + for account, kvPairs := range changes { sc = append(sc, store.StateChanges{ Actor: []byte(account), - StateChanges: kvChanges, + StateChanges: kvPairs, }) } return sc, nil } +func (b WriterMap) recurseStateChanges(changes map[string][]store.KVPair) error { + // depth first + if wr, ok := b.state.(WriterMap); ok { + if err := wr.recurseStateChanges(changes); err != nil { + return err + } + } + for account, stateChange := range b.branchedWriterState { + kvChanges, err := stateChange.ChangeSets() + if err != nil { + return err + } + changes[account] = append(changes[account], kvChanges...) + } + return nil +} + func (b WriterMap) applyStateChange(sc store.StateChanges) error { writableState, err := b.GetWriter(sc.Actor) if err != nil { diff --git a/server/v2/stf/core_router_service.go b/server/v2/stf/core_router_service.go index f64e90cc285d..15da47e87cdc 100644 --- a/server/v2/stf/core_router_service.go +++ b/server/v2/stf/core_router_service.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "reflect" "strings" "google.golang.org/protobuf/runtime/protoiface" @@ -61,14 +62,8 @@ func (m *msgRouterService) InvokeUntyped(ctx context.Context, msg protoiface.Mes // NewQueryRouterService implements router.Service. func NewQueryRouterService(queryRouterBuilder *MsgRouterBuilder) router.Service { - queryRouter, err := queryRouterBuilder.Build() - if err != nil { - panic(fmt.Errorf("cannot create queryRouter: %w", err)) - } - return &queryRouterService{ builder: queryRouterBuilder, - handler: queryRouter, } } @@ -100,8 +95,21 @@ func (m *queryRouterService) InvokeTyped( ctx context.Context, req, resp protoiface.MessageV1, ) error { - // see https://github.com/cosmos/cosmos-sdk/pull/20349 - panic("not implemented") + // TODO lazy initialization is ugly and not thread safe. we don't want to check a mutex on every InvokeTyped either. + if m.handler == nil { + var err error + m.handler, err = m.builder.Build() + if err != nil { + return fmt.Errorf("cannot create queryRouter: %w", err) + } + } + // reflection is required, see https://github.com/cosmos/cosmos-sdk/pull/20349 + res, err := m.handler(ctx, req) + if err != nil { + return err + } + reflect.Indirect(reflect.ValueOf(resp)).Set(reflect.Indirect(reflect.ValueOf(res))) + return nil } // InvokeUntyped execute a message and returns a response. diff --git a/server/v2/stf/stf.go b/server/v2/stf/stf.go index 4848a8c765ab..fd6d434c91c6 100644 --- a/server/v2/stf/stf.go +++ b/server/v2/stf/stf.go @@ -7,6 +7,7 @@ import ( appmanager "cosmossdk.io/core/app" appmodulev2 "cosmossdk.io/core/appmodule/v2" + corecontext "cosmossdk.io/core/context" "cosmossdk.io/core/event" "cosmossdk.io/core/gas" "cosmossdk.io/core/header" @@ -17,6 +18,9 @@ import ( "cosmossdk.io/server/v2/stf/internal" ) +// Identity defines STF's bytes identity and it's used by STF to store things in its own state. +var Identity = []byte("stf") + // STF is a struct that manages the state transition component of the app. type STF[T transaction.Tx] struct { logger log.Logger @@ -108,10 +112,15 @@ func (s STF[T]) DeliverBlock( // reset events exCtx.events = make([]event.Event, 0) + // begin block - beginBlockEvents, err := s.beginBlock(exCtx) - if err != nil { - return nil, nil, err + var beginBlockEvents []event.Event + if !block.IsGenesis { + // begin block + beginBlockEvents, err = s.beginBlock(exCtx) + if err != nil { + return nil, nil, err + } } // check if we need to return early @@ -401,11 +410,13 @@ func (s STF[T]) validatorUpdates( return ctx.events, valSetUpdates, nil } -const headerInfoPrefix = 0x0 +const headerInfoPrefix = 0x37 // setHeaderInfo sets the header info in the state to be used by queries in the future. func (s STF[T]) setHeaderInfo(state store.WriterMap, headerInfo header.Info) error { - runtimeStore, err := state.GetWriter(appmanager.RuntimeIdentity) + // TODO storing header info is too low level here, stf should be stateless. + // We should have a keeper that does this. + runtimeStore, err := state.GetWriter(Identity) if err != nil { return err } @@ -422,7 +433,7 @@ func (s STF[T]) setHeaderInfo(state store.WriterMap, headerInfo header.Info) err // getHeaderInfo gets the header info from the state. It should only be used for queries func (s STF[T]) getHeaderInfo(state store.WriterMap) (i header.Info, err error) { - runtimeStore, err := state.GetWriter(appmanager.RuntimeIdentity) + runtimeStore, err := state.GetWriter(Identity) if err != nil { return header.Info{}, err } @@ -579,11 +590,12 @@ func (s STF[T]) makeContext( store store.WriterMap, execMode transaction.ExecMode, ) *executionContext { + valuedCtx := context.WithValue(ctx, corecontext.ExecModeKey, execMode) return newExecutionContext( s.makeGasMeter, s.makeGasMeteredState, s.branchFn, - ctx, + valuedCtx, sender, store, execMode,