diff --git a/go.mod b/go.mod index 61c6fc9..a335bc9 100644 --- a/go.mod +++ b/go.mod @@ -10,7 +10,7 @@ require ( github.com/ethereum/go-ethereum v1.14.6 github.com/goccy/go-json v0.10.3 github.com/hashicorp/go-multierror v1.1.1 - github.com/ice-blockchain/eskimo v1.351.0 + github.com/ice-blockchain/eskimo v1.353.0 github.com/ice-blockchain/go-tarantool-client v0.0.0-20230327200757-4fc71fa3f7bb github.com/ice-blockchain/wintr v1.143.0 github.com/imroc/req/v3 v3.43.7 @@ -99,7 +99,7 @@ require ( github.com/go-playground/validator/v10 v10.22.0 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/goccy/go-reflect v1.2.0 // indirect - github.com/gofrs/flock v0.11.0 // indirect + github.com/gofrs/flock v0.12.0 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang-jwt/jwt/v4 v4.5.0 // indirect github.com/golang-jwt/jwt/v5 v5.2.1 // indirect @@ -190,11 +190,11 @@ require ( github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 // indirect - go.opentelemetry.io/otel v1.27.0 // indirect - go.opentelemetry.io/otel/metric v1.27.0 // indirect - go.opentelemetry.io/otel/trace v1.27.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 // indirect + go.opentelemetry.io/otel v1.28.0 // indirect + go.opentelemetry.io/otel/metric v1.28.0 // indirect + go.opentelemetry.io/otel/trace v1.28.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/mock v0.4.0 // indirect go.uber.org/multierr v1.11.0 // indirect diff --git a/go.sum b/go.sum index 91b7aba..d72d43e 100644 --- a/go.sum +++ b/go.sum @@ -217,8 +217,8 @@ github.com/goccy/go-json v0.10.3/go.mod h1:oq7eo15ShAhp70Anwd5lgX2pLfOS3QCiwU/PU github.com/goccy/go-reflect v1.2.0 h1:O0T8rZCuNmGXewnATuKYnkL0xm6o8UNOJZd/gOkb9ms= github.com/goccy/go-reflect v1.2.0/go.mod h1:n0oYZn8VcV2CkWTxi8B9QjkCoq6GTtCEdfmR66YhFtE= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gofrs/flock v0.11.0 h1:AGFQxrpWd8ezw60AvLWIPbxMydNfF8564pwH3FCty0g= -github.com/gofrs/flock v0.11.0/go.mod h1:FirDy1Ing0mI2+kB6wk+vyyAH+e6xiE+EYA0jnzV9jc= +github.com/gofrs/flock v0.12.0 h1:xHW8t8GPAiGtqz7KxiSqfOEXwpOaqhpYZrTE2MQBgXY= +github.com/gofrs/flock v0.12.0/go.mod h1:FirDy1Ing0mI2+kB6wk+vyyAH+e6xiE+EYA0jnzV9jc= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= @@ -300,8 +300,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.351.0 h1:igc4PZwU0enDBAG+QX5WmSvfM8BZ55mh1cGZc2YHbdY= -github.com/ice-blockchain/eskimo v1.351.0/go.mod h1:ODsZC4RYZQc8dOXW8JzwK9SBzDXxFYEauYpBMiTlBoo= +github.com/ice-blockchain/eskimo v1.353.0 h1:D+4xxO5HLrLMxuPTbIAvdtQqrplyo5UnOJUBNH67I/w= +github.com/ice-blockchain/eskimo v1.353.0/go.mod h1:Zwf7tnSRDPmuO1hBj7mFA5KjDgc0mLNDsq+tudGxwj0= 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.143.0 h1:KID/M01KN1jl7mlDF+VnIBScR7uT277mJtebYtemSF0= @@ -543,18 +543,18 @@ github.com/zeebo/xxh3 v1.0.2 h1:xZmwmqxHZA8AI603jOQ0tMqmBr9lPeFwGg6d+xy9DC0= github.com/zeebo/xxh3 v1.0.2/go.mod h1:5NWz9Sef7zIDm2JHfFlcQvNekmcEl9ekUZQQKCYaDcA= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0 h1:vS1Ao/R55RNV4O7TA2Qopok8yN+X0LIP6RVWLFkprck= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.52.0/go.mod h1:BMsdeOxN04K0L5FNUBfjFdvwWGNe/rkmSwH4Aelu/X0= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0 h1:9l89oX4ba9kHbBol3Xin3leYJ+252h0zszDtBwyKe2A= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.52.0/go.mod h1:XLZfZboOJWHNKUv7eH0inh0E9VV6eWDFB/9yJyTLPp0= -go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg= -go.opentelemetry.io/otel v1.27.0/go.mod h1:DMpAK8fzYRzs+bi3rS5REupisuqTheUlSZJ1WnZaPAQ= -go.opentelemetry.io/otel/metric v1.27.0 h1:hvj3vdEKyeCi4YaYfNjv2NUje8FqKqUY8IlF0FxV/ik= -go.opentelemetry.io/otel/metric v1.27.0/go.mod h1:mVFgmRlhljgBiuk/MP/oKylr4hs85GZAylncepAX/ak= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 h1:9G6E0TXzGFVfTnawRzrPl83iHOAV7L8NJiR8RSGYV1g= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0/go.mod h1:azvtTADFQJA8mX80jIH/akaE7h+dbm/sVuaHqN13w74= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 h1:4K4tsIXefpVJtvA/8srF4V4y0akAoPHkIslgAkjixJA= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0/go.mod h1:jjdQuTGVsXV4vSs+CJ2qYDeDPf9yIJV23qlIzBm73Vg= +go.opentelemetry.io/otel v1.28.0 h1:/SqNcYk+idO0CxKEUOtKQClMK/MimZihKYMruSMViUo= +go.opentelemetry.io/otel v1.28.0/go.mod h1:q68ijF8Fc8CnMHKyzqL6akLO46ePnjkgfIMIjUIX9z4= +go.opentelemetry.io/otel/metric v1.28.0 h1:f0HGvSl1KRAU1DLgLGFjrwVyismPlnuU6JD6bOeuA5Q= +go.opentelemetry.io/otel/metric v1.28.0/go.mod h1:Fb1eVBFZmLVTMb6PPohq3TO9IIhUisDsbJoL/+uQW4s= go.opentelemetry.io/otel/sdk v1.24.0 h1:YMPPDNymmQN3ZgczicBY3B6sf9n62Dlj9pWD3ucgoDw= go.opentelemetry.io/otel/sdk v1.24.0/go.mod h1:KVrIYw6tEubO9E96HQpcmpTKDVn9gdv35HoYiQWGDFg= -go.opentelemetry.io/otel/trace v1.27.0 h1:IqYb813p7cmbHk0a5y6pD5JPakbVfftRXABGt5/Rscw= -go.opentelemetry.io/otel/trace v1.27.0/go.mod h1:6RiD1hkAprV4/q+yd2ln1HG9GoPx39SuvvstaLBl+l4= +go.opentelemetry.io/otel/trace v1.28.0 h1:GhQ9cUuQGmNDd5BTCP2dAvv75RdMxEfTmYejp+lkx9g= +go.opentelemetry.io/otel/trace v1.28.0/go.mod h1:jPyXzNPg6da9+38HEwElrQiHlVMTnVfM3/yv2OlIHaI= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= diff --git a/miner/contract.go b/miner/contract.go index a93d0a2..2299fc7 100644 --- a/miner/contract.go +++ b/miner/contract.go @@ -74,6 +74,7 @@ type ( model.ExtraBonusField model.ActiveT1ReferralsField model.ActiveT2ReferralsField + model.T1ReferralsSharingEnabledField } UpdatedUser struct { // This is public only because we have to embed it, and it has to be if so. diff --git a/miner/mining.go b/miner/mining.go index 9fe41ab..d09602e 100644 --- a/miner/mining.go +++ b/miner/mining.go @@ -143,7 +143,11 @@ func mine(now *time.Time, usr *user, t0Ref, tMinus1Ref *referral) (updatedUser * } activeT1Referrals := int32(0) if updatedUser.MiningBoostLevelIndex != nil { - activeT1Referrals = int32(math.Min(float64((*cfg.miningBoostLevels.Load())[int(*updatedUser.MiningBoostLevelIndex)].MaxT1Referrals), float64(updatedUser.ActiveT1Referrals))) + if updatedUser.T1ReferralsSharingEnabled { + activeT1Referrals = int32((*cfg.miningBoostLevels.Load())[int(*updatedUser.MiningBoostLevelIndex)].MaxT1Referrals) + } else { + activeT1Referrals = int32(math.Min(float64((*cfg.miningBoostLevels.Load())[int(*updatedUser.MiningBoostLevelIndex)].MaxT1Referrals), float64(updatedUser.ActiveT1Referrals))) + } } t1Rate := (25 * float64(activeT1Referrals)) * baseMiningRate * elapsedTimeFraction / 100 t2Rate := (5 * float64(updatedUser.ActiveT2Referrals)) * baseMiningRate * elapsedTimeFraction / 100 diff --git a/model/model.go b/model/model.go index 6e08810..2663afc 100644 --- a/model/model.go +++ b/model/model.go @@ -325,6 +325,9 @@ type ( HideRankingField struct { HideRanking bool `redis:"hide_ranking" json:"-"` } + T1ReferralsSharingEnabledField struct { + T1ReferralsSharingEnabled bool `json:"t1ReferralsSharingEnabled" redis:"t1_referrals_sharing_enabled"` + } CreatedAtField struct { CreatedAt *time.Time `json:"-" redis:"created_at"` } diff --git a/tokenomics/contract.go b/tokenomics/contract.go index f913c69..1f5a9fb 100644 --- a/tokenomics/contract.go +++ b/tokenomics/contract.go @@ -208,6 +208,7 @@ type ( UserID *string `json:"userId,omitempty" swaggerignore:"true" example:"did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2"` Extension stdlibtime.Duration `json:"extension,omitempty" swaggerignore:"true" example:"24h"` MiningStreak uint64 `json:"miningStreak,omitempty" swaggerignore:"true" example:"11"` + MiningBoostLevel uint8 `json:"miningBoostLevel,omitempty" swaggerignore:"true" example:"1"` } ExtraBonusSummary struct { UserID string `json:"userId,omitempty" swaggerignore:"true" example:"did:ethr:0x4B73C58370AEfcEf86A6021afCDe5673511376B2"` diff --git a/tokenomics/kyc.go b/tokenomics/kyc.go index 509f718..365e702 100644 --- a/tokenomics/kyc.go +++ b/tokenomics/kyc.go @@ -494,6 +494,7 @@ func (r *repository) overrideKYCStateWithEskimoKYCState(ctx context.Context, use model.KYCState model.DeserializedUsersKey model.HideRankingField + model.T1ReferralsSharingEnabledField KycFaceAvailable bool `json:"kycFaceAvailable" redis:"-"` } if err3 := json.Unmarshal(data, &usr); err3 != nil { diff --git a/tokenomics/mining.go b/tokenomics/mining.go index fd989bc..42c1d60 100644 --- a/tokenomics/mining.go +++ b/tokenomics/mining.go @@ -195,6 +195,7 @@ func (r *repository) GetMiningSummary(ctx context.Context, userID string) (*Mini model.ExtraBonusDaysClaimNotAvailableResettableField model.NewsSeenField model.KYCStepBlockedField + model.T1ReferralsSharingEnabledField }](ctx, r.db, model.SerializedUsersKey(id)) if err != nil || len(ms) == 0 { if err == nil { @@ -220,7 +221,11 @@ func (r *repository) GetMiningSummary(ctx context.Context, userID string) (*Mini maxMiningSessionDuration := r.cfg.maxMiningSessionDuration(ms[0].MiningBoostLevelIndexField) activeT1Referrals := int32(0) if ms[0].MiningBoostLevelIndex != nil { - activeT1Referrals = int32(math.Min(float64((*r.cfg.MiningBoost.levels.Load())[int(*ms[0].MiningBoostLevelIndex)].MaxT1Referrals), float64(ms[0].ActiveT1Referrals))) + if ms[0].T1ReferralsSharingEnabled { + activeT1Referrals = int32((*r.cfg.MiningBoost.levels.Load())[int(*ms[0].MiningBoostLevelIndex)].MaxT1Referrals) + } else { + activeT1Referrals = int32(math.Min(float64((*r.cfg.MiningBoost.levels.Load())[int(*ms[0].MiningBoostLevelIndex)].MaxT1Referrals), float64(ms[0].ActiveT1Referrals))) + } } return &MiningSummary{ diff --git a/tokenomics/mining_sessions.go b/tokenomics/mining_sessions.go index 823fb87..4f7929a 100644 --- a/tokenomics/mining_sessions.go +++ b/tokenomics/mining_sessions.go @@ -71,6 +71,10 @@ func (r *repository) StartNewMiningSession( //nolint:funlen,gocognit // A lot of return errors.Wrapf(err, "failed to get miningSummary for id:%v", id) } + var miningBoostLevel uint8 + if old[0].MiningBoostLevelIndex != nil { + miningBoostLevel = uint8(*old[0].MiningBoostLevelIndex) + 1 + } maxMiningSessionDuration := r.cfg.maxMiningSessionDuration(old[0].MiningBoostLevelIndexField) if !old[0].MiningSessionSoloEndedAt.IsNil() && !old[0].MiningSessionSoloLastStartedAt.IsNil() && @@ -126,6 +130,7 @@ func (r *repository) StartNewMiningSession( //nolint:funlen,gocognit // A lot of UserID: &userID, ResettableStartingAt: time.New(newMS.MiningSessionSoloLastStartedAt.Add(r.cfg.MiningSessionDuration.Min)), WarnAboutExpirationStartingAt: time.New(newMS.MiningSessionSoloLastStartedAt.Add(maxMiningSessionDuration - r.cfg.MiningSessionDuration.Max).Add(r.cfg.MiningSessionDuration.WarnAboutExpirationAfter)), + MiningBoostLevel: miningBoostLevel, } if err = r.sendMiningSessionMessage(ctx, sess); err != nil { return errors.Wrapf(err, "failed to sendMiningSessionMessage:%#v", sess) diff --git a/tokenomics/users.go b/tokenomics/users.go index 4a4a2c4..287d178 100644 --- a/tokenomics/users.go +++ b/tokenomics/users.go @@ -179,6 +179,7 @@ func (s *usersTableSource) replaceUser(ctx context.Context, usr *users.User) err model.KYCStepPassedField model.KYCStepBlockedField model.HideRankingField + model.T1ReferralsSharingEnabledField } readOnlyUser struct { LocalUser @@ -218,12 +219,16 @@ func (s *usersTableSource) replaceUser(ctx context.Context, usr *users.User) err newPartialState.KYCStepsCreatedAt = &val } newPartialState.HideRanking = buildHideRanking(usr.HiddenProfileElements) + if usr.T1ReferralsSharingEnabled != nil { + newPartialState.T1ReferralsSharingEnabled = *usr.T1ReferralsSharingEnabled + } if newPartialState.ProfilePictureName != dbUser[0].ProfilePictureName || newPartialState.Username != dbUser[0].Username || !strings.EqualFold(newPartialState.Country, dbUser[0].Country) || newPartialState.MiningBlockchainAccountAddress != dbUser[0].MiningBlockchainAccountAddress || newPartialState.BlockchainAccountAddress != dbUser[0].BlockchainAccountAddress || newPartialState.HideRanking != dbUser[0].HideRanking || + newPartialState.T1ReferralsSharingEnabled != dbUser[0].T1ReferralsSharingEnabled || (dbUser[0].CreatedAt.IsNil() || !newPartialState.CreatedAt.Equal(*dbUser[0].CreatedAt.Time)) || !newPartialState.KYCStepsCreatedAt.Equals(dbUser[0].KYCStepsCreatedAt) || !newPartialState.KYCStepsLastUpdatedAt.Equals(dbUser[0].KYCStepsLastUpdatedAt) ||