Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Commit f856f71

Browse files
committed
init pr
1 parent e65a675 commit f856f71

21 files changed

+1838
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
rpc-gateway

Dockerfile

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM golang:1.17-alpine3.13 as builder
2+
3+
RUN apk update && apk add git build-base
4+
5+
WORKDIR /src
6+
7+
ADD . ./
8+
9+
RUN go build
10+
11+
# final image
12+
FROM alpine:3.13
13+
14+
RUN apk update && apk add ca-certificates --no-cache
15+
16+
RUN mkdir -p /app
17+
18+
COPY --from=builder /src/rpc-gateway /app/rpc-gateway
19+
20+
USER app
21+
VOLUME ["/app"]
22+
CMD ["/app/rpc-gateway"]

config.go

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package main
2+
3+
import (
4+
"net/url"
5+
"time"
6+
)
7+
8+
type MetricsConfig struct {
9+
Port string `yaml:"port"`
10+
}
11+
12+
type ProxyConfig struct {
13+
Port string `yaml:"port"`
14+
AllowedNumberOfRetries uint `yaml:"allowedNumberOfRetries"`
15+
AllowedNumberOfAttempts uint `yaml:"allowedNumberOfAttempts"`
16+
RetryDelay time.Duration `yaml:"retryDelay"`
17+
UpstreamTimeout time.Duration `yaml:"upstreamTimeout"`
18+
}
19+
20+
type HealthCheckConfig struct {
21+
Interval time.Duration `yaml:"interval"`
22+
Timeout time.Duration `yaml:"timeout"`
23+
FailureThreshold uint `yaml:"failureThreshold"`
24+
SuccessThreshold uint `yaml:"successThreshold"`
25+
}
26+
27+
type TargetConnectionHTTP struct {
28+
URL string `yaml:"url"`
29+
Compression bool `yaml:"compression"`
30+
}
31+
32+
type TargetConfigConnection struct {
33+
HTTP TargetConnectionHTTP `yaml:"http"`
34+
}
35+
36+
type TargetConfig struct {
37+
Name string `yaml:"name"`
38+
Connection TargetConfigConnection `yaml:"connection"`
39+
}
40+
41+
func (t *TargetConfig) GetParsedHttpURL() (*url.URL, error) {
42+
return url.Parse(t.Connection.HTTP.URL)
43+
}
44+
45+
type RpcGatewayConfig struct {
46+
Metrics MetricsConfig `yaml:"metrics"`
47+
Proxy ProxyConfig `yaml:"proxy"`
48+
HealthChecks HealthCheckConfig `yaml:"healthChecks"`
49+
Targets []TargetConfig `yaml:"targets"`
50+
}

contracts/GasLeft.sol

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
pragma solidity ^0.8;
2+
3+
contract GasLeft {
4+
5+
function getGasLeft()
6+
external
7+
returns (uint256)
8+
{
9+
return gasleft();
10+
}
11+
}

docker-compose.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
version: "3.9"
2+
services:
3+
toxiproxy:
4+
image: ghcr.io/shopify/toxiproxy
5+
restart: always
6+
network_mode: host

example_config.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
metrics:
2+
port: "9090" # port for prometheus metrics, served on /metrics and /
3+
4+
proxy:
5+
port: "3000" # port for RPC gateway
6+
allowedNumberOfRetries: 2 # how many retries should an individual failed RPC request take
7+
allowedNumberOfAttempts: 2 # how many attemps should an individual failed RPC request take
8+
retryDelay: "10ms" # delay between retries
9+
upstreamTimeout: "5s" # when is a request considered timed out
10+
11+
healthChecks:
12+
interval: "5s" # how often to do healthchecks
13+
timeout: "1s" # when should the timeout occur and considered unhealthy
14+
failureThreshold: 2 # how many failed checks until marked as unhealthy
15+
successThreshold: 1 # how many successes to be marked as healthy again
16+
17+
targets:
18+
- name: "Cloudflare"
19+
connection:
20+
http: # ws is supported by default, it will be a sticky connection.
21+
url: "https://cloudflare-eth.com"

go.mod

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
module 0xProject/rpc-gateway
2+
3+
go 1.17
4+
5+
require (
6+
github.com/Shopify/toxiproxy v2.1.4+incompatible
7+
github.com/ethereum/go-ethereum v1.10.15
8+
github.com/gorilla/mux v1.8.0
9+
github.com/prometheus/client_golang v1.11.0
10+
go.uber.org/zap v1.21.0
11+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
12+
gopkg.in/yaml.v2 v2.4.0
13+
)
14+
15+
require (
16+
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
17+
github.com/beorn7/perks v1.0.1 // indirect
18+
github.com/btcsuite/btcd v0.20.1-beta // indirect
19+
github.com/cespare/xxhash/v2 v2.1.1 // indirect
20+
github.com/deckarep/golang-set v0.0.0-20180603214616-504e848d77ea // indirect
21+
github.com/go-ole/go-ole v1.2.1 // indirect
22+
github.com/go-stack/stack v1.8.0 // indirect
23+
github.com/golang/protobuf v1.4.3 // indirect
24+
github.com/google/uuid v1.1.5 // indirect
25+
github.com/gorilla/websocket v1.4.2 // indirect
26+
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
27+
github.com/prometheus/client_model v0.2.0 // indirect
28+
github.com/prometheus/common v0.26.0 // indirect
29+
github.com/prometheus/procfs v0.6.0 // indirect
30+
github.com/rjeczalik/notify v0.9.1 // indirect
31+
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
32+
github.com/tklauser/go-sysconf v0.3.5 // indirect
33+
github.com/tklauser/numcpus v0.2.2 // indirect
34+
go.uber.org/atomic v1.9.0 // indirect
35+
go.uber.org/multierr v1.7.0 // indirect
36+
golang.org/x/crypto v0.0.0-20210322153248-0c34fe9e7dc2 // indirect
37+
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
38+
google.golang.org/protobuf v1.26.0-rc.1 // indirect
39+
gopkg.in/natefinch/npipe.v2 v2.0.0-20160621034901-c1b8fa8bdcce // indirect
40+
)

0 commit comments

Comments
 (0)