Skip to content

Commit

Permalink
reset prestaking unconditionally
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-cronus committed Dec 13, 2023
1 parent b368e05 commit 10a2bb0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
2 changes: 2 additions & 0 deletions extra-bonus-notifier/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ type (
model.ExtraBonusLastClaimAvailableAtField
model.DeserializedUsersKey
model.ExtraBonusDaysClaimNotAvailableResettableField
model.PreStakingBonusField
model.PreStakingAllocationField
ExtraBonusIndex uint16 `redis:"-"`
}
ExtraBonusAvailable struct {
Expand Down
2 changes: 2 additions & 0 deletions miner/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ type (
model.DeserializedUsersKey
model.IDT0Field
model.IDTMinus1Field
model.PreStakingBonusField
model.PreStakingAllocationField
}

backupUserUpdated struct {
Expand Down
29 changes: 9 additions & 20 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"context"
"fmt"
"sort"
"strconv"
"strings"
"sync"
"sync/atomic"
Expand Down Expand Up @@ -218,9 +217,6 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
shouldSynchronizeBalanceFunc = m.telemetry.shouldSynchronizeBalanceFunc(uint64(workerNumber), totalBatches, iteration)
}
batchNumber = 0
if err := preStakingResetFinishedForWorker(ctx, m.db, workerNumber, time.Now()); err != nil {
log.Error(err, "can't finish prestaking reset, worker:", workerNumber)
}
} else if success {
go m.telemetry.collectElapsed(1, *now.Time)
}
Expand Down Expand Up @@ -505,21 +501,16 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
if isAdvancedTeamDisabled(usr.LatestDevice) {
usr.ActiveT2Referrals = 0
}
prestakingReset := false
if usr.PreStakingAllocation != 0 && usr.PreStakingBonus != 0 {
usr.PreStakingAllocation = 0
usr.PreStakingBonus = 0
prestakingReset = true
}
usr.PreStakingAllocation = 0
usr.PreStakingBonus = 0
updatedUser, shouldGenerateHistory, IDT0Changed := mine(currentAdoption.BaseMiningRate, now, usr, t0Ref, tMinus1Ref)
if shouldGenerateHistory {
userHistoryKeys = append(userHistoryKeys, usr.Key())
}
if updatedUser != nil {
if prestakingReset {
updatedUser.UpdatedUser.PreStakingAllocation = 0
updatedUser.UpdatedUser.PreStakingBonus = 0
}
updatedUser.UpdatedUser.PreStakingAllocation = 0
updatedUser.UpdatedUser.PreStakingBonus = 0

var extraBonusIndex uint16
if isAvailable, _ := extrabonusnotifier.IsExtraBonusAvailable(now, m.extraBonusStartDate, updatedUser.ExtraBonusStartedAt, m.extraBonusIndicesDistribution, updatedUser.ID, int16(updatedUser.UTCOffset), &extraBonusIndex, &updatedUser.ExtraBonusDaysClaimNotAvailable, &updatedUser.ExtraBonusLastClaimAvailableAt); isAvailable {
eba := &extrabonusnotifier.ExtraBonusAvailable{UserID: updatedUser.UserID, ExtraBonusIndex: extraBonusIndex}
Expand Down Expand Up @@ -560,6 +551,8 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
updatedUsers = append(updatedUsers, &updatedUser.UpdatedUser)
} else {
extraBonusOnlyUpdatedUsr := extrabonusnotifier.UpdatedUser{
PreStakingAllocationField: model.PreStakingAllocationField{PreStakingAllocation: 0},
PreStakingBonusField: model.PreStakingBonusField{PreStakingBonus: 0},
ExtraBonusLastClaimAvailableAtField: usr.ExtraBonusLastClaimAvailableAtField,
DeserializedUsersKey: usr.DeserializedUsersKey,
ExtraBonusDaysClaimNotAvailableResettableField: model.ExtraBonusDaysClaimNotAvailableResettableField{ExtraBonusDaysClaimNotAvailable: usr.ExtraBonusDaysClaimNotAvailable},
Expand All @@ -570,6 +563,8 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
extraBonusOnlyUpdatedUsers = append(extraBonusOnlyUpdatedUsers, &extraBonusOnlyUpdatedUsr)
}
if updUsr := updateT0AndTMinus1ReferralsForUserHasNeverMined(usr); updUsr != nil {
updUsr.PreStakingAllocation = 0
updUsr.PreStakingBonus = 0
referralsUpdated = append(referralsUpdated, updUsr)
if t0Ref != nil && t0Ref.ID != 0 && usr.ActiveT1Referrals > 0 {
t2ReferralsToIncrementActiveValue[t0Ref.ID] += usr.ActiveT1Referrals
Expand Down Expand Up @@ -827,9 +822,3 @@ func isAdvancedTeamEnabled(device string) bool {
func isAdvancedTeamDisabled(device string) bool {
return !isAdvancedTeamEnabled(device)
}

func preStakingResetFinishedForWorker(ctx context.Context, db storage.DB, w int64, now *time.Time) (err error) {
_, err = db.HSetNX(ctx, "prestaking_reset_end_date", strconv.FormatInt(w, 10), now).Result()

return errors.Wrapf(err, "failed to set finished for prestaking-reset, worker: %v", w)
}

0 comments on commit 10a2bb0

Please sign in to comment.