Skip to content

Commit

Permalink
Revert "TMinus1Balance recalculations (with dry run flag enabled). Ba…
Browse files Browse the repository at this point in the history
…lanceT2 recalculations disabled. (#59)"

This reverts commits c4b4d62, a44b46f, 4f520ba.
  • Loading branch information
ice-myles committed Dec 18, 2023
1 parent 4f520ba commit 2b5a52c
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 892 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
16 changes: 0 additions & 16 deletions miner/.testdata/DDL.sql

This file was deleted.

23 changes: 2 additions & 21 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,24 +40,13 @@ const (
applicationYamlKey = "miner"
parentApplicationYamlKey = "tokenomics"
requestDeadline = 30 * stdlibtime.Second

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

balanceForTMinusBugfixEnabled = true
balanceForTMinusBugfixDryRunEnabled = true

balanceT2BugfixDryRunEnabled = false
balanceT2BugfixEnabled = false
balanceBugFixEnabled = 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 @@ -132,17 +119,12 @@ type (
}

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

recalculated struct {
model.RecalculatedBalanceForTMinus1AtField
model.RecalculatedBalanceT2AtField
model.DeserializedRecalculatedUsersKey
}

referralCountGuardUpdatedUser struct {
model.ReferralsCountChangeGuardUpdatedAtField
model.DeserializedUsersKey
Expand All @@ -161,7 +143,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 2b5a52c

Please sign in to comment.