From 5bf771a545b871db7d3b213d9992a12b22c7b77e Mon Sep 17 00:00:00 2001 From: Troy Kessler Date: Thu, 26 Oct 2023 12:15:02 +0200 Subject: [PATCH] feat: implemented new pool status which halts if voting power is too high --- docs/swagger.yml | 9 +++ proto/kyve/pool/v1beta1/pool.proto | 2 + x/bundles/keeper/logic_bundles.go | 20 +++++- x/bundles/types/errors.go | 1 + x/pool/types/pool.pb.go | 110 +++++++++++++++-------------- x/query/keeper/helper.go | 15 +++- 6 files changed, 102 insertions(+), 55 deletions(-) diff --git a/docs/swagger.yml b/docs/swagger.yml index ad6f0ddf..eb0c1245 100644 --- a/docs/swagger.yml +++ b/docs/swagger.yml @@ -683,6 +683,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VP_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string @@ -1083,6 +1084,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VP_TOO_HIGH default: POOL_STATUS_UNSPECIFIED title: >- BasicPool contains the necessary properties need for a @@ -3949,6 +3951,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VP_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string @@ -4999,6 +5002,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VP_TOO_HIGH default: POOL_STATUS_UNSPECIFIED account: type: string @@ -5515,6 +5519,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VP_TOO_HIGH default: POOL_STATUS_UNSPECIFIED account: type: string @@ -5992,6 +5997,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VP_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string @@ -6421,6 +6427,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VP_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string @@ -6962,6 +6969,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VP_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string @@ -7434,6 +7442,7 @@ paths: - POOL_STATUS_NO_FUNDS - POOL_STATUS_NOT_ENOUGH_DELEGATION - POOL_STATUS_UPGRADING + - POOL_STATUS_VP_TOO_HIGH default: POOL_STATUS_UNSPECIFIED points: type: string diff --git a/proto/kyve/pool/v1beta1/pool.proto b/proto/kyve/pool/v1beta1/pool.proto index 77541e34..782eecb9 100644 --- a/proto/kyve/pool/v1beta1/pool.proto +++ b/proto/kyve/pool/v1beta1/pool.proto @@ -22,6 +22,8 @@ enum PoolStatus { POOL_STATUS_NOT_ENOUGH_DELEGATION = 4; // POOL_STATUS_UPGRADING ... POOL_STATUS_UPGRADING = 5; + // POOL_STATUS_VP_TOO_HIGH ... + POOL_STATUS_VP_TOO_HIGH = 6; } // Protocol holds all info about the current pool version and the diff --git a/x/bundles/keeper/logic_bundles.go b/x/bundles/keeper/logic_bundles.go index f29812c4..0ad807f6 100644 --- a/x/bundles/keeper/logic_bundles.go +++ b/x/bundles/keeper/logic_bundles.go @@ -28,11 +28,29 @@ func (k Keeper) AssertPoolCanRun(ctx sdk.Context, poolId uint64) error { return types.ErrPoolDisabled } + totalDelegation := uint64(0) + maxDelegation := uint64(0) + + // Get the total delegation and the highest delegation of a staker in the pool + for _, address := range k.stakerKeeper.GetAllStakerAddressesOfPool(ctx, poolId) { + delegation := k.delegationKeeper.GetDelegationAmount(ctx, address) + totalDelegation += delegation + + if delegation > maxDelegation { + maxDelegation = delegation + } + } + // Error if min delegation is not reached - if k.delegationKeeper.GetDelegationOfPool(ctx, pool.Id) < pool.MinDelegation { + if totalDelegation < pool.MinDelegation { return types.ErrMinDelegationNotReached } + // Error if the top staker has more than 50% + if maxDelegation*2 > totalDelegation { + return types.ErrVPTooHigh + } + return nil } diff --git a/x/bundles/types/errors.go b/x/bundles/types/errors.go index bacc1e93..e3c27589 100644 --- a/x/bundles/types/errors.go +++ b/x/bundles/types/errors.go @@ -23,4 +23,5 @@ var ( ErrAlreadyVotedValid = errors.Register(ModuleName, 1204, "already voted valid on bundle proposal") ErrAlreadyVotedInvalid = errors.Register(ModuleName, 1205, "already voted invalid on bundle proposal") ErrAlreadyVotedAbstain = errors.Register(ModuleName, 1206, "already voted abstain on bundle proposal") + ErrVPTooHigh = errors.Register(ModuleName, 1207, "staker in pool has more than 50% voting power") ) diff --git a/x/pool/types/pool.pb.go b/x/pool/types/pool.pb.go index 27ae02e5..210d7b29 100644 --- a/x/pool/types/pool.pb.go +++ b/x/pool/types/pool.pb.go @@ -39,6 +39,8 @@ const ( POOL_STATUS_NOT_ENOUGH_DELEGATION PoolStatus = 4 // POOL_STATUS_UPGRADING ... POOL_STATUS_UPGRADING PoolStatus = 5 + // POOL_STATUS_VP_TOO_HIGH ... + POOL_STATUS_VP_TOO_HIGH PoolStatus = 6 ) var PoolStatus_name = map[int32]string{ @@ -48,6 +50,7 @@ var PoolStatus_name = map[int32]string{ 3: "POOL_STATUS_NO_FUNDS", 4: "POOL_STATUS_NOT_ENOUGH_DELEGATION", 5: "POOL_STATUS_UPGRADING", + 6: "POOL_STATUS_VP_TOO_HIGH", } var PoolStatus_value = map[string]int32{ @@ -57,6 +60,7 @@ var PoolStatus_value = map[string]int32{ "POOL_STATUS_NO_FUNDS": 3, "POOL_STATUS_NOT_ENOUGH_DELEGATION": 4, "POOL_STATUS_UPGRADING": 5, + "POOL_STATUS_VP_TOO_HIGH": 6, } func (x PoolStatus) String() string { @@ -504,59 +508,59 @@ func init() { func init() { proto.RegisterFile("kyve/pool/v1beta1/pool.proto", fileDescriptor_40c1730f47ff2ef8) } var fileDescriptor_40c1730f47ff2ef8 = []byte{ - // 818 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x41, 0x6f, 0xdb, 0x36, - 0x14, 0xc7, 0xad, 0xc4, 0x75, 0x6c, 0x3a, 0x71, 0x5c, 0x2e, 0xcd, 0xd8, 0x64, 0xf0, 0xdc, 0x0c, - 0xdd, 0xbc, 0x1d, 0x6c, 0xb4, 0x1d, 0x30, 0x60, 0xc0, 0x0e, 0x8e, 0xed, 0x64, 0x42, 0x03, 0xdb, - 0x90, 0xed, 0x02, 0xdb, 0x45, 0xa0, 0x45, 0x56, 0x21, 0x22, 0x91, 0x02, 0x49, 0x79, 0x71, 0x8f, - 0x3b, 0xed, 0xb8, 0xef, 0xd0, 0xcf, 0xb1, 0xfb, 0x8e, 0x3d, 0xee, 0x38, 0x24, 0x5f, 0x64, 0x20, - 0x25, 0x79, 0xee, 0xd6, 0x53, 0x6f, 0x7c, 0xbf, 0xff, 0xff, 0xe9, 0x3d, 0xf3, 0xf1, 0x19, 0x7c, - 0x76, 0xb3, 0x5e, 0xd1, 0x5e, 0x22, 0x44, 0xd4, 0x5b, 0x3d, 0x5b, 0x52, 0x8d, 0x9f, 0xd9, 0xa0, - 0x9b, 0x48, 0xa1, 0x05, 0x7c, 0x68, 0xd4, 0xae, 0x05, 0xb9, 0x7a, 0x72, 0x14, 0x8a, 0x50, 0x58, - 0xb5, 0x67, 0x4e, 0x99, 0xf1, 0x2c, 0x00, 0xd5, 0xa9, 0x39, 0x04, 0x22, 0x82, 0x08, 0xec, 0xad, - 0xa8, 0x54, 0x4c, 0x70, 0xe4, 0xb4, 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a7, 0xe0, 0xc9, 0xfb, 0xca, 0xdc, 0x1f, 0x8d, - 0x27, 0x8b, 0xcb, 0x1f, 0xfd, 0xe1, 0xe8, 0x6a, 0x74, 0xd9, 0x9f, 0xbb, 0x93, 0x71, 0xb3, 0x0c, - 0x1f, 0x83, 0x47, 0xef, 0xf5, 0x33, 0xbd, 0xf4, 0xfa, 0x43, 0x77, 0x7c, 0xd9, 0x7c, 0x70, 0x52, - 0xfe, 0xed, 0x6d, 0xab, 0x74, 0x3e, 0xf8, 0xf3, 0xae, 0xe5, 0xbc, 0xbb, 0x6b, 0x39, 0x7f, 0xdf, - 0xb5, 0x9c, 0xdf, 0xef, 0x5b, 0xa5, 0x77, 0xf7, 0xad, 0xd2, 0x5f, 0xf7, 0xad, 0xd2, 0xcf, 0x5f, - 0x87, 0x4c, 0x5f, 0xa7, 0xcb, 0x6e, 0x20, 0xe2, 0xde, 0xcb, 0x9f, 0x5e, 0x8d, 0xc6, 0x54, 0xff, - 0x22, 0xe4, 0x4d, 0x2f, 0xb8, 0xc6, 0x8c, 0xf7, 0x6e, 0xb3, 0xbf, 0x61, 0xbd, 0x4e, 0xa8, 0x5a, - 0x56, 0xec, 0x18, 0x5f, 0xfc, 0x13, 0x00, 0x00, 0xff, 0xff, 0xec, 0x2d, 0x4a, 0x94, 0xa0, 0x05, - 0x00, 0x00, + // 832 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x9c, 0x94, 0x41, 0x6f, 0x1a, 0x47, + 0x14, 0xc7, 0x59, 0x9b, 0x60, 0x18, 0x6c, 0x4c, 0xa6, 0x8e, 0x3b, 0xb1, 0x2b, 0x4a, 0x5c, 0xa5, + 0xa5, 0x3d, 0x80, 0x92, 0x54, 0xaa, 0x54, 0xa9, 0x07, 0x0c, 0x18, 0xaf, 0x62, 0x01, 0x5a, 0xc0, + 0x52, 0x7b, 0x19, 0x0d, 0xcc, 0x64, 0x3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5, 0x31, 0x53, 0x2a, + 0x2f, 0x9f, 0x85, 0xf0, 0x10, 0x94, 0x48, 0x28, 0x13, 0xa1, 0x6d, 0xf1, 0xa2, 0x97, 0x45, 0x27, + 0xef, 0x4a, 0xa0, 0x38, 0x91, 0x32, 0x80, 0x35, 0xb0, 0xc5, 0xa9, 0xcd, 0x2a, 0x7a, 0x5b, 0x9c, + 0x42, 0x08, 0x8a, 0x82, 0x84, 0x2c, 0xeb, 0xd5, 0x9e, 0xcd, 0xe7, 0xe3, 0x44, 0x68, 0x1e, 0xa6, + 0x77, 0x51, 0xf1, 0xf2, 0xd0, 0xb8, 0x03, 0xe9, 0x4b, 0xdb, 0x5a, 0xc5, 0xb3, 0x67, 0x53, 0x72, + 0x29, 0xc5, 0x1b, 0xee, 0xa3, 0x47, 0x96, 0x66, 0x11, 0x3c, 0x06, 0x15, 0xa5, 0x49, 0xac, 0xf1, + 0x35, 0x5b, 0xa3, 0x52, 0x7a, 0x15, 0x16, 0xbc, 0x66, 0x6b, 0xf8, 0x25, 0xa8, 0x2e, 0x93, 0x38, + 0x66, 0x22, 0x95, 0x77, 0xac, 0x0c, 0x32, 0x64, 0x0c, 0xdf, 0x80, 0xfd, 0xdc, 0xa0, 0x92, 0x30, + 0x24, 0xf1, 0x1a, 0x95, 0xad, 0xa9, 0x96, 0xe1, 0x69, 0x4a, 0xe1, 0x57, 0x60, 0x2f, 0x37, 0x72, + 0x41, 0xd9, 0x0d, 0xaa, 0xd8, 0xdf, 0xb6, 0x9b, 0x41, 0xd7, 0x30, 0x63, 0xd2, 0x52, 0x93, 0x00, + 0x2f, 0x12, 0x41, 0x03, 0xa6, 0x10, 0x48, 0x4d, 0x16, 0x9e, 0xa6, 0xcc, 0x94, 0x4c, 0xa2, 0x40, + 0x12, 0x8a, 0xb9, 0xd0, 0x2c, 0x5e, 0x91, 0x00, 0x55, 0xad, 0xad, 0x96, 0x62, 0x37, 0xa3, 0xf0, + 0x39, 0xa8, 0xc9, 0x88, 0x99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f, 0xbe, 0xf5, 0xb9, 0xbe, + 0x4a, 0x16, 0xed, 0xa5, 0x0c, 0x3b, 0xaf, 0x7f, 0xbe, 0x1c, 0x8c, 0x98, 0xfe, 0x55, 0xc6, 0xd7, + 0x9d, 0xe5, 0x15, 0xe1, 0xa2, 0x73, 0x93, 0xfe, 0x47, 0xeb, 0x75, 0xc4, 0xd4, 0xa2, 0x64, 0x67, + 0xfc, 0xea, 0xdf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x08, 0x81, 0x78, 0xd4, 0xbd, 0x05, 0x00, 0x00, } func (m *Protocol) Marshal() (dAtA []byte, err error) { diff --git a/x/query/keeper/helper.go b/x/query/keeper/helper.go index 0536becd..6fa20e57 100644 --- a/x/query/keeper/helper.go +++ b/x/query/keeper/helper.go @@ -82,7 +82,18 @@ func (k Keeper) GetFullStaker(ctx sdk.Context, stakerAddress string) *types.Full } func (k Keeper) GetPoolStatus(ctx sdk.Context, pool *pooltypes.Pool) pooltypes.PoolStatus { - totalDelegation := k.delegationKeeper.GetDelegationOfPool(ctx, pool.Id) + totalDelegation := uint64(0) + maxDelegation := uint64(0) + + // Get the total delegation and the highest delegation of a staker in the pool + for _, address := range k.stakerKeeper.GetAllStakerAddressesOfPool(ctx, pool.Id) { + delegation := k.delegationKeeper.GetDelegationAmount(ctx, address) + totalDelegation += delegation + + if delegation > maxDelegation { + maxDelegation = delegation + } + } var poolStatus pooltypes.PoolStatus @@ -92,6 +103,8 @@ func (k Keeper) GetPoolStatus(ctx sdk.Context, pool *pooltypes.Pool) pooltypes.P poolStatus = pooltypes.POOL_STATUS_DISABLED } else if totalDelegation < pool.MinDelegation { poolStatus = pooltypes.POOL_STATUS_NOT_ENOUGH_DELEGATION + } else if maxDelegation*2 > totalDelegation { + poolStatus = pooltypes.POOL_STATUS_VP_TOO_HIGH } else if pool.TotalFunds == 0 { poolStatus = pooltypes.POOL_STATUS_NO_FUNDS } else {