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: add end-key to pool #177

Merged
merged 11 commits into from
May 3, 2024
15 changes: 15 additions & 0 deletions docs/static/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,7 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VOTING_POWER_TOO_HIGH
- POOL_STATUS_END_KEY_REACHED
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down Expand Up @@ -1092,6 +1093,7 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VOTING_POWER_TOO_HIGH
- POOL_STATUS_END_KEY_REACHED
default: POOL_STATUS_UNSPECIFIED
title: >-
BasicPool contains the necessary properties need for a
Expand Down Expand Up @@ -3966,6 +3968,7 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VOTING_POWER_TOO_HIGH
- POOL_STATUS_END_KEY_REACHED
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down Expand Up @@ -4985,6 +4988,9 @@ paths:
type: integer
format: int64
description: compression_id ...
end_key:
type: string
description: end_key ...
bundle_proposal:
description: bundle_proposal ...
type: object
Expand Down Expand Up @@ -5102,6 +5108,7 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VOTING_POWER_TOO_HIGH
- POOL_STATUS_END_KEY_REACHED
default: POOL_STATUS_UNSPECIFIED
account:
type: string
Expand Down Expand Up @@ -5518,6 +5525,9 @@ paths:
type: integer
format: int64
description: compression_id ...
end_key:
type: string
description: end_key ...
bundle_proposal:
description: bundle_proposal ...
type: object
Expand Down Expand Up @@ -5635,6 +5645,7 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VOTING_POWER_TOO_HIGH
- POOL_STATUS_END_KEY_REACHED
default: POOL_STATUS_UNSPECIFIED
account:
type: string
Expand Down Expand Up @@ -6153,6 +6164,7 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VOTING_POWER_TOO_HIGH
- POOL_STATUS_END_KEY_REACHED
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down Expand Up @@ -6580,6 +6592,7 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VOTING_POWER_TOO_HIGH
- POOL_STATUS_END_KEY_REACHED
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down Expand Up @@ -7120,6 +7133,7 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VOTING_POWER_TOO_HIGH
- POOL_STATUS_END_KEY_REACHED
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down Expand Up @@ -7589,6 +7603,7 @@ paths:
- POOL_STATUS_NOT_ENOUGH_DELEGATION
- POOL_STATUS_UPGRADING
- POOL_STATUS_VOTING_POWER_TOO_HIGH
- POOL_STATUS_END_KEY_REACHED
default: POOL_STATUS_UNSPECIFIED
points:
type: string
Expand Down
2 changes: 2 additions & 0 deletions proto/kyve/pool/v1beta1/events.proto
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ message EventCreatePool {
// compression_id is the unique id of the compression type the bundles
// get compressed with
uint32 compression_id = 14;
// end_key is the last key before the pool should stop indexing
string end_key = 15;
}

// EventPoolEnabled ...
Expand Down
6 changes: 6 additions & 0 deletions proto/kyve/pool/v1beta1/pool.proto
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ enum PoolStatus {
// POOL_STATUS_VOTING_POWER_TOO_HIGH indicates, that one validator
// has more than 50% voting power and that the pool is halted
POOL_STATUS_VOTING_POWER_TOO_HIGH = 6;
// POOL_STATUS_END_KEY_REACHED indicates, that the end key has been
// reached and that the pool is halted
POOL_STATUS_END_KEY_REACHED = 7;
}

// Protocol holds all info about the current pool version and the
Expand Down Expand Up @@ -109,4 +112,7 @@ message Pool {
uint32 current_storage_provider_id = 18;
// compression_id ...
uint32 current_compression_id = 19;

// end_key ...
string end_key = 20;
}
2 changes: 2 additions & 0 deletions proto/kyve/pool/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ message MsgCreatePool {
uint32 storage_provider_id = 13;
// compression_id ...
uint32 compression_id = 14;
// end_key ...
string end_key = 15;
}

// MsgCreatePoolResponse defines the Msg/CreatePool response type.
Expand Down
5 changes: 5 additions & 0 deletions x/bundles/keeper/logic_bundles.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ func (k Keeper) AssertPoolCanRun(ctx sdk.Context, poolId uint64) error {
return types.ErrPoolDisabled
}

// Error if the end key is reached
if pool.EndKey != "" && pool.CurrentKey == pool.EndKey {
return types.ErrEndKeyReached
}

// Get the total and the highest delegation of a single validator in the pool
totalDelegation, highestDelegation := k.delegationKeeper.GetTotalAndHighestDelegationOfPool(ctx, poolId)

Expand Down
49 changes: 32 additions & 17 deletions x/bundles/keeper/logic_bundles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ TEST CASES - logic_bundles.go
* Assert pool can run while min delegation is not reached
* Assert pool can run
* Assert pool can run while pool has no funds
* Assert pool can run when endKey is reached

* Assert can vote if sender is no staker
* Assert can vote if bundle is dropped
Expand Down Expand Up @@ -84,7 +85,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
// ASSERT POOL CAN RUN

