Skip to content

Commit

Permalink
Merge pull request #1160 from lavanet/CNS-828-add-authz-module
Browse files Browse the repository at this point in the history
CNS-828: adding Authz module
  • Loading branch information
Yaroms authored Jan 25, 2024
2 parents 4aa23e7 + 2bb39f0 commit d710b85
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
12 changes: 12 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/cosmos/cosmos-sdk/client/grpc/node"
"github.com/cosmos/cosmos-sdk/runtime"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/x/authz"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
v1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
Expand Down Expand Up @@ -44,6 +45,8 @@ import (
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
"github.com/cosmos/cosmos-sdk/x/auth/vesting"
vestingtypes "github.com/cosmos/cosmos-sdk/x/auth/vesting/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
Expand Down Expand Up @@ -237,6 +240,7 @@ var (
plansmodule.AppModuleBasic{},
downtimemodule.AppModuleBasic{},
rewardsmodule.AppModuleBasic{},
authzmodule.AppModuleBasic{},
// this line is used by starport scaffolding # stargate/app/moduleBasic
)

Expand Down Expand Up @@ -344,6 +348,7 @@ func New(
plansmoduletypes.StoreKey,
downtimemoduletypes.StoreKey,
rewardsmoduletypes.StoreKey,
authzkeeper.StoreKey,
// this line is used by starport scaffolding # stargate/app/storeKey
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
Expand Down Expand Up @@ -407,6 +412,7 @@ func New(
)

app.FeeGrantKeeper = feegrantkeeper.NewKeeper(appCodec, keys[feegrant.StoreKey], app.AccountKeeper)
app.AuthzKeeper = authzkeeper.NewKeeper(keys[authzkeeper.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper)
app.UpgradeKeeper = *upgradekeeper.NewKeeper(
skipUpgradeHeights,
keys[upgradetypes.StoreKey],
Expand Down Expand Up @@ -684,6 +690,7 @@ func New(
staking.NewAppModule(appCodec, app.StakingKeeper, app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName)),
upgrade.NewAppModule(&app.UpgradeKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
ibc.NewAppModule(app.IBCKeeper),
params.NewAppModule(app.ParamsKeeper),
transferModule,
Expand Down Expand Up @@ -726,6 +733,7 @@ func New(
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
authz.ModuleName,
icatypes.ModuleName,
specmoduletypes.ModuleName,
epochstoragemoduletypes.ModuleName,
Expand Down Expand Up @@ -754,6 +762,7 @@ func New(
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
authz.ModuleName,
icatypes.ModuleName,
specmoduletypes.ModuleName,
epochstoragemoduletypes.ModuleName,
Expand Down Expand Up @@ -794,6 +803,7 @@ func New(
evidencetypes.ModuleName,
ibctransfertypes.ModuleName,
ibcexported.ModuleName,
authz.ModuleName,
icatypes.ModuleName,
specmoduletypes.ModuleName,
subscriptionmoduletypes.ModuleName,
Expand Down Expand Up @@ -833,6 +843,7 @@ func New(
params.NewAppModule(app.ParamsKeeper),
evidence.NewAppModule(app.EvidenceKeeper),
ibc.NewAppModule(app.IBCKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
transferModule,
specModule,
epochstorageModule,
Expand Down Expand Up @@ -1073,6 +1084,7 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(plansmoduletypes.ModuleName)
paramsKeeper.Subspace(downtimemoduletypes.ModuleName)
paramsKeeper.Subspace(rewardsmoduletypes.ModuleName)
paramsKeeper.Subspace(authz.ModuleName)
// this line is used by starport scaffolding # stargate/app/paramSubspace

return paramsKeeper
Expand Down
2 changes: 2 additions & 0 deletions app/keepers/lavaKeepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keepers

import (
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
capabilitykeeper "github.com/cosmos/cosmos-sdk/x/capability/keeper"
consensusparamkeeper "github.com/cosmos/cosmos-sdk/x/consensus/keeper"
Expand Down Expand Up @@ -69,5 +70,6 @@ type LavaKeepers struct {
DowntimeKeeper downtimemodulekeeper.Keeper
RewardsKeeper rewardsmodulekeeper.Keeper
ConsensusParamsKeeper consensusparamkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
ICAHostKeeper icahostkeeper.Keeper
}
13 changes: 7 additions & 6 deletions app/upgrades/empty_upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
store "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
minttypes "github.com/cosmos/cosmos-sdk/x/mint/types"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
icacontrollertypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/controller/types"
Expand Down Expand Up @@ -190,12 +191,6 @@ var Upgrade_0_32_3 = Upgrade{
StoreUpgrades: store.StoreUpgrades{},
}

var Upgrade_0_35_0 = Upgrade{
UpgradeName: "v0.35.0",
CreateUpgradeHandler: v_35_0,
StoreUpgrades: store.StoreUpgrades{},
}

var Upgrade_0_33_0 = Upgrade{
UpgradeName: "v0.33.0",
CreateUpgradeHandler: defaultUpgradeHandler,
Expand All @@ -209,3 +204,9 @@ var Upgrade_0_34_0 = Upgrade{
Added: []string{icahosttypes.StoreKey, icacontrollertypes.StoreKey},
},
}

var Upgrade_0_35_0 = Upgrade{
UpgradeName: "v0.35.0",
CreateUpgradeHandler: v_35_0,
StoreUpgrades: store.StoreUpgrades{Added: []string{authzkeeper.StoreKey}},
}
40 changes: 36 additions & 4 deletions x/dualstaking/ante/ante_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/cosmos/cosmos-sdk/x/authz"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
"github.com/lavanet/lava/utils"
"github.com/lavanet/lava/x/dualstaking/keeper"
)

Expand All @@ -20,9 +22,40 @@ func NewRedelegationFlager(dualstaking keeper.Keeper) RedelegationFlager {
}

func (rf RedelegationFlager) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate bool, next sdk.AnteHandler) (newCtx sdk.Context, err error) {
msgs, err := rf.unwrapAuthz(tx)
if err != nil {
return ctx, err
}

err = rf.disableRedelegationHooks(ctx, msgs)
if err != nil {
return ctx, err
}

return next(ctx, tx, simulate)
}

func (rf RedelegationFlager) unwrapAuthz(tx sdk.Tx) ([]sdk.Msg, error) {
var unwrappedMsgs []sdk.Msg
for _, txMsg := range tx.GetMsgs() {
if authzMsg, ok := txMsg.(*authz.MsgExec); ok {
msgs, err := authzMsg.GetMessages()
if err != nil {
return nil, utils.LavaFormatError("could not unwrap authz from msgs", err)
}
unwrappedMsgs = append(unwrappedMsgs, msgs...)
} else {
unwrappedMsgs = append(unwrappedMsgs, txMsg)
}
}

return unwrappedMsgs, nil
}

func (rf RedelegationFlager) disableRedelegationHooks(ctx sdk.Context, msgs []sdk.Msg) error {
redelegations := false
others := false
for _, msg := range tx.GetMsgs() {
for _, msg := range msgs {
if _, ok := msg.(*stakingtypes.MsgBeginRedelegate); ok {
redelegations = true
} else {
Expand All @@ -31,10 +64,9 @@ func (rf RedelegationFlager) AnteHandle(ctx sdk.Context, tx sdk.Tx, simulate boo
}

if redelegations && others {
return ctx, fmt.Errorf("cannot send batch requests with redelegation messages")
return utils.LavaFormatWarning("could not disable redelegation hooks", fmt.Errorf("cannot send batch requests with redelegation messages"))
}

keeper.DisableDualstakingHook = redelegations

return next(ctx, tx, simulate)
return nil
}

0 comments on commit d710b85

Please sign in to comment.