Skip to content

Commit

Permalink
Merge branch 'staging' into BIDS-3231/migrate_rewards_data_access_to_…
Browse files Browse the repository at this point in the history
…clickhouse
  • Loading branch information
Eisei24 committed Jul 30, 2024
2 parents c2dd92c + 7bd40d4 commit a73557c
Show file tree
Hide file tree
Showing 104 changed files with 16,838 additions and 1,166 deletions.
3 changes: 2 additions & 1 deletion backend/cmd/eth1indexer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ func main() {
configPath := flag.String("config", "", "Path to the config file, if empty string defaults will be used")

enableEnsUpdater := flag.Bool("ens.enabled", false, "Enable ens update process")
ensBatchSize := flag.Int64("ens.batch", 200, "Batch size for ens updates")

flag.Parse()

Expand Down Expand Up @@ -362,7 +363,7 @@ func main() {
}

if *enableEnsUpdater {
err := bt.ImportEnsUpdates(client.GetNativeClient(), 1000)
err := bt.ImportEnsUpdates(client.GetNativeClient(), *ensBatchSize)
if err != nil {
log.Error(err, "error importing ens updates", 0, nil)
continue
Expand Down
50 changes: 47 additions & 3 deletions backend/pkg/api/data_access/dummy.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dataaccess
import (
"context"
"fmt"
"math/rand"
"math/rand/v2"
"reflect"
"time"

Expand Down Expand Up @@ -31,13 +31,19 @@ func NewDummyService() *DummyService {
El: randomEthDecimal(),
}, nil
})
_ = faker.AddProvider("chain_ids", func(v reflect.Value) (interface{}, error) {
possibleChainIds := []uint64{1, 100, 17000, 10200}
rand.Shuffle(len(possibleChainIds), func(i, j int) {
possibleChainIds[i], possibleChainIds[j] = possibleChainIds[j], possibleChainIds[i]
})
return possibleChainIds[:rand.IntN(len(possibleChainIds))], nil
})
return &DummyService{}
}

// generate random decimal.Decimal, should result in somewhere around 0.001 ETH (+/- a few decimal places) in Wei
func randomEthDecimal() decimal.Decimal {
//nolint:gosec
decimal, _ := decimal.NewFromString(fmt.Sprintf("%d00000000000", rand.Int63n(10000000)))
decimal, _ := decimal.NewFromString(fmt.Sprintf("%d00000000000", rand.Int64N(10000000)))
return decimal
}

Expand Down Expand Up @@ -429,6 +435,34 @@ func (d *DummyService) GetValidatorDashboardTotalWithdrawals(ctx context.Context
return &r, err
}

func (d *DummyService) GetValidatorDashboardRocketPool(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBRocketPoolColumn], search string, limit uint64) ([]t.VDBRocketPoolTableRow, *t.Paging, error) {
r := []t.VDBRocketPoolTableRow{}
p := t.Paging{}
_ = commonFakeData(&r)
err := commonFakeData(&p)
return r, &p, err
}

func (d *DummyService) GetValidatorDashboardTotalRocketPool(ctx context.Context, dashboardId t.VDBId, search string) (*t.VDBRocketPoolTableRow, error) {
r := t.VDBRocketPoolTableRow{}
err := commonFakeData(&r)
return &r, err
}

func (d *DummyService) GetValidatorDashboardNodeRocketPool(ctx context.Context, dashboardId t.VDBId, node string) (*t.VDBNodeRocketPoolData, error) {
r := t.VDBNodeRocketPoolData{}
err := commonFakeData(&r)
return &r, err
}

func (d *DummyService) GetValidatorDashboardRocketPoolMinipools(ctx context.Context, dashboardId t.VDBId, node string, cursor string, colSort t.Sort[enums.VDBRocketPoolMinipoolsColumn], search string, limit uint64) ([]t.VDBRocketPoolMinipoolsTableRow, *t.Paging, error) {
r := []t.VDBRocketPoolMinipoolsTableRow{}
p := t.Paging{}
_ = commonFakeData(&r)
err := commonFakeData(&p)
return r, &p, err
}

