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

refactor(incentives): skip epoch distribution to perpetual gauges #1655

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion x/incentives/keeper/distribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func (k Keeper) getToDistributeCoinsFromGauges(gauges []types.Gauge) sdk.Coins {
// updateGaugePostDistribute increments the gauge's filled epochs field.
// Also adds the coins that were just distributed to the gauge's distributed coins field.
func (k Keeper) updateGaugePostDistribute(ctx sdk.Context, gauge types.Gauge, newlyDistributedCoins sdk.Coins, epochEnd bool) error {
if epochEnd {
if !gauge.IsPerpetual && epochEnd {
gauge.FilledEpochs += 1
}
gauge.DistributedCoins = gauge.DistributedCoins.Add(newlyDistributedCoins...)
Expand Down
16 changes: 11 additions & 5 deletions x/incentives/keeper/hooks.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package keeper

import (
"github.com/dymensionxyz/dymension/v3/x/incentives/types"
epochstypes "github.com/osmosis-labs/osmosis/v15/x/epochs/types"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -15,7 +16,7 @@ func (k Keeper) BeforeEpochStart(ctx sdk.Context, epochIdentifier string, epochN
func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumber int64) error {
params := k.GetParams(ctx)
if epochIdentifier == params.DistrEpochIdentifier {
// begin distribution if it's start time
// activate gauges that have started
gauges := k.GetUpcomingGauges(ctx)
for _, gauge := range gauges {
if !ctx.BlockTime().Before(gauge.StartTime) {
Expand All @@ -25,12 +26,17 @@ func (k Keeper) AfterEpochEnd(ctx sdk.Context, epochIdentifier string, epochNumb
}
}

// if len(gauges) > 10 {
// ctx.EventManager().IncreaseCapacity(2e6)
// }
// get active, non-perpetual gauges
// perpetual gauges are paid directly by the protocol (i.e streamer)
newGauges := make([]types.Gauge, 0, len(gauges))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

super nit: i guess most of the gauges will be perpetual, so maybe it's worth doing make([]types.Gauge, 0) to avoid runtime overhead. otherwise runtime will try to find a memory slice for len(gauges) though in fact we need much less.

for _, gauge := range k.GetActiveGauges(ctx) {
if !gauge.IsPerpetual {
newGauges = append(newGauges, gauge)
}
}
gauges = newGauges

// distribute due to epoch event
gauges = k.GetActiveGauges(ctx)
_, err := k.DistributeOnEpochEnd(ctx, gauges)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion x/incentives/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (server msgServer) CreateGauge(goCtx context.Context, msg *types.MsgCreateG
return nil, fmt.Errorf("charge gauge fee: %w", err)
}

gaugeID, err := server.keeper.CreateGauge(ctx, msg.IsPerpetual, owner, msg.Coins, msg.DistributeTo, msg.StartTime, msg.NumEpochsPaidOver)
gaugeID, err := server.keeper.CreateGauge(ctx, false, owner, msg.Coins, msg.DistributeTo, msg.StartTime, msg.NumEpochsPaidOver)
if err != nil {
return nil, fmt.Errorf("create gauge: %w", err)
}
Expand Down
5 changes: 3 additions & 2 deletions x/incentives/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ func (m MsgCreateGauge) ValidateBasic() error {
if m.NumEpochsPaidOver == 0 {
return errors.New("distribution period should be at least 1 epoch")
}
if m.IsPerpetual && m.NumEpochsPaidOver != 1 {
return errors.New("distribution period should be 1 epoch for perpetual gauge")

if m.IsPerpetual {
return errors.New("custom perpetual gauges are not supported")
}

if lockuptypes.LockQueryType_name[int32(m.DistributeTo.LockQueryType)] != "ByDuration" {
Expand Down
18 changes: 0 additions & 18 deletions x/incentives/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,24 +118,6 @@ func TestMsgCreateGauge(t *testing.T) {
}),
expectPass: false,
},
{
name: "invalid num epochs paid over for perpetual gauge",
msg: createMsg(func(msg incentivestypes.MsgCreateGauge) incentivestypes.MsgCreateGauge {
msg.NumEpochsPaidOver = 2
msg.IsPerpetual = true
return msg
}),
expectPass: false,
},
{
name: "valid num epochs paid over for perpetual gauge",
msg: createMsg(func(msg incentivestypes.MsgCreateGauge) incentivestypes.MsgCreateGauge {
msg.NumEpochsPaidOver = 1
msg.IsPerpetual = true
return msg
}),
expectPass: true,
},
}

for _, test := range tests {
Expand Down
Loading