Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/staging' into BEDS-628/refactor-…
Browse files Browse the repository at this point in the history
…vdb-blocks-query
  • Loading branch information
remoterami committed Oct 21, 2024
2 parents 327a88e + d5103c1 commit effeb35
Show file tree
Hide file tree
Showing 67 changed files with 3,208 additions and 2,607 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/backend-converted-types-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Backend-Converted-Types-Check
on:
push:
paths:
- 'backend/**'
- 'frontend/types/api/**'
branches:
- main
- staging
pull_request:
paths:
- 'backend/**'
- 'frontend/types/api/**'
branches:
- '*'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

permissions:
contents: read
pull-requests: read
checks: write

jobs:
build:
name: converted-types-check
runs-on: self-hosted
steps:
- uses: actions/checkout@v3
- uses: actions/setup-go@v4
with:
go-version-file: 'backend/go.mod'
cache-dependency-path: 'backend/go.sum'
- name: Check if all backend-types have been converted to frontend-types
working-directory: backend
run: |
currHash=$(find ../frontend/types/api -type f -print0 | sort -z | xargs -0 sha1sum | sha256sum | head -c 64)
make frontend-types
newHash=$(find ../frontend/types/api -type f -print0 | sort -z | xargs -0 sha1sum | sha256sum | head -c 64)
if [ "$currHash" != "$newHash" ]; then
echo "frontend-types have changed, please commit the changes"
exit 1
fi
36 changes: 35 additions & 1 deletion backend/cmd/misc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,40 @@ func collectNotifications(startEpoch uint64) error {
if len(notifications[0]) > 0 {
spew.Dump(notifications[0])
}

emails, err := notification.RenderEmailsForUserEvents(0, notifications)
if err != nil {
return err
}

for _, email := range emails {
// if email.Address == "" {
log.Infof("to: %v", email.Address)
log.Infof("subject: %v", email.Subject)
log.Infof("body: %v", email.Email.Body)
log.Info("-----")
// }
}

// pushMessages, err := notification.RenderPushMessagesForUserEvents(0, notifications)
// if err != nil {
// return err
// }

// for _, pushMessage := range pushMessages {
// message := pushMessage.Messages[0]
// log.Infof("title: %v body: %v", message.Notification.Title, message.Notification.Body)

// if message.Token == "" {
// log.Info("sending test message")

// err = notification.SendPushBatch(pushMessage.UserId, []*messaging.Message{message}, false)
// if err != nil {
// log.Error(err, "error sending firebase batch job", 0)
// }
// }
// }

return nil
}

Expand Down Expand Up @@ -606,7 +640,7 @@ func collectUserDbNotifications(startEpoch uint64) error {
if message.Token == "" {
log.Info("sending test message")

err = notification.SendPushBatch(pushMessage.UserId, []*messaging.Message{message}, false)
err = notification.SendPushBatch(pushMessage.UserId, []*messaging.Message{message}, true)
if err != nil {
log.Error(err, "error sending firebase batch job", 0)
}
Expand Down
2 changes: 1 addition & 1 deletion backend/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ require (
github.com/prysmaticlabs/go-ssz v0.0.0-20210121151755-f6208871c388
github.com/rocket-pool/rocketpool-go v1.8.3-0.20240618173422-783b8668f5b4
github.com/rocket-pool/smartnode v1.13.6
github.com/shopspring/decimal v1.3.1
github.com/shopspring/decimal v1.4.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.9.0
github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
Expand Down
2 changes: 2 additions & 0 deletions backend/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -873,6 +873,8 @@ github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9Nz
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/shopspring/decimal v1.4.0 h1:bxl37RwXBklmTi0C79JfXCEBD1cqqHt0bbgBAGFp81k=
github.com/shopspring/decimal v1.4.0/go.mod h1:gawqmDU56v4yIKSwfBSFip1HdCCXN8/+DMd9qYNcwME=
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
github.com/sirupsen/logrus v1.4.1/go.mod h1:ni0Sbl8bgC9z8RoU9G6nDWqqs/fq4eDPysMBDgk/93Q=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
Expand Down
43 changes: 43 additions & 0 deletions backend/pkg/api/data_access/header.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
package dataaccess

import (
"context"
"database/sql"
"fmt"

t "github.com/gobitfly/beaconchain/pkg/api/types"
"github.com/gobitfly/beaconchain/pkg/commons/cache"
"github.com/gobitfly/beaconchain/pkg/commons/log"
"github.com/gobitfly/beaconchain/pkg/commons/price"
"github.com/gobitfly/beaconchain/pkg/commons/utils"
)

func (d *DataAccessService) GetLatestSlot() (uint64, error) {
Expand All @@ -26,6 +32,43 @@ func (d *DataAccessService) GetBlockHeightAt(slot uint64) (uint64, error) {
return d.dummy.GetBlockHeightAt(slot)
}

// returns the block number of the latest existing block at or before the given slot
func (d *DataAccessService) GetLatestBlockHeightForSlot(ctx context.Context, slot uint64) (uint64, error) {
query := `SELECT MAX(exec_block_number) FROM blocks WHERE slot <= $1`
res := uint64(0)
err := d.alloyReader.GetContext(ctx, &res, query, slot)
if err != nil {
if err == sql.ErrNoRows {
log.Warnf("no EL block found at or before slot %d", slot)
return 0, nil
}
return 0, fmt.Errorf("failed to get latest existing block height at or before slot %d: %w", slot, err)
}
return res, nil
}

func (d *DataAccessService) GetLatestBlockHeightsForEpoch(ctx context.Context, epoch uint64) ([]uint64, error) {
// use 2 epochs as safety margin
query := `
WITH recent_blocks AS (
SELECT slot, exec_block_number
FROM blocks
WHERE slot < $1
ORDER BY slot DESC
LIMIT $2 * 2
)
SELECT MAX(exec_block_number) OVER (ORDER BY slot) AS block
FROM recent_blocks
ORDER BY slot DESC
LIMIT $2`
res := []uint64{}
err := d.alloyReader.SelectContext(ctx, &res, query, (epoch+1)*utils.Config.Chain.ClConfig.SlotsPerEpoch, utils.Config.Chain.ClConfig.SlotsPerEpoch)
if err != nil {
return nil, fmt.Errorf("failed to get latest existing block heights for slots in epoch %d: %w", epoch, err)
}
return res, nil
}

func (d *DataAccessService) GetLatestExchangeRates() ([]t.EthConversionRate, error) {
result := []t.EthConversionRate{}

Expand Down
Loading

0 comments on commit effeb35

Please sign in to comment.