Skip to content

Commit

Permalink
added support for advanced team feature toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-ares committed Oct 17, 2023
1 parent f2e22ba commit 1165ac1
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 42 deletions.
16 changes: 8 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/cenkalti/backoff/v4 v4.2.1
github.com/goccy/go-json v0.10.2
github.com/hashicorp/go-multierror v1.1.1
github.com/ice-blockchain/eskimo v1.163.0
github.com/ice-blockchain/eskimo v1.166.0
github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb
github.com/ice-blockchain/wintr v1.125.0
github.com/pkg/errors v0.9.1
Expand Down Expand Up @@ -40,14 +40,14 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.0 // indirect
github.com/cloudflare/circl v1.3.3 // indirect
github.com/cloudflare/circl v1.3.5 // indirect
github.com/containerd/cgroups v1.1.0 // indirect
github.com/containerd/containerd v1.7.7 // indirect
github.com/containerd/continuity v0.4.2 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/distribution/reference v0.5.0 // indirect
github.com/dmarkham/enumer v1.5.8 // indirect
github.com/dmarkham/enumer v1.5.9 // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker v24.0.6+incompatible // indirect
github.com/docker/go-connections v0.4.0 // indirect
Expand Down Expand Up @@ -101,7 +101,7 @@ require (
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/moby/sys/mount v0.3.3 // indirect
github.com/moby/sys/mountinfo v0.6.2 // indirect
Expand All @@ -119,7 +119,7 @@ require (
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.3.4 // indirect
github.com/quic-go/quic-go v0.39.0 // indirect
github.com/quic-go/quic-go v0.39.1 // indirect
github.com/refraction-networking/utls v1.5.4 // indirect
github.com/rs/zerolog v1.31.0 // indirect
github.com/sagikazarmark/locafero v0.3.0 // indirect
Expand Down Expand Up @@ -163,9 +163,9 @@ require (
google.golang.org/api v0.147.0 // indirect
google.golang.org/appengine v1.6.8 // indirect
google.golang.org/appengine/v2 v2.0.5 // indirect
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a // indirect
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b // indirect
google.golang.org/grpc v1.58.3 // indirect
google.golang.org/protobuf v1.31.0 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand Down
31 changes: 16 additions & 15 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWR
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cloudflare/circl v1.3.3 h1:fE/Qz0QdIGqeWfnwq0RE0R7MI51s0M2E4Ga9kq5AEMs=
github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cloudflare/circl v1.3.5 h1:g+wWynZqVALYAlpSQFAa7TscDnUK8mKYtrxMpw6AUKo=
github.com/cloudflare/circl v1.3.5/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20200629203442-efcf912fb354/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
Expand All @@ -120,8 +120,8 @@ github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/r
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/dmarkham/enumer v1.5.8 h1:fIF11F9l5jyD++YYvxcSH5WgHfeaSGPaN/T4kOQ4qEM=
github.com/dmarkham/enumer v1.5.8/go.mod h1:d10o8R3t/gROm2p3BXqTkMt2+HMuxEmWCXzorAruYak=
github.com/dmarkham/enumer v1.5.9 h1:NM/1ma/AUNieHZg74w67GkHFBNB15muOt3sj486QVZk=
github.com/dmarkham/enumer v1.5.9/go.mod h1:e4VILe2b1nYK3JKJpRmNdl5xbDQvELc6tQ8b+GsGk6E=
github.com/docker/distribution v2.8.3+incompatible h1:AtKxIZ36LoNK51+Z6RpzLpddBirtxJnzDrHLEKxTAYk=
github.com/docker/distribution v2.8.3+incompatible/go.mod h1:J2gT2udsDAN96Uj4KfcMRqY0/ypR+oyYUYmja8H+y+w=
github.com/docker/docker v20.10.3+incompatible h1:+HS4XO73J41FpA260ztGujJ+0WibrA2TPJEnWNSyGNE=
Expand Down Expand Up @@ -300,8 +300,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ice-blockchain/eskimo v1.163.0 h1:IkZG/Ph3KlNEFVNUcWSvPWhufKMmpn2cv/fvVjVLPx0=
github.com/ice-blockchain/eskimo v1.163.0/go.mod h1:cC+mkCLFhf7DwZiiaUm4r/UXsDr5GiaWYaDiQhm277E=
github.com/ice-blockchain/eskimo v1.166.0 h1:nSpHai2wRgNAk3CVEsO7q2DvUBOqiu+JorgJU2KZXzk=
github.com/ice-blockchain/eskimo v1.166.0/go.mod h1:zdpTgLZHaDDJxgXe0ngtOHCjOwWp27OIrbP4VJzIQHo=
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.125.0 h1:pk/SVyztstUF19+JDCufJRMXJeNpchVA4O26xp47l3Y=
Expand Down Expand Up @@ -357,8 +357,9 @@ github.com/mailru/easyjson v0.7.7/go.mod h1:xzfreul335JAWq5oZzymOObrkdz5UnU4kGfJ
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/moby/sys/mount v0.3.3 h1:fX1SVkXFJ47XWDoeFW4Sq7PdQJnV2QIDZAqjNqgEjUs=
Expand Down Expand Up @@ -402,8 +403,8 @@ github.com/quic-go/qpack v0.4.0 h1:Cr9BXA1sQS2SmDUWjSofMPNKmvF6IiIfDRmgU0w1ZCo=
github.com/quic-go/qpack v0.4.0/go.mod h1:UZVnYIfi5GRk+zI9UMaCPsmZ2xKJP7XBUvVyT1Knj9A=
github.com/quic-go/qtls-go1-20 v0.3.4 h1:MfFAPULvst4yoMgY9QmtpYmfij/em7O8UUi+bNVm7Cg=
github.com/quic-go/qtls-go1-20 v0.3.4/go.mod h1:X9Nh97ZL80Z+bX/gUXMbipO6OxdiDi58b/fMC9mAL+k=
github.com/quic-go/quic-go v0.39.0 h1:AgP40iThFMY0bj8jGxROhw3S0FMGa8ryqsmi9tBH3So=
github.com/quic-go/quic-go v0.39.0/go.mod h1:T09QsDQWjLiQ74ZmacDfqZmhY/NLnw5BC40MANNNZ1Q=
github.com/quic-go/quic-go v0.39.1 h1:d/m3oaN/SD2c+f7/yEjZxe2zEVotXprnrCCJ2y/ZZFE=
github.com/quic-go/quic-go v0.39.1/go.mod h1:T09QsDQWjLiQ74ZmacDfqZmhY/NLnw5BC40MANNNZ1Q=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 h1:N/ElC8H3+5XpJzTSTfLsJV/mx9Q9g7kxmchpfZyxgzM=
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
github.com/redis/go-redis/v9 v9.0.5 h1:CuQcn5HIEeK7BgElubPP8CGtE0KakrnbBSTLjathl5o=
Expand Down Expand Up @@ -810,12 +811,12 @@ google.golang.org/genproto v0.0.0-20201210142538-e3217bee35cc/go.mod h1:FWY/as6D
google.golang.org/genproto v0.0.0-20201214200347-8c77b98c765d/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210108203827-ffc7fda8c3d7/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20210226172003-ab064af71705/go.mod h1:FWY/as6DDZQgahTzZj3fqbO1CbirC29ZNUFHwi0/+no=
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a h1:fwgW9j3vHirt4ObdHoYNwuO24BEZjSzbh+zPaNWoiY8=
google.golang.org/genproto v0.0.0-20231012201019-e917dd12ba7a/go.mod h1:EMfReVxb80Dq1hhioy0sOsY9jCE46YDgHlJ7fWVUWRE=
google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a h1:myvhA4is3vrit1a6NZCWBIwN0kNEnX21DJOJX/NvIfI=
google.golang.org/genproto/googleapis/api v0.0.0-20231012201019-e917dd12ba7a/go.mod h1:SUBoKXbI1Efip18FClrQVGjWcyd0QZd8KkvdP34t7ww=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a h1:a2MQQVoTo96JC9PMGtGBymLp7+/RzpFc2yX/9WfFg1c=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231012201019-e917dd12ba7a/go.mod h1:4cYg8o5yUbm77w8ZX00LhMVNl/YVBFJRYWDc0uYWMs0=
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b h1:+YaDE2r2OG8t/z5qmsh7Y+XXwCbvadxxZ0YY6mTdrVA=
google.golang.org/genproto v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:CgAqfJo+Xmu0GwA0411Ht3OU3OntXwsGmrmjI8ioGXI=
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b h1:CIC2YMXmIhYw6evmhPxBKJ4fmLbOFtXQN/GV3XOZR8k=
google.golang.org/genproto/googleapis/api v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:IBQ646DjkDkvUIsVq/cc03FUFQ9wbZu7yE396YcL870=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b h1:ZlWIi1wSK56/8hn4QcBp/j9M7Gt3U/3hZw3mC7vDICo=
google.golang.org/genproto/googleapis/rpc v0.0.0-20231016165738-49dd2c1f3d0b/go.mod h1:swOH3j0KzcDDgGUWr+SNpyTen5YrXjS3eyPzFYKc6lc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38=
google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM=
Expand Down
15 changes: 9 additions & 6 deletions miner/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"io"
"sync"
"sync/atomic"
stdlibtime "time"

dwh "github.com/ice-blockchain/freezer/bookkeeper/storage"
Expand Down Expand Up @@ -54,6 +55,7 @@ type (
model.MiningSessionSoloEndedAtField
model.MiningSessionSoloPreviouslyEndedAtField
model.ExtraBonusStartedAtField
model.LatestDeviceField
model.UserIDField
UpdatedUser
model.BalanceSoloPendingField
Expand Down Expand Up @@ -105,12 +107,12 @@ type (
}

referral struct {
model.UserIDField
model.IDT0Field
model.MiningSessionSoloStartedAtField
model.MiningSessionSoloEndedAtField
model.MiningSessionSoloPreviouslyEndedAtField
model.ResurrectSoloUsedAtField
model.UserIDField
model.IDT0Field
model.DeserializedUsersKey
}

Expand All @@ -130,9 +132,10 @@ type (
extraBonusIndicesDistribution map[uint16]map[uint16]uint16
}
config struct {
tokenomics.Config `mapstructure:",squash"` //nolint:tagliatelle // Nope.
Workers int64 `yaml:"workers"`
BatchSize int64 `yaml:"batchSize"`
Development bool `yaml:"development"`
disableAdvancedTeam *atomic.Pointer[[]string]
tokenomics.Config `mapstructure:",squash"` //nolint:tagliatelle // Nope.
Workers int64 `yaml:"workers"`
BatchSize int64 `yaml:"batchSize"`
Development bool `yaml:"development"`
}
)
71 changes: 70 additions & 1 deletion miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ package miner
import (
"context"
"fmt"
"sort"
"strings"
"sync"
"sync/atomic"
stdlibtime "time"

"github.com/goccy/go-json"
"github.com/hashicorp/go-multierror"
Expand All @@ -27,6 +31,7 @@ import (
func init() {
appCfg.MustLoadFromKey(parentApplicationYamlKey, &cfg.Config)
appCfg.MustLoadFromKey(applicationYamlKey, &cfg)
cfg.disableAdvancedTeam = new(atomic.Pointer[[]string])
}

func MustStartMining(ctx context.Context, cancel context.CancelFunc) Client {
Expand All @@ -37,6 +42,7 @@ func MustStartMining(ctx context.Context, cancel context.CancelFunc) Client {
wg: new(sync.WaitGroup),
telemetry: new(telemetry).mustInit(cfg),
}
go mi.startDisableAdvancedTeamCfgSyncer(ctx)
mi.wg.Add(int(cfg.Workers))
mi.cancel = cancel
mi.extraBonusStartDate = extrabonusnotifier.MustGetExtraBonusStartDate(ctx, mi.db)
Expand Down Expand Up @@ -282,6 +288,9 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
if usr.IDTMinus1 < 0 {
tMinus1Ref = tMinus1Referrals[-usr.IDTMinus1]
}
if isAdvancedTeamDisabled(usr.LatestDevice) {
usr.ActiveT2Referrals = 0
}
updatedUser, shouldGenerateHistory, IDT0Changed := mine(currentAdoption.BaseMiningRate, now, usr, t0Ref, tMinus1Ref)
if shouldGenerateHistory {
userHistoryKeys = append(userHistoryKeys, usr.Key())
Expand Down Expand Up @@ -503,7 +512,6 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) {
reqCancel()
resetVars(true)
}

}

func (m *miner) getAdoption(ctx context.Context, db storage.DB, workerNumber int64) (currentAdoption *tokenomics.Adoption[float64]) {
Expand All @@ -516,3 +524,64 @@ func (m *miner) getAdoption(ctx context.Context, db storage.DB, workerNumber int

return currentAdoption
}

func (m *miner) startDisableAdvancedTeamCfgSyncer(ctx context.Context) {
ticker := stdlibtime.NewTicker(5 * stdlibtime.Minute) //nolint:gosec,gomnd // Not an issue.
defer ticker.Stop()
log.Panic(errors.Wrap(m.syncDisableAdvancedTeamCfg(ctx), "failed to syncDisableAdvancedTeamCfg"))

for {
select {
case <-ticker.C:
reqCtx, cancel := context.WithTimeout(ctx, requestDeadline)
log.Error(errors.Wrap(m.syncDisableAdvancedTeamCfg(reqCtx), "failed to syncDisableAdvancedTeamCfg"))
cancel()
case <-ctx.Done():
return
}
}
}

func (m *miner) syncDisableAdvancedTeamCfg(ctx context.Context) error {
result, err := m.db.Get(ctx, "disable_advanced_team_cfg").Result()
if err != nil && !errors.Is(err, redis.Nil) {
return errors.Wrap(err, "could not get `disable_advanced_team_cfg`")
}
var (
oldCfg []string
newCfg = strings.Split(strings.ReplaceAll(strings.ToLower(result), " ", ""), ",")
)
sort.SliceStable(newCfg, func(ii, jj int) bool { return newCfg[ii] < newCfg[jj] })
if old := cfg.disableAdvancedTeam.Swap(&newCfg); old != nil {
oldCfg = *old
}
if strings.Join(oldCfg, "") != strings.Join(newCfg, "") {
log.Info(fmt.Sprintf("`disable_advanced_team_cfg` changed from: %#v, to: %#v", oldCfg, newCfg))
}

return nil
}

func isAdvancedTeamEnabled(device string) bool {
if device == "" {
return true
}
var disableAdvancedTeamFor []string
if cfgVal := cfg.disableAdvancedTeam.Load(); cfgVal != nil {
disableAdvancedTeamFor = *cfgVal
}
if len(disableAdvancedTeamFor) == 0 {
return true
}
for _, disabled := range disableAdvancedTeamFor {
if strings.EqualFold(device, disabled) {
return false
}
}

return true
}

func isAdvancedTeamDisabled(device string) bool {
return !isAdvancedTeamEnabled(device)
}
5 changes: 4 additions & 1 deletion model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ type (
ExtraBonusField
IDT0Field
IDTMinus1Field
UTCOffsetField
ActiveT1ReferralsField
ActiveT2ReferralsField
NewsSeenField
ExtraBonusDaysClaimNotAvailableField
UTCOffsetField
HideRankingField
}
BalanceLastUpdatedAtField struct {
Expand Down Expand Up @@ -111,6 +111,9 @@ type (
BlockchainAccountAddressField struct {
BlockchainAccountAddress string `redis:"blockchain_account_address,omitempty"`
}
LatestDeviceField struct {
LatestDevice string `redis:"latest_device,omitempty"`
}
BalanceTotalStandardField struct {
BalanceTotalStandard float64 `redis:"balance_total_standard"`
}
Expand Down
4 changes: 4 additions & 0 deletions tokenomics/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (r *repository) GetBalanceSummary( //nolint:lll // .
}
res, err := storage.Get[struct {
model.UserIDField
model.LatestDeviceField
model.BalanceSoloField
model.BalanceT0Field
model.BalanceT1Field
Expand All @@ -44,6 +45,9 @@ func (r *repository) GetBalanceSummary( //nolint:lll // .

return nil, errors.Wrapf(err, "failed to get balanceSummary for id:%v", id)
}
if r.isAdvancedTeamDisabled(res[0].LatestDevice) {
res[0].BalanceT2 = 0
}
t1Standard, t1PreStaking := ApplyPreStaking(res[0].BalanceT0+res[0].BalanceT1, res[0].PreStakingAllocation, res[0].PreStakingBonus)
t2Standard, t2PreStaking := ApplyPreStaking(res[0].BalanceT2, res[0].PreStakingAllocation, res[0].PreStakingBonus)
soloStandard, soloPreStaking := ApplyPreStaking(res[0].BalanceSolo, res[0].PreStakingAllocation, res[0].PreStakingBonus)
Expand Down
2 changes: 2 additions & 0 deletions tokenomics/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
_ "embed"
"io"
"sync/atomic"
stdlibtime "time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -236,6 +237,7 @@ type (
}

Config struct {
disableAdvancedTeam *atomic.Pointer[[]string]
AdoptionMilestoneSwitch struct {
ActiveUserMilestones []struct {
Users uint64 `yaml:"users"`
Expand Down
11 changes: 8 additions & 3 deletions tokenomics/extra_bonus.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,11 @@ func (s *deviceMetadataTableSource) Process(ctx context.Context, msg *messagebro
}
type (
deviceMetadata struct {
Before *deviceMetadata `json:"before,omitempty"`
UserID string `json:"userId,omitempty" example:"did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2"`
TZ string `json:"tz,omitempty" example:"+03:00"`
Before *deviceMetadata `json:"before,omitempty"`
UserID string `json:"userId,omitempty" example:"did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2"`
TZ string `json:"tz,omitempty" example:"+03:00"`
SystemName string `json:"systemName,omitempty" example:"Android"`
ReadableVersion string `json:"readableVersion,omitempty" example:"9.9.9.2637"`
}
)
var dm deviceMetadata
Expand All @@ -149,12 +151,15 @@ func (s *deviceMetadataTableSource) Process(ctx context.Context, msg *messagebro
if err != nil {
return errors.Wrapf(err, "failed to getOrInitInternalID for %#v", &dm)
}
sanitizedDeviceSystemName := strings.ReplaceAll(strings.ToLower(dm.SystemName), " ", "")
val := &struct {
model.LatestDeviceField
model.DeserializedUsersKey
model.UTCOffsetField
}{
DeserializedUsersKey: model.DeserializedUsersKey{ID: id},
UTCOffsetField: model.UTCOffsetField{UTCOffset: int64(duration / stdlibtime.Minute)},
LatestDeviceField: model.LatestDeviceField{LatestDevice: fmt.Sprintf("%v:%v", sanitizedDeviceSystemName, dm.ReadableVersion)},
}

return errors.Wrapf(storage.Set(ctx, s.db, val), "failed to update users' timezone for %#v", &dm)
Expand Down
Loading

0 comments on commit 1165ac1

Please sign in to comment.