Skip to content

Commit

Permalink
feat: dyncomm module (#355)
Browse files Browse the repository at this point in the history
Co-authored-by: alchemist-ti <[email protected]>
Co-authored-by: StrathCole <[email protected]>
Co-authored-by: nghuyenthevinh2000 <[email protected]>
  • Loading branch information
4 people authored Nov 4, 2023
1 parent 3802b9a commit 95b9728
Show file tree
Hide file tree
Showing 40 changed files with 4,303 additions and 17 deletions.
16 changes: 15 additions & 1 deletion app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,10 @@ import (
v3 "github.com/classic-terra/core/v2/app/upgrades/v3"
v4 "github.com/classic-terra/core/v2/app/upgrades/v4"
v5 "github.com/classic-terra/core/v2/app/upgrades/v5"
v6 "github.com/classic-terra/core/v2/app/upgrades/v6"

customante "github.com/classic-terra/core/v2/custom/auth/ante"
custompost "github.com/classic-terra/core/v2/custom/auth/post"
customauthtx "github.com/classic-terra/core/v2/custom/auth/tx"

"github.com/CosmWasm/wasmd/x/wasm"
Expand All @@ -64,7 +66,7 @@ var (
DefaultNodeHome string

// Upgrades defines upgrades to be applied to the network
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade, v5.Upgrade}
Upgrades = []upgrades.Upgrade{v2.Upgrade, v3.Upgrade, v4.Upgrade, v5.Upgrade, v6.Upgrade}

// Forks defines forks to be applied to the network
Forks = []upgrades.Fork{}
Expand Down Expand Up @@ -210,13 +212,25 @@ func NewTerraApp(
GovKeeper: app.GovKeeper,
WasmConfig: &wasmConfig,
TXCounterStoreKey: app.GetKey(wasm.StoreKey),
DyncommKeeper: app.DyncommKeeper,
StakingKeeper: app.StakingKeeper,
},
)
if err != nil {
panic(err)
}

postHandler, err := custompost.NewPostHandler(
custompost.HandlerOptions{
DyncommKeeper: app.DyncommKeeper,
},
)
if err != nil {
panic(err)
}

app.SetAnteHandler(anteHandler)
app.SetPostHandler(postHandler)
app.SetEndBlocker(app.EndBlocker)

if loadLatest {
Expand Down
12 changes: 12 additions & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ import (
customwasmkeeper "github.com/classic-terra/core/v2/custom/wasm/keeper"
terrawasm "github.com/classic-terra/core/v2/wasmbinding"

dyncommkeeper "github.com/classic-terra/core/v2/x/dyncomm/keeper"
dyncommtypes "github.com/classic-terra/core/v2/x/dyncomm/types"
marketkeeper "github.com/classic-terra/core/v2/x/market/keeper"
markettypes "github.com/classic-terra/core/v2/x/market/types"
oraclekeeper "github.com/classic-terra/core/v2/x/oracle/keeper"
Expand Down Expand Up @@ -92,6 +94,7 @@ type AppKeepers struct {
MarketKeeper marketkeeper.Keeper
TreasuryKeeper treasurykeeper.Keeper
WasmKeeper wasmkeeper.Keeper
DyncommKeeper dyncommkeeper.Keeper

// make scoped keepers public for test purposes
ScopedIBCKeeper capabilitykeeper.ScopedKeeper
Expand Down Expand Up @@ -137,6 +140,7 @@ func NewAppKeepers(
markettypes.StoreKey,
treasurytypes.StoreKey,
wasmtypes.StoreKey,
dyncommtypes.StoreKey,
)
tkeys := sdk.NewTransientStoreKeys(paramstypes.TStoreKey)
memKeys := sdk.NewMemoryStoreKeys(capabilitytypes.MemStoreKey)
Expand Down Expand Up @@ -407,6 +411,13 @@ func NewAppKeepers(
govConfig,
)

appKeepers.DyncommKeeper = dyncommkeeper.NewKeeper(
appCodec,
appKeepers.keys[dyncommtypes.StoreKey],
appKeepers.GetSubspace(dyncommtypes.ModuleName),
appKeepers.StakingKeeper,
)

appKeepers.ScopedIBCKeeper = scopedIBCKeeper
appKeepers.ScopedICAHostKeeper = scopedICAHostKeeper
appKeepers.ScopedICAControllerKeeper = scopedICAControllerKeeper
Expand Down Expand Up @@ -442,6 +453,7 @@ func initParamsKeeper(
paramsKeeper.Subspace(oracletypes.ModuleName)
paramsKeeper.Subspace(treasurytypes.ModuleName)
paramsKeeper.Subspace(wasmtypes.ModuleName)
paramsKeeper.Subspace(dyncommtypes.ModuleName)

return paramsKeeper
}
Expand Down
8 changes: 8 additions & 0 deletions app/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ import (
"github.com/CosmWasm/wasmd/x/wasm"
wasmclient "github.com/CosmWasm/wasmd/x/wasm/client"
wasmtypes "github.com/CosmWasm/wasmd/x/wasm/types"
"github.com/classic-terra/core/v2/x/dyncomm"
dyncommtypes "github.com/classic-terra/core/v2/x/dyncomm/types"
"github.com/classic-terra/core/v2/x/market"
markettypes "github.com/classic-terra/core/v2/x/market/types"
"github.com/classic-terra/core/v2/x/oracle"
Expand Down Expand Up @@ -121,6 +123,7 @@ var (
treasury.AppModuleBasic{},
customwasm.AppModuleBasic{},
ibcfee.AppModuleBasic{},
dyncomm.AppModuleBasic{},
)

// module account permissions
Expand Down Expand Up @@ -182,6 +185,7 @@ func appModules(
oracle.NewAppModule(appCodec, app.OracleKeeper, app.AccountKeeper, app.BankKeeper),
treasury.NewAppModule(appCodec, app.TreasuryKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
dyncomm.NewAppModule(appCodec, app.DyncommKeeper, app.StakingKeeper),
}
}

Expand Down Expand Up @@ -213,6 +217,7 @@ func simulationModules(
market.NewAppModule(appCodec, app.MarketKeeper, app.AccountKeeper, app.BankKeeper, app.OracleKeeper),
treasury.NewAppModule(appCodec, app.TreasuryKeeper),
wasm.NewAppModule(appCodec, &app.WasmKeeper, app.StakingKeeper, app.AccountKeeper, app.BankKeeper),
dyncomm.NewAppModule(appCodec, app.DyncommKeeper, app.StakingKeeper),
}
}

Expand Down Expand Up @@ -243,6 +248,7 @@ func orderBeginBlockers() []string {
treasurytypes.ModuleName,
markettypes.ModuleName,
wasmtypes.ModuleName,
dyncommtypes.ModuleName,
}
}

Expand Down Expand Up @@ -273,6 +279,7 @@ func orderEndBlockers() []string {
treasurytypes.ModuleName,
markettypes.ModuleName,
wasmtypes.ModuleName,
dyncommtypes.ModuleName,
}
}

Expand Down Expand Up @@ -303,5 +310,6 @@ func orderInitGenesis() []string {
oracletypes.ModuleName,
treasurytypes.ModuleName,
wasmtypes.ModuleName,
dyncommtypes.ModuleName,
}
}
19 changes: 19 additions & 0 deletions app/upgrades/v6/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package v6

import (
"github.com/classic-terra/core/v2/app/upgrades"
dyncommtypes "github.com/classic-terra/core/v2/x/dyncomm/types"
store "github.com/cosmos/cosmos-sdk/store/types"
)

const UpgradeName = "v6"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateV6UpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
dyncommtypes.StoreKey,
},
},
}
20 changes: 20 additions & 0 deletions app/upgrades/v6/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v6

import (
"github.com/classic-terra/core/v2/app/keepers"
"github.com/classic-terra/core/v2/app/upgrades"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
)

func CreateV6UpgradeHandler(
mm *module.Manager,
cfg module.Configurator,
_ upgrades.BaseAppParamManager,
_ *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, _ upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, cfg, fromVM)
}
}
6 changes: 2 additions & 4 deletions client/docs/statik/statik.go

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion contrib/updates/prepare_cosmovisor.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# These fields should be fetched automatically in the future
# Need to do more upgrade to see upgrade patterns
OLD_VERSION=v2.0.1
OLD_VERSION=v2.2.1
# this command will retrieve the folder with the largest number in format v<number>
SOFTWARE_UPGRADE_NAME=$(ls -d -- ./app/upgrades/v* | sort -Vr | head -n 1 | xargs basename)
BUILDDIR=$1
Expand Down
13 changes: 12 additions & 1 deletion contrib/updates/upgrade-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,18 @@ CHAIN_ID=${STATUS_INFO[0]}
UPGRADE_HEIGHT=$((STATUS_INFO[1] + 20))
echo $UPGRADE_HEIGHT

$BINARY_OLD tx gov submit-proposal software-upgrade "$SOFTWARE_UPGRADE_NAME" --upgrade-height $UPGRADE_HEIGHT --upgrade-info "temp" --title "upgrade" --description "upgrade" --from node1 --keyring-backend test --chain-id $CHAIN_ID --home $NODE1_HOME -y
docker exec terradnode1 tar -cf ./terrad.tar -C . terrad
SUM=$(docker exec terradnode1 sha256sum ./terrad.tar | cut -d ' ' -f1)
DOCKER_BASE_PATH=$(docker exec terradnode1 pwd)
echo $SUM
UPGRADE_INFO=$(jq -n '
{
"binaries": {
"linux/amd64": "file://'$DOCKER_BASE_PATH'/terrad.tar?checksum=sha256:'"$SUM"'",
}
}')

$BINARY_OLD tx gov submit-legacy-proposal software-upgrade "$SOFTWARE_UPGRADE_NAME" --upgrade-height $UPGRADE_HEIGHT --upgrade-info "$UPGRADE_INFO" --title "upgrade" --description "upgrade" --from node1 --keyring-backend test --chain-id $CHAIN_ID --home $NODE1_HOME -y

sleep 5

Expand Down
6 changes: 6 additions & 0 deletions custom/auth/ante/ante.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package ante

import (
dyncommante "github.com/classic-terra/core/v2/x/dyncomm/ante"
dyncommkeeper "github.com/classic-terra/core/v2/x/dyncomm/keeper"
stakingkeeper "github.com/cosmos/cosmos-sdk/x/staking/keeper"
ibcante "github.com/cosmos/ibc-go/v6/modules/core/ante"
ibckeeper "github.com/cosmos/ibc-go/v6/modules/core/keeper"

Expand Down Expand Up @@ -31,6 +34,8 @@ type HandlerOptions struct {
GovKeeper govkeeper.Keeper
WasmConfig *wasmtypes.WasmConfig
TXCounterStoreKey storetypes.StoreKey
DyncommKeeper dyncommkeeper.Keeper
StakingKeeper stakingkeeper.Keeper
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
Expand Down Expand Up @@ -85,5 +90,6 @@ func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) {
ante.NewSigVerificationDecorator(options.AccountKeeper, options.SignModeHandler),
ante.NewIncrementSequenceDecorator(options.AccountKeeper),
ibcante.NewRedundantRelayDecorator(&options.IBCKeeper),
dyncommante.NewDyncommDecorator(options.DyncommKeeper, options.StakingKeeper),
), nil
}
21 changes: 21 additions & 0 deletions custom/auth/post/post.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package post

import (
dyncommkeeper "github.com/classic-terra/core/v2/x/dyncomm/keeper"
dyncommpost "github.com/classic-terra/core/v2/x/dyncomm/post"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// HandlerOptions are the options required for constructing a default SDK AnteHandler.
type HandlerOptions struct {
DyncommKeeper dyncommkeeper.Keeper
}

// NewAnteHandler returns an AnteHandler that checks and increments sequence
// numbers, checks signatures & account numbers, and deducts fees from the first
// signer.
func NewPostHandler(options HandlerOptions) (sdk.AnteHandler, error) {
return sdk.ChainAnteDecorators(
dyncommpost.NewDyncommPostDecorator(options.DyncommKeeper),
), nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ go 1.20
module github.com/classic-terra/core/v2

require (
cosmossdk.io/math v1.0.0-rc.0
github.com/CosmWasm/wasmd v0.30.0
github.com/CosmWasm/wasmvm v1.1.2
github.com/cosmos/cosmos-sdk v0.46.14
Expand Down Expand Up @@ -33,7 +34,6 @@ require (
cloud.google.com/go/iam v1.1.1 // indirect
cloud.google.com/go/storage v1.30.1 // indirect
cosmossdk.io/errors v1.0.0-beta.7 // indirect
cosmossdk.io/math v1.0.0-rc.0 // indirect
filippo.io/edwards25519 v1.0.0-rc.1 // indirect
github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect
github.com/99designs/keyring v1.2.1 // indirect
Expand Down
36 changes: 36 additions & 0 deletions proto/terra/dyncomm/v1beta1/dyncomm.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
syntax = "proto3";
package terra.dyncomm.v1beta1;

import "gogoproto/gogo.proto";

option go_package = "github.com/classic-terra/core/v2/x/dyncomm/types";

// Params defines the parameters for the dyncomm module.
message Params {
option (gogoproto.equal) = true;
option (gogoproto.goproto_stringer) = false;

string max_zero = 1 [
(gogoproto.moretags) = "yaml:\"max_zero\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string slope_base = 2 [
(gogoproto.moretags) = "yaml:\"slope_base\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string slope_vp_impact = 3 [
(gogoproto.moretags) = "yaml:\"slope_vp_impact\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];

string cap = 4 [
(gogoproto.moretags) = "yaml:\"cap\"",
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}
22 changes: 22 additions & 0 deletions proto/terra/dyncomm/v1beta1/genesis.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";
package terra.dyncomm.v1beta1;

import "gogoproto/gogo.proto";
import "terra/dyncomm/v1beta1/dyncomm.proto";

option go_package = "github.com/classic-terra/core/v2/x/dyncomm/types";

// GenesisState defines the dyncomm module's genesis state.
message GenesisState {
// params defines all the paramaters of the module.
Params params = 1 [(gogoproto.nullable) = false];
repeated ValidatorCommissionRate validator_commission_rates = 2 [(gogoproto.nullable) = false];
}

// MinDynCommission defines a validator - min commission rate
// pair to be enforced by the blockchain
message ValidatorCommissionRate {
string validator_address = 1;
string min_commission_rate = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"];
string target_commission_rate = 3 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"];
}
41 changes: 41 additions & 0 deletions proto/terra/dyncomm/v1beta1/query.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
syntax = "proto3";
package terra.dyncomm.v1beta1;

import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "terra/dyncomm/v1beta1/dyncomm.proto";

option go_package = "github.com/classic-terra/core/v2/x/dyncomm/types";

// Query defines the gRPC querier service.
service Query {
// Params queries all parameters.
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/terra/dyncomm/v1beta1/params";
}

rpc Rate(QueryRateRequest) returns (QueryRateResponse){
option (google.api.http).get = "/terra/dyncomm/v1beta1/rates/{validator_addr}";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
message QueryParamsRequest {}

// QueryParamsResponse is the response type for the Query/Params RPC method.
message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [(gogoproto.nullable) = false];
}

// QueryRateRequest is the request type for the Query/Rate RPC method.
message QueryRateRequest {
// validator_addr defines the validator address to query for.
string validator_addr = 1;
}

// QueryRateResponse is the response type for the Query/Rate RPC method.
message QueryRateResponse {
string rate = 1 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"];
string target = 2 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec"];
}
3 changes: 2 additions & 1 deletion scripts/run-node.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
BINARY=$1
CONTINUE=${CONTINUE:-"false"}
HOME_DIR=mytestnet
ENV=${ENV:-""}

if [ "$CONTINUE" == "true" ]; then
$BINARY start --home $HOME_DIR
$BINARY start --home $HOME_DIR --log_level debug
exit 0
fi

Expand Down
Loading

0 comments on commit 95b9728

Please sign in to comment.