Skip to content

Commit

Permalink
Support Sentry, pull bloom filter
Browse files Browse the repository at this point in the history
  • Loading branch information
af-afk committed Jun 25, 2024
1 parent 6285eb4 commit 191cff0
Show file tree
Hide file tree
Showing 15 changed files with 140 additions and 227 deletions.
3 changes: 0 additions & 3 deletions cmd/faucet.superposition/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ include ../golang.mk

lambda: bootstrap.zip

stakers.json: ../../config/stakers.json
@cp ../../config/stakers.json stakers.json

bootstrap: faucet.superposition
@cp faucet.superposition bootstrap

Expand Down
18 changes: 9 additions & 9 deletions cmd/faucet.superposition/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"context"
"crypto/ecdsa"
_ "embed"
"log"
"net/http"
"os"

"github.com/fluidity-money/long.so/lib/config"
"github.com/fluidity-money/long.so/lib/features"
_ "github.com/fluidity-money/long.so/lib/setup"
"github.com/fluidity-money/long.so/lib/setup"

"github.com/fluidity-money/long.so/cmd/faucet.superposition/graph"
"github.com/fluidity-money/long.so/cmd/faucet.superposition/lib/faucet"
Expand Down Expand Up @@ -63,35 +62,36 @@ func (m requestMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

func main() {
defer setup.Flush()
config := config.Get()
db, err := gorm.Open(postgres.Open(config.TimescaleUrl), &gorm.Config{
DisableAutomaticPing: true,
Logger: gormLogger.Default.LogMode(gormLogger.Silent),
})
if err != nil {
log.Fatalf("database open: %v", err)
setup.Exitf("database open: %v", err)
}
// Get the private key to use to make transactions to the faucet with later.
key_ := os.Getenv(EnvPrivateKey)
if key_ == "" {
log.Fatalf("%#v unset", EnvPrivateKey)
setup.Exitf("%#v unset", EnvPrivateKey)
}
key, err := ethCrypto.HexToECDSA(key_)
if err != nil {
log.Fatalf("private key: %v", err)
setup.Exitf("private key: %v", err)
}
faucetAddr := ethCommon.HexToAddress(os.Getenv(EnvFaucetAddr))
senderPub, _ := key.Public().(*ecdsa.PublicKey) // Should be fine.
senderAddr := ethCrypto.PubkeyToAddress(*senderPub)
geth, err := ethclient.Dial(config.GethUrl)
if err != nil {
log.Fatalf("geth open: %v", err)
setup.Exitf("geth open: %v", err)
}
defer geth.Close()
// Get the chain id for sending out requests to the faucet.
chainId, err := geth.ChainID(context.Background())
if err != nil {
log.Fatalf("chain id: %v", err)
setup.Exitf("chain id: %v", err)
}
// Start the sender in another Go routine to send batch requests
// out of the SPN (gas) token.
Expand All @@ -113,13 +113,13 @@ func main() {
lambda.Start(httpadapter.New(http.DefaultServeMux).ProxyWithContext)
case "http":
err := http.ListenAndServe(os.Getenv(EnvListenAddr), nil)
log.Fatalf( // This should only return if there's an error.
setup.Exitf( // This should only return if there's an error.
"err listening, %#v not set?: %v",
EnvListenAddr,
err,
)
default:
log.Fatalf(
setup.Exitf(
"unexpected listen type: %#v, use either (lambda|http) for SPN_LISTEN_BACKEND",
typ,
)
Expand Down
19 changes: 11 additions & 8 deletions cmd/graphql.ethereum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@ package main
//go:generate go run github.com/99designs/gqlgen generate

import (
"log"
"net/http"
"os"

"github.com/fluidity-money/long.so/lib/config"
"github.com/fluidity-money/long.so/lib/features"
_ "github.com/fluidity-money/long.so/lib/setup"
"github.com/fluidity-money/long.so/lib/setup"

"github.com/fluidity-money/long.so/cmd/graphql.ethereum/graph"

Expand All @@ -20,7 +19,7 @@ import (

"gorm.io/driver/postgres"
"gorm.io/gorm"
gormLogger "gorm.io/gorm/logger"
gormSlog "github.com/orandin/slog-gorm"

"github.com/aws/aws-lambda-go/lambda"

Expand All @@ -46,17 +45,18 @@ func (m corsMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}

func main() {
defer setup.Flush()
config := config.Get()
db, err := gorm.Open(postgres.Open(config.TimescaleUrl), &gorm.Config{
DisableAutomaticPing: true,
Logger: gormLogger.Default.LogMode(gormLogger.Silent),
Logger: gormSlog.New(), // Use default slog
})
if err != nil {
log.Fatalf("database open: %v", err)
setup.Exitf("database open: %v", err)
}
geth, err := ethclient.Dial(config.GethUrl)
if err != nil {
log.Fatalf("geth open: %v", err)
setup.Exitf("geth open: %v", err)
}
defer geth.Close()
srv := handler.NewDefaultServer(graph.NewExecutableSchema(graph.Config{
Expand All @@ -74,12 +74,15 @@ func main() {
lambda.Start(httpadapter.New(http.DefaultServeMux).ProxyWithContext)
case "http":
err := http.ListenAndServe(os.Getenv(EnvListenAddr), nil)
log.Fatalf( // This should only return if there's an error.
setup.Exitf( // This should only return if there's an error.
"err listening, %#v not set?: %v",
EnvListenAddr,
err,
)
default:
log.Fatalf("unexpected listen type: %#v, use either (lambda|http) for SPN_LISTEN_BACKEND", typ)
setup.Exitf(
"unexpected listen type: %#v, use either (lambda|http) for SPN_LISTEN_BACKEND",
typ,
)
}
}
14 changes: 7 additions & 7 deletions cmd/ingestor.logs.ethereum/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import (
"context"
"encoding/json"
"fmt"
"log"
"log/slog"
"math/big"
"time"

"github.com/fluidity-money/long.so/lib/events/erc20"
"github.com/fluidity-money/long.so/lib/events/seawater"
"github.com/fluidity-money/long.so/lib/config"
"github.com/fluidity-money/long.so/lib/setup"
"github.com/fluidity-money/long.so/lib/features"
"github.com/fluidity-money/long.so/lib/heartbeat"

Expand Down Expand Up @@ -59,7 +59,7 @@ func IngestPolling(f features.F, c *ethclient.Client, db *gorm.DB, ingestorPagin
// Start by finding the latest block number.
from, err := getLastBlockCheckpointed(db)
if err != nil {
log.Fatalf("failed to get the last block checkpoint: %v", err)
setup.Exitf("failed to get the last block checkpoint: %v", err)
}
to := from + ingestorPagination
from++ // Increase the starting block by 1 so we always get the next block.
Expand Down Expand Up @@ -87,7 +87,7 @@ func IngestBlockRange(f features.F, c *ethclient.Client, db *gorm.DB, seawaterAd
Topics: FilterTopics,
})
if err != nil {
log.Fatalf("failed to filter logs: %v", err)
setup.Exitf("failed to filter logs: %v", err)
}
err = db.Transaction(func(db *gorm.DB) error {
wasChanged := false
Expand All @@ -111,7 +111,7 @@ func IngestBlockRange(f features.F, c *ethclient.Client, db *gorm.DB, seawaterAd
return nil
})
if err != nil {
log.Fatalf("failed to ingest logs into db: %v", err)
setup.Exitf("failed to ingest logs into db: %v", err)
}
}

Expand All @@ -129,15 +129,15 @@ func IngestWebsocket(f features.F, c *ethclient.Client, db *gorm.DB, seawaterAdd
go func() {
subscription, err := c.SubscribeFilterLogs(context.Background(), filter, logs)
if err != nil {
log.Fatalf("eth log subscription: %v", err)
setup.Exitf("eth log subscription: %v", err)
}
err = <-subscription.Err()
errors <- err
}()
for {
select {
case err := <-errors:
log.Fatalf("subscription error: %v", err)
setup.Exitf("subscription error: %v", err)
case l := <-logs:
// Figure out what kind of log this is, and then insert it into the database.
err := db.Transaction(func(db *gorm.DB) error {
Expand All @@ -151,7 +151,7 @@ func IngestWebsocket(f features.F, c *ethclient.Client, db *gorm.DB, seawaterAdd
return nil
})
if err != nil {
log.Fatalf("failed to handle a database log: %v", err)
setup.Exitf("failed to handle a database log: %v", err)
}
heartbeat.Pulse() // Report that we're alive.
}
Expand Down
12 changes: 6 additions & 6 deletions cmd/ingestor.logs.ethereum/main.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package main

import (
"log"
"log/slog"
"os"
"strconv"

_ "github.com/fluidity-money/long.so/lib/setup"
"github.com/fluidity-money/long.so/lib/setup"

"github.com/fluidity-money/long.so/lib/config"
"github.com/fluidity-money/long.so/lib/features"
Expand Down Expand Up @@ -36,17 +35,18 @@ const (
)

func main() {
defer setup.Flush()
config := config.Get()
db, err := gorm.Open(postgres.Open(config.TimescaleUrl), &gorm.Config{
Logger: gormLogger.Default.LogMode(gormLogger.Silent),
})
if err != nil {
log.Fatalf("opening postgres: %v", err)
setup.Exitf("opening postgres: %v", err)
}
// Start to ingest block headers by connecting to the websocket given.
c, err := ethclient.Dial(config.GethUrl)
if err != nil {
log.Fatalf("websocket dial: %v", err)
setup.Exitf("websocket dial: %v", err)
}
defer c.Close()
/* Ingestor-specific configuration. */
Expand All @@ -63,7 +63,7 @@ func main() {
var err error
ingestorPagination, err = strconv.ParseUint(ingestorPagination_, 10, 64)
if err != nil {
log.Fatalf(
setup.Exitf(
"failed to parse pagination block increase, string is %#v: %v",
ingestorPagination_,
err,
Expand All @@ -80,7 +80,7 @@ func main() {
} else {
i, err := strconv.ParseInt(ingestorPollWait_, 10, 32)
if err != nil {
log.Fatalf(
setup.Exitf(
"failed to parse pagination poll wait, string is %#v: %v",
ingestorPollWait_,
err,
Expand Down
14 changes: 7 additions & 7 deletions cmd/snapshot.ethereum/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ import (
"context"
"fmt"
"io"
"log"
"log/slog"
"math/big"
"net/http"

"github.com/fluidity-money/long.so/lib/config"
"github.com/fluidity-money/long.so/lib/math"
_ "github.com/fluidity-money/long.so/lib/setup"
"github.com/fluidity-money/long.so/lib/setup"
"github.com/fluidity-money/long.so/lib/types"
"github.com/fluidity-money/long.so/lib/types/seawater"

Expand All @@ -30,12 +29,13 @@ type PoolDetails struct {
}

func main() {
defer setup.Flush()
config := config.Get()
db, err := gorm.Open(postgres.Open(config.TimescaleUrl), &gorm.Config{
Logger: gormLogger.Default.LogMode(gormLogger.Silent),
})
if err != nil {
log.Fatalf("database open: %v", err)
setup.Exitf("database open: %v", err)
}
slog.Debug("about to make another lookup")
// Get every active position in the database, including the pools.
Expand All @@ -45,7 +45,7 @@ func main() {
Scan(&positions).
Error
if err != nil {
log.Fatalf("seawater positions scan: %v", err)
setup.Exitf("seawater positions scan: %v", err)
}
slog.Debug("positions we're about to scan", "positions", positions)
var poolDetails []PoolDetails
Expand All @@ -55,7 +55,7 @@ func main() {
Scan(&poolDetails).
Error
if err != nil {
log.Fatalf("scan positions: %v", err)
setup.Exitf("scan positions: %v", err)
}
slog.Debug("pools we're about to scan", "pools", poolDetails)
poolMap := make(map[string]PoolDetails, len(poolDetails))
Expand All @@ -80,7 +80,7 @@ func main() {
// Makes multiple requests if the request size exceeds the current restriction.
resps, err := reqPositions(context.Background(), config.GethUrl, d, httpPost)
if err != nil {
log.Fatalf("positions request: %v", err)
setup.Exitf("positions request: %v", err)
}
var (
ids = make([]int, len(positions))
Expand Down Expand Up @@ -130,7 +130,7 @@ func main() {
return
}
if err := storePositions(db, ids, amount0s, amount1s); err != nil {
log.Fatalf("store positions: %v", err)
setup.Exitf("store positions: %v", err)
}
}

Expand Down
5 changes: 5 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ require (
github.com/aws/aws-lambda-go v1.47.0
github.com/awslabs/aws-lambda-go-api-proxy v0.16.2
github.com/ethereum/go-ethereum v1.14.5
github.com/getsentry/sentry-go v0.22.0
github.com/lib/pq v1.10.9
github.com/orandin/slog-gorm v1.3.2
github.com/samber/slog-sentry/v2 v2.5.0
github.com/stretchr/testify v1.9.0
github.com/vektah/gqlparser/v2 v2.5.16
gorm.io/driver/postgres v1.5.9
Expand Down Expand Up @@ -43,6 +46,8 @@ require (
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/samber/lo v1.38.1 // indirect
github.com/samber/slog-common v0.16.0 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/sosodev/duration v1.3.1 // indirect
github.com/supranational/blst v0.3.11 // indirect
Expand Down
16 changes: 14 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,10 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff h1:tY80oXqGNY4FhTFhk+o9oFHGINQ/+vhlm8HFzi6znCI=
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff/go.mod h1:x7DCsMOv1taUwEWCzT4cmDeAkigA5/QCwUodaVOe8Ww=
github.com/getsentry/sentry-go v0.18.0 h1:MtBW5H9QgdcJabtZcuJG80BMOwaBpkRDZkxRkNC1sN0=
github.com/getsentry/sentry-go v0.18.0/go.mod h1:Kgon4Mby+FJ7ZWHFUAZgVaIa8sxHtnRJRLTXZr51aKQ=
github.com/getsentry/sentry-go v0.22.0 h1:XNX9zKbv7baSEI65l+H1GEJgSeIC1c7EN5kluWaP6dM=
github.com/getsentry/sentry-go v0.22.0/go.mod h1:lc76E2QywIyW8WuBnwl8Lc4bkmQH4+w1gwTf25trprY=
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-ole/go-ole v1.2.6/go.mod h1:pprOEPIfldk/42T2oK7lQ4v4JSDwmV0As9GaiUsvbm0=
github.com/go-ole/go-ole v1.3.0 h1:Dt6ye7+vXGIKZ7Xtk4s6/xVdGDQynvom7xCFEdWr6uE=
github.com/go-ole/go-ole v1.3.0/go.mod h1:5LS6F96DhAwUc7C+1HLexzMXY1xGRSryjyPPKW6zv78=
Expand Down Expand Up @@ -160,6 +162,10 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.27.7 h1:fVih9JD6ogIiHUN6ePK7HJidyEDpWGVB5mzM7cWNXoU=
github.com/onsi/gomega v1.27.7/go.mod h1:1p8OOlwo2iUUDsHnOrjE5UKYJ+e3W8eQ3qSlRahPmr4=
github.com/orandin/slog-gorm v1.3.2 h1:C0lKDQPAx/pF+8K2HL7bdShPwOEJpPM0Bn80zTzxU1g=
github.com/orandin/slog-gorm v1.3.2/go.mod h1:MoZ51+b7xE9lwGNPYEhxcUtRNrYzjdcKvA8QXQQGEPA=
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand All @@ -180,6 +186,12 @@ github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/samber/slog-common v0.16.0 h1:2/t1EcFd1Ru77mh2ab+8B6NBHnEXsBBHtOJc7PSH0aI=
github.com/samber/slog-common v0.16.0/go.mod h1:Qjrfhwk79XiCIhBj8+jTq1Cr0u9rlWbjawh3dWXzaHk=
github.com/samber/slog-sentry/v2 v2.5.0 h1:aY5DdmTJF/HibevGWnIGYpxB3zeryPxJkMCfxbfBiRM=
github.com/samber/slog-sentry/v2 v2.5.0/go.mod h1:B3Q9VVYIBhQ1oqFHpPvtam3wIzn5eUpVBEqcLImxfjQ=
github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8=
github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I=
github.com/shirou/gopsutil v3.21.11+incompatible h1:+1+c1VGhc88SSonWP6foOcLhvnKlUeu/erjjvaPEYiI=
Expand Down
Loading

0 comments on commit 191cff0

Please sign in to comment.