Skip to content

Caching proxy for eth_getBlockByNumber API backed by Cloudflare

Notifications You must be signed in to change notification settings

Scratch-net/ethproxy

Repository files navigation

Ethereum caching proxy

Build Status GitHub go.mod Go version

Topics

Overview

Ethproxy is a service providing LRU cache for API method eth_getBlockByNumber backed by Cloudflare gateway.

  • It uses CCache as its cache engine.
  • Singleflight to prevent simultaneous requests to a single block
  • Configuration using envconfig
  • Latest 20 blocks have a default TTL of 5 seconds. Blocks from 20 to 1000 have TTL="distance from latest" * 5s
  • All blocks further than 1000 from the latest are considered immutable
  • Requesting an expired cache item does not block the service. It refreshes the requested block in background
  • Implements graceful shutdown
  • Linter support
  • Docker image building. Due to the multi-stage static build, the resulting image size is less than 6 mb

Settings

env Default value
ETHPROXY_LOG_LEVEL info
ETHPROXY_LISTEN_ADDRESS :8080
ETHPROXY_CLIENT_TIMEOUT 5s
ETHPROXY_READ_TIMEOUT 5s
ETHPROXY_WRITE_TIMEOUT 5s
ETHPROXY_CACHE_SIZE 5000

Usage

Build

make build

Tests

make tests

Linter

make lint

Build docker image

make dockerise

Run in Docker

make docker_run

Endpoints

Block

  • GET /block/<block number>/txs/<tx>

block number is either "latest", or a decimal block number.

tx is either decimal transaction index or tx hash.

Response:

HTTP 200 OK

{
    "blockHash":"0x1d59ff54b1eb26b013ce3cb5fc9dab3705b415a67127a003c3e61eb445bb8df2",
    "blockNumber":"0x5daf3b", // 6139707
    "from":"0xa7d9ddbe1f17865597fbd27ec712455208b6b76d",
    "gas":"0xc350", // 50000
    "gasPrice":"0x4a817c800", // 20000000000
    "hash":"0x88df016429689c079f3b2f6ad39fa052532c56795b733da78a91ebe6a713944b",
    "input":"0x68656c6c6f21",
    "nonce":"0x15", // 21
    "to":"0xf02c1c8e6114b1dbe8937a39260b5b0a374432bb",
    "transactionIndex":"0x41", // 65
    "value":"0xf3dbb76162000", // 4290000000000000
    "v":"0x25", // 37
    "r":"0x1b5e176d927f8e9ab405058b2d2457392da3e20f328b16ddabcebc33eaac5fea",
    "s":"0x4ba69724e8f69de52f0125ad8b3c5c2cef33019bac3249e2c0a2192766d1721c"
}

Returned errors

HTTP code description
404 block not found
404 transaction not found
400 block number too high
502 Bad gateway (Cloudflare returned an error)
500 Internal server error

About

Caching proxy for eth_getBlockByNumber API backed by Cloudflare

Resources

Stars

Watchers

Forks

Packages

No packages published