Skip to content

Commit

Permalink
Merge branch 'staging' into BEDS-991/new-clickhouse-schema-changes
Browse files Browse the repository at this point in the history
  • Loading branch information
sasha-bitfly committed Dec 16, 2024
2 parents 647580e + bfaf2e2 commit 5f293b0
Show file tree
Hide file tree
Showing 61 changed files with 804 additions and 602 deletions.
4 changes: 4 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
# in order to work execute once:
# git config blame.ignoreRevsFile .git-blame-ignore-revs

# chore(eslint): reenabled rule to have only `one attribute` per line in `vue files`
6a51d528edfc71ffe46653f694a64c563ad70ceb
# chore(deps): update `eslint rule set` and apply changes
f67f385625eff411b47e4d82bd8d21f88b5486b6
#chore(eslint): add `natural sorting` for `json` files
f3da99c5c685eae1914aad8513d3b4b2f1cdcaa2
# style(eslint): add `typescript delimiter` rule
Expand Down
26 changes: 8 additions & 18 deletions backend/pkg/api/data_access/mobile.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ import (
"time"

"github.com/doug-martin/goqu/v9"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/gobitfly/beaconchain/pkg/api/enums"
t "github.com/gobitfly/beaconchain/pkg/api/types"
"github.com/gobitfly/beaconchain/pkg/commons/cache"
"github.com/gobitfly/beaconchain/pkg/commons/utils"
constypes "github.com/gobitfly/beaconchain/pkg/consapi/types"
"github.com/gobitfly/beaconchain/pkg/userservice"
"github.com/lib/pq"
"github.com/pkg/errors"
"github.com/shopspring/decimal"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -231,10 +229,9 @@ func (d *DataAccessService) GetValidatorDashboardMobileWidget(ctx context.Contex
goqu.COALESCE(goqu.SUM("rpln.rpl_stake"), 0).As("rpl_stake")).
From(goqu.L("rocketpool_nodes AS rpln")).
LeftJoin(goqu.L("rocketpool_minipools AS m"), goqu.On(goqu.L("m.node_address = rpln.address"))).
LeftJoin(goqu.L("validators AS v"), goqu.On(goqu.L("m.pubkey = v.pubkey"))).
Where(goqu.L("node_deposit_balance IS NOT NULL")).
Where(goqu.L("user_deposit_balance IS NOT NULL")).
LeftJoin(goqu.L("users_val_dashboards_validators uvdv"), goqu.On(goqu.L("uvdv.validator_index = v.validatorindex"))).
LeftJoin(goqu.L("users_val_dashboards_validators uvdv"), goqu.On(goqu.L("m.validator_index = uvdv.validator_index"))).
Where(goqu.L("uvdv.dashboard_id = ?", dashboardId))

query, args, err := ds.Prepared(true).ToSQL()
Expand Down Expand Up @@ -357,6 +354,7 @@ func (d *DataAccessService) getInternalRpNetworkStats(ctx context.Context) (*t.R
EXTRACT(EPOCH FROM claim_interval_time) / 3600 AS claim_interval_hours,
node_operator_rewards,
effective_rpl_staked,
ts,
rpl_price
FROM rocketpool_network_stats
ORDER BY ID
Expand All @@ -372,17 +370,8 @@ func (d *DataAccessService) GetValidatorDashboardMobileValidators(ctx context.Co
return nil, p, err
}

// Get extra information for this result subset
validatorMapping, err := d.services.GetCurrentValidatorMapping()
if err != nil {
return nil, nil, errors.Wrap(err, "validator mapping error")
}

pubKeys := make([][]byte, 0, len(result))
indices := make([]uint64, 0, len(result))
for _, row := range result {
metadata := validatorMapping.ValidatorMetadata[row.Index]
pubKeys = append(pubKeys, metadata.PublicKey)
indices = append(indices, row.Index)
}

Expand All @@ -395,6 +384,7 @@ func (d *DataAccessService) GetValidatorDashboardMobileValidators(ctx context.Co
DepositAmount decimal.Decimal `db:"node_deposit_balance"`
Status string `db:"status"`
IsInSmoothingPool bool `db:"smoothing_pool_opted_in"`
Index uint64 `db:"validator_index"`
}

var rocketPoolMap map[uint64]RocketPoolData
Expand All @@ -408,20 +398,20 @@ func (d *DataAccessService) GetValidatorDashboardMobileValidators(ctx context.Co
penalty_count,
node_deposit_balance,
status,
rn.smoothing_pool_opted_in
rn.smoothing_pool_opted_in,
validator_index
FROM rocketpool_minipools
LEFT JOIN rocketpool_nodes rn ON rocketpool_minipools.node_address = rn.address
WHERE pubkey = ANY($1)
WHERE validator_index = ANY($1)
`
err := d.alloyReader.SelectContext(ctx, &rocketPoolResults, validatorsQuery, pq.ByteaArray(pubKeys))
err := d.alloyReader.SelectContext(ctx, &rocketPoolResults, validatorsQuery, indices)
if err != nil {
return errors.Wrap(err, "error retrieving rocketpool data")
}

rocketPoolMap = make(map[uint64]RocketPoolData, len(rocketPoolResults))
for _, row := range rocketPoolResults {
validatorIndex := validatorMapping.ValidatorIndices[string(t.PubKey(hexutil.Encode(row.PubKey)))]
rocketPoolMap[validatorIndex] = row
rocketPoolMap[row.Index] = row
}
return nil
})
Expand Down
54 changes: 1 addition & 53 deletions backend/pkg/api/data_access/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -1301,11 +1301,6 @@ func (d *DataAccessService) GetNotificationSettingsDefaultValues(ctx context.Con
}

func (d *DataAccessService) UpdateNotificationSettingsGeneral(ctx context.Context, userId uint64, settings t.NotificationSettingsGeneral) error {
epoch := utils.TimeToEpoch(time.Now())

var eventsToInsert []goqu.Record
var eventsToDelete []goqu.Expression

tx, err := d.userWriter.BeginTxx(ctx, nil)
if err != nil {
return fmt.Errorf("error starting db transactions to update general notification settings: %w", err)
Expand Down Expand Up @@ -1341,60 +1336,13 @@ func (d *DataAccessService) UpdateNotificationSettingsGeneral(ctx context.Contex
return err
}

// -------------------------------------
// Collect the machine and rocketpool events to set and delete

//Machine events
d.AddOrRemoveEvent(&eventsToInsert, &eventsToDelete, settings.IsMachineOfflineSubscribed, userId, types.MonitoringMachineOfflineEventName, "", "", epoch, 0)
d.AddOrRemoveEvent(&eventsToInsert, &eventsToDelete, settings.IsMachineStorageUsageSubscribed, userId, types.MonitoringMachineDiskAlmostFullEventName, "", "", epoch, settings.MachineStorageUsageThreshold)
d.AddOrRemoveEvent(&eventsToInsert, &eventsToDelete, settings.IsMachineCpuUsageSubscribed, userId, types.MonitoringMachineCpuLoadEventName, "", "", epoch, settings.MachineCpuUsageThreshold)
d.AddOrRemoveEvent(&eventsToInsert, &eventsToDelete, settings.IsMachineMemoryUsageSubscribed, userId, types.MonitoringMachineMemoryUsageEventName, "", "", epoch, settings.MachineMemoryUsageThreshold)

// Insert all the events or update the threshold if they already exist
if len(eventsToInsert) > 0 {
insertDs := goqu.Dialect("postgres").
Insert("users_subscriptions").
Cols("user_id", "event_name", "event_filter", "created_ts", "created_epoch", "event_threshold").
Rows(eventsToInsert).
OnConflict(goqu.DoUpdate(
"user_id, event_name, event_filter",
goqu.Record{"event_threshold": goqu.L("EXCLUDED.event_threshold")},
))

query, args, err := insertDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %w", err)
}

_, err = tx.ExecContext(ctx, query, args...)
if err != nil {
return err
}
}

// Delete all the events
if len(eventsToDelete) > 0 {
deleteDs := goqu.Dialect("postgres").
Delete("users_subscriptions").
Where(goqu.Or(eventsToDelete...))

query, args, err := deleteDs.Prepared(true).ToSQL()
if err != nil {
return fmt.Errorf("error preparing query: %w", err)
}

_, err = tx.ExecContext(ctx, query, args...)
if err != nil {
return err
}
}

err = tx.Commit()
if err != nil {
return fmt.Errorf("error committing tx to update general notification settings: %w", err)
}
return nil
}

func (d *DataAccessService) UpdateNotificationSettingsNetworks(ctx context.Context, userId uint64, chainId uint64, settings t.NotificationSettingsNetwork) error {
epoch := utils.TimeToEpoch(time.Now())

Expand Down
2 changes: 1 addition & 1 deletion backend/pkg/api/data_access/vdb_blocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ func (d *DataAccessService) GetValidatorDashboardBlocks(ctx context.Context, das
reward.El = proposal.ElReward.Decimal.Mul(decimal.NewFromInt(1e18))
}
if clReward, ok := clRewards[proposal.Slot]; ok && clReward.Valid {
reward.Cl = clReward.Decimal.Mul(decimal.NewFromInt(1e18))
reward.Cl = clReward.Decimal.Mul(decimal.NewFromInt(1e9))
}
proposals[i].Reward = proposal.ElReward.Decimal.Add(proposal.ClReward.Decimal)
data[i].Reward = &reward
Expand Down
Loading

0 comments on commit 5f293b0

Please sign in to comment.