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":"account_creates"},
"jsonrpc": "2.0",
"id": 1
}
Any json-rpc method with no period in the method name is presumed to be in the "steemd" namespace and will be forwarded to a steemd endpoint:
POST / HTTP/1.1
Content-Type: application/json
{
"method": "get_block",
"params": [1],
"jsonrpc": "2.0",
"id": 1
}
- begin a task make a
steemd.get_dynamic_global_properties
every 3 seconds to know the currentlast_irreversible_block
- create statsd stats queue to hold stats between flush intervals
- begin a a task to flush the statsd stats queue every flush interval
- open websocket and/or http connections to upstreams
- initialize memory cache and open connections to redis cache
- register route and error handler
- validate jsonrpc request
- log call
- start statsd downsteam request timers and increment request counters
- canonicalize both forms of steemd jsonrpc api calls for cache key generation
- generate cache key
- 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 responses
- send response
- if any jsonrpc call results arent in cache:
- determine which upstream url and protocol (websockets or http) to use to fetch them
- start upsteam request timers
- fetch missing jsonrpc calls, retry fetching if there are errors
- end upstream response timers and increment statsd counters
- log response
- decide if response is a valid jsonrpc response and that it is not a jsonrpc error response
- if not an 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
- cache response in redis cache
- cache response in memory
- return single jsonrpc response or assembled jsonrpc responses for batch requests