5
5
6
6
"cosmossdk.io/math"
7
7
sdk "github.com/cosmos/cosmos-sdk/types"
8
+ "github.com/osmosis-labs/osmosis/v15/osmoutils"
8
9
9
10
"github.com/dymensionxyz/dymension/v3/utils/pagination"
10
11
"github.com/dymensionxyz/dymension/v3/x/streamer/types"
@@ -53,48 +54,6 @@ func (k Keeper) DistributeToGauge(ctx sdk.Context, coins sdk.Coins, record types
53
54
return totalAllocated , nil
54
55
}
55
56
56
- // UpdateStreamAtEpochStart updates the stream for a new epoch. Streams distribute rewards post factum.
57
- // Meaning, first increase the filled epoch pointer, then distribute rewards for this epoch.
58
- func (k Keeper ) UpdateStreamAtEpochStart (ctx sdk.Context , stream types.Stream ) (types.Stream , error ) {
59
- // Check if stream has completed its distribution. This is a post factum check.
60
- if stream .FilledEpochs >= stream .NumEpochsPaidOver {
61
- err := k .moveActiveStreamToFinishedStream (ctx , stream )
62
- if err != nil {
63
- return types.Stream {}, fmt .Errorf ("move active stream to finished stream: %w" , err )
64
- }
65
- return stream , nil
66
- }
67
-
68
- // If the stream is not finalized, update it for the next distribution
69
-
70
- remainCoins := stream .Coins .Sub (stream .DistributedCoins ... )
71
- remainEpochs := stream .NumEpochsPaidOver - stream .FilledEpochs
72
- epochCoins := remainCoins .QuoInt (math .NewIntFromUint64 (remainEpochs ))
73
-
74
- // If the stream uses a sponsorship plan, query it and update stream distr info. The distribution
75
- // might be empty and this is a valid scenario. In that case, we'll just skip at without
76
- // filling the epoch.
77
- if stream .Sponsored {
78
- distr , err := k .sk .GetDistribution (ctx )
79
- if err != nil {
80
- return types.Stream {}, fmt .Errorf ("get sponsorship distribution: %w" , err )
81
- }
82
- // Update stream distr info
83
- stream .DistributeTo = types .DistrInfoFromDistribution (distr )
84
- }
85
-
86
- // Add coins to distribute during the next epoch
87
- stream .EpochCoins = epochCoins
88
-
89
- // Don't fill streams in which there's nothing to fill. Note that rewards are distributed post factum.
90
- // I.e., first increase the filled epoch number, then distribute rewards during the epoch.
91
- if ! stream .DistributeTo .TotalWeight .IsZero () {
92
- stream .FilledEpochs += 1
93
- }
94
-
95
- return stream , nil
96
- }
97
-
98
57
type DistributeRewardsResult struct {
99
58
NewPointer types.EpochPointer
100
59
FilledStreams []types.Stream
@@ -117,12 +76,18 @@ func (k Keeper) DistributeRewards(
117
76
118
77
// Distribute to all the remaining gauges that are left after EndBlock
119
78
newPointer , iterations := IterateEpochPointer (pointer , streams , limit , func (v StreamGauge ) pagination.Stop {
120
- distributed , errX := k .DistributeToGauge (ctx , v .Stream .EpochCoins , v .Gauge , v .Stream .DistributeTo .TotalWeight )
121
- if errX != nil {
79
+ var distributed sdk.Coins
80
+ err := osmoutils .ApplyFuncIfNoError (ctx , func (ctx sdk.Context ) error {
81
+ var err error
82
+ distributed , err = k .DistributeToGauge (ctx , v .Stream .EpochCoins , v .Gauge , v .Stream .DistributeTo .TotalWeight )
83
+ return err
84
+ })
85
+ if err != nil {
122
86
// Ignore this gauge
123
87
k .Logger (ctx ).
124
- With ("streamID" , v .Stream .Id , "gaugeID" , v .Gauge .GaugeId , "error" , errX .Error ()).
88
+ With ("streamID" , v .Stream .Id , "gaugeID" , v .Gauge .GaugeId , "error" , err .Error ()).
125
89
Error ("Failed to distribute to gauge" )
90
+ return pagination .Continue
126
91
}
127
92
128
93
totalDistributed = totalDistributed .Add (distributed ... )
0 commit comments