Skip to content

Commit

Permalink
Revert t1/t2 balance and t1/t2 active counts recalculation.
Browse files Browse the repository at this point in the history
This reverts commits 0642276 (#33), 93040b8 (#35), 77b2f69 (#36), 3768872 (#37), 227611e (#38).
  • Loading branch information
ice-myles committed Nov 3, 2023
1 parent 9ccbb91 commit be0c480
Show file tree
Hide file tree
Showing 12 changed files with 12 additions and 1,352 deletions.
9 changes: 0 additions & 9 deletions application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -156,20 +156,11 @@ tokenomics: &tokenomics
- 5
- 9
- 20
wintr/connectors/storage/v2: &db
runDDL: true
primaryURL: postgresql://root:pass@localhost:5433/eskimo
credentials:
user: root
password: pass
replicaURLs:
- postgresql://root:pass@localhost:5433/eskimo
miner:
bookkeeper/storage: *bookkeeperStorage
development: true
workers: 1
batchSize: 100
wintr/connectors/storage/v2: *db
extra-bonus-notifier:
workers: 1
miningSessionDuration: 1m
Expand Down
22 changes: 0 additions & 22 deletions bookkeeper/storage/contract.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,6 @@ 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 []string, limit, offset int64) ([]*AdjustUserInfo, error)
}
AdjustUserInfo struct {
MiningSessionSoloStartedAt *time.Time
MiningSessionSoloEndedAt *time.Time
MiningSessionSoloLastStartedAt *time.Time
MiningSessionSoloPreviouslyEndedAt *time.Time
CreatedAt *time.Time
ResurrectSoloUsedAt *time.Time
UserID string
ID int64
SlashingRateSolo float64
SlashingRateT1 float64
SlashingRateT2 float64
BalanceSolo float64
BalanceT0 float64
BalanceT1Pending float64
BalanceT1PendingApplied float64
BalanceT2Pending float64
BalanceT2PendingApplied float64
PrestakingAllocation uint16
PrestakingBonus uint16
}
BalanceHistory struct {
CreatedAt *time.Time
Expand Down
130 changes: 0 additions & 130 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 @@ -443,132 +442,3 @@ func (db *db) SelectBalanceHistory(ctx context.Context, id int64, createdAts []s

return res, nil
}

func (db *db) GetAdjustUserInformation(ctx context.Context, userIDs []string, limit, offset int64) ([]*AdjustUserInfo, error) {
const (
maxIDCount = 25_000
)
var (
res = make([]*AdjustUserInfo, 0, len(userIDs))
counter = 0
)
var userIDArray []string
for _, id := range userIDs {
userIDArray = append(userIDArray, id)
counter++
if counter >= maxIDCount { // Hack not to have 'Max query size exceeded' error.
result, err := db.getAdjustUserInformation(ctx, userIDArray, limit, offset)
if err != nil {
return nil, errors.Wrapf(err, "can't get adjust user information for userIDs:%#v", userIDArray)
}
res = append(res, result...)
userIDArray = userIDArray[:0]
counter = 0

continue
}
}
if len(userIDArray) > 0 {
result, err := db.getAdjustUserInformation(ctx, userIDArray, limit, offset)
if err != nil {
return nil, errors.Wrapf(err, "can't get adjust user information for userIDs:%#v", userIDArray)
}
res = append(res, result...)
}

return res, nil
}

func (db *db) getAdjustUserInformation(ctx context.Context, userIDArray []string, limit, offset int64) ([]*AdjustUserInfo, error) {
var (
id = make(proto.ColInt64, 0, len(userIDArray))
userID = &proto.ColStr{Buf: make([]byte, 0, 40*len(userIDArray)), Pos: make([]proto.Position, 0, len(userIDArray))}
miningSessionSoloStartedAt = proto.ColDateTime64{Data: make([]proto.DateTime64, 0, len(userIDArray)), Location: stdlibtime.UTC}
miningSessionSoloEndedAt = proto.ColDateTime64{Data: make([]proto.DateTime64, 0, len(userIDArray)), Location: stdlibtime.UTC}
miningSessionSoloPreviouslyEndedAt = proto.ColDateTime64{Data: make([]proto.DateTime64, 0, len(userIDArray)), Location: stdlibtime.UTC}
slashingRateSolo = make(proto.ColFloat64, 0, len(userIDArray))
createdAt = proto.ColDateTime{Data: make([]proto.DateTime, 0), Location: stdlibtime.UTC}
resurrectSoloUsedAt = proto.ColDateTime64{Data: make([]proto.DateTime64, 0, len(userIDArray)), Location: stdlibtime.UTC}
balanceSolo = make(proto.ColFloat64, 0, len(userIDArray))
balanceT1Pending = make(proto.ColFloat64, 0, len(userIDArray))
balanceT1PendingApplied = make(proto.ColFloat64, 0, len(userIDArray))
balanceT2Pending = make(proto.ColFloat64, 0, len(userIDArray))
balanceT2PendingApplied = make(proto.ColFloat64, 0, len(userIDArray))
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,
user_id,
mining_session_solo_started_at,
mining_session_solo_ended_at,
mining_session_solo_previously_ended_at,
slashing_rate_solo,
created_at,
resurrect_solo_used_at,
balance_solo,
balance_t1_pending,
balance_t1_pending_applied,
balance_t2_pending,
balance_t2_pending_applied
FROM %[1]v
WHERE id IN [%[2]v]
ORDER BY created_at ASC
LIMIT %[3]v, %[4]v
`, tableName, strings.Join(userIDArray, ","), offset, limit),
Result: append(make(proto.Results, 0, 13),
proto.ResultColumn{Name: "id", Data: &id},
proto.ResultColumn{Name: "user_id", Data: userID},
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: "slashing_rate_solo", Data: &slashingRateSolo},
proto.ResultColumn{Name: "created_at", Data: &createdAt},
proto.ResultColumn{Name: "resurrect_solo_used_at", Data: &resurrectSoloUsedAt},
proto.ResultColumn{Name: "balance_solo", Data: &balanceSolo},
proto.ResultColumn{Name: "balance_t1_pending", Data: &balanceT1Pending},
proto.ResultColumn{Name: "balance_t1_pending_applied", Data: &balanceT1PendingApplied},
proto.ResultColumn{Name: "balance_t2_pending", Data: &balanceT2Pending},
proto.ResultColumn{Name: "balance_t2_pending_applied", Data: &balanceT2PendingApplied},
),
OnResult: func(_ context.Context, block proto.Block) error {
for ix := 0; ix < block.Rows; ix++ {
res = append(res, &AdjustUserInfo{
ID: (&id).Row(ix),
UserID: userID.Row(ix),
MiningSessionSoloStartedAt: time.New((&miningSessionSoloStartedAt).Row(ix)),
MiningSessionSoloEndedAt: time.New((&miningSessionSoloEndedAt).Row(ix)),
MiningSessionSoloPreviouslyEndedAt: time.New((&miningSessionSoloPreviouslyEndedAt).Row(ix)),
SlashingRateSolo: (&slashingRateSolo).Row(ix),
CreatedAt: time.New((&createdAt).Row(ix)),
ResurrectSoloUsedAt: time.New((&resurrectSoloUsedAt).Row(ix)),
BalanceSolo: (&balanceSolo).Row(ix),
BalanceT1Pending: (&balanceT1Pending).Row(ix),
BalanceT1PendingApplied: (&balanceT1PendingApplied).Row(ix),
BalanceT2Pending: (&balanceT2Pending).Row(ix),
BalanceT2PendingApplied: (&balanceT2PendingApplied).Row(ix),
})
}
(&id).Reset()
userID.Reset()
(&miningSessionSoloStartedAt).Reset()
(&miningSessionSoloEndedAt).Reset()
(&miningSessionSoloPreviouslyEndedAt).Reset()
(&slashingRateSolo).Reset()
(&createdAt).Reset()
(&resurrectSoloUsedAt).Reset()
(&balanceSolo).Reset()
(&balanceT1Pending).Reset()
(&balanceT1PendingApplied).Reset()
(&balanceT2Pending).Reset()
(&balanceT2PendingApplied).Reset()

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

return res, nil
}
37 changes: 0 additions & 37 deletions bookkeeper/storage/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,40 +113,3 @@ func TestStorage(t *testing.T) {
sort.SliceStable(h2, func(ii, jj int) bool { return h2[ii].CreatedAt.Before(*h2[jj].CreatedAt.Time) })
assert.EqualValues(t, []*BalanceHistory{}, h2)
}

func TestStorage_SelectAdjustUserInformation_NoError_On_LongValues(t *testing.T) {
cl := MustConnect(context.Background(), "self")
defer func() {
if err := recover(); err != nil {
cl.Close()
panic(err)
}
cl.Close()
}()
require.NoError(t, cl.Ping(context.Background()))

limit := int64(1000)
offset := int64(0)
userIDs := make(map[int64]struct{}, 1_000_000)
for ix := 1_000_000; ix < 2_000_000; ix++ {
userIDs[int64(ix)] = struct{}{}
}
_, err := cl.GetAdjustUserInformation(context.Background(), userIDs, limit, offset)
require.NoError(t, err)

userIDs = nil
userIDs = make(map[int64]struct{}, 1_000_000)
for ix := 10_000_000; ix < 11_000_000; ix++ {
userIDs[int64(ix)] = struct{}{}
}
_, err = cl.GetAdjustUserInformation(context.Background(), userIDs, limit, offset)
require.NoError(t, err)

userIDs = nil
userIDs = make(map[int64]struct{}, 1_000_000)
for ix := 54_000_000; ix < 55_000_000; ix++ {
userIDs[int64(ix)] = struct{}{}
}
_, err = cl.GetAdjustUserInformation(context.Background(), userIDs, limit, offset)
require.NoError(t, err)
}
151 changes: 0 additions & 151 deletions miner/adoption_range_test.go

This file was deleted.

Loading

0 comments on commit be0c480

Please sign in to comment.