diff --git a/cmd/freezer-refrigerant/contract.go b/cmd/freezer-refrigerant/contract.go index 4afd2ad..ed60f2d 100644 --- a/cmd/freezer-refrigerant/contract.go +++ b/cmd/freezer-refrigerant/contract.go @@ -3,6 +3,8 @@ package main import ( + "github.com/pkg/errors" + "github.com/ice-blockchain/eskimo/users" coindistribution "github.com/ice-blockchain/freezer/coin-distribution" "github.com/ice-blockchain/freezer/tokenomics" @@ -67,6 +69,16 @@ const ( transactionAlreadyUsed = "TRANSACTION_ALREADY_USED" defaultDistributionLimit = 5000 + + doctorXTenant = "doctorx" +) + +// . +var ( + //nolint:gochecknoglobals // Because its loaded once, at runtime. + cfg config + errMiningDisabled = errors.New("mining disabled") + errMiningBoostDisabled = errors.New("mining boost disabled") ) type ( diff --git a/cmd/freezer-refrigerant/freezer_refrigerant.go b/cmd/freezer-refrigerant/freezer_refrigerant.go index fdf3eef..99d5adb 100644 --- a/cmd/freezer-refrigerant/freezer_refrigerant.go +++ b/cmd/freezer-refrigerant/freezer_refrigerant.go @@ -28,7 +28,6 @@ func main() { ctx, cancel := context.WithCancel(context.Background()) defer cancel() - var cfg config appCfg.MustLoadFromKey(applicationYamlKey, &cfg) api.SwaggerInfo.Host = cfg.Host api.SwaggerInfo.Version = cfg.Version diff --git a/cmd/freezer-refrigerant/tokenomics.go b/cmd/freezer-refrigerant/tokenomics.go index 382ba75..82d43df 100644 --- a/cmd/freezer-refrigerant/tokenomics.go +++ b/cmd/freezer-refrigerant/tokenomics.go @@ -46,6 +46,9 @@ func (s *service) InitializeMiningBoostUpgrade( //nolint:gocritic // False negat ctx context.Context, req *server.Request[InitializeMiningBoostUpgradeRequestBody, tokenomics.PendingMiningBoostUpgrade], ) (*server.Response[tokenomics.PendingMiningBoostUpgrade], *server.Response[server.ErrorResponse]) { + if cfg.Tenant == doctorXTenant { + return nil, server.Forbidden(errMiningBoostDisabled) + } resp, err := s.tokenomicsProcessor.InitializeMiningBoostUpgrade(ctx, *req.Data.MiningBoostLevelIndex, req.Data.UserID) if err = errors.Wrapf(err, "failed to InitializeMiningBoostUpgrade for data:%#v", req.Data); err != nil { switch { @@ -83,6 +86,9 @@ func (s *service) FinalizeMiningBoostUpgrade( //nolint:gocritic // False negativ ctx context.Context, req *server.Request[FinalizeMiningBoostUpgradeRequestBody, tokenomics.PendingMiningBoostUpgrade], ) (*server.Response[tokenomics.PendingMiningBoostUpgrade], *server.Response[server.ErrorResponse]) { + if cfg.Tenant == doctorXTenant { + return nil, server.Forbidden(errMiningBoostDisabled) + } resp, err := s.tokenomicsProcessor.FinalizeMiningBoostUpgrade(ctx, req.Data.Network, req.Data.TXHash, req.Data.UserID) if err = errors.Wrapf(err, "failed to FinalizeMiningBoostUpgrade for data:%#v", req.Data); err != nil { switch { @@ -127,6 +133,9 @@ func (s *service) StartNewMiningSession( //nolint:gocritic // False negative. ctx context.Context, req *server.Request[StartNewMiningSessionRequestBody, tokenomics.MiningSummary], ) (*server.Response[tokenomics.MiningSummary], *server.Response[server.ErrorResponse]) { + if cfg.Tenant == doctorXTenant { + return nil, server.Forbidden(errMiningDisabled) + } ms := &tokenomics.MiningSummary{MiningSession: &tokenomics.MiningSession{UserID: &req.Data.UserID}} ctx = contextWithHashCode(ctx, req) ctx = tokenomics.ContextWithClientType(ctx, req.Data.XClientType) diff --git a/go.mod b/go.mod index 279e093..5edca6d 100644 --- a/go.mod +++ b/go.mod @@ -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.429.0 + github.com/ice-blockchain/eskimo v1.434.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 @@ -50,8 +50,8 @@ require ( github.com/Microsoft/hcsshim v0.12.9 // indirect github.com/VictoriaMetrics/fastcache v1.12.2 // indirect github.com/andybalholm/brotli v1.1.1 // indirect - github.com/bits-and-blooms/bitset v1.16.0 // indirect - github.com/bytedance/sonic v1.12.4 // indirect + github.com/bits-and-blooms/bitset v1.17.0 // indirect + github.com/bytedance/sonic v1.12.5 // indirect github.com/bytedance/sonic/loader v0.2.1 // indirect github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect @@ -110,10 +110,10 @@ require ( github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v4 v4.5.1 // indirect github.com/golang-jwt/jwt/v5 v5.2.1 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.5-0.20231225225746-43d5d4cd4e0e // indirect - github.com/google/pprof v0.0.0-20241122213907-cbe949e5a41b // indirect + github.com/google/pprof v0.0.0-20241128161848-dc51965c6481 // indirect github.com/google/s2a-go v0.1.8 // indirect github.com/google/uuid v1.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect @@ -160,7 +160,7 @@ require ( github.com/planetscale/vtprotobuf v0.6.1-0.20240917153116-6f2963f01587 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect github.com/quic-go/qpack v0.5.1 // indirect - github.com/quic-go/quic-go v0.48.1 // indirect + github.com/quic-go/quic-go v0.48.2 // indirect github.com/refraction-networking/utls v1.6.7 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rs/zerolog v1.33.0 // indirect @@ -214,9 +214,9 @@ require ( golang.org/x/tools v0.27.0 // indirect google.golang.org/api v0.209.0 // indirect google.golang.org/appengine/v2 v2.0.6 // indirect - google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697 // indirect + google.golang.org/genproto v0.0.0-20241202173237-19429a94021a // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect google.golang.org/grpc v1.68.0 // indirect google.golang.org/grpc/stats/opentelemetry v0.0.0-20241028142157-ada6787961b3 // indirect google.golang.org/protobuf v1.35.2 // indirect diff --git a/go.sum b/go.sum index 7418f84..bc4368c 100644 --- a/go.sum +++ b/go.sum @@ -62,16 +62,16 @@ github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7X github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/bits-and-blooms/bitset v1.16.0 h1:G3lirLlhFTcW/7ym/SLtYYLHQS0hBOcC8fPNJxbTYm4= -github.com/bits-and-blooms/bitset v1.16.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= +github.com/bits-and-blooms/bitset v1.17.0 h1:1X2TS7aHz1ELcC0yU1y2stUs/0ig5oMU6STFZGrhvHI= +github.com/bits-and-blooms/bitset v1.17.0/go.mod h1:7hO7Gc7Pp1vODcmWvKMRA9BNmbv6a/7QIWpPxHddWR8= github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/bsm/redislock v0.9.4 h1:X/Wse1DPpiQgHbVYRE9zv6m070UcKoOGekgvpNhiSvw= github.com/bsm/redislock v0.9.4/go.mod h1:Epf7AJLiSFwLCiZcfi6pWFO/8eAYrYpQXFxEDPoDeAk= -github.com/bytedance/sonic v1.12.4 h1:9Csb3c9ZJhfUWeMtpCDCq6BUoH5ogfDFLUgQ/jG+R0k= -github.com/bytedance/sonic v1.12.4/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= +github.com/bytedance/sonic v1.12.5 h1:hoZxY8uW+mT+OpkcUWw4k0fDINtOcVavEsGfzwzFU/w= +github.com/bytedance/sonic v1.12.5/go.mod h1:B8Gt/XvtZ3Fqj+iSKMypzymZxw/FVwgIGKzMzT9r/rk= github.com/bytedance/sonic/loader v0.1.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= github.com/bytedance/sonic/loader v0.2.1 h1:1GgorWTqf12TA8mma4DDSbaQigE2wOgQo7iCjjJv3+E= github.com/bytedance/sonic/loader v0.2.1/go.mod h1:ncP89zfokxS5LZrJxl5z0UJcsk4M4yY2JpfqGeCtNLU= @@ -249,8 +249,8 @@ github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17w github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ= +github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -284,8 +284,8 @@ github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/ github.com/google/martian/v3 v3.3.3 h1:DIhPTQrbPkgs2yJYdXU/eNACCG5DVQjySNRNlflZ9Fc= github.com/google/martian/v3 v3.3.3/go.mod h1:iEPrYcgCF7jA9OtScMFQyAlZZ4YXTKEtJ1E6RWzmBA0= github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= -github.com/google/pprof v0.0.0-20241122213907-cbe949e5a41b h1:SXO0REt4iu865upYCk8aKBBJQ4BqoE0ReP23ClMu60s= -github.com/google/pprof v0.0.0-20241122213907-cbe949e5a41b/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= +github.com/google/pprof v0.0.0-20241128161848-dc51965c6481 h1:yudKIrXagAOl99WQzrP1gbz5HLB9UjhcOFnPzdd6Qec= +github.com/google/pprof v0.0.0-20241128161848-dc51965c6481/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk= @@ -321,8 +321,8 @@ 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.429.0 h1:PyPq3bC/xlCpyCHEZzWhJH1zya/EwfaGS5dApRSyAbI= -github.com/ice-blockchain/eskimo v1.429.0/go.mod h1:Dea8N48fs7IACUtAQXL6jj25hRm1awr5Wq+kkCg2xIc= +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/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= @@ -454,8 +454,8 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/quic-go/qpack v0.5.1 h1:giqksBPnT/HDtZ6VhtFKgoLOWmlyo9Ei6u9PqzIMbhI= github.com/quic-go/qpack v0.5.1/go.mod h1:+PC4XFrEskIVkcLzpEkbLqq1uCoxPhQuvK5rH1ZgaEg= -github.com/quic-go/quic-go v0.48.1 h1:y/8xmfWI9qmGTc+lBr4jKRUWLGSlSigv847ULJ4hYXA= -github.com/quic-go/quic-go v0.48.1/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs= +github.com/quic-go/quic-go v0.48.2 h1:wsKXZPeGWpMpCGSWqOcqpW2wZYic/8T3aqiOID0/KWE= +github.com/quic-go/quic-go v0.48.2/go.mod h1:yBgs3rWBOADpga7F+jJsb6Ybg1LSYiQvwWlLX+/6HMs= 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.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E= @@ -704,12 +704,12 @@ google.golang.org/appengine/v2 v2.0.6/go.mod h1:WoEXGoXNfa0mLvaH5sV3ZSGXwVmy8yf7 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20241118233622-e639e219e697 h1:ToEetK57OidYuqD4Q5w+vfEnPvPpuTwedCNVohYJfNk= -google.golang.org/genproto v0.0.0-20241118233622-e639e219e697/go.mod h1:JJrvXBWRZaFMxBufik1a4RpFw4HhgVtBBWQeQgUj2cc= -google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697 h1:pgr/4QbFyktUv9CtQ/Fq4gzEE6/Xs7iCXbktaGzLHbQ= -google.golang.org/genproto/googleapis/api v0.0.0-20241118233622-e639e219e697/go.mod h1:+D9ySVjN8nY8YCVjc5O7PZDIdZporIDY3KaGfJunh88= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697 h1:LWZqQOEjDyONlF1H6afSWpAL/znlREo2tHfLoe+8LMA= -google.golang.org/genproto/googleapis/rpc v0.0.0-20241118233622-e639e219e697/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= +google.golang.org/genproto v0.0.0-20241202173237-19429a94021a h1:4voejwOVTsjw6IMfnGt8IzTQBIw45hP8S0e77UMounA= +google.golang.org/genproto v0.0.0-20241202173237-19429a94021a/go.mod h1:dW27OyXi0Ph+N43jeCWMFC86aTT5VgdeQtOSf0Hehdw= +google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a h1:OAiGFfOiA0v9MRYsSidp3ubZaBnteRUyn3xB2ZQ5G/E= +google.golang.org/genproto/googleapis/api v0.0.0-20241202173237-19429a94021a/go.mod h1:jehYqy3+AhJU9ve55aNOaSml7wUXjF9x6z2LcCfpAhY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a h1:hgh8P4EuoxpsuKMXX/To36nOFD7vixReXgn8lPGnt+o= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/miner/contract.go b/miner/contract.go index e127709..6be4292 100644 --- a/miner/contract.go +++ b/miner/contract.go @@ -42,6 +42,7 @@ const ( applicationYamlKey = "miner" parentApplicationYamlKey = "tokenomics" requestDeadline = 30 * stdlibtime.Second + doctorXTenant = "doctorx" ) // . diff --git a/miner/miner.go b/miner/miner.go index b890935..59f0f30 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -374,31 +374,33 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) { } if updatedUser != nil { - if userStoppedMining := didUserStoppedMining(now, usr); userStoppedMining != nil { - referralsCountGuardOnlyUpdatedUsers = append(referralsCountGuardOnlyUpdatedUsers, userStoppedMining) - } - if userStoppedMining := didReferralJustStopMining(now, usr, t0Ref, tMinus1Ref); userStoppedMining != nil { - referralsThatStoppedMining = append(referralsThatStoppedMining, userStoppedMining) - } - if dayOffStarted := didANewDayOffJustStart(now, usr); dayOffStarted != nil { - msgs = append(msgs, dayOffStartedMessage(reqCtx, dayOffStarted)) - } - if t0Ref != nil { - if IDT0Changed { - if !usr.BalanceLastUpdatedAt.IsNil() { - t1ReferralsToIncrementActiveValue[t0Ref.ID]++ - if t0Ref.IDT0 != 0 { - t2ReferralsToIncrementActiveValue[t0Ref.IDT0]++ + if cfg.Tenant != doctorXTenant { + if userStoppedMining := didUserStoppedMining(now, usr); userStoppedMining != nil { + referralsCountGuardOnlyUpdatedUsers = append(referralsCountGuardOnlyUpdatedUsers, userStoppedMining) + } + if userStoppedMining := didReferralJustStopMining(now, usr, t0Ref, tMinus1Ref); userStoppedMining != nil { + referralsThatStoppedMining = append(referralsThatStoppedMining, userStoppedMining) + } + if dayOffStarted := didANewDayOffJustStart(now, usr); dayOffStarted != nil { + msgs = append(msgs, dayOffStartedMessage(reqCtx, dayOffStarted)) + } + if t0Ref != nil { + if IDT0Changed { + if !usr.BalanceLastUpdatedAt.IsNil() { + t1ReferralsToIncrementActiveValue[t0Ref.ID]++ + if t0Ref.IDT0 != 0 { + t2ReferralsToIncrementActiveValue[t0Ref.IDT0]++ + } + } + if usr.ActiveT1Referrals > 0 && t0Ref.ID != 0 { + t2ReferralsToIncrementActiveValue[t0Ref.ID] += usr.ActiveT1Referrals } } - if usr.ActiveT1Referrals > 0 && t0Ref.ID != 0 { - t2ReferralsToIncrementActiveValue[t0Ref.ID] += usr.ActiveT1Referrals + if usr.IDTMinus1 != t0Ref.IDT0 { + updatedUser.IDTMinus1 = t0Ref.IDT0 + tMinus1Ref = tMinus1Referrals[updatedUser.IDTMinus1] } } - if usr.IDTMinus1 != t0Ref.IDT0 { - updatedUser.IDTMinus1 = t0Ref.IDT0 - tMinus1Ref = tMinus1Referrals[updatedUser.IDTMinus1] - } } userCoinDistributions, balanceDistributedForT0, balanceDistributedForTMinus1 := updatedUser.processEthereumCoinDistribution(startedCoinDistributionCollecting, now, t0Ref, tMinus1Ref) coinDistributions = append(coinDistributions, userCoinDistributions...) @@ -408,39 +410,45 @@ func (m *miner) mine(ctx context.Context, workerNumber int64) { if balanceDistributedForTMinus1 > 0 { balanceT2EthereumIncr[tMinus1Ref.ID] += balanceDistributedForTMinus1 } - if tMinus1Ref != nil && tMinus1Ref.ID != 0 && pendingAmountForTMinus1 != 0 { - pendingBalancesForTMinus1[tMinus1Ref.ID] += pendingAmountForTMinus1 - } - if t0Ref != nil && t0Ref.ID != 0 && pendingAmountForT0 != 0 { - pendingBalancesForT0[t0Ref.ID] += pendingAmountForT0 - } - if afterWelcomeBonusV2Applied := updatedUser.WelcomeBonusV2Applied != nil && *updatedUser.WelcomeBonusV2Applied; t0Ref != nil && t0Ref.ID != 0 && beforeWelcomeBonusV2NotApplied && afterWelcomeBonusV2Applied { - idT0 := t0Ref.ID - if idT0 < 0 { - idT0 *= -1 + if cfg.Tenant != doctorXTenant { + if tMinus1Ref != nil && tMinus1Ref.ID != 0 && pendingAmountForTMinus1 != 0 { + pendingBalancesForTMinus1[tMinus1Ref.ID] += pendingAmountForTMinus1 + } + if t0Ref != nil && t0Ref.ID != 0 && pendingAmountForT0 != 0 { + pendingBalancesForT0[t0Ref.ID] += pendingAmountForT0 + } + if afterWelcomeBonusV2Applied := updatedUser.WelcomeBonusV2Applied != nil && *updatedUser.WelcomeBonusV2Applied; t0Ref != nil && t0Ref.ID != 0 && beforeWelcomeBonusV2NotApplied && afterWelcomeBonusV2Applied { + idT0 := t0Ref.ID + if idT0 < 0 { + idT0 *= -1 + } + balanceT1WelcomeBonusIncr[idT0] += cfg.WelcomeBonusV2Amount } - balanceT1WelcomeBonusIncr[idT0] += cfg.WelcomeBonusV2Amount } updatedUsers = append(updatedUsers, &updatedUser.UpdatedUser) } else { - if updUsr := updateT0AndTMinus1ReferralsForUserHasNeverMined(usr); updUsr != nil { - referralsUpdated = append(referralsUpdated, updUsr) - if t0Ref != nil && t0Ref.ID != 0 && usr.ActiveT1Referrals > 0 { - t2ReferralsToIncrementActiveValue[t0Ref.ID] += usr.ActiveT1Referrals + if cfg.Tenant != doctorXTenant { + if updUsr := updateT0AndTMinus1ReferralsForUserHasNeverMined(usr); updUsr != nil { + referralsUpdated = append(referralsUpdated, updUsr) + if t0Ref != nil && t0Ref.ID != 0 && usr.ActiveT1Referrals > 0 { + t2ReferralsToIncrementActiveValue[t0Ref.ID] += usr.ActiveT1Referrals + } } } } - totalStandardBalance, totalPreStakingBalance := usr.BalanceTotalStandard, usr.BalanceTotalPreStaking - if updatedUser != nil { - totalStandardBalance, totalPreStakingBalance = updatedUser.BalanceTotalStandard, updatedUser.BalanceTotalPreStaking - } - totalBalance := totalStandardBalance + totalPreStakingBalance - if shouldSynchronizeBalance { - userGlobalRanks = append(userGlobalRanks, balancesynchronizer.GlobalRank(usr.ID, totalBalance)) - if math.IsNaN(totalStandardBalance) || math.IsNaN(totalPreStakingBalance) { - log.Info(fmt.Sprintf("bmr[%#v],before[%+v], after[%+v]", updatedUser.baseMiningRate(now), usr, updatedUser)) + if cfg.Tenant != doctorXTenant { + totalStandardBalance, totalPreStakingBalance := usr.BalanceTotalStandard, usr.BalanceTotalPreStaking + if updatedUser != nil { + totalStandardBalance, totalPreStakingBalance = updatedUser.BalanceTotalStandard, updatedUser.BalanceTotalPreStaking + } + totalBalance := totalStandardBalance + totalPreStakingBalance + if shouldSynchronizeBalance { + userGlobalRanks = append(userGlobalRanks, balancesynchronizer.GlobalRank(usr.ID, totalBalance)) + if math.IsNaN(totalStandardBalance) || math.IsNaN(totalPreStakingBalance) { + log.Info(fmt.Sprintf("bmr[%#v],before[%+v], after[%+v]", updatedUser.baseMiningRate(now), usr, updatedUser)) + } + msgs = append(msgs, balancesynchronizer.BalanceUpdatedMessage(reqCtx, usr.UserID, totalStandardBalance, totalPreStakingBalance)) } - msgs = append(msgs, balancesynchronizer.BalanceUpdatedMessage(reqCtx, usr.UserID, totalStandardBalance, totalPreStakingBalance)) } } diff --git a/miner/mining.go b/miner/mining.go index 9fb1f0f..5e5b204 100644 --- a/miner/mining.go +++ b/miner/mining.go @@ -17,6 +17,10 @@ func mine(now *time.Time, usr *user, t0Ref, tMinus1Ref *referral) (updatedUser * } clonedUser1 := *usr updatedUser = &clonedUser1 + if cfg.Tenant == doctorXTenant { + return updatedUser, false, false, 0, 0 + } + pendingResurrectionForTMinus1, pendingResurrectionForT0 := resurrect(now, updatedUser, t0Ref, tMinus1Ref) IDT0Changed, _ = changeT0AndTMinus1Referrals(updatedUser) if updatedUser.MiningSessionSoloEndedAt.Before(*now.Time) && updatedUser.isAbsoluteZero() {