Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
8c5b8f4
feat: add use-upstream directive to target specific providers
aramalipoor Sep 8, 2024
ba9d420
test: add cases for using specific upstreams via directive
aramalipoor Sep 8, 2024
8a1d08f
chore: add gosec step in gha
aramalipoor Sep 8, 2024
dc7abc1
Merge pull request #61: add use-upstream directive to target specific…
aramalipoor Sep 8, 2024
7c60f72
fix: explicitly throw an error for filter methods until subscriptions…
aramalipoor Sep 8, 2024
ab0f820
test: initialize upstream registry for network
aramalipoor Sep 8, 2024
a47071d
fix: consider invalid argument errors as client-side (#63)
aramalipoor Sep 14, 2024
42dee51
test: prepare upstreams with unsupported network (#58)
kasrakhosravi Sep 14, 2024
091f964
fix: print provided project-id for ProjectNotFound errors (#64)
kasrakhosravi Sep 15, 2024
b6cf66f
fix: improve thread-safety of request handling for high load (#65)
aramalipoor Sep 18, 2024
b9a3974
feat: use buffer stream for efficient json unmarshalling
aramalipoor Sep 18, 2024
93e6514
feat: tune sonic json encoding and decoding for streaming
aramalipoor Sep 20, 2024
7fb73f4
feat: use custom parser for lowest memory usage
aramalipoor Sep 25, 2024
a166b10
fix: add special cases for upstream errors
aramalipoor Sep 25, 2024
6758be0
test: when request is missing id and in batch mode
aramalipoor Sep 26, 2024
2beb081
feat: add more rpc error cases
aramalipoor Sep 29, 2024
1a52389
fix: less aggressive default circuit-breaker
aramalipoor Sep 30, 2024
879f0c4
feat: use stream reader on response to reduce mem usage
aramalipoor Oct 1, 2024
3cbbe28
feat: skip hedging for write methods
aramalipoor Oct 1, 2024
ef069f0
feat: set Server and User-Agent headers with version and commit sha
aramalipoor Oct 2, 2024
1433983
feat: upgrade sonic library and configure faster searcher for json-rp…
aramalipoor Oct 3, 2024
2a0574f
feat: explicit error on partial network config
aramalipoor Oct 3, 2024
1caff45
fix: mutex for json-rpc response during parsing and reading
aramalipoor Oct 3, 2024
c558d14
fix: make request normalization more robust
aramalipoor Oct 7, 2024
78dc7a4
feat: add error case for block height passed is invalid
aramalipoor Oct 8, 2024
14130a8
Merge pull request #66: efficient json unmarshalling, mutex improveme…
aramalipoor Oct 8, 2024
03921f4
fix: add blockHash support for certain eth_* methods (eip-1898) (#67)
kasrakhosravi Oct 9, 2024
d223cde
feat: add a simple GET /healthcheck endpoint (#68)
aramalipoor Oct 9, 2024
a84317d
fix: consider gas too low a client-side call exception
aramalipoor Oct 9, 2024
90d1cc5
fix: extend too-large error to cover address limits
aramalipoor Oct 9, 2024
3c55d67
fix: support blockHash for eth_getBlockReceipts and eth_getAccount
aramalipoor Oct 9, 2024
22ff31f
docs: add timeout example under server
aramalipoor Oct 9, 2024
8808cb0
docs: add case-studies to readme
kasrakhosravi Oct 10, 2024
473b46c
fix: reduce potential race deadlocks when caching enabled
aramalipoor Oct 10, 2024
19d4392
fix: use atomic values for leaner race condition handling
aramalipoor Oct 10, 2024
b535bbf
fix: add more error cases based on real provider reports
aramalipoor Oct 10, 2024
5bc0ed9
fix: use -32000 for generic call exceptions for consistency with majo…
aramalipoor Oct 11, 2024
183cb73
Merge pull request #71: fix: reduce potential race deadlocks when cac…
aramalipoor Oct 11, 2024
f4c3b51
docs: add example for rate limiter auto-tuner per upstream
aramalipoor Oct 11, 2024
47fd410
chore: release an image on main branch pushes
aramalipoor Oct 14, 2024
9c74b3a
fix: correct resp parsing for unknown network checks
aramalipoor Oct 14, 2024
b239cb8
fix: use int64 for id across the board for requests and responses
aramalipoor Oct 14, 2024
1b1531b
fix: print full response when IDs were not found
aramalipoor Oct 14, 2024
e71c985
fix: skip parsing ID when missing in response
aramalipoor Oct 14, 2024
75edd2a
fix: correctly ignore unsupported responses for drpc
aramalipoor Oct 15, 2024
4b8dee8
fix: avoid null data field on error object
aramalipoor Oct 16, 2024
1bb3c81
adds newly supported scroll upstream to alchemy (#73)
WesleyCharlesBlake Oct 16, 2024
3f5c124
fix: improve multiplex race condition handling
aramalipoor Oct 16, 2024
2fc702b
feat: add proper default values for network failsafe
aramalipoor Oct 16, 2024
f0c0520
fix: move cause outside error object to comply with subgraphs
aramalipoor Oct 17, 2024
2ec63ad
fix: always add id and jsonrpc fields for upstreams
aramalipoor Oct 17, 2024
9a11434
fix: always propagate error.data field from upstream
aramalipoor Oct 17, 2024
9c352a8
fix: retry requests if they are cancelled as part of a batch
aramalipoor Oct 17, 2024
0b422b0
fix: add new case for block missing data errors
aramalipoor Oct 19, 2024
ab19be7
chore: auto remove untagged images
aramalipoor Oct 20, 2024
65d3fc5
fix: remove missing multiplex entries
aramalipoor Oct 21, 2024
2918b09
chore: run-dry the image pruner
aramalipoor Oct 21, 2024
f770b95
chore: correct condition for image build step
aramalipoor Oct 21, 2024
8d28b89
fix: automatically use random id when explicitly 0 is provided (#76)
aramalipoor Oct 21, 2024
6c87a3f
add ability to set ttls by method name
Aug 30, 2024
f2b177a
push docker imgae to gihub.repository.owner instead of erpc
Aug 30, 2024
b84cf75
use ttl override, but if blockref exists then cache indefinitely
Aug 30, 2024
1380dac
change binary locations and set permissions
Aug 30, 2024
18c4aed
initialize ttl datastruct
Sep 6, 2024
ba5810d
update mock_connector to support connector interface
Sep 7, 2024
4df7840
Fix : Mock HasTTL() to pass tests
OBlackmon3 Sep 11, 2024
82a6cfe
fix: improve thread-safety of request handling for high load (#65)
aramalipoor Sep 18, 2024
0b1555e
add ability to set ttls by method name
Aug 30, 2024
73787a0
Merge branch 'polymer-develop' into oblackmon3/rebase-polymer-develop…
OBlackmon3 Oct 22, 2024
b387991
Fix : Use ubunut-latest
OBlackmon3 Oct 22, 2024
21f9a1c
Fix : Resolve build errors
OBlackmon3 Oct 22, 2024
b903700
Fix : Fix test failures
OBlackmon3 Oct 22, 2024
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
38 changes: 38 additions & 0 deletions .github/workflows/prune.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: prune

on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *"
push:
branches:
- main

jobs:
clean:
runs-on: ubuntu-latest
name: Prune images
steps:
- name: Login to GitHub Container Registry
uses: docker/login-action@v3.0.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Fetch multi-platform package version SHAs
id: multi-arch-digests
run: |
erpc=$(docker manifest inspect ghcr.io/erpc/erpc | jq -r '.manifests.[] | .digest' | paste -s -d ' ' -)
echo "multi-arch-digests=$erpc" >> $GITHUB_OUTPUT

- uses: snok/container-retention-policy@v3.0.0
with:
account: erpc
token: ${{ secrets.GITHUB_TOKEN }}
image-names: "erpc"
image-tags: "!latest !main !*.*.*"
skip-shas: ${{ steps.multi-arch-digests.outputs.multi-arch-digests }}
tag-selection: both
cut-off: 0ms
dry-run: true
35 changes: 31 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ on:
description: 'Commit SHA (default: last commit of the current branch)'
required: false
default: ''
push:
branches:
- main

permissions:
contents: write
Expand All @@ -20,17 +23,20 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
if: github.event.inputs.version_tag != ''
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.commit_sha || github.ref }}

- name: Configure Git
if: github.event.inputs.version_tag != ''
run: |
git config user.name github-actions
git config user.email github-actions@github.com

- name: Tag commit and push
if: github.event.inputs.version_tag != ''
run: |
git tag ${{ github.event.inputs.version_tag }} -f
git push origin ${{ github.event.inputs.version_tag }} -f
Expand All @@ -40,17 +46,20 @@ jobs:
needs: tag
steps:
- name: Checkout
if: github.event.inputs.version_tag != ''
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.commit_sha || github.ref }}

- name: Set up Go
if: github.event.inputs.version_tag != ''
uses: actions/setup-go@v5
with:
go-version: '1.22.x'

- name: Run GoReleaser
if: github.event.inputs.version_tag != ''
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
Expand All @@ -66,7 +75,7 @@ jobs:
- uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.event.inputs.version_tag }}
ref: ${{ github.event.inputs.version_tag || 'main' }}

- name: Login to GitHub Container Registry
uses: docker/login-action@v3
Expand All @@ -87,15 +96,33 @@ jobs:
REPO="${{ github.repository }}"
echo "repo=${REPO@L}" >> "$GITHUB_OUTPUT"

- name: Build and push Docker image
- name: Generate short SHA
id: short_sha
run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
Comment on lines +99 to +101
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix: Use double quotes in short SHA generation

The short SHA generation step is a good addition, but there's a potential issue flagged by the static analysis tool.

To fix the shellcheck warning and prevent potential word splitting issues, use double quotes around the command substitution:

- name: Generate short SHA
  id: short_sha
  run: echo "SHORT_SHA=$(git rev-parse --short HEAD)" >> "$GITHUB_OUTPUT"
🧰 Tools
🪛 actionlint

101-101: shellcheck reported issue in this script: SC2086:info:1:51: Double quote to prevent globbing and word splitting

(shellcheck)


- name: Build and push Docker image from main
if: github.event.inputs.version_tag == ''
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=main
COMMIT_SHA=${{ steps.short_sha.outputs.SHORT_SHA }}
tags: |
ghcr.io/${{ steps.tag_param.outputs.repo }}:main

- name: Build and push Docker image with tags
if: github.event.inputs.version_tag != ''
uses: docker/build-push-action@v5
with:
context: .
push: true
platforms: linux/amd64,linux/arm64
build-args: |
VERSION=${{ github.event.inputs.version_tag }}
COMMIT_SHA=${{ github.sha }}
COMMIT_SHA=${{ steps.short_sha.outputs.SHORT_SHA }}
tags: |
ghcr.io/${{ steps.tag_param.outputs.repo }}:latest
ghcr.io/${{ steps.tag_param.outputs.repo }}:${{ github.event.inputs.version_tag }}
ghcr.io/${{ steps.tag_param.outputs.repo }}:latest
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4.0.1
with:
token: ${{ secrets.CODECOV_TOKEN }}
args: -exclude-dir=test -tests=false ./...
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Remove duplicated Gosec arguments

This line appears to be an unintentional duplication of the Gosec Security Scanner arguments. It's redundant and may cause confusion.

Please remove this line:

-          args: -exclude-dir=test -tests=false ./...
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
args: -exclude-dir=test -tests=false ./...

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ coverage.txt
.DS_Store
erpc.yaml
.generated-go-semantic-release-changelog.md
.semrel/
.semrel/
__debug*
5 changes: 5 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
"mode": "auto",
"program": "${workspaceFolder}/cmd/erpc",
"args": ["${workspaceFolder}/erpc.yaml"],
"env": {
"CC": "/usr/bin/cc",
"CXX": "/usr/bin/c++",
"CGO_ENABLED": "1"
}
}
]
}
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ RUN go mod download
COPY . .

# Build the application without pprof
RUN CGO_ENABLED=0 GOOS=linux LDFLAGS="-w -s -X main.version=${VERSION} -X main.commitSHA=${COMMIT_SHA}" go build -a -installsuffix cgo -o erpc-server ./cmd/erpc/main.go
RUN CGO_ENABLED=0 GOOS=linux LDFLAGS="-w -s -X common.ErpcVersion=${VERSION} -X common.ErpcCommitSha=${COMMIT_SHA}" go build -a -installsuffix cgo -o erpc-server ./cmd/erpc/main.go

# Build the application with pprof
RUN CGO_ENABLED=0 GOOS=linux LDFLAGS="-w -s -X main.version=${VERSION} -X main.commitSHA=${COMMIT_SHA}" go build -a -installsuffix cgo -tags pprof -o erpc-server-pprof ./cmd/erpc/*.go
RUN CGO_ENABLED=0 GOOS=linux LDFLAGS="-w -s -X common.ErpcVersion=${VERSION} -X common.ErpcCommitSha=${COMMIT_SHA}" go build -a -installsuffix cgo -tags pprof -o erpc-server-pprof ./cmd/erpc/*.go

# Final stage
FROM alpine:3.18
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ build:
test:
@go clean -testcache
@go test ./cmd/... -count 1 -parallel 1
@go test $$(ls -d */ | grep -v "cmd/" | grep -v "test/" | awk '{print "./" $$1 "..."}') -covermode=atomic -race -count 3 -parallel 1
@go test $$(ls -d */ | grep -v "cmd/" | grep -v "test/" | awk '{print "./" $$1 "..."}') -covermode=atomic -race -count 5 -parallel 1

.PHONY: coverage
coverage:
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
✅ [Authentication](https://docs.erpc.cloud/config/auth) modules such as basic auth, secret-based, JWT and SIWE.<br/>
✅ [Smart batching](https://docs.erpc.cloud/operation/batch) to aggregates multiple RPC or contract calls into one.<br/>

# Case Studies

[🚀 Moonwell: How eRPC slashed RPC calls by 67%](https://erpc.cloud/case-studies/moonwell)<br/>
[🚀 Chronicle: How eRPC reduced RPC cost by 45%](https://erpc.cloud/case-studies/chronicle)

# Usage & Docs

- Visit [docs.erpc.cloud](https://docs.erpc.cloud) for documentation and guides.
Expand Down
25 changes: 13 additions & 12 deletions auth/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"strings"

"github.com/erpc/erpc/common"
"github.com/erpc/erpc/util"
"github.com/valyala/fasthttp"
)

Expand All @@ -19,15 +20,15 @@ func NewPayloadFromHttp(projectId string, nq *common.NormalizedRequest, headers
if args.Has("token") {
ap.Type = common.AuthTypeSecret
ap.Secret = &SecretPayload{
Value: string(args.Peek("token")),
Value: util.Mem2Str(args.Peek("token")),
}
} else if tkn := headers.Peek("X-ERPC-Secret-Token"); tkn != nil {
ap.Type = common.AuthTypeSecret
ap.Secret = &SecretPayload{
Value: string(tkn),
Value: util.Mem2Str(tkn),
}
} else if ath := headers.Peek("Authorization"); ath != nil {
ath := strings.TrimSpace(string(ath))
ath := strings.TrimSpace(util.Mem2Str(ath))
label := strings.ToLower(ath[0:6])

if strings.EqualFold(label, "basic") {
Expand All @@ -36,7 +37,7 @@ func NewPayloadFromHttp(projectId string, nq *common.NormalizedRequest, headers
if err != nil {
return nil, err
}
parts := strings.Split(string(basicAuth), ":")
parts := strings.Split(util.Mem2Str(basicAuth), ":")
if len(parts) != 2 {
return nil, errors.New("invalid basic auth must be base64 of username:password")
}
Expand All @@ -55,20 +56,20 @@ func NewPayloadFromHttp(projectId string, nq *common.NormalizedRequest, headers
} else if args.Has("jwt") {
ap.Type = common.AuthTypeJwt
ap.Jwt = &JwtPayload{
Token: string(args.Peek("jwt")),
Token: util.Mem2Str(args.Peek("jwt")),
}
} else if args.Has("signature") && args.Has("message") {
ap.Type = common.AuthTypeSiwe
ap.Siwe = &SiwePayload{
Signature: string(args.Peek("signature")),
Message: normalizeSiweMessage(string(args.Peek("message"))),
Signature: util.Mem2Str(args.Peek("signature")),
Message: normalizeSiweMessage(util.Mem2Str(args.Peek("message"))),
}
} else if msg := headers.Peek("X-Siwe-Message"); msg != nil {
if sig := headers.Peek("X-Siwe-Signature"); sig != nil {
ap.Type = common.AuthTypeSiwe
ap.Siwe = &SiwePayload{
Signature: string(sig),
Message: normalizeSiweMessage(string(msg)),
Signature: util.Mem2Str(sig),
Message: normalizeSiweMessage(util.Mem2Str(msg)),
}
}
}
Expand All @@ -77,8 +78,8 @@ func NewPayloadFromHttp(projectId string, nq *common.NormalizedRequest, headers
if ap.Type == "" {
ap.Type = common.AuthTypeNetwork
ap.Network = &NetworkPayload{
Address: string(headers.Peek("X-Forwarded-For")),
ForwardProxies: strings.Split(string(headers.Peek("X-Forwarded-For")), ","),
Address: util.Mem2Str(headers.Peek("X-Forwarded-For")),
ForwardProxies: strings.Split(util.Mem2Str(headers.Peek("X-Forwarded-For")), ","),
}

}
Expand All @@ -91,5 +92,5 @@ func normalizeSiweMessage(msg string) string {
if err != nil {
return msg
}
return string(decoded)
return util.Mem2Str(decoded)
}
9 changes: 9 additions & 0 deletions cmd/erpc/init_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package main

import (
"github.com/rs/zerolog"
)

func init() {
zerolog.SetGlobalLevel(zerolog.Disabled)
}
8 changes: 2 additions & 6 deletions cmd/erpc/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@ import (
"os/signal"
"syscall"

"github.com/erpc/erpc/common"
"github.com/erpc/erpc/erpc"
"github.com/erpc/erpc/util"
"github.com/rs/zerolog/log"
"github.com/spf13/afero"
)

var (
version = "dev"
commitSHA = "none"
)

func main() {
logger := log.With().Logger()

logger.Info().Msgf("starting eRPC version: %s, commit: %s", version, commitSHA)
logger.Info().Msgf("starting eRPC version: %s, commit: %s", common.ErpcVersion, common.ErpcCommitSha)

err := erpc.Init(
context.Background(),
Expand Down
3 changes: 1 addition & 2 deletions cmd/erpc/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bytes"
"context"
"encoding/json"
"fmt"
"io"
"math/rand"
Expand Down Expand Up @@ -158,7 +157,7 @@ func TestInit_HappyPath(t *testing.T) {
Times(5).
Post("").
Reply(200).
JSON(json.RawMessage(`{"result":{"hash":"0x64d340d2470d2ed0ec979b72d79af9cd09fc4eb2b89ae98728d5fb07fd89baf9"}}`))
JSON([]byte(`{"result":{"hash":"0x64d340d2470d2ed0ec979b72d79af9cd09fc4eb2b89ae98728d5fb07fd89baf9"}}`))

//
// 2) Initialize the eRPC server with a mock configuration
Expand Down
Loading