Skip to content

Commit

Permalink
Work on comments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-myles committed Oct 19, 2023
1 parent 635c61a commit be7ccfe
Show file tree
Hide file tree
Showing 12 changed files with 294 additions and 366 deletions.
2 changes: 1 addition & 1 deletion bookkeeper/storage/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type (
Ping(ctx context.Context) error
Insert(ctx context.Context, columns *Columns, input InsertMetadata, usrs []*model.User) error
SelectBalanceHistory(ctx context.Context, id int64, createdAts []stdlibtime.Time) ([]*BalanceHistory, error)
GetAdjustUserInformation(ctx context.Context, userIDs map[int64]struct{}) ([]*AdjustUserInfo, error)
GetAdjustUserInformation(ctx context.Context, userIDs map[int64]struct{}, limit, offset int64) ([]*AdjustUserInfo, error)
}
AdjustUserInfo struct {
MiningSessionSoloStartedAt *time.Time
Expand Down
9 changes: 7 additions & 2 deletions bookkeeper/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ func (db *db) SelectBalanceHistory(ctx context.Context, id int64, createdAts []s
return res, nil
}

func (db *db) GetAdjustUserInformation(ctx context.Context, userIDs map[int64]struct{}) ([]*AdjustUserInfo, error) {
func (db *db) GetAdjustUserInformation(ctx context.Context, userIDs map[int64]struct{}, limit, offset int64) ([]*AdjustUserInfo, error) {
var (
id = make(proto.ColInt64, 0, len(userIDs))
miningSessionSoloStartedAt = proto.ColDateTime64{Data: make([]proto.DateTime64, 0, len(userIDs)), Location: stdlibtime.UTC}
Expand All @@ -463,6 +463,10 @@ func (db *db) GetAdjustUserInformation(ctx context.Context, userIDs map[int64]st
for key, _ := range userIDs {
userIDArray = append(userIDArray, fmt.Sprint(key))
}
var offsetStr string
if offset > 0 {
offsetStr = fmt.Sprintf(", %v", offset)
}
if err := db.pools[atomic.AddUint64(&db.currentIndex, 1)%uint64(len(db.pools))].Do(ctx, ch.Query{
Body: fmt.Sprintf(`SELECT id,
mining_session_solo_started_at,
Expand All @@ -479,7 +483,8 @@ func (db *db) GetAdjustUserInformation(ctx context.Context, userIDs map[int64]st
FROM %[1]v
WHERE id IN [%[2]v]
ORDER BY created_at ASC
`, tableName, strings.Join(userIDArray, ",")),
LIMIT %[3]v %[4]v
`, tableName, strings.Join(userIDArray, ","), limit, offsetStr),
Result: append(make(proto.Results, 0, 12),
proto.ResultColumn{Name: "id", Data: &id},
proto.ResultColumn{Name: "mining_session_solo_started_at", Data: &miningSessionSoloStartedAt},
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ require (
)

require (
cloud.google.com/go v0.110.8 // indirect
cloud.google.com/go v0.110.9 // indirect
cloud.google.com/go/compute v1.23.1 // indirect
cloud.google.com/go/compute/metadata v0.2.3 // indirect
cloud.google.com/go/firestore v1.13.0 // indirect
cloud.google.com/go/firestore v1.14.0 // indirect
cloud.google.com/go/iam v1.1.3 // indirect
cloud.google.com/go/longrunning v0.5.2 // indirect
cloud.google.com/go/storage v1.33.0 // indirect
Expand Down Expand Up @@ -159,7 +159,7 @@ require (
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.14.0 // indirect
golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 // indirect
google.golang.org/api v0.147.0 // indirect
google.golang.org/api v0.148.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-20231016165738-49dd2c1f3d0b // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ cloud.google.com/go v0.65.0/go.mod h1:O5N8zS7uWy9vkA9vayVHs65eM1ubvY4h553ofrNHOb
cloud.google.com/go v0.72.0/go.mod h1:M+5Vjvlc2wnp6tjzE102Dw08nGShTscUx2nZMufOKPI=
cloud.google.com/go v0.74.0/go.mod h1:VV1xSbzvo+9QJOxLDaJfTjx5e+MePCpCWwvftOeQmWk=
cloud.google.com/go v0.75.0/go.mod h1:VGuuCn7PG0dwsd5XPVm2Mm3wlh3EL55/79EKB6hlPTY=
cloud.google.com/go v0.110.8 h1:tyNdfIxjzaWctIiLYOTalaLKZ17SI44SKFW26QbOhME=
cloud.google.com/go v0.110.8/go.mod h1:Iz8AkXJf1qmxC3Oxoep8R1T36w8B92yU29PcBhHO5fk=
cloud.google.com/go v0.110.9 h1:e7ITSqGFFk4rbz/JFIqZh3G4VEHguhAL4BQcFlWtU68=
cloud.google.com/go v0.110.9/go.mod h1:rpxevX/0Lqvlbc88b7Sc1SPNdyK1riNBTUU6JXhYNpM=
cloud.google.com/go/bigquery v1.0.1/go.mod h1:i/xbL2UlR5RvWAURpBYZTtm/cXjCha9lbfbpx4poX+o=
cloud.google.com/go/bigquery v1.3.0/go.mod h1:PjpwJnslEMmckchkHFfq+HTD2DmtT67aNFKH1/VBDHE=
cloud.google.com/go/bigquery v1.4.0/go.mod h1:S8dzgnTigyfTmLBfrtrhyYhwRxG72rYxvftPBK2Dvzc=
Expand All @@ -31,8 +31,8 @@ cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGB
cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA=
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
cloud.google.com/go/firestore v1.13.0 h1:/3S4RssUV4GO/kvgJZB+tayjhOfyAHs+KcpJgRVu/Qk=
cloud.google.com/go/firestore v1.13.0/go.mod h1:QojqqOh8IntInDUSTAh0c8ZsPYAr68Ma8c5DWOy8xb8=
cloud.google.com/go/firestore v1.14.0 h1:8aLcKnMPoldYU3YHgu4t2exrKhLQkqaXAGqT0ljrFVw=
cloud.google.com/go/firestore v1.14.0/go.mod h1:96MVaHLsEhbvkBEdZgfN+AS/GIkco1LRpH9Xp9YZfzQ=
cloud.google.com/go/iam v1.1.3 h1:18tKG7DzydKWUnLjonWcJO6wjSCAtzh4GcRKlH/Hrzc=
cloud.google.com/go/iam v1.1.3/go.mod h1:3khUlaBXfPKKe7huYgEpDn6FtgRyMEqbkvBxrQyY5SE=
cloud.google.com/go/longrunning v0.5.2 h1:u+oFqfEwwU7F9dIELigxbe0XVnBAo9wqMuQLA50CZ5k=
Expand Down Expand Up @@ -762,8 +762,8 @@ google.golang.org/api v0.30.0/go.mod h1:QGmEvQ87FHZNiUVJkT14jQNYJ4ZJjdRF23ZXz513
google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ1dg=
google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE=
google.golang.org/api v0.40.0/go.mod h1:fYKFpnQN0DsDSKRVRcQSDQNtqWPfM9i+zNPxepjRCQ8=
google.golang.org/api v0.147.0 h1:Can3FaQo9LlVqxJCodNmeZW/ib3/qKAY3rFeXiHo5gc=
google.golang.org/api v0.147.0/go.mod h1:pQ/9j83DcmPd/5C9e2nFOdjjNkDZ1G+zkbK2uvdkJMs=
google.golang.org/api v0.148.0 h1:HBq4TZlN4/1pNcu0geJZ/Q50vIwIXT532UIMYoo0vOs=
google.golang.org/api v0.148.0/go.mod h1:8/TBgwaKjfqTdacOJrOv2+2Q6fBDU1uHKK06oGSkxzU=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
Expand Down
32 changes: 0 additions & 32 deletions miner/DDL.sql

This file was deleted.

150 changes: 150 additions & 0 deletions miner/adoption_range_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
// SPDX-License-Identifier: ice License 1.0

package miner

import (
"testing"
stdlibtime "time"

"github.com/ice-blockchain/freezer/tokenomics"
"github.com/ice-blockchain/wintr/time"
"github.com/stretchr/testify/assert"
)

func TestGetAdoptionsRange_1AdoptionPerRange(t *testing.T) {
var adoptions []*tokenomics.Adoption[float64]
adoptions = append(adoptions, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-58 * stdlibtime.Minute)),
BaseMiningRate: 16.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-55 * stdlibtime.Minute)),
BaseMiningRate: 8.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-30 * stdlibtime.Minute)),
BaseMiningRate: 4.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-10 * stdlibtime.Minute)),
BaseMiningRate: 2.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: nil,
BaseMiningRate: 1.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: nil,
BaseMiningRate: 0.5,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: nil,
BaseMiningRate: 0.25,
Milestone: 1,
TotalActiveUsers: 1,
})
startedAt := time.New(time.Now().Add(-1 * stdlibtime.Minute))
endedAt := time.Now()
ranges := splitByAdoptionTimeRanges(adoptions, startedAt, endedAt)
assert.Equal(t, 2., ranges[0].BaseMiningRate)
assert.Equal(t, 2., ranges[1].BaseMiningRate)
}

func TestGetAdoptionsRange_2AdoptionsPerRange(t *testing.T) {
var adoptions []*tokenomics.Adoption[float64]
adoptions = append(adoptions, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-58 * stdlibtime.Minute)),
BaseMiningRate: 16.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-55 * stdlibtime.Minute)),
BaseMiningRate: 8.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-30 * stdlibtime.Minute)),
BaseMiningRate: 4.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-10 * stdlibtime.Minute)),
BaseMiningRate: 2.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-30 * stdlibtime.Second)),
BaseMiningRate: 1.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: nil,
BaseMiningRate: 0.5,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: nil,
BaseMiningRate: 0.25,
Milestone: 1,
TotalActiveUsers: 1,
})
startedAt := time.New(time.Now().Add(-1 * stdlibtime.Minute))
endedAt := time.Now()
ranges := splitByAdoptionTimeRanges(adoptions, startedAt, endedAt)
assert.Equal(t, 2., ranges[0].BaseMiningRate)
assert.Equal(t, 1., ranges[1].BaseMiningRate)
assert.Equal(t, 1., ranges[2].BaseMiningRate)
}

func TestGetAdoptionsRange_AdoptionDemotionPerRange(t *testing.T) {
var adoptions []*tokenomics.Adoption[float64]
adoptions = append(adoptions, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-30 * stdlibtime.Second)),
BaseMiningRate: 16.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-55 * stdlibtime.Minute)),
BaseMiningRate: 8.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-30 * stdlibtime.Minute)),
BaseMiningRate: 4.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: time.New(time.Now().Add(-1 * stdlibtime.Minute)),
BaseMiningRate: 2.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: nil,
BaseMiningRate: 1.0,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: nil,
BaseMiningRate: 0.5,
Milestone: 1,
TotalActiveUsers: 1,
}, &tokenomics.Adoption[float64]{
AchievedAt: nil,
BaseMiningRate: 0.25,
Milestone: 1,
TotalActiveUsers: 1,
})
startedAt := time.New(time.Now().Add(-2 * stdlibtime.Minute))
endedAt := time.Now()
ranges := splitByAdoptionTimeRanges(adoptions, startedAt, endedAt)
assert.Equal(t, 4., ranges[0].BaseMiningRate)
assert.Equal(t, 2., ranges[1].BaseMiningRate)
assert.Equal(t, 16., ranges[2].BaseMiningRate)
assert.Equal(t, 16., ranges[3].BaseMiningRate)
}
9 changes: 1 addition & 8 deletions miner/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ const (

// .
var (
//go:embed DDL.sql
ddl string

//nolint:gochecknoglobals // Singleton & global config mounted only during bootstrap.
cfg config
)
Expand Down Expand Up @@ -116,11 +113,6 @@ type (
model.BalanceT2Field
}

recalculatedUser struct {
model.DeserializedRecalculatedUsersKey
model.RecalculatedTiersBalancesAtField
}

referral struct {
model.MiningSessionSoloStartedAtField
model.MiningSessionSoloEndedAtField
Expand All @@ -146,6 +138,7 @@ type (
wg *sync.WaitGroup
extraBonusStartDate *time.Time
extraBonusIndicesDistribution map[uint16]map[uint16]uint16
recalculationBalanceStartDate *time.Time
}
config struct {
disableAdvancedTeam *atomic.Pointer[[]string]
Expand Down
Loading

0 comments on commit be7ccfe

Please sign in to comment.