Skip to content

Commit

Permalink
v3 halt condition forgot about plan made deals
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Aug 1, 2023
1 parent f537ff0 commit d4f306c
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions x/storage/keeper/rewards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Check warning on line 161 in x/storage/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/storage/keeper/rewards.go#L161

Added line #L161 was not covered by tests
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

Check warning on line 178 in x/storage/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/storage/keeper/rewards.go#L173-L178

Added lines #L173 - L178 were not covered by tests
}
}

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()))

Check warning on line 184 in x/storage/keeper/rewards.go

View check run for this annotation

Codecov / codecov/patch

x/storage/keeper/rewards.go#L183-L184

Added lines #L183 - L184 were not covered by tests
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))
Expand All @@ -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)
Expand Down

0 comments on commit d4f306c

Please sign in to comment.