-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added queue pruning and other before-operation changes
- Loading branch information
Showing
8 changed files
with
58 additions
and
255 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,11 @@ | ||
package beam | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"github.com/cosmos/cosmos-sdk/telemetry" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
|
||
"github.com/lum-network/chain/x/beam/keeper" | ||
"github.com/lum-network/chain/x/beam/types" | ||
) | ||
|
||
// EndBlocker Called every block, process the beam expiration and auto close | ||
func EndBlocker(ctx sdk.Context, keeper keeper.Keeper) { | ||
// Notify the telemetry module | ||
defer telemetry.ModuleMeasureSince(types.ModuleName, time.Now(), telemetry.MetricKeyEndBlocker) | ||
|
||
// Acquire the list of beams | ||
ids := keeper.GetBeamIDsFromBlockQueue(ctx, int(ctx.BlockHeight())) | ||
|
||
// Process beams expirations | ||
for _, value := range ids { | ||
err := keeper.UpdateBeamStatus(ctx, value, types.BeamState_StateCanceled) | ||
if err != nil { | ||
panic(err) | ||
} | ||
keeper.Logger(ctx).Info(fmt.Sprintf("Canceling beam #%s due to crossed auto close thresold", value), "height", ctx.BlockHeight()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package v162 | ||
|
||
import ( | ||
"fmt" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
beamkeeper "github.com/lum-network/chain/x/beam/keeper" | ||
beamtypes "github.com/lum-network/chain/x/beam/types" | ||
) | ||
|
||
func DeleteBeamsData(ctx sdk.Context, bk beamkeeper.Keeper) error { | ||
bk.IterateOpenBeamsQueue(ctx, func(beam beamtypes.Beam) bool { | ||
bk.RemoveFromOpenBeamQueue(ctx, beam.GetId()) | ||
bk.Logger(ctx).Info(fmt.Sprintf("Removed beam %s from open beam queue", beam.GetId())) | ||
return false | ||
}) | ||
bk.IterateClosedBeamsQueue(ctx, func(beam beamtypes.Beam) bool { | ||
bk.RemoveFromClosedBeamQueue(ctx, beam.GetId()) | ||
bk.Logger(ctx).Info(fmt.Sprintf("Removed beam %s from open beam queue", beam.GetId())) | ||
return false | ||
}) | ||
bk.IterateOpenBeamsByBlockQueue(ctx, func(beam beamtypes.Beam) bool { | ||
bk.RemoveFromOpenBeamByBlockQueue(ctx, int(beam.GetClosesAtBlock()), beam.GetId()) | ||
bk.Logger(ctx).Info(fmt.Sprintf("Removed beam %s from open beam by block queue", beam.GetId())) | ||
return false | ||
}) | ||
bk.IterateBeams(ctx, func(beam beamtypes.Beam) bool { | ||
if err := bk.DeleteBeam(ctx, beam.GetId()); err != nil { | ||
panic(err) | ||
} | ||
bk.Logger(ctx).Info(fmt.Sprintf("Deleted beam entity with ID %s", beam.GetId())) | ||
return false | ||
}) | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package v162 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters