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

GNS-187 Temporarily add pagination #1

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
49 changes: 49 additions & 0 deletions .github/workflows/deploy-portal-loop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Deploy portal-loop API by create tag

on:
push:
tags:
- '*-portal-loop'
- '*-portal-loop-*'

env:
KUBE_CONFIG: ${{ secrets.KUBE_CLUSTER_CONFIG_C2 }}
KUBE_DEPLOYMENT_NAME: tx-indexer
KUBE_NAMESPACE: portal-loop-onbloc
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_GROUP: onbloc
REGISTRY_SERVICE: tx-indexer
IMAGE_TAG: ${{ github.ref_name }}

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: development

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Login to docker registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_URL }}
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ env.REGISTRY_PASSWORD }}

- name: Build and push image to docker registry
id: build-image
run: |
# Build docker images
docker build -t $REGISTRY_URL/$REGISTRY_GROUP/$REGISTRY_SERVICE:$IMAGE_TAG .
# Push images
docker push $REGISTRY_URL/$REGISTRY_GROUP/$REGISTRY_SERVICE:$IMAGE_TAG
echo "image=$REGISTRY_URL/$REGISTRY_GROUP/$REGISTRY_SERVICE:$IMAGE_TAG" >> $GITHUB_OUTPUT

- name: Redeploy service
uses: actions-hub/kubectl@master
with:
args: set image deployment/${{ env.KUBE_DEPLOYMENT_NAME }} container-0=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_GROUP }}/${{ env.KUBE_DEPLOYMENT_NAME }}:${{ env.IMAGE_TAG }} --namespace ${{ env.KUBE_NAMESPACE }}
49 changes: 49 additions & 0 deletions .github/workflows/deploy-test3.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Deploy testnet3 API by create tag

on:
push:
tags:
- '*-test3'
- '*-test3-*'

env:
KUBE_CONFIG: ${{ secrets.KUBE_CLUSTER_CONFIG_C2 }}
KUBE_DEPLOYMENT_NAME: tx-indexer
KUBE_NAMESPACE: testnet3-onbloc
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_PASSWORD: ${{ secrets.REGISTRY_PASSWORD }}
REGISTRY_GROUP: onbloc
REGISTRY_SERVICE: tx-indexer
IMAGE_TAG: ${{ github.ref_name }}

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: development

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Login to docker registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_URL }}
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ env.REGISTRY_PASSWORD }}

- name: Build and push image to docker registry
id: build-image
run: |
# Build docker images
docker build -t $REGISTRY_URL/$REGISTRY_GROUP/$REGISTRY_SERVICE:$IMAGE_TAG .
# Push images
docker push $REGISTRY_URL/$REGISTRY_GROUP/$REGISTRY_SERVICE:$IMAGE_TAG
echo "image=$REGISTRY_URL/$REGISTRY_GROUP/$REGISTRY_SERVICE:$IMAGE_TAG" >> $GITHUB_OUTPUT

- name: Redeploy service
uses: actions-hub/kubectl@master
with:
args: set image deployment/${{ env.KUBE_DEPLOYMENT_NAME }} container-0=${{ env.REGISTRY_URL }}/${{ env.REGISTRY_GROUP }}/${{ env.KUBE_DEPLOYMENT_NAME }}:${{ env.IMAGE_TAG }} --namespace ${{ env.KUBE_NAMESPACE }}
2 changes: 1 addition & 1 deletion .github/workflows/gen.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Checkout code
uses: actions/checkout@v4
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/lint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Checkout code
uses: actions/checkout@v4

- name: Lint
uses: golangci/golangci-lint-action@v6
with:
args:
--config=./.github/golangci.yaml
args: --config=./.github/golangci.yaml
43 changes: 0 additions & 43 deletions .github/workflows/releaser.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Checkout code
uses: actions/checkout@v4
Expand All @@ -23,7 +23,7 @@ jobs:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: 1.21.x
go-version: 1.22.x