func (d *DummyService) GetAllNetworks() ([]t.NetworkInfo, error) {
r := []t.NetworkInfo{}
err := commonFakeData(&r)
Expand Down Expand Up @@ -577,6 +611,16 @@ func (d *DummyService) GetNotificationSettingsDashboards(ctx context.Context, us
p := t.Paging{}
_ = commonFakeData(&r)
err := commonFakeData(&p)
for i, n := range r {
var settings interface{}
if n.IsAccountDashboard {
settings = t.NotificationSettingsAccountDashboard{}
} else {
settings = t.NotificationSettingsValidatorDashboard{}
}
_ = commonFakeData(&settings)
r[i].Settings = settings
}
return r, &p, err
}
func (d *DummyService) UpdateNotificationSettingsValidatorDashboard(ctx context.Context, dashboardId t.VDBIdPrimary, groupId uint64, settings t.NotificationSettingsValidatorDashboard) error {
Expand Down
39 changes: 5 additions & 34 deletions backend/pkg/api/data_access/vdb_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
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/lib/pq"
"github.com/pkg/errors"
"github.com/shopspring/decimal"
Expand Down Expand Up @@ -80,6 +79,11 @@ type ValidatorDashboardRepository interface {

GetValidatorDashboardWithdrawals(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBWithdrawalsColumn], search string, limit uint64, protocolModes t.VDBProtocolModes) ([]t.VDBWithdrawalsTableRow, *t.Paging, error)
GetValidatorDashboardTotalWithdrawals(ctx context.Context, dashboardId t.VDBId, search string, protocolModes t.VDBProtocolModes) (*t.VDBTotalWithdrawalsData, error)

GetValidatorDashboardRocketPool(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBRocketPoolColumn], search string, limit uint64) ([]t.VDBRocketPoolTableRow, *t.Paging, error)
GetValidatorDashboardTotalRocketPool(ctx context.Context, dashboardId t.VDBId, search string) (*t.VDBRocketPoolTableRow, error)
GetValidatorDashboardNodeRocketPool(ctx context.Context, dashboardId t.VDBId, node string) (*t.VDBNodeRocketPoolData, error)
GetValidatorDashboardRocketPoolMinipools(ctx context.Context, dashboardId t.VDBId, node, cursor string, colSort t.Sort[enums.VDBRocketPoolMinipoolsColumn], search string, limit uint64) ([]t.VDBRocketPoolMinipoolsTableRow, *t.Paging, error)
}

//////////////////// Helper functions (must be used by more than one VDB endpoint!)
Expand Down Expand Up @@ -173,39 +177,6 @@ func (d DataAccessService) calculateChartEfficiency(efficiencyType enums.VDBSumm
return efficiency, nil
}

func (d DataAccessService) getValidatorStatuses(validators []uint64) (map[uint64]enums.ValidatorStatus, error) {
validatorStatuses := make(map[uint64]enums.ValidatorStatus, len(validators))

// Get the current validator state
validatorMapping, releaseValMapLock, err := d.services.GetCurrentValidatorMapping()
defer releaseValMapLock()
if err != nil {
return nil, err
}

// Fill the data
for _, validator := range validators {
metadata := validatorMapping.ValidatorMetadata[validator]

switch constypes.ValidatorDbStatus(metadata.Status) {
case constypes.DbDeposited:
validatorStatuses[validator] = enums.ValidatorStatuses.Deposited
case constypes.DbPending:
validatorStatuses[validator] = enums.ValidatorStatuses.Pending
case constypes.DbActiveOnline, constypes.DbExitingOnline, constypes.DbSlashingOnline:
validatorStatuses[validator] = enums.ValidatorStatuses.Online
case constypes.DbActiveOffline, constypes.DbExitingOffline, constypes.DbSlashingOffline:
validatorStatuses[validator] = enums.ValidatorStatuses.Offline
case constypes.DbSlashed:
validatorStatuses[validator] = enums.ValidatorStatuses.Slashed
case constypes.DbExited:
validatorStatuses[validator] = enums.ValidatorStatuses.Exited
}
}

return validatorStatuses, nil
}

func (d *DataAccessService) getWithdrawableCountFromCursor(validatorindex t.VDBValidator, cursor uint64) (uint64, error) {
// the validators' balance will not be checked here as this is only a rough estimation
// checking the balance for hundreds of thousands of validators is too expensive
Expand Down
9 changes: 2 additions & 7 deletions backend/pkg/api/data_access/vdb_management.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,11 +511,6 @@ func (d *DataAccessService) GetValidatorDashboardValidators(ctx context.Context,
return nil, nil, err
}

validatorStatuses, err := d.getValidatorStatuses(validators)
if err != nil {
return nil, nil, err
}

// Fill the data
data := []t.VDBManageValidatorsTableRow{}
for _, validator := range validators {
Expand All @@ -526,11 +521,11 @@ func (d *DataAccessService) GetValidatorDashboardValidators(ctx context.Context,
PublicKey: t.PubKey(hexutil.Encode(metadata.PublicKey)),
GroupId: validatorGroupMap[validator].GroupId,
Balance: utils.GWeiToWei(big.NewInt(int64(metadata.Balance))),
Status: metadata.Status,
WithdrawalCredential: t.Hash(hexutil.Encode(metadata.WithdrawalCredentials)),
}

row.Status = validatorStatuses[validator].ToString()
if validatorStatuses[validator] == enums.ValidatorStatuses.Pending && metadata.Queues.ActivationIndex.Valid {
if constypes.ValidatorDbStatus(metadata.Status) == constypes.DbPending && metadata.Queues.ActivationIndex.Valid {
activationIndex := uint64(metadata.Queues.ActivationIndex.Int64)
row.QueuePosition = &activationIndex
}
Expand Down
28 changes: 28 additions & 0 deletions backend/pkg/api/data_access/vdb_rocket_pool.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package dataaccess

import (
"context"

"github.com/gobitfly/beaconchain/pkg/api/enums"
t "github.com/gobitfly/beaconchain/pkg/api/types"
)

func (d *DataAccessService) GetValidatorDashboardRocketPool(ctx context.Context, dashboardId t.VDBId, cursor string, colSort t.Sort[enums.VDBRocketPoolColumn], search string, limit uint64) ([]t.VDBRocketPoolTableRow, *t.Paging, error) {
// TODO @DATA-ACCESS
return d.dummy.GetValidatorDashboardRocketPool(ctx, dashboardId, cursor, colSort, search, limit)
}

func (d *DataAccessService) GetValidatorDashboardTotalRocketPool(ctx context.Context, dashboardId t.VDBId, search string) (*t.VDBRocketPoolTableRow, error) {
// TODO @DATA-ACCESS
return d.dummy.GetValidatorDashboardTotalRocketPool(ctx, dashboardId, search)
}

func (d *DataAccessService) GetValidatorDashboardNodeRocketPool(ctx context.Context, dashboardId t.VDBId, node string) (*t.VDBNodeRocketPoolData, error) {
// TODO @DATA-ACCESS
return d.dummy.GetValidatorDashboardNodeRocketPool(ctx, dashboardId, node)
}

func (d *DataAccessService) GetValidatorDashboardRocketPoolMinipools(ctx context.Context, dashboardId t.VDBId, node, cursor string, colSort t.Sort[enums.VDBRocketPoolMinipoolsColumn], search string, limit uint64) ([]t.VDBRocketPoolMinipoolsTableRow, *t.Paging, error) {
// TODO @DATA-ACCESS
return d.dummy.GetValidatorDashboardRocketPoolMinipools(ctx, dashboardId, node, cursor, colSort, search, limit)
}
Loading

0 comments on commit a73557c

Please sign in to comment.