Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(BIDS-2548) add total deposits columns #2707

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/misc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1135,6 +1135,8 @@ func exportStatsTotals(columns string, dayStart, dayEnd, concurrency uint64) {
"orphaned_sync_total",
"withdrawals_total",
"withdrawals_amount_total",
"deposits_total",
"deposits_amount_total",
}

OUTER:
Expand Down
13 changes: 13 additions & 0 deletions db/migrations/tbd_add_total_deposits.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
-- +goose Up
-- +goose StatementBegin
SELECT 'up SQL query - add total deposits count and amount columns to stats';
ALTER TABLE validator_stats ADD COLUMN IF NOT EXISTS deposits_total INT;
ALTER TABLE validator_stats ADD COLUMN IF NOT EXISTS deposits_amount_total BIGINT;
-- +goose StatementEnd

-- +goose Down
-- +goose StatementBegin
SELECT 'down SQL query - remove total deposits count and amount columns from stats';
ALTER TABLE validator_stats DROP COLUMN IF EXISTS deposits_total;
ALTER TABLE validator_stats DROP COLUMN IF EXISTS deposits_amount_total;
-- +goose StatementEnd
Copy link
Collaborator

@LuccaBitfly LuccaBitfly Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor:
image
I think this means that file should end with newline?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have some migration files that don't end on a newline but since most of them do I added it.

10 changes: 10 additions & 0 deletions db/statistics.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,10 @@ func WriteValidatorStatisticsForDay(day uint64, client rpc.Client) error {
data.WithdrawalsTotal = previousDayData.WithdrawalsTotal + data.Withdrawals
data.WithdrawalsAmountTotal = previousDayData.WithdrawalsAmountTotal + data.WithdrawalsAmount

// update deposits total
data.DepositsTotal = previousDayData.DepositsTotal + data.Deposits
data.DepositsAmountTotal = previousDayData.DepositsAmountTotal + data.DepositsAmount

if statisticsData1d != nil && len(statisticsData1d) > index {
data.ClPerformance1d = data.ClRewardsGWeiTotal - statisticsData1d[index].ClRewardsGWeiTotal
data.ElPerformance1d = data.ElRewardsWeiTotal.Sub(statisticsData1d[index].ElRewardsWeiTotal)
Expand Down Expand Up @@ -304,7 +308,9 @@ func WriteValidatorStatisticsForDay(day uint64, client rpc.Client) error {
"attester_slashings",
"proposer_slashings",
"deposits",
"deposits_total",
"deposits_amount",
"deposits_amount_total",
"withdrawals",
"withdrawals_total",
"withdrawals_amount",
Expand Down Expand Up @@ -342,7 +348,9 @@ func WriteValidatorStatisticsForDay(day uint64, client rpc.Client) error {
validatorData[i].AttesterSlashings,
validatorData[i].ProposerSlashing,
validatorData[i].Deposits,
validatorData[i].DepositsTotal,
validatorData[i].DepositsAmount,
validatorData[i].DepositsAmountTotal,
validatorData[i].Withdrawals,
validatorData[i].WithdrawalsTotal,
validatorData[i].WithdrawalsAmount,
Expand Down Expand Up @@ -1147,7 +1155,9 @@ func gatherStatisticsForDay(day int64) ([]*types.ValidatorStatsTableDbRow, error
COALESCE(attester_slashings, 0) AS attester_slashings,
COALESCE(proposer_slashings, 0) AS proposer_slashings,
COALESCE(deposits, 0) AS deposits,
COALESCE(deposits_total, 0) AS deposits_total,
COALESCE(deposits_amount, 0) AS deposits_amount,
COALESCE(deposits_amount_total, 0) AS deposits_amount_total,
COALESCE(withdrawals, 0) AS withdrawals,
COALESCE(withdrawals_total, 0) AS withdrawals_total,
COALESCE(withdrawals_amount, 0) AS withdrawals_amount,
Expand Down
6 changes: 4 additions & 2 deletions types/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,10 @@ type ValidatorStatsTableDbRow struct {
AttesterSlashings int64 `db:"attester_slashings"`
ProposerSlashing int64 `db:"proposer_slashings"`

Deposits int64 `db:"deposits"`
DepositsAmount int64 `db:"deposits_amount"`
Deposits int64 `db:"deposits"`
DepositsTotal int64 `db:"deposits_total"`
DepositsAmount int64 `db:"deposits_amount"`
DepositsAmountTotal int64 `db:"deposits_amount_total"`

Withdrawals int64 `db:"withdrawals"`
WithdrawalsTotal int64 `db:"withdrawals_total"`
Expand Down
Loading