Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add message router interface #15035

Merged
merged 5 commits into from
Feb 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/staking) [#14590](https://github.com/cosmos/cosmos-sdk/pull/14590) Return undelegate amount in MsgUndelegateResponse
* (tools) [#14793](https://github.com/cosmos/cosmos-sdk/pull/14793) Dockerfile optimization.
* (cli) [#14953](https://github.com/cosmos/cosmos-sdk/pull/14953) Enable profiling block replay during abci handshake with `--cpu-profile`.
* (baseapp) [#15023](https://github.com/cosmos/cosmos-sdk/pull/15023) Add `MessageRouter` interface to baseapp and pass it to authz instead of concrete type.

### State Machine Breaking

Expand Down
7 changes: 7 additions & 0 deletions baseapp/msg_service_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ import (
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)

// MessageRouter ADR 031 request type routing
// https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-031-msg-service.md
type MessageRouter interface {
Handler(msg sdk.Msg) MsgServiceHandler
HandlerByTypeURL(typeURL string) MsgServiceHandler
}

// MsgServiceRouter routes fully-qualified Msg service methods to their handler.
type MsgServiceRouter struct {
interfaceRegistry codectypes.InterfaceRegistry
Expand Down
4 changes: 2 additions & 2 deletions x/authz/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ const gasCostPerIteration = uint64(20)
type Keeper struct {
storeKey storetypes.StoreKey
cdc codec.BinaryCodec
router *baseapp.MsgServiceRouter
router baseapp.MessageRouter
authKeeper authz.AccountKeeper
}

// NewKeeper constructs a message authorization Keeper
func NewKeeper(storeKey storetypes.StoreKey, cdc codec.BinaryCodec, router *baseapp.MsgServiceRouter, ak authz.AccountKeeper) Keeper {
func NewKeeper(storeKey storetypes.StoreKey, cdc codec.BinaryCodec, router baseapp.MessageRouter, ak authz.AccountKeeper) Keeper {
return Keeper{
storeKey: storeKey,
cdc: cdc,
Expand Down
2 changes: 1 addition & 1 deletion x/authz/module/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ type AuthzInputs struct {
AccountKeeper authz.AccountKeeper
BankKeeper authz.BankKeeper
Registry cdctypes.InterfaceRegistry
MsgServiceRouter *baseapp.MsgServiceRouter
MsgServiceRouter baseapp.MessageRouter
}

//nolint:revive
Expand Down
4 changes: 2 additions & 2 deletions x/gov/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ type Keeper struct {
legacyRouter v1beta1.Router

// Msg server router
router *baseapp.MsgServiceRouter
router baseapp.MessageRouter

config types.Config

Expand Down Expand Up @@ -126,7 +126,7 @@ func (k Keeper) Logger(ctx sdk.Context) log.Logger {
}

// Router returns the gov keeper's router
func (k Keeper) Router() *baseapp.MsgServiceRouter {
func (k Keeper) Router() baseapp.MessageRouter {
return k.router
}

Expand Down
4 changes: 2 additions & 2 deletions x/group/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ type Keeper struct {
voteByProposalIndex orm.Index
voteByVoterIndex orm.Index

router *baseapp.MsgServiceRouter
router baseapp.MessageRouter

config group.Config
}

// NewKeeper creates a new group keeper.
func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router *baseapp.MsgServiceRouter, accKeeper group.AccountKeeper, config group.Config) Keeper {
func NewKeeper(storeKey storetypes.StoreKey, cdc codec.Codec, router baseapp.MessageRouter, accKeeper group.AccountKeeper, config group.Config) Keeper {
k := Keeper{
key: storeKey,
router: router,
Expand Down
2 changes: 1 addition & 1 deletion x/group/keeper/proposal_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (

// doExecuteMsgs routes the messages to the registered handlers. Messages are limited to those that require no authZ or
// by the account of group policy only. Otherwise this gives access to other peoples accounts as the sdk middlewares are bypassed
func (s Keeper) doExecuteMsgs(ctx sdk.Context, router *baseapp.MsgServiceRouter, proposal group.Proposal, groupPolicyAcc sdk.AccAddress, decisionPolicy group.DecisionPolicy) ([]sdk.Result, error) {
func (s Keeper) doExecuteMsgs(ctx sdk.Context, router baseapp.MessageRouter, proposal group.Proposal, groupPolicyAcc sdk.AccAddress, decisionPolicy group.DecisionPolicy) ([]sdk.Result, error) {
// Ensure it's not too early to execute the messages.
minExecutionDate := proposal.SubmitTime.Add(decisionPolicy.GetMinExecutionPeriod())
if ctx.BlockTime().Before(minExecutionDate) {
Expand Down