-
Notifications
You must be signed in to change notification settings - Fork 133
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
Changes from 6 commits
01ef875
3cc63a5
247a97f
e1b924f
030a4be
76adfd6
287efa5
46e0f31
9ff75f7
902985d
697482c
07ce065
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -234,6 +237,7 @@ type App struct { | |
|
||
// keepers | ||
AccountKeeper authkeeper.AccountKeeper | ||
AuthzKeeper authzkeeper.Keeper | ||
BankKeeper bankkeeper.Keeper | ||
CapabilityKeeper *capabilitykeeper.Keeper | ||
StakingKeeper *stakingkeeper.Keeper | ||
|
@@ -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, | ||
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, | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the order of these params is also reversed vs most There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah |
||
app.MsgServiceRouter(), | ||
app.AccountKeeper, | ||
) | ||
|
||
app.BankKeeper = bankkeeper.NewBaseKeeper( | ||
appCodec, | ||
runtime.NewKVStoreService(keys[banktypes.StoreKey]), | ||
|
@@ -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)), | ||
|
@@ -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. | ||
jayy04 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
epochsmoduletypes.ModuleName, | ||
capabilitytypes.ModuleName, | ||
distrtypes.ModuleName, | ||
|
@@ -1116,6 +1140,7 @@ func New( | |
rewardsmoduletypes.ModuleName, | ||
epochsmoduletypes.ModuleName, | ||
delaymsgmoduletypes.ModuleName, | ||
authz.ModuleName, // No-op. | ||
blocktimemoduletypes.ModuleName, // Must be last | ||
) | ||
|
||
|
@@ -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, | ||
|
@@ -1194,6 +1220,7 @@ func New( | |
rewardsmoduletypes.ModuleName, | ||
sendingmoduletypes.ModuleName, | ||
delaymsgmoduletypes.ModuleName, | ||
authz.ModuleName, | ||
|
||
// Auth must be migrated after staking. | ||
authtypes.ModuleName, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,17 @@ package msgs | |
|
||
import ( | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/cosmos/cosmos-sdk/x/authz" | ||
gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
) | ||
|
||
var ( | ||
// NestedMsgSamples are msgs that have can include other arbitrary messages inside. | ||
NestedMsgSamples = map[string]sdk.Msg{ | ||
// authz | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so this PR also updates nested messages verification (see this commit). see
|
||
"/cosmos.authz.v1beta1.MsgExec": &authz.MsgExec{}, | ||
"/cosmos.authz.v1beta1.MsgExecResponse": nil, | ||
|
||
// gov | ||
"/cosmos.gov.v1.MsgSubmitProposal": &gov.MsgSubmitProposal{}, | ||
"/cosmos.gov.v1.MsgSubmitProposalResponse": nil, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,9 @@ | |
}, | ||
"accounts": [] | ||
}, | ||
"authz": { | ||
"authorization": [] | ||
}, | ||
"bank": { | ||
"params": { | ||
"send_enabled": [], | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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" | ||
|
@@ -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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there anything else needed in the upgrade to initialize There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
authzkeeper.StoreKey, | ||
}, | ||
}, | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"fmt" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
authz "github.com/cosmos/cosmos-sdk/x/authz" | ||
gov "github.com/cosmos/cosmos-sdk/x/gov/types/v1" | ||
) | ||
|
||
|
@@ -12,6 +13,8 @@ func IsNestedMsg(msg sdk.Msg) bool { | |
switch msg.(type) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good callout. I think so since it also wraps other messages. Let's add this in a separate PR since it's unrelated. I also have less context on delay messages so maybe one of the OTE eng can pick this up? |
||
case | ||
// ------- CosmosSDK default modules | ||
// authz | ||
*authz.MsgExec, | ||
// gov | ||
*gov.MsgSubmitProposal: | ||
return true | ||
|
@@ -45,6 +48,8 @@ func getInnerMsgs(msg sdk.Msg) ([]sdk.Msg, error) { | |
case | ||
*gov.MsgSubmitProposal: | ||
return msg.GetMsgs() | ||
case *authz.MsgExec: | ||
return msg.GetMessages() | ||
default: | ||
return nil, fmt.Errorf("unsupported msg type: %T", msg) | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,18 @@ func TestValidateNestedMsg(t *testing.T) { | |
msg: testmsgs.MsgSubmitProposalWithDoubleNestedInner, | ||
expectedErr: invalidInnerMsgErr_Nested, | ||
}, | ||
"Invalid MsgExec: unsupported inner msg": { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we add a testcase for the dydx custom msg types? |
||
msg: &testmsgs.MsgExecWithUnsupportedInner, | ||
expectedErr: invalidInnerMsgErr_Unsupported, | ||
}, | ||
"Invalid MsgExec: app-injected inner msg": { | ||
msg: &testmsgs.MsgExecWithAppInjectedInner, | ||
expectedErr: invalidInnerMsgErr_AppInjected, | ||
}, | ||
"Invalid MsgExec: double-nested inner msg": { | ||
msg: &testmsgs.MsgExecWithDoubleNestedInner, | ||
expectedErr: invalidInnerMsgErr_Nested, | ||
}, | ||
"Valid: empty inner msg": { | ||
msg: testmsgs.MsgSubmitProposalWithEmptyInner, | ||
expectedErr: nil, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: should we add test cases for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree this would be valuable to have 👍 |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ | |
"tx_size_cost_per_byte": "10" | ||
} | ||
}, | ||
"authz": { | ||
"authorization": [] | ||
}, | ||
"bank": { | ||
"balances": [ | ||
{ | ||
|
There was a problem hiding this comment.
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
?There was a problem hiding this comment.
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 noauthz/types
and the key is underkeeper/keys.go
😕There was a problem hiding this comment.
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