- name: Checkout code
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Stage 1: Build
#===============

FROM golang:1.21-alpine as builder
FROM golang:1.22-alpine as builder

COPY . /app

Expand Down
37 changes: 19 additions & 18 deletions cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import (
"flag"
"fmt"
"net/http"
"time"

"github.com/go-chi/chi/v5"
"github.com/go-chi/httprate"
"github.com/peterbourgon/ff/v3/ffcli"
"go.uber.org/zap"

Expand Down Expand Up @@ -168,22 +166,7 @@ func (c *startCfg) exec(ctx context.Context) error {

mux := chi.NewMux()

if c.rateLimit != 0 {
logger.Info("rate-limit set", zap.Int("rate-limit", c.rateLimit))
mux.Use(httprate.Limit(
c.rateLimit,
1*time.Minute,
httprate.WithKeyFuncs(httprate.KeyByRealIP),
httprate.WithLimitHandler(func(w http.ResponseWriter, r *http.Request) {
//nolint:errcheck // no need to handle error here, it had been checked before
ip, _ := httprate.KeyByRealIP(r)
logger.Debug("too many requests", zap.String("from", ip))

// send a json response to give more info when using the graphQL explorer
http.Error(w, `{"error": "too many requests"}`, http.StatusTooManyRequests)
}),
))
}
mux.Use(NewCORSHandler())

mux = j.SetupRoutes(mux)
mux = graph.Setup(db, em, mux)
Expand Down Expand Up @@ -231,3 +214,21 @@ func setupJSONRPC(

return j
}

func NewCORSHandler() func(next http.Handler) http.Handler {
return func(next http.Handler) http.Handler {
return http.HandlerFunc(
func(writer http.ResponseWriter, request *http.Request) {
allowedHeaders := "*"

if origin := request.Header.Get("Origin"); origin != "" {
writer.Header().Set("Access-Control-Allow-Origin", "*")
writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
writer.Header().Set("Access-Control-Allow-Headers", allowedHeaders)
}

next.ServeHTTP(writer, request)
},
)
}
}
7 changes: 6 additions & 1 deletion fetch/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,16 @@ func (f *Fetcher) FetchChainData(ctx context.Context) error {
}

// Check if there is a block gap
if latestRemote <= latestLocal {
if latestRemote == latestLocal {
// No gap, nothing to sync
return nil
}

// Check if there is reset chains
if latestRemote < latestLocal {
return fmt.Errorf("reset chain: latestRemote(%d) < latestLocal(%d)", latestRemote, latestLocal)
}

gaps := f.chunkBuffer.reserveChunkRanges(
latestLocal+1,
latestRemote,
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ module github.com/gnolang/tx-indexer

go 1.22

toolchain go1.22.5
toolchain go1.22.1

require (
github.com/99designs/gqlgen v0.17.49
github.com/cockroachdb/pebble v1.1.1
github.com/gnolang/gno v0.1.0-nightly.20240707
github.com/go-chi/chi/v5 v5.1.0
github.com/go-chi/httprate v0.9.0
github.com/google/uuid v1.6.0
github.com/madz-lab/insertion-queue v0.0.0-20230520191346-295d3348f63a
github.com/olahol/melody v1.2.1
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216 h1:GKvsK3oLWG9B1G
github.com/gnolang/overflow v0.0.0-20170615021017-4d914c927216/go.mod h1:xJhtEL7ahjM1WJipt89gel8tHzfIl/LyMY+lCYh38d8=
github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-chi/httprate v0.9.0 h1:21A+4WDMDA5FyWcg7mNrhj63aNT8CGh+Z1alOE/piU8=
github.com/go-chi/httprate v0.9.0/go.mod h1:6GOYBSwnpra4CQfAKXu8sQZg+nZ0M1g9QnyFvxrAB8A=
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-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
Expand Down
22 changes: 20 additions & 2 deletions serve/graph/generated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions serve/graph/model/models_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 20 additions & 2 deletions serve/graph/query.resolvers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading