From d4f306cb59ce9e83e063211a7373b5c499bb64d9 Mon Sep 17 00:00:00 2001 From: marston Date: Tue, 1 Aug 2023 10:45:50 -0400 Subject: [PATCH] v3 halt condition forgot about plan made deals --- x/storage/keeper/rewards.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/x/storage/keeper/rewards.go b/x/storage/keeper/rewards.go index 35acc28d3..2180b7204 100644 --- a/x/storage/keeper/rewards.go +++ b/x/storage/keeper/rewards.go @@ -147,27 +147,41 @@ func (k Keeper) manageDealReward(ctx sdk.Context, deal types.ActiveDeals, networ } func (k Keeper) loopDeals(ctx sdk.Context, allDeals []types.ActiveDeals, networkSize sdk.Dec, balance sdk.Coin) { + currentBlock := ctx.BlockHeight() for _, deal := range allDeals { end, err := strconv.ParseInt(deal.Endblock, 10, 64) if err != nil { ctx.Logger().Error(err.Error()) continue } - ctx.Logger().Info(fmt.Sprintf("Is %d < %d?", end, ctx.BlockHeight())) - if end < ctx.BlockHeight() { - ctx.Logger().Info(fmt.Sprintf("%d < %d = true", end, ctx.BlockHeight())) - info, found := k.GetStoragePaymentInfo(ctx, deal.Signee) - if !found { + info, found := k.GetStoragePaymentInfo(ctx, deal.Signee) + if !found { // user has no storage plan, we'll check if the deal was made with no plan before removing it + if end == 0 { // the deal was made with a plan yet the user has no plan, remove it ctx.Logger().Debug(fmt.Sprintf("Removing %s due to no payment info", deal.Cid)) cerr := k.CanContract(ctx, deal.Cid, deal.Signee) if cerr != nil { ctx.Logger().Error(cerr.Error()) } continue + } + } + if end == 0 { // for deals that were made with a subscription, we remove them if there is not enough space in the plan + if info.SpaceUsed > info.SpaceAvailable { // remove file if the user doesn't have enough space + ctx.Logger().Debug(fmt.Sprintf("Removing %s for space used", deal.Cid)) + err := k.CanContract(ctx, deal.Cid, deal.Signee) + if err != nil { + ctx.Logger().Error(err.Error()) + } + continue } + } + + if currentBlock > end && end > 0 { // check if end block has passed and was made with a timed storage deal + ctx.Logger().Info(fmt.Sprintf("deal has expired at %d", ctx.BlockHeight())) + grace := info.End.Add(time.Hour * 24 * 30) if grace.Before(ctx.BlockTime()) { ctx.Logger().Debug(fmt.Sprintf("Removing %s after grace period", deal.Cid)) @@ -177,15 +191,6 @@ func (k Keeper) loopDeals(ctx sdk.Context, allDeals []types.ActiveDeals, network } continue } - - if info.SpaceUsed > info.SpaceAvailable { // remove file if the user doesn't have enough space - ctx.Logger().Debug(fmt.Sprintf("Removing %s for space used", deal.Cid)) - err := k.CanContract(ctx, deal.Cid, deal.Signee) - if err != nil { - ctx.Logger().Error(err.Error()) - } - continue - } } err = k.manageDealReward(ctx, deal, networkSize, balance)