-
Notifications
You must be signed in to change notification settings - Fork 11
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
instant slashing of all balance in case of kycQuizResetAt passed #107
base: master
Are you sure you want to change the base?
Changes from 2 commits
9c9c38c
fdd092f
3537243
6521e71
d098077
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,19 @@ func mine(baseMiningRate float64, now *time.Time, usr *user, t0Ref, tMinus1Ref * | |
clonedUser1 := *usr | ||
updatedUser = &clonedUser1 | ||
pendingResurrectionForTMinus1, pendingResurrectionForT0 := resurrect(now, updatedUser, t0Ref, tMinus1Ref) | ||
wasResurrected := !updatedUser.ResurrectSoloUsedAt.IsNil() && updatedUser.ResurrectSoloUsedAt.Equal(*now.Time) | ||
|
||
IDT0Changed, _ = changeT0AndTMinus1Referrals(updatedUser) | ||
if updatedUser.MiningSessionSoloEndedAt.Before(*now.Time) && updatedUser.isAbsoluteZero() { | ||
if updatedUser.BalanceT1Pending-updatedUser.BalanceT1PendingApplied != 0 || | ||
updatedUser.BalanceT2Pending-updatedUser.BalanceT2PendingApplied != 0 { | ||
updatedUser.BalanceT1PendingApplied = updatedUser.BalanceT1Pending | ||
updatedUser.BalanceT2PendingApplied = updatedUser.BalanceT2Pending | ||
updatedUser.BalanceLastUpdatedAt = now | ||
|
||
needInstantSlashing := usr.WasQuizReset(updatedUser.BalanceLastUpdatedAt) | ||
if wasResurrected && needInstantSlashing { | ||
updatedUser.ResurrectSoloUsedAt = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should consume the resurrection, but it shouldn't resurrect the coins u lost forever There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But it seems situation when we have to resurrect part of the coins are impossible, in instant slashing we slash all the balance, and slashing stops, nothing to be resuttected if instant slashing occured (so that reset date does not affect to resurrectedDelta in anyway it seems) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yea but u dont consume the resurrection |
||
} | ||
return updatedUser, false, IDT0Changed, 0, 0 | ||
} | ||
|
||
|
@@ -78,7 +83,13 @@ func mine(baseMiningRate float64, now *time.Time, usr *user, t0Ref, tMinus1Ref * | |
updatedUser.BalanceT2Pending = 0 | ||
updatedUser.BalanceT2PendingApplied = 0 | ||
} | ||
|
||
needInstantSlashing := usr.WasQuizReset(updatedUser.BalanceLastUpdatedAt) | ||
if wasResurrected && needInstantSlashing { | ||
updatedUser.ResurrectSoloUsedAt = nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same thing here |
||
} | ||
if needInstantSlashing { | ||
updatedUser.applyInstantSlashing(usr, t0Ref, tMinus1Ref, unAppliedSoloPending, elapsedTimeFraction) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will not lines 111, 118 affect on slashingRatesForT0 and TMinus1 that they will not be accepted at 165-166? |
||
} | ||
if updatedUser.MiningSessionSoloEndedAt.After(*now.Time) { | ||
if !updatedUser.ExtraBonusStartedAt.IsNil() && now.Before(updatedUser.ExtraBonusStartedAt.Add(cfg.ExtraBonuses.Duration)) { | ||
rate := (100 + float64(updatedUser.ExtraBonus)) * baseMiningRate * elapsedTimeFraction / 100. | ||
|
@@ -95,14 +106,14 @@ func mine(baseMiningRate float64, now *time.Time, usr *user, t0Ref, tMinus1Ref * | |
updatedUser.BalanceT0 += rate | ||
mintedAmount += rate | ||
|
||
if updatedUser.SlashingRateForT0 != 0 { | ||
if updatedUser.SlashingRateForT0 != 0 && (!needInstantSlashing) { | ||
updatedUser.SlashingRateForT0 = 0 | ||
} | ||
} | ||
if tMinus1Ref != nil && !tMinus1Ref.MiningSessionSoloEndedAt.IsNil() && tMinus1Ref.MiningSessionSoloEndedAt.After(*now.Time) { | ||
updatedUser.BalanceForTMinus1 += 5 * baseMiningRate * elapsedTimeFraction / 100 | ||
|
||
if updatedUser.SlashingRateForTMinus1 != 0 { | ||
if updatedUser.SlashingRateForTMinus1 != 0 && (!needInstantSlashing) { | ||
updatedUser.SlashingRateForTMinus1 = 0 | ||
} | ||
} | ||
|
@@ -208,6 +219,13 @@ func mine(baseMiningRate float64, now *time.Time, usr *user, t0Ref, tMinus1Ref * | |
updatedUser.BalanceTotalSlashed += slashedStandard + slashedPreStaking | ||
updatedUser.BalanceLastUpdatedAt = now | ||
|
||
if needInstantSlashing { | ||
updatedUser.SlashingRateSolo = 0 | ||
updatedUser.SlashingRateT0 = 0 | ||
updatedUser.SlashingRateForT0 = 0 | ||
updatedUser.SlashingRateForTMinus1 = 0 | ||
} | ||
|
||
return updatedUser, shouldGenerateHistory, IDT0Changed, pendingAmountForTMinus1, pendingAmountForT0 | ||
} | ||
|
||
|
@@ -226,6 +244,20 @@ func updateT0AndTMinus1ReferralsForUserHasNeverMined(usr *user) (updatedUser *re | |
return nil | ||
} | ||
|
||
func (updatedUser *user) applyInstantSlashing(usr *user, t0Ref, tMinus1Ref *referral, unAppliedSoloPending, elapsedTimeFraction float64) { | ||
updatedUser.SlashingRateSolo = (usr.BalanceSolo / elapsedTimeFraction) | ||
if unAppliedSoloPending != 0 { | ||
updatedUser.SlashingRateSolo += unAppliedSoloPending / elapsedTimeFraction | ||
} | ||
if t0Ref != nil { | ||
updatedUser.SlashingRateT0 = usr.BalanceT0 / elapsedTimeFraction | ||
updatedUser.SlashingRateForT0 = usr.BalanceForT0 / elapsedTimeFraction | ||
} | ||
if tMinus1Ref != nil { | ||
updatedUser.SlashingRateForTMinus1 = usr.BalanceForTMinus1 / elapsedTimeFraction | ||
} | ||
} | ||
|
||
func (u *user) isAbsoluteZero() bool { | ||
return u.BalanceSolo == 0 && | ||
u.BalanceT0 == 0 && | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,10 @@ func resurrect(now *time.Time, usr *user, t0Ref, tMinus1Ref *referral) (pendingR | |
} else { | ||
resurrectDelta = timeSpent.Hours() | ||
} | ||
|
||
usr.BalanceSolo += usr.SlashingRateSolo * resurrectDelta | ||
usr.BalanceT0 += usr.SlashingRateT0 * resurrectDelta | ||
amountSolo := usr.SlashingRateSolo * resurrectDelta | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rollback |
||
amountT0 := usr.SlashingRateT0 * resurrectDelta | ||
usr.BalanceSolo += amountSolo | ||
usr.BalanceT0 += amountT0 | ||
mintedAmount := (usr.SlashingRateSolo + usr.SlashingRateT0) * resurrectDelta | ||
mintedStandard, mintedPreStaking := tokenomics.ApplyPreStaking(mintedAmount, usr.PreStakingAllocation, usr.PreStakingBonus) | ||
usr.BalanceTotalMinted += mintedStandard + mintedPreStaking | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,7 @@ type ( | |
KYCStepsLastUpdatedAtField | ||
KYCStepPassedField | ||
KYCStepBlockedField | ||
KYCQuizResetAtField | ||
} | ||
SoloLastEthereumCoinDistributionProcessedAtField struct { | ||
SoloLastEthereumCoinDistributionProcessedAt *time.Time `redis:"solo_last_ethereum_coin_distribution_processed_at,omitempty"` | ||
|
@@ -311,6 +312,10 @@ type ( | |
KYCStepBlockedField struct { | ||
KYCStepBlocked users.KYCStep `json:"kycStepBlocked" redis:"kyc_step_blocked"` | ||
} | ||
|
||
KYCQuizResetAtField struct { | ||
KYCQuizResetAt *TimeSlice `json:"kycQuizResetAt" redis:"kyc_quiz_reset_at"` | ||
} | ||
) | ||
|
||
type ( | ||
|
@@ -408,6 +413,20 @@ func (kyc *KYCState) DelayPassedSinceLastKYCStepAttempt(kycStep users.KYCStep, d | |
return kyc.KYCStepAttempted(kycStep) && time.Now().Sub(*(*kyc.KYCStepsLastUpdatedAt)[kycStep-1].Time) >= duration | ||
} | ||
|
||
func (kyc *KYCState) WasQuizReset(now *time.Time) bool { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. now is not a good name; try |
||
res := false | ||
if kyc.KYCQuizResetAt != nil { | ||
for _, quizResettedDate := range *kyc.KYCQuizResetAt { | ||
if quizResettedDate.After(*now.Time) { | ||
res = true | ||
|
||
break | ||
} | ||
} | ||
} | ||
return res | ||
} | ||
|
||
type ( | ||
TimeSlice []*time.Time | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about if t0/t-1 resurrected?