Skip to content

Commit

Permalink
Stop mining session for distribution tenant if user was active. (#224)
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-myles authored Dec 3, 2024
1 parent 0a5ac0e commit 005dcc7
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 10 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/ethereum/go-ethereum v1.14.12
github.com/goccy/go-json v0.10.3
github.com/hashicorp/go-multierror v1.1.1
github.com/ice-blockchain/eskimo v1.434.0
github.com/ice-blockchain/eskimo v1.435.0
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb
github.com/ice-blockchain/wintr v1.154.0
github.com/imroc/req/v3 v3.48.0
Expand All @@ -26,7 +26,7 @@ require (
)

require (
cel.dev/expr v0.18.0 // indirect
cel.dev/expr v0.19.0 // indirect
cloud.google.com/go v0.116.0 // indirect
cloud.google.com/go/auth v0.11.0 // indirect
cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect
Expand Down Expand Up @@ -124,7 +124,7 @@ require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/holiman/bloomfilter/v2 v2.0.3 // indirect
github.com/holiman/uint256 v1.3.1 // indirect
github.com/ip2location/ip2location-go/v9 v9.7.0 // indirect
github.com/ip2location/ip2location-go/v9 v9.7.1 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
github.com/jackc/pgx/v5 v5.7.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cel.dev/expr v0.18.0 h1:CJ6drgk+Hf96lkLikr4rFf19WrU0BOWEihyZnI2TAzo=
cel.dev/expr v0.18.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
cel.dev/expr v0.19.0 h1:lXuo+nDhpyJSpWxpPVi5cPUwzKb+dsdOiw6IreM5yt0=
cel.dev/expr v0.19.0/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE=
cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U=
Expand Down Expand Up @@ -321,16 +321,16 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
github.com/huin/goupnp v1.3.0 h1:UvLUlWDNpoUdYzb2TCn+MuTWtcjXKSza2n6CBdQ0xXc=
github.com/huin/goupnp v1.3.0/go.mod h1:gnGPsThkYa7bFi/KWmEysQRf48l2dvR5bxr2OFckNX8=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ice-blockchain/eskimo v1.434.0 h1:tS1Zw6hH4YqF+s7OIuFR5dw8oYcFnNfzPfjbgRwaBGU=
github.com/ice-blockchain/eskimo v1.434.0/go.mod h1:44EGWQqA2PiX8zJ0H3NMhODEyt7TLA1jFDhzJP73Qfc=
github.com/ice-blockchain/eskimo v1.435.0 h1:jyDTXW7vhDmjunU5KI9LaZzkk3Qid7g9n+R7x6KMfp0=
github.com/ice-blockchain/eskimo v1.435.0/go.mod h1:4V9HfeL8L9HpeoB4bZQxinPw0lNkE6jTSttnxxxZOv0=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb h1:8TnFP3mc7O+tc44kv2e0/TpZKnEVUaKH+UstwfBwRkk=
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb/go.mod h1:ZsQU7i3mxhgBBu43Oev7WPFbIjP4TniN/b1UPNGbrq8=
github.com/ice-blockchain/wintr v1.154.0 h1:yZSQtAEwGHTSmJ5pXjX0tpui1TNnG615QfpBkhY99a4=
github.com/ice-blockchain/wintr v1.154.0/go.mod h1:DoUn66XJGzPzfCZTsHyMjfgj2aVLGvjqDSuKj2pa3KE=
github.com/imroc/req/v3 v3.48.0 h1:IYuMGetuwLzOOTzDCquDqs912WNwpsPK0TBXWPIvoqg=
github.com/imroc/req/v3 v3.48.0/go.mod h1:weam9gmyb00QnOtu6HXSnk44dNFkIUQb5QdMx13FeUU=
github.com/ip2location/ip2location-go/v9 v9.7.0 h1:ipwl67HOWcrw+6GOChkEXcreRQR37NabqBd2ayYa4Q0=
github.com/ip2location/ip2location-go/v9 v9.7.0/go.mod h1:MPLnsKxwQlvd2lBNcQCsLoyzJLDBFizuO67wXXdzoyI=
github.com/ip2location/ip2location-go/v9 v9.7.1 h1:eXu/DqS13QE0h1Yrc9oji+6/anLD9KDf6Ulf5GdIQs8=
github.com/ip2location/ip2location-go/v9 v9.7.1/go.mod h1:MPLnsKxwQlvd2lBNcQCsLoyzJLDBFizuO67wXXdzoyI=
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
Expand Down
6 changes: 6 additions & 0 deletions miner/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ type (
model.DeserializedUsersKey
}

userThatStoppedMiningForDistribution struct {
model.ReferralsCountChangeGuardUpdatedAtField
model.MiningSessionSoloEndedAtField
model.DeserializedUsersKey
}

referralThatStoppedMining struct {
StoppedMiningAt *time.Time
ID, IDT0, IDTMinus1 int64
Expand Down
19 changes: 18 additions & 1 deletion miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
updatedUsers = make([]*UpdatedUser, 0, batchSize)
extraBonusOnlyUpdatedUsers = make([]*extrabonusnotifier.UpdatedUser, 0, batchSize)
referralsCountGuardOnlyUpdatedUsers = make([]*referralCountGuardUpdatedUser, 0, batchSize)
usersThatStoppedMiningForDistribution = make([]*userThatStoppedMiningForDistribution, 0, batchSize)
referralsUpdated = make([]*referralUpdated, 0, batchSize)
histories = make([]*model.User, 0, batchSize)
quizStatuses = make(map[string]*quiz.QuizStatus, batchSize)
Expand Down Expand Up @@ -228,6 +229,7 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
userGlobalRanks = userGlobalRanks[:0]
referralsThatStoppedMining = referralsThatStoppedMining[:0]
coinDistributions = coinDistributions[:0]
usersThatStoppedMiningForDistribution = usersThatStoppedMiningForDistribution[:0]

for k := range t0Referrals {
delete(t0Referrals, k)
Expand Down Expand Up @@ -401,6 +403,14 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
tMinus1Ref = tMinus1Referrals[updatedUser.IDTMinus1]
}
}
} else {
if updatedUser.MiningSessionSoloEndedAt.After(*now.Time) {
usersThatStoppedMiningForDistribution = append(usersThatStoppedMiningForDistribution, &userThatStoppedMiningForDistribution{
DeserializedUsersKey: usr.DeserializedUsersKey,
ReferralsCountChangeGuardUpdatedAtField: model.ReferralsCountChangeGuardUpdatedAtField{ReferralsCountChangeGuardUpdatedAt: now},
MiningSessionSoloEndedAtField: model.MiningSessionSoloEndedAtField{MiningSessionSoloEndedAt: now},
})
}
}
userCoinDistributions, balanceDistributedForT0, balanceDistributedForTMinus1 := updatedUser.processEthereumCoinDistribution(startedCoinDistributionCollecting, now, t0Ref, tMinus1Ref)
coinDistributions = append(coinDistributions, userCoinDistributions...)
Expand Down Expand Up @@ -573,7 +583,7 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {

var pipeliner redis.Pipeliner
var transactional bool
if len(pendingBalancesForTMinus1)+len(pendingBalancesForT0)+len(balanceT1WelcomeBonusIncr)+len(balanceT1EthereumIncr)+len(balanceT2EthereumIncr)+len(t1ReferralsToIncrementActiveValue)+len(t2ReferralsToIncrementActiveValue)+len(referralsCountGuardOnlyUpdatedUsers)+len(t1ReferralsThatStoppedMining)+len(t2ReferralsThatStoppedMining)+len(extraBonusOnlyUpdatedUsers)+len(referralsUpdated)+len(userGlobalRanks) > 0 {
if len(pendingBalancesForTMinus1)+len(pendingBalancesForT0)+len(balanceT1WelcomeBonusIncr)+len(balanceT1EthereumIncr)+len(balanceT2EthereumIncr)+len(t1ReferralsToIncrementActiveValue)+len(t2ReferralsToIncrementActiveValue)+len(referralsCountGuardOnlyUpdatedUsers)+len(t1ReferralsThatStoppedMining)+len(t2ReferralsThatStoppedMining)+len(extraBonusOnlyUpdatedUsers)+len(referralsUpdated)+len(userGlobalRanks)+len(usersThatStoppedMiningForDistribution) > 0 {
pipeliner = m.db.TxPipeline()
transactional = true
} else {
Expand Down Expand Up @@ -666,6 +676,13 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
return err
}
}
if cfg.Tenant == doctorXTenant {
for _, value := range usersThatStoppedMiningForDistribution {
if err := pipeliner.HSet(reqCtx, value.Key(), storage.SerializeValue(value)...).Err(); err != nil {
return err
}
}
}

return nil
}); err != nil {
Expand Down
3 changes: 3 additions & 0 deletions tokenomics/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ func (s *completedTasksSource) Process(ctx context.Context, message *messagebrok
if ctx.Err() != nil || len(message.Value) == 0 {
return errors.Wrap(ctx.Err(), "unexpected deadline while processing message")
}
if s.cfg.Tenant == doctorXTenant {
return nil
}
const requiredCompletedTasks, adoptionMultiplicationFactor = 6, 168
var val struct {
UserID string `json:"userId" example:"edfd8c02-75e0-4687-9ac2-1ce4723865c4"`
Expand Down
2 changes: 2 additions & 0 deletions tokenomics/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ const (
totalCoinStatsDetailsLockDuration = 1 * stdlibtime.Minute
totalCoinStatsDetailsKey = "totalCoinStatsDetailsData"
miningBoostPricePrecision = 4 // 4 digits after floating point.

doctorXTenant = "doctorx"
)

type (
Expand Down

0 comments on commit 005dcc7

Please sign in to comment.