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

[CORE-794] enable authz module to allow granting privileges #960

Merged
merged 12 commits into from
Jan 25, 2024
35 changes: 31 additions & 4 deletions protocol/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ import (
authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper"
authtx "github.com/cosmos/cosmos-sdk/x/auth/tx"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
authz "github.com/cosmos/cosmos-sdk/x/authz"
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 @@ -234,6 +237,7 @@ type App struct {

// keepers
AccountKeeper authkeeper.AccountKeeper
AuthzKeeper authzkeeper.Keeper
BankKeeper bankkeeper.Keeper
CapabilityKeeper *capabilitykeeper.Keeper
StakingKeeper *stakingkeeper.Keeper
Expand Down Expand Up @@ -346,10 +350,20 @@ func New(
bApp.SetTxEncoder(txConfig.TxEncoder())

keys := storetypes.NewKVStoreKeys(
authtypes.StoreKey, banktypes.StoreKey, stakingtypes.StoreKey, crisistypes.StoreKey,
distrtypes.StoreKey, slashingtypes.StoreKey,
govtypes.StoreKey, paramstypes.StoreKey, consensusparamtypes.StoreKey, upgradetypes.StoreKey, feegrant.StoreKey,
ibcexported.StoreKey, ibctransfertypes.StoreKey,
authtypes.StoreKey,
authzkeeper.StoreKey,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

weird this one is not set up in the same way... no authztypes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah not sure how authz was bootstrapped initially, but there is no authz/types and the key is under keeper/keys.go 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looked into this quickly. types got removed in this PR. still not sure why though

banktypes.StoreKey,
stakingtypes.StoreKey,
crisistypes.StoreKey,
distrtypes.StoreKey,
slashingtypes.StoreKey,
govtypes.StoreKey,
paramstypes.StoreKey,
consensusparamtypes.StoreKey,
upgradetypes.StoreKey,
feegrant.StoreKey,
ibcexported.StoreKey,
ibctransfertypes.StoreKey,
ratelimitmoduletypes.StoreKey,
icacontrollertypes.StoreKey,
icahosttypes.StoreKey,
Expand Down Expand Up @@ -429,6 +443,14 @@ func New(
sdk.GetConfig().GetBech32AccountAddrPrefix(),
lib.GovModuleAddress.String(),
)

app.AuthzKeeper = authzkeeper.NewKeeper(
runtime.NewKVStoreService(keys[authzkeeper.StoreKey]),
appCodec,
Comment on lines +451 to +452
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the order of these params is also reversed vs most NewKeeper methods?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah authz always have store key before codec, not sure how it was bootstrapped

app.MsgServiceRouter(),
app.AccountKeeper,
)

app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec,
runtime.NewKVStoreService(keys[banktypes.StoreKey]),
Expand Down Expand Up @@ -987,6 +1009,7 @@ func New(
),
auth.NewAppModule(appCodec, app.AccountKeeper, nil, app.getSubspace(authtypes.ModuleName)),
bank.NewAppModule(appCodec, app.BankKeeper, app.AccountKeeper, app.getSubspace(banktypes.ModuleName)),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
capability.NewAppModule(appCodec, *app.CapabilityKeeper, false),
feegrantmodule.NewAppModule(appCodec, app.AccountKeeper, app.BankKeeper, app.FeeGrantKeeper, app.interfaceRegistry),
crisis.NewAppModule(app.CrisisKeeper, skipGenesisInvariants, app.getSubspace(crisistypes.ModuleName)),
Expand Down Expand Up @@ -1048,6 +1071,7 @@ func New(
// NOTE: staking module is required if HistoricalEntries param > 0
app.ModuleManager.SetOrderBeginBlockers(
blocktimemoduletypes.ModuleName, // Must be first
authz.ModuleName, // Delete expired grants.
epochsmoduletypes.ModuleName,
capabilitytypes.ModuleName,
distrtypes.ModuleName,
Expand Down Expand Up @@ -1116,6 +1140,7 @@ func New(
rewardsmoduletypes.ModuleName,
epochsmoduletypes.ModuleName,
delaymsgmoduletypes.ModuleName,
authz.ModuleName, // No-op.
blocktimemoduletypes.ModuleName, // Must be last
)

Expand Down Expand Up @@ -1157,6 +1182,7 @@ func New(
rewardsmoduletypes.ModuleName,
sendingmoduletypes.ModuleName,
delaymsgmoduletypes.ModuleName,
authz.ModuleName,
)

// NOTE: by default, set migration order here to be the same as init genesis order,
Expand Down Expand Up @@ -1194,6 +1220,7 @@ func New(
rewardsmoduletypes.ModuleName,
sendingmoduletypes.ModuleName,
delaymsgmoduletypes.ModuleName,
authz.ModuleName,

// Auth must be migrated after staking.
authtypes.ModuleName,
Expand Down
2 changes: 2 additions & 0 deletions protocol/app/basic_manager/basic_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"cosmossdk.io/x/upgrade"
"github.com/cosmos/cosmos-sdk/types/module"
"github.com/cosmos/cosmos-sdk/x/auth"
authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module"
"github.com/cosmos/cosmos-sdk/x/bank"
"github.com/cosmos/cosmos-sdk/x/consensus"
"github.com/cosmos/cosmos-sdk/x/crisis"
Expand Down Expand Up @@ -71,6 +72,7 @@ var (
evidence.AppModuleBasic{},
transfer.AppModuleBasic{},
consensus.AppModuleBasic{},
authzmodule.AppModuleBasic{},

// Custom modules
pricesmodule.AppModuleBasic{},
Expand Down
4 changes: 4 additions & 0 deletions protocol/app/upgrades/v4.0.0/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package v_4_0_0
import (
store "cosmossdk.io/store/types"
circuittypes "cosmossdk.io/x/circuit/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
icacontrollertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types"
icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types"
"github.com/dydxprotocol/v4-chain/protocol/app/upgrades"
Expand All @@ -23,6 +24,9 @@ var Upgrade = upgrades.Upgrade{
// Add new ICA stores that are needed by ICA host types as of v8.
icacontrollertypes.StoreKey,
icahosttypes.StoreKey,

// Add authz module to allow granting arbitrary privileges from one account to another acocunt.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there anything else needed in the upgrade to initialize authz state? Is this inherently left empty with no Authorization?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I think this should be empty. there is currently no authorizations since it was not enabled previously

Each Authorization consists of (granter, grantee, msgURL) and permissions needs to be granted explicitly by the granter

authzkeeper.StoreKey,
},
},
}
Loading