A reverse proxy that only speaks json-rpc 2.0. Upstream routing is done using json-rpc method "namespaces".
A json-rpc method namespace is a json-rpc method prefix joined to the method name with a period, so a method in the "sbds" namespace begins with sbds.
and will be forwarded to a sbds endpoint:
POST / HTTP/1.1
Content-Type: application/json
{
"method": "sbds.count_operations",
"params": {"operation":"accountCreates"},
"jsonrpc": "2.0",
"id": 1
}
Any json-rpc method with no period in the method name is presumed to be in the "node" namespace and will be forwarded to a node endpoint:
POST / HTTP/1.1
Content-Type: application/json
{
"method": "get_block",
"params": [1],
"jsonrpc": "2.0",
"id": 1
}
- parse the upstream config and build the routing, caching, timeout data structures
- open websocket and/or http connections to upstreams
- initialize memory cache and open connections to redis cache
- register route and error handlers
- validate jsonrpc request
- convert individual jsonrpc requests into
JSONRPCRequest
objects, which add its pseudo-urn and upstream configuration - generate cache key (pseudo-urn for the moment)
- if a single jsonrpc request:
- check in-memory cache, if miss
- make a redis
get
call
- if a batch call:
- check in-memory cache for all keys
- for any misses:
- make a redis
mget
request for any keys not found in memory cache
- if all data loaded from cache:
- merge cached data with requests to form response
- send response
- if any jsonrpc call results aren't in cache:
- determine which upstream url and protocol (websockets or http) to use to fetch them
- start upsteam request timers
- fetch missing jsonrpc calls
- end upstream response timers
- decide if response is a valid jsonrpc response and that it is not a jsonrpc error response
- if response is valid, and response is not a jsonrpc error response, determine the cache ttl for that jsonrpc namespace.method
- for some calls, verify the the response is a consensus response or not, and modify cache ttl for irreversible block responses
- return single jsonrpc response or assembled jsonrpc responses for batch requests
- cache response in redis cache
- cache response in memory