Skip to content

Commit

Permalink
Merge branch 'main' into hoa/refactor-defer
Browse files Browse the repository at this point in the history
  • Loading branch information
hoank101 authored Jun 10, 2024
2 parents 7c3d613 + e799965 commit e198b46
Show file tree
Hide file tree
Showing 16 changed files with 182 additions and 50 deletions.
32 changes: 29 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
40 changes: 33 additions & 7 deletions server/v2/stf/branch/writer_map.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 16 additions & 8 deletions server/v2/stf/core_router_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"errors"
"fmt"
"reflect"
"strings"

"google.golang.org/protobuf/runtime/protoiface"
Expand Down Expand Up @@ -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,
}
}

Expand Down Expand Up @@ -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.
Expand Down
26 changes: 19 additions & 7 deletions server/v2/stf/stf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion simapp/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion tests/integration/distribution/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -163,6 +163,7 @@ func initFixture(t *testing.T) *fixture {
},
},
},
ProposerAddress: valConsAddr,
})

integrationApp := integration.NewIntegrationApp(ctx, logger, keys, cdc,
Expand Down
24 changes: 13 additions & 11 deletions tools/hubl/internal/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion x/distribution/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -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.
* [#19301](https://github.com/cosmos/cosmos-sdk/pull/19301) Fix vulnerability in `incrementReferenceCount` in distribution.
9 changes: 6 additions & 3 deletions x/distribution/depinject.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -69,6 +71,7 @@ func ProvideModule(in ModuleInputs) ModuleOutputs {
in.BankKeeper,
in.StakingKeeper,
in.PoolKeeper,
in.CometService,
feeCollectorName,
authorityAddr,
)
Expand Down
Loading

0 comments on commit e198b46

Please sign in to comment.