It("Assert pool can run while pool is upgrading", func() {
// ASSERT
// ARRANGE
pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0)
pool.UpgradePlan = &pooltypes.UpgradePlan{
Version: "1.0.0",
Expand Down Expand Up @@ -126,7 +127,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert pool can run while pool is disabled", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -164,7 +165,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert pool can run while min delegation is not reached", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 20 * i.KYVE,
Expand Down Expand Up @@ -197,7 +198,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert pool can run while voting power of one node is too high", func() {
// ASSERT
// ARRANGE
msg := &pooltypes.MsgCreatePool{
Authority: gov,
Name: "PoolTest",
Expand Down Expand Up @@ -248,7 +249,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert pool can run", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 50 * i.KYVE,
Expand Down Expand Up @@ -281,7 +282,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert pool can run while pool has no funds", func() {
// ASSERT
// ARRANGE
msg := &pooltypes.MsgCreatePool{
Authority: gov,
Name: "PoolTest",
Expand Down Expand Up @@ -331,10 +332,24 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
Expect(err).NotTo(HaveOccurred())
})

It("Assert pool can run when endKey is reached", func() {
// ARRANGE
pool, _ := s.App().PoolKeeper.GetPool(s.Ctx(), 0)
pool.EndKey = "0"
pool.CurrentKey = "0"
s.App().PoolKeeper.SetPool(s.Ctx(), pool)

// ACT
err := s.App().BundlesKeeper.AssertPoolCanRun(s.Ctx(), 0)

// ASSERT
Expect(err).To(Equal(bundlesTypes.ErrEndKeyReached))
})

// ASSERT CAN VOTE

It("Assert can vote if sender is no staker", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -396,7 +411,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert can vote if bundle is dropped", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -455,7 +470,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert can vote if storage id does not match", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -513,7 +528,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert can vote if sender has already voted valid", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -580,7 +595,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert can vote if sender has already voted invalid", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -647,7 +662,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert can vote", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -708,7 +723,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
// ASSERT CAN PROPOSE

It("Assert can propose if sender is no staker", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -750,7 +765,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert can propose if sender is not next uploader", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -792,7 +807,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert can propose if upload interval has not passed", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -837,7 +852,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert can propose if index does not match", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down Expand Up @@ -879,7 +894,7 @@ var _ = Describe("logic_bundles.go", Ordered, func() {
})

It("Assert can propose", func() {
// ASSERT
// ARRANGE
s.RunTxStakersSuccess(&stakertypes.MsgCreateStaker{
Creator: i.STAKER_0,
Amount: 100 * i.KYVE,
Expand Down
1 change: 1 addition & 0 deletions x/bundles/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ var (
ErrAlreadyVotedInvalid = errors.Register(ModuleName, 1205, "already voted invalid on bundle proposal")
ErrAlreadyVotedAbstain = errors.Register(ModuleName, 1206, "already voted abstain on bundle proposal")
ErrVotingPowerTooHigh = errors.Register(ModuleName, 1207, "staker in pool has more than 50% voting power")
ErrEndKeyReached = errors.Register(ModuleName, 1208, "end key reached")
)
2 changes: 2 additions & 0 deletions x/pool/keeper/msg_server_create_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func (k msgServer) CreatePool(goCtx context.Context, req *types.MsgCreatePool) (
Logo: req.Logo,
Config: req.Config,
StartKey: req.StartKey,
EndKey: req.EndKey,
UploadInterval: req.UploadInterval,
InflationShareWeight: req.InflationShareWeight,
MinDelegation: req.MinDelegation,
Expand All @@ -56,6 +57,7 @@ func (k msgServer) CreatePool(goCtx context.Context, req *types.MsgCreatePool) (
Logo: req.Logo,
Config: req.Config,
StartKey: req.StartKey,
EndKey: req.EndKey,
UploadInterval: req.UploadInterval,
InflationShareWeight: req.InflationShareWeight,
MinDelegation: req.MinDelegation,
Expand Down
3 changes: 3 additions & 0 deletions x/pool/keeper/msg_server_create_pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ var _ = Describe("msg_server_create_pool.go", Ordered, func() {
Logo: "ar://Tewyv2P5VEG8EJ6AUQORdqNTectY9hlOrWPK8wwo-aU",
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
EndKey: "100",
UploadInterval: 60,
InflationShareWeight: 10000,
MinDelegation: 100 * i.KYVE,
Expand Down Expand Up @@ -137,6 +138,7 @@ var _ = Describe("msg_server_create_pool.go", Ordered, func() {
Logo: "ar://Tewyv2P5VEG8EJ6AUQORdqNTectY9hlOrWPK8wwo-aU",
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
EndKey: "100",
CurrentKey: "",
CurrentSummary: "",
CurrentIndex: 0,
Expand Down Expand Up @@ -244,6 +246,7 @@ var _ = Describe("msg_server_create_pool.go", Ordered, func() {
Logo: "ar://Tewyv2P5VEG8EJ6AUQORdqNTectY9hlOrWPK8wwo-aU",
Config: "ar://DgdB-2hLrxjhyEEbCML__dgZN5_uS7T6Z5XDkaFh3P0",
StartKey: "0",
EndKey: "",
CurrentKey: "",
CurrentSummary: "",
CurrentIndex: 0,
Expand Down
3 changes: 3 additions & 0 deletions x/pool/keeper/msg_server_update_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ func (k msgServer) UpdatePool(goCtx context.Context, req *types.MsgUpdatePool) (
if update.CompressionId != nil {
pool.CurrentCompressionId = *update.CompressionId
}
if update.EndKey != nil {
pool.EndKey = *update.EndKey
}

k.SetPool(ctx, pool)

Expand Down
Loading
Loading