Skip to content
forked from steemit/jussi

JSON-RPC 2.0 Reverse Proxy Frontend for Steemit

License

Notifications You must be signed in to change notification settings

KINGdotNET/jussi

 
 

Repository files navigation

jussi

A reverse proxy that only speaks json-rpc 2.0. Upstream routing is done using json-rpc method "namespaces".

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
}

Default Namespace

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
}

What jussi does

At Startup

  1. begin a task make a steemd.get_dynamic_global_properties every 3 seconds to know the current last_irreversible_block
  2. create statsd stats queue to hold stats between flush intervals
  3. begin a a task to flush the statsd stats queue every flush interval
  4. open websocket and/or http connections to upstreams
  5. initialize memory cache and open connections to redis cache
  6. register route and error handler

Request/Response Cycle

  1. validate jsonrpc request
  2. log call
  3. start statsd downsteam request timers and increment request counters
  4. canonicalize both forms of steemd jsonrpc api calls for cache key generation
  5. generate cache key
  6. if a single jsonrpc request:
    1. check in memory cache, if miss
    2. make a redis get call if a batch call:
    3. check in memory cache for all keys
    4. for any misses:
    5. make a redis mget request for any keys not found in memory cache
  7. if all data loaded from cache:
    1. merge cached data with requests to form responses
    2. send response
  8. if any jsonrpc call results arent in cache:
  9. determine which upstream url and protocol (websockets or http) to use to fetch them
  10. start upsteam request timers
  11. fetch missing jsonrpc calls, retry fetching if there are errors
  12. end upstream response timers and increment statsd counters
  13. log response
  14. decide if response is a valid jsonrpc response and that it is not a jsonrpc error response
  15. if not an jsonrpc error response, determine the cache ttl for that jsonrpc namespace.method
  16. for some calls, verify the the response is a consensus response or not, and modify cache ttl for irreversible block responses
  17. cache response in redis cache
  18. cache response in memory
  19. return single jsonrpc response or assembled jsonrpc responses for batch requests

About

JSON-RPC 2.0 Reverse Proxy Frontend for Steemit

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 95.6%
  • Makefile 2.2%
  • Lua 1.2%
  • Shell 1.0%