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: dyncomm module #355

Merged
merged 32 commits into from
Nov 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
1843d12
feat: dyncomm first boilerplate
fragwuerdig Sep 22, 2023
864a567
fix: delete duplicate query.proto
fragwuerdig Sep 22, 2023
287ce7a
fix: no module account for dyncomm
fragwuerdig Sep 22, 2023
3eac75c
fix: inject staking instead of account keeper
fragwuerdig Sep 22, 2023
c5786be
add: dyncomm.go routines and param getters
fragwuerdig Sep 22, 2023
927b49f
fix: miscalculation of dyn. commission rate
fragwuerdig Sep 23, 2023
191ea40
fix: return dyncomm as fraction
fragwuerdig Sep 23, 2023
3f94b8d
fix: paramspace get accepts pointer
fragwuerdig Sep 23, 2023
25bd177
finalize core logic of the module
fragwuerdig Sep 23, 2023
a6a2881
add: per-validator min commission store
fragwuerdig Sep 23, 2023
5178fea
add: ante handler checking MsgEditValidator
fragwuerdig Sep 24, 2023
a670236
add: create test mock
fragwuerdig Sep 25, 2023
704cd6c
fix: test utils mockup
fragwuerdig Sep 25, 2023
e520532
add: TestCalculateVotingPower()
fragwuerdig Sep 25, 2023
b35378d
add: TestCalculateDynCommission
fragwuerdig Sep 25, 2023
552a6c3
add cli for dyncomm (#359)
alchemist-ti Sep 26, 2023
201f0a0
fix: update min rates more often
fragwuerdig Sep 26, 2023
940f53f
add: add straths suggestions
fragwuerdig Sep 26, 2023
43c6797
Fix regression (#365)
StrathCole Oct 4, 2023
17541c7
fix: move dyncomm state changes to post handler
fragwuerdig Oct 6, 2023
d868d4b
fix: improve/fix parameter validation
fragwuerdig Oct 16, 2023
3124e54
fix: latest compiler messages
fragwuerdig Oct 16, 2023
faa765a
chore: adjust upgrade test to requirements of SDK v0.46
fragwuerdig Oct 16, 2023
fe3fb0e
add: upgrade handling
fragwuerdig Oct 18, 2023
5f18601
add: test to ensure ante handler
fragwuerdig Oct 21, 2023
51d5557
fix: workaround for staking simulation interfering with dyncomm
fragwuerdig Oct 21, 2023
57dca07
style: make lint-strict
fragwuerdig Oct 21, 2023
3529f01
fix: more linting
fragwuerdig Oct 21, 2023
c8b5c5e
prepare testnet release with 10mins epoch
fragwuerdig Oct 21, 2023
673cf03
style: another lint
fragwuerdig Oct 21, 2023
2c64e20
fix upgrade test
nghuyenthevinh2000 Nov 1, 2023
24c61c4
revert: target rate shall only be updated through create and edit val…
fragwuerdig Nov 1, 2023
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
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 @@ -65,7 +67,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{forks.FixMinCommissionFork, forks.FixMinCommissionForkRebel}
Expand Down Expand Up @@ -211,13 +213,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
Loading