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

feat: implement authority module #1815

Merged
merged 35 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6d87623
iniialize proto
lumtis Feb 27, 2024
cebd1cf
module init
lumtis Feb 27, 2024
3827c5f
typescript init
lumtis Feb 27, 2024
339a950
add authority to app
lumtis Feb 27, 2024
88f7e98
fix import name in app.go
lumtis Feb 27, 2024
844aa7a
policy proto
lumtis Feb 27, 2024
f5452d3
policy proto 21
lumtis Feb 27, 2024
f49dd49
add policies object
lumtis Feb 27, 2024
68063df
add policies query
lumtis Feb 28, 2024
fc6855d
update policies message
lumtis Feb 28, 2024
068d605
type tests
lumtis Feb 28, 2024
699bd5b
keeper test
lumtis Feb 28, 2024
3700159
Merge branch 'develop' into feat/authority
lumtis Feb 28, 2024
0684d0a
initialize is authorized
lumtis Feb 29, 2024
34b8313
Merge branch 'develop' into feat/authority
lumtis Feb 29, 2024
b768231
add authority in test keeper
lumtis Feb 29, 2024
bf5525d
fix keeper
lumtis Feb 29, 2024
7cb4222
changelog
lumtis Feb 29, 2024
5400eb7
use mock for update crosschain flags
lumtis Feb 29, 2024
a03ca7d
refactor observer tests
lumtis Feb 29, 2024
250e6fc
refactor fungible
lumtis Feb 29, 2024
c2de478
initialize crosschain refactoring
lumtis Feb 29, 2024
d4d0510
refactor crosschain tests
lumtis Feb 29, 2024
4d7b101
add governance address for message
lumtis Feb 29, 2024
571e17d
fix e2e tests
lumtis Mar 1, 2024
17fde47
add migration script
lumtis Mar 1, 2024
8e84fb9
add breaking change changelogs
lumtis Mar 1, 2024
f0d702f
goimport
lumtis Mar 1, 2024
4ad7f95
Update x/authority/client/cli/query.go
lumtis Mar 5, 2024
42f62a7
Update x/observer/keeper/msg_server_update_observer.go
lumtis Mar 5, 2024
4fc7c5e
Merge branch 'develop' into feat/authority
lumtis Mar 5, 2024
a922576
rename policy address
lumtis Mar 5, 2024
1f8c17b
Merge branch 'develop' into feat/authority
lumtis Mar 5, 2024
2476e06
add more tests
lumtis Mar 5, 2024
da33217
Merge branch 'develop' into feat/authority
lumtis Mar 5, 2024
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
160 changes: 98 additions & 62 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import (
"github.com/gorilla/mux"
"github.com/rakyll/statik/fs"
"github.com/spf13/cast"
emissionsModule "github.com/zeta-chain/zetacore/x/emissions"
emissionsModuleKeeper "github.com/zeta-chain/zetacore/x/emissions/keeper"
emissionsModuleTypes "github.com/zeta-chain/zetacore/x/emissions/types"

"github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/client"
Expand Down Expand Up @@ -97,13 +94,21 @@ import (
"github.com/zeta-chain/zetacore/docs/openapi"
srvflags "github.com/zeta-chain/zetacore/server/flags"

authoritymodule "github.com/zeta-chain/zetacore/x/authority"
authoritykeeper "github.com/zeta-chain/zetacore/x/authority/keeper"
authoritytypes "github.com/zeta-chain/zetacore/x/authority/types"

crosschainmodule "github.com/zeta-chain/zetacore/x/crosschain"
crosschainkeeper "github.com/zeta-chain/zetacore/x/crosschain/keeper"
crosschaintypes "github.com/zeta-chain/zetacore/x/crosschain/types"

fungibleModule "github.com/zeta-chain/zetacore/x/fungible"
fungibleModuleKeeper "github.com/zeta-chain/zetacore/x/fungible/keeper"
fungibleModuleTypes "github.com/zeta-chain/zetacore/x/fungible/types"
emissionsmodule "github.com/zeta-chain/zetacore/x/emissions"
emissionskeeper "github.com/zeta-chain/zetacore/x/emissions/keeper"
emissionstypes "github.com/zeta-chain/zetacore/x/emissions/types"

fungiblemodule "github.com/zeta-chain/zetacore/x/fungible"
fungiblekeeper "github.com/zeta-chain/zetacore/x/fungible/keeper"
fungibletypes "github.com/zeta-chain/zetacore/x/fungible/types"

observermodule "github.com/zeta-chain/zetacore/x/observer"
observerkeeper "github.com/zeta-chain/zetacore/x/observer/keeper"
Expand Down Expand Up @@ -175,27 +180,28 @@ var (
vesting.AppModuleBasic{},
evm.AppModuleBasic{},
feemarket.AppModuleBasic{},
authoritymodule.AppModuleBasic{},
crosschainmodule.AppModuleBasic{},
observermodule.AppModuleBasic{},
fungibleModule.AppModuleBasic{},
emissionsModule.AppModuleBasic{},
fungiblemodule.AppModuleBasic{},
emissionsmodule.AppModuleBasic{},
groupmodule.AppModuleBasic{},
authzmodule.AppModuleBasic{},
)

// module account permissions
maccPerms = map[string][]string{
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
fungibleModuleTypes.ModuleName: {authtypes.Minter, authtypes.Burner},
emissionsModuleTypes.ModuleName: nil,
emissionsModuleTypes.UndistributedObserverRewardsPool: nil,
emissionsModuleTypes.UndistributedTssRewardsPool: nil,
authtypes.FeeCollectorName: nil,
distrtypes.ModuleName: nil,
stakingtypes.BondedPoolName: {authtypes.Burner, authtypes.Staking},
stakingtypes.NotBondedPoolName: {authtypes.Burner, authtypes.Staking},
govtypes.ModuleName: {authtypes.Burner},
crosschaintypes.ModuleName: {authtypes.Minter, authtypes.Burner},
evmtypes.ModuleName: {authtypes.Minter, authtypes.Burner},
fungibletypes.ModuleName: {authtypes.Minter, authtypes.Burner},
emissionstypes.ModuleName: nil,
emissionstypes.UndistributedObserverRewardsPool: nil,
emissionstypes.UndistributedTssRewardsPool: nil,
}

// module accounts that are NOT allowed to receive tokens
Expand Down Expand Up @@ -226,28 +232,34 @@ type App struct {
tkeys map[string]*storetypes.TransientStoreKey
memKeys map[string]*storetypes.MemoryStoreKey

// keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
mm *module.Manager
sm *module.SimulationManager
configurator module.Configurator

// sdk keepers
AccountKeeper authkeeper.AccountKeeper
BankKeeper bankkeeper.Keeper
StakingKeeper stakingkeeper.Keeper
SlashingKeeper slashingkeeper.Keeper
DistrKeeper distrkeeper.Keeper
GovKeeper govkeeper.Keeper
CrisisKeeper crisiskeeper.Keeper
UpgradeKeeper upgradekeeper.Keeper
ParamsKeeper paramskeeper.Keeper
EvidenceKeeper evidencekeeper.Keeper
GroupKeeper groupkeeper.Keeper
AuthzKeeper authzkeeper.Keeper

// evm keepers
EvmKeeper *evmkeeper.Keeper
FeeMarketKeeper feemarketkeeper.Keeper

// zetachain keepers
AuthorityKeeper authoritykeeper.Keeper
CrosschainKeeper crosschainkeeper.Keeper
ObserverKeeper *observerkeeper.Keeper
mm *module.Manager
sm *module.SimulationManager
configurator module.Configurator
EvmKeeper *evmkeeper.Keeper
FeeMarketKeeper feemarketkeeper.Keeper
FungibleKeeper fungibleModuleKeeper.Keeper
EmissionsKeeper emissionsModuleKeeper.Keeper
GroupKeeper groupkeeper.Keeper
AuthzKeeper authzkeeper.Keeper
FungibleKeeper fungiblekeeper.Keeper
EmissionsKeeper emissionskeeper.Keeper
}

// New returns a reference to an initialized ZetaApp.
Expand Down Expand Up @@ -279,12 +291,14 @@ func New(
group.StoreKey,
upgradetypes.StoreKey,
evidencetypes.StoreKey,
authzkeeper.StoreKey,
evmtypes.StoreKey,
feemarkettypes.StoreKey,
authoritytypes.StoreKey,
crosschaintypes.StoreKey,
observertypes.StoreKey,
evmtypes.StoreKey, feemarkettypes.StoreKey,
fungibleModuleTypes.StoreKey,
emissionsModuleTypes.StoreKey,
authzkeeper.StoreKey,
fungibletypes.StoreKey,
emissionstypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey, evmtypes.TransientKey, feemarkettypes.TransientKey)
memKeys := sdk.NewMemoryStoreKeys()
Expand Down Expand Up @@ -316,10 +330,13 @@ func New(
maccPerms,
sdk.GetConfig().GetBech32AccountAddrPrefix(),
)

logger.Info("bank keeper blocklist addresses", "addresses", app.BlockedAddrs())

app.BankKeeper = bankkeeper.NewBaseKeeper(
appCodec, keys[banktypes.StoreKey], app.AccountKeeper, app.GetSubspace(banktypes.ModuleName), app.BlockedAddrs(),
)

stakingKeeper := stakingkeeper.NewKeeper(
appCodec, keys[stakingtypes.StoreKey], app.AccountKeeper, app.BankKeeper, app.GetSubspace(stakingtypes.ModuleName),
)
Expand All @@ -328,22 +345,33 @@ func New(
appCodec, keys[distrtypes.StoreKey], app.GetSubspace(distrtypes.ModuleName), app.AccountKeeper, app.BankKeeper,
&stakingKeeper, authtypes.FeeCollectorName,
)

app.SlashingKeeper = slashingkeeper.NewKeeper(
appCodec, keys[slashingtypes.StoreKey], &stakingKeeper, app.GetSubspace(slashingtypes.ModuleName),
)

app.CrisisKeeper = crisiskeeper.NewKeeper(
app.GetSubspace(crisistypes.ModuleName), invCheckPeriod, app.BankKeeper, authtypes.FeeCollectorName,
)

app.UpgradeKeeper = upgradekeeper.NewKeeper(skipUpgradeHeights, keys[upgradetypes.StoreKey], appCodec, homePath, app.BaseApp,
authtypes.NewModuleAddress(govtypes.ModuleName).String())

app.AuthorityKeeper = authoritykeeper.NewKeeper(
appCodec,
keys[authoritytypes.StoreKey],
keys[authoritytypes.MemStoreKey],
authtypes.NewModuleAddress(govtypes.ModuleName),
)

app.ObserverKeeper = observerkeeper.NewKeeper(
appCodec,
keys[observertypes.StoreKey],
keys[observertypes.MemStoreKey],
app.GetSubspace(observertypes.ModuleName),
&stakingKeeper,
app.SlashingKeeper,
app.AuthorityKeeper,
)

// register the staking hooks
Expand All @@ -356,19 +384,21 @@ func New(
keys[authzkeeper.StoreKey],
appCodec,
app.MsgServiceRouter(),
app.AccountKeeper)
app.AccountKeeper,
)

app.EmissionsKeeper = *emissionsModuleKeeper.NewKeeper(
app.EmissionsKeeper = *emissionskeeper.NewKeeper(
appCodec,
keys[emissionsModuleTypes.StoreKey],
keys[emissionsModuleTypes.MemStoreKey],
app.GetSubspace(emissionsModuleTypes.ModuleName),
keys[emissionstypes.StoreKey],
keys[emissionstypes.MemStoreKey],
app.GetSubspace(emissionstypes.ModuleName),
authtypes.FeeCollectorName,
app.BankKeeper,
app.StakingKeeper,
app.ObserverKeeper,
app.AccountKeeper,
)

// Create Ethermint keepers
tracer := cast.ToString(appOpts.Get(srvflags.EVMTracer))
feeSs := app.GetSubspace(feemarkettypes.ModuleName)
Expand All @@ -385,15 +415,16 @@ func New(
tracer, evmSs,
)

app.FungibleKeeper = *fungibleModuleKeeper.NewKeeper(
app.FungibleKeeper = *fungiblekeeper.NewKeeper(
appCodec,
keys[fungibleModuleTypes.StoreKey],
keys[fungibleModuleTypes.MemStoreKey],
app.GetSubspace(fungibleModuleTypes.ModuleName),
keys[fungibletypes.StoreKey],
keys[fungibletypes.MemStoreKey],
app.GetSubspace(fungibletypes.ModuleName),
app.AccountKeeper,
app.EvmKeeper,
app.BankKeeper,
app.ObserverKeeper,
app.AuthorityKeeper,
)

app.CrosschainKeeper = *crosschainkeeper.NewKeeper(
Expand All @@ -406,6 +437,7 @@ func New(
app.BankKeeper,
app.ObserverKeeper,
&app.FungibleKeeper,
app.AuthorityKeeper,
)
app.GroupKeeper = groupkeeper.NewKeeper(keys[group.StoreKey], appCodec, app.MsgServiceRouter(), app.AccountKeeper, group.Config{
MaxExecutionPeriod: 2 * time.Hour, // Two hours.
Expand Down Expand Up @@ -476,10 +508,11 @@ func New(
groupmodule.NewAppModule(appCodec, app.GroupKeeper, app.AccountKeeper, app.BankKeeper, interfaceRegistry),
evm.NewAppModule(app.EvmKeeper, app.AccountKeeper, evmSs),
feemarket.NewAppModule(app.FeeMarketKeeper, feeSs),
authoritymodule.NewAppModule(appCodec, app.AuthorityKeeper),
crosschainmodule.NewAppModule(appCodec, app.CrosschainKeeper),
observermodule.NewAppModule(appCodec, *app.ObserverKeeper),
fungibleModule.NewAppModule(appCodec, app.FungibleKeeper),
emissionsModule.NewAppModule(appCodec, app.EmissionsKeeper),
fungiblemodule.NewAppModule(appCodec, app.FungibleKeeper),
emissionsmodule.NewAppModule(appCodec, app.EmissionsKeeper),
authzmodule.NewAppModule(appCodec, app.AuthzKeeper, app.AccountKeeper, app.BankKeeper, app.interfaceRegistry),
)

Expand All @@ -506,9 +539,10 @@ func New(
feemarkettypes.ModuleName,
crosschaintypes.ModuleName,
observertypes.ModuleName,
fungibleModuleTypes.ModuleName,
emissionsModuleTypes.ModuleName,
fungibletypes.ModuleName,
emissionstypes.ModuleName,
authz.ModuleName,
authoritytypes.ModuleName,
)
app.mm.SetOrderEndBlockers(
banktypes.ModuleName,
Expand All @@ -528,9 +562,10 @@ func New(
feemarkettypes.ModuleName,
crosschaintypes.ModuleName,
observertypes.ModuleName,
fungibleModuleTypes.ModuleName,
emissionsModuleTypes.ModuleName,
fungibletypes.ModuleName,
emissionstypes.ModuleName,
authz.ModuleName,
authoritytypes.ModuleName,
)

// NOTE: The genutils module must occur after staking so that pools are
Expand All @@ -557,9 +592,10 @@ func New(
vestingtypes.ModuleName,
observertypes.ModuleName,
crosschaintypes.ModuleName,
fungibleModuleTypes.ModuleName,
emissionsModuleTypes.ModuleName,
fungibletypes.ModuleName,
emissionstypes.ModuleName,
authz.ModuleName,
authoritytypes.ModuleName,
)

app.mm.RegisterInvariants(&app.CrisisKeeper)
Expand Down Expand Up @@ -769,8 +805,8 @@ func initParamsKeeper(appCodec codec.BinaryCodec, legacyAmino *codec.LegacyAmino
paramsKeeper.Subspace(group.ModuleName)
paramsKeeper.Subspace(crosschaintypes.ModuleName)
paramsKeeper.Subspace(observertypes.ModuleName)
paramsKeeper.Subspace(fungibleModuleTypes.ModuleName)
paramsKeeper.Subspace(emissionsModuleTypes.ModuleName)
paramsKeeper.Subspace(fungibletypes.ModuleName)
paramsKeeper.Subspace(emissionstypes.ModuleName)
return paramsKeeper
}

Expand Down
8 changes: 8 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@

## Unreleased

### Breaking Changes

* Admin policies have been moved from `observer` to a new module `authority`.
* Updating admin policies now requires to send a governance proposal executing the `UpdatePolicies` message in the `authority` module.
* The `Policies` query of the `authority` module must be used to get the current admin policies.
* `PolicyType_group1` has been renamed into `PolicyType_groupEmergency` and `PolicyType_group2` has been renamed into `PolicyType_groupAdmin`.

### Refactor

* [1511](https://github.com/zeta-chain/node/pull/1511) - move ballot voting logic from `crosschain` to `observer`
Expand All @@ -15,6 +22,7 @@
### Features

* [1789](https://github.com/zeta-chain/node/issues/1789) - block cross-chain transactions that involve restricted addresses
* [1815](https://github.com/zeta-chain/node/pull/1815) - add authority module for authorized actions

### Tests

Expand Down
2 changes: 2 additions & 0 deletions contrib/localnet/scripts/start-zetacored.sh
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ then
# set admin account
zetacored add-genesis-account zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk 100000000000000000000000000azeta
zetacored add-genesis-account zeta1n0rn6sne54hv7w2uu93fl48ncyqz97d3kty6sh 100000000000000000000000000azeta # Funds the localnet_gov_admin account
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["authority"]["policies"]["items"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][0]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json
cat $HOME/.zetacored/config/genesis.json | jq '.app_state["observer"]["params"]["admin_policy"][1]["address"]="zeta1srsq755t654agc0grpxj4y3w0znktrpr9tcdgk"' > $HOME/.zetacored/config/tmp_genesis.json && mv $HOME/.zetacored/config/tmp_genesis.json $HOME/.zetacored/config/genesis.json

Expand Down
1 change: 1 addition & 0 deletions docs/cli/zetacored/zetacored_query.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ zetacored query [flags]
* [zetacored](zetacored.md) - Zetacore Daemon (server)
* [zetacored query account](zetacored_query_account.md) - Query for account by address
* [zetacored query auth](zetacored_query_auth.md) - Querying commands for the auth module
* [zetacored query authority](zetacored_query_authority.md) - Querying commands for the authority module
* [zetacored query authz](zetacored_query_authz.md) - Querying commands for the authz module
* [zetacored query bank](zetacored_query_bank.md) - Querying commands for the bank module
* [zetacored query block](zetacored_query_block.md) - Get verified data for the block at given height
Expand Down
29 changes: 29 additions & 0 deletions docs/cli/zetacored/zetacored_query_authority.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# query authority

Querying commands for the authority module

```
zetacored query authority [flags]
```

### Options

```
-h, --help help for authority
```

### Options inherited from parent commands

```
--chain-id string The network chain ID
--home string directory for config and data
--log_format string The logging format (json|plain)
--log_level string The logging level (trace|debug|info|warn|error|fatal|panic)
--trace print out full stack trace on errors
```

### SEE ALSO

* [zetacored query](zetacored_query.md) - Querying subcommands
* [zetacored query authority show-policies](zetacored_query_authority_show-policies.md) - show the policies

Loading
Loading