Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rollback pre-staging reset after processing #52

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions cmd/freezer-refrigerant/tokenomics.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,6 @@ func (s *service) StartOrUpdatePreStaking( //nolint:gocritic // False negative.
Allocation: float64(req.Data.Allocation),
},
}
if true {
return nil, server.ForbiddenWithCode(errors.Errorf("Endpoint disabled due to reset"), decreasingPreStakingAllocationOrYearsNotAllowedErrorCode)
}

if err := s.tokenomicsProcessor.StartOrUpdatePreStaking(contextWithHashCode(ctx, req), st); err != nil {
err = errors.Wrapf(err, "failed to StartOrUpdatePreStaking for %#v", req.Data)
switch {
Expand Down
6 changes: 0 additions & 6 deletions miner/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,6 @@ type (
model.DeserializedUsersKey
}

prestakingResettableUpdatedUser struct {
model.PreStakingBonusField
model.PreStakingAllocationField
model.DeserializedUsersKey
}

referralCountGuardUpdatedUser struct {
model.ReferralsCountChangeGuardUpdatedAtField
model.DeserializedUsersKey
Expand Down
17 changes: 1 addition & 16 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
backupedUsers = make(map[int64]*backupUserUpdated, batchSize)
backupUsersUpdated = make([]*backupUserUpdated, 0, batchSize)
recalculatedTiersBalancesUsers = make(map[int64]*user, batchSize)
prestakingResettableUsers = make([]*prestakingResettableUpdatedUser, 0, batchSize)
historyColumns, historyInsertMetadata = dwh.InsertDDL(int(batchSize))
shouldSynchronizeBalanceFunc = func(batchNumberArg uint64) bool { return false }
recalculationHistory *historyData
Expand Down Expand Up @@ -237,7 +236,6 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
referralsThatStoppedMining = referralsThatStoppedMining[:0]
allAdoptions = allAdoptions[:0]
backupUsersUpdated = backupUsersUpdated[:0]
prestakingResettableUsers = prestakingResettableUsers[:0]
for k := range t0Referrals {
delete(t0Referrals, k)
}
Expand Down Expand Up @@ -503,18 +501,10 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
if isAdvancedTeamDisabled(usr.LatestDevice) {
usr.ActiveT2Referrals = 0
}
usr.PreStakingAllocation = 0
usr.PreStakingBonus = 0

updatedUser, shouldGenerateHistory, IDT0Changed := mine(currentAdoption.BaseMiningRate, now, usr, t0Ref, tMinus1Ref)
if shouldGenerateHistory {
userHistoryKeys = append(userHistoryKeys, usr.Key())
}
prestakingResettableUsers = append(prestakingResettableUsers, &prestakingResettableUpdatedUser{
PreStakingBonusField: model.PreStakingBonusField{PreStakingBonus: 0},
PreStakingAllocationField: model.PreStakingAllocationField{PreStakingAllocation: 0},
DeserializedUsersKey: usr.DeserializedUsersKey,
})
if updatedUser != nil {
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 {
Expand Down Expand Up @@ -657,7 +647,7 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
}

var pipeliner redis.Pipeliner
if len(t1ReferralsToIncrementActiveValue)+len(t2ReferralsToIncrementActiveValue)+len(referralsCountGuardOnlyUpdatedUsers)+len(t1ReferralsThatStoppedMining)+len(t2ReferralsThatStoppedMining)+len(extraBonusOnlyUpdatedUsers)+len(referralsUpdated)+len(userGlobalRanks)+len(backupUsersUpdated)+len(prestakingResettableUsers) > 0 {
if len(t1ReferralsToIncrementActiveValue)+len(t2ReferralsToIncrementActiveValue)+len(referralsCountGuardOnlyUpdatedUsers)+len(t1ReferralsThatStoppedMining)+len(t2ReferralsThatStoppedMining)+len(extraBonusOnlyUpdatedUsers)+len(referralsUpdated)+len(userGlobalRanks)+len(backupUsersUpdated) > 0 {
pipeliner = m.db.TxPipeline()
} else {
pipeliner = m.db.Pipeline()
Expand Down Expand Up @@ -712,11 +702,6 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
}
}
}
for _, value := range prestakingResettableUsers {
if err := pipeliner.HSet(reqCtx, value.Key(), storage.SerializeValue(value)...).Err(); err != nil {
return err
}
}
if len(userGlobalRanks) > 0 {
if err := pipeliner.ZAdd(reqCtx, "top_miners", userGlobalRanks...).Err(); err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,10 +205,10 @@ type (
SlashingRateForTMinus1 float64 `redis:"slashing_rate_for_tminus1"`
}
PreStakingBonusField struct {
PreStakingBonus float64 `redis:"pre_staking_bonus"`
PreStakingBonus float64 `redis:"pre_staking_bonus,omitempty"`
}
PreStakingAllocationField struct {
PreStakingAllocation float64 `redis:"pre_staking_allocation"`
PreStakingAllocation float64 `redis:"pre_staking_allocation,omitempty"`
}
ExtraBonusField struct {
ExtraBonus float64 `redis:"extra_bonus,omitempty"`
Expand Down
Loading