Skip to content

Commit

Permalink
Revert of balanceTMinus1/BalanceT2 recalculations. (#62)
Browse files Browse the repository at this point in the history
This reverts balanceTMinus1/BalanceT2 recalculations.
  • Loading branch information
ice-myles authored Dec 19, 2023
1 parent 9d8a4aa commit 9a8b37b
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 1,030 deletions.
13 changes: 0 additions & 13 deletions bookkeeper/storage/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ type (
Insert(ctx context.Context, columns *Columns, input InsertMetadata, usrs []*model.User) error
SelectBalanceHistory(ctx context.Context, id int64, createdAts []stdlibtime.Time) ([]*BalanceHistory, error)
SelectTotalCoins(ctx context.Context, createdAts []stdlibtime.Time) ([]*TotalCoins, error)
GetAdjustUserInformation(ctx context.Context, userIDs []string, startFrom string, limit, offset int64) ([]*AdjustUserInfo, error)
GetBaseBalanceForTMinus1(ctx context.Context, userIDs []string, limit, offset int64) (map[int64]float64, error)
}
AdjustUserInfo struct {
MiningSessionSoloStartedAt *time.Time
MiningSessionSoloEndedAt *time.Time
MiningSessionSoloLastStartedAt *time.Time
MiningSessionSoloPreviouslyEndedAt *time.Time
ResurrectSoloUsedAt *time.Time
CreatedAt *time.Time
ID int64
}
BalanceHistory struct {
CreatedAt *time.Time
Expand Down Expand Up @@ -118,8 +107,6 @@ type (

const (
tableName = "freezer_user_history"

validBalanceForTMinus1DateTime = "2023-11-20T14:00:00"
)

// .
Expand Down
96 changes: 0 additions & 96 deletions bookkeeper/storage/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/ClickHouse/ch-go/chpool"
"github.com/ClickHouse/ch-go/proto"
"github.com/hashicorp/go-multierror"
"github.com/pkg/errors"
"go.uber.org/zap"

"github.com/ice-blockchain/freezer/model"
Expand Down Expand Up @@ -529,101 +528,6 @@ func (db *db) SelectBalanceHistory(ctx context.Context, id int64, createdAts []s
return res, nil
}

func (db *db) GetAdjustUserInformation(ctx context.Context, userIDArray []string, startFrom string, limit, offset int64) ([]*AdjustUserInfo, error) {
var (
id = make(proto.ColInt64, 0)
miningSessionSoloStartedAt = proto.ColDateTime64{Data: make([]proto.DateTime64, 0), Location: stdlibtime.UTC}
miningSessionSoloEndedAt = proto.ColDateTime64{Data: make([]proto.DateTime64, 0), Location: stdlibtime.UTC}
miningSessionSoloPreviouslyEndedAt = proto.ColDateTime64{Data: make([]proto.DateTime64, 0), Location: stdlibtime.UTC}
resurrectSoloUsedAt = proto.ColDateTime64{Data: make([]proto.DateTime64, 0), Location: stdlibtime.UTC}
createdAt = proto.ColDateTime{Data: make([]proto.DateTime, 0), Location: stdlibtime.UTC}
res = make([]*AdjustUserInfo, 0, len(userIDArray))
)
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,
max(mining_session_solo_ended_at) AS mining_session_solo_ended_at,
mining_session_solo_previously_ended_at,
resurrect_solo_used_at,
max(created_at) as created_at_time
FROM %[1]v
WHERE id IN [%[2]v] AND created_at > toDateTime('%[3]v', 'UTC')
GROUP BY mining_session_solo_started_at, id, mining_session_solo_previously_ended_at, resurrect_solo_used_at
ORDER BY id ASC, created_at_time ASC
LIMIT %[4]v, %[5]v
`, tableName, strings.Join(userIDArray, ","), startFrom, offset, limit),
Result: append(make(proto.Results, 0, 6),
proto.ResultColumn{Name: "id", Data: &id},
proto.ResultColumn{Name: "mining_session_solo_started_at", Data: &miningSessionSoloStartedAt},
proto.ResultColumn{Name: "mining_session_solo_ended_at", Data: &miningSessionSoloEndedAt},
proto.ResultColumn{Name: "mining_session_solo_previously_ended_at", Data: &miningSessionSoloPreviouslyEndedAt},
proto.ResultColumn{Name: "resurrect_solo_used_at", Data: &resurrectSoloUsedAt},
proto.ResultColumn{Name: "created_at_time", Data: &createdAt},
),
OnResult: func(_ context.Context, block proto.Block) error {
for ix := 0; ix < block.Rows; ix++ {
res = append(res, &AdjustUserInfo{
ID: (&id).Row(ix),
MiningSessionSoloStartedAt: time.New((&miningSessionSoloStartedAt).Row(ix)),
MiningSessionSoloEndedAt: time.New((&miningSessionSoloEndedAt).Row(ix)),
MiningSessionSoloPreviouslyEndedAt: time.New((&miningSessionSoloPreviouslyEndedAt).Row(ix)),
CreatedAt: time.New((&createdAt).Row(ix)),
ResurrectSoloUsedAt: time.New((&resurrectSoloUsedAt).Row(ix)),
})
}
(&id).Reset()
(&miningSessionSoloStartedAt).Reset()
(&miningSessionSoloEndedAt).Reset()
(&miningSessionSoloPreviouslyEndedAt).Reset()
(&resurrectSoloUsedAt).Reset()
(&createdAt).Reset()

return nil
},
Secret: "",
InitialUser: "",
}); err != nil {
return nil, err
}

return res, nil
}

func (db *db) GetBaseBalanceForTMinus1(ctx context.Context, userIDs []string, limit, offset int64) (map[int64]float64, error) {
var (
id = make(proto.ColInt64, 0, len(userIDs))
balanceForTMinus1 = make(proto.ColFloat64, 0, len(userIDs))
res = make(map[int64]float64)
)
if err := db.pools[atomic.AddUint64(&db.currentIndex, 1)%uint64(len(db.pools))].Do(ctx, ch.Query{
Body: fmt.Sprintf(`SELECT id, balance_for_tminus1
FROM %[1]v
WHERE id IN [%[2]v] AND created_at = toDateTime('%[3]v', 'UTC')
LIMIT %[4]v, %[5]v
`, tableName, strings.Join(userIDs, ","), validBalanceForTMinus1DateTime, offset, limit),
Result: append(make(proto.Results, 0, 2),
proto.ResultColumn{Name: "id", Data: &id},
proto.ResultColumn{Name: "balance_for_tminus1", Data: &balanceForTMinus1},
),
OnResult: func(_ context.Context, block proto.Block) error {
for ix := 0; ix < block.Rows; ix++ {
res[(&id).Row(ix)] = (&balanceForTMinus1).Row(ix)
}
(&id).Reset()
(&balanceForTMinus1).Reset()

return nil
},
Secret: "",
InitialUser: "",
}); err != nil {
return nil, errors.Wrapf(err, "failed to call clickhouse for balance_for_tminus1 at %v, offset %v", validBalanceForTMinus1DateTime, offset)
}

return res, nil
}

func (db *db) SelectTotalCoins(ctx context.Context, createdAts []stdlibtime.Time) ([]*TotalCoins, error) {
var (
createdAt = proto.ColDateTime{Data: make([]proto.DateTime, 0, len(createdAts)), Location: stdlibtime.UTC}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ require (
go.uber.org/multierr v1.11.0 // indirect
golang.org/x/arch v0.6.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/exp v0.0.0-20231219160207-73b9e39aefca // indirect
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 // indirect
golang.org/x/mod v0.14.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/oauth2 v0.15.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -407,8 +407,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y
golang.org/x/crypto v0.17.0 h1:r8bRNjWL3GshPW3gkd+RpvzWrZAwPS49OmTGZ/uhM4k=
golang.org/x/crypto v0.17.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/exp v0.0.0-20231219160207-73b9e39aefca h1:+xQfFu/HO/82Wwg4zuJ5xiLp0yaOLJjBGnuafXp85YQ=
golang.org/x/exp v0.0.0-20231219160207-73b9e39aefca/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848 h1:+iq7lrkxmFNBM7xx+Rae2W6uyPfhPeDWD+n+JgppptE=
golang.org/x/exp v0.0.0-20231219180239-dc181d75b848/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
Expand Down
16 changes: 0 additions & 16 deletions miner/.testdata/DDL.sql

This file was deleted.

36 changes: 0 additions & 36 deletions miner/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ package miner

import (
"context"
_ "embed"
"io"
"sync"
"sync/atomic"
Expand All @@ -14,7 +13,6 @@ import (
"github.com/ice-blockchain/freezer/model"
"github.com/ice-blockchain/freezer/tokenomics"
messagebroker "github.com/ice-blockchain/wintr/connectors/message_broker"
storagePG "github.com/ice-blockchain/wintr/connectors/storage/v2"
"github.com/ice-blockchain/wintr/connectors/storage/v3"
"github.com/ice-blockchain/wintr/time"
)
Expand Down Expand Up @@ -42,28 +40,12 @@ const (
applicationYamlKey = "miner"
parentApplicationYamlKey = "tokenomics"
requestDeadline = 30 * stdlibtime.Second

startRecalculationsFrom = "2023-11-20T14:00:00"
timeLayout = "2006-01-02T15:04:05"

// Dry run.
balanceForTMinusBugfixDryRunEnabled = false
balanceT2BugfixDryRunEnabled = false

// !!! [CRUCUAL] Real run if this is TRUE and DRY RUN false.
balanceForTMinusBugfixEnabled = false
balanceT2BugfixEnabled = false

clearBugfixDebugInfoEnabled = true
)

// .
var (
//nolint:gochecknoglobals // Singleton & global config mounted only during bootstrap.
cfg config

//go:embed .testdata/DDL.sql
eskimoDDL string
)

type (
Expand Down Expand Up @@ -135,17 +117,6 @@ type (
model.DeserializedUsersKey
}

recalculateReferral struct {
model.BalanceForTMinus1Field
model.UserIDField
model.DeserializedUsersKey
}

recalculated struct {
model.RecalculatedBalanceForTMinus1AtField
model.DeserializedRecalculatedUsersKey
}

referralCountGuardUpdatedUser struct {
model.ReferralsCountChangeGuardUpdatedAtField
model.DeserializedUsersKey
Expand All @@ -156,12 +127,6 @@ type (
ID, IDT0, IDTMinus1 int64
}

dryrunUser struct {
model.DeserializedDryRunUsersKey
model.IDTMinus1Field
model.RecalculatedBalanceForTMinus1AtField
}

miner struct {
mb messagebroker.Client
db storage.DB
Expand All @@ -170,7 +135,6 @@ type (
telemetry *telemetry
wg *sync.WaitGroup
extraBonusStartDate *time.Time
dbPG *storagePG.DB
extraBonusIndicesDistribution map[uint16]map[uint16]uint16
}
config struct {
Expand Down
Loading

0 comments on commit 9a8b37b

Please sign in to comment.