You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

90 lines
3.7 KiB

  1. # ADR 057: RPC
  2. ## Changelog
  3. - 19-05-2020: created
  4. ## Context
  5. Currently the RPC layer of Tendermint is using a variant of the JSON-RPC protocol. This ADR is meant to serve as a pro/con list for possible alternatives and JSON-RPC.
  6. There are currently two options being discussed: gRPC & JSON-RPC.
  7. ### JSON-RPC
  8. JSON-RPC is a JSON-based RPC protocol. Tendermint has implemented its own variant of JSON-RPC which is not compatible with the [JSON-RPC 2.0 specification](https://www.jsonrpc.org/specification).
  9. **Pros:**
  10. - Easy to use & implement (by default)
  11. - Well-known and well-understood by users and integrators
  12. - Integrates reasonably well with web infrastructure (proxies, API gateways, service meshes, caches, etc)
  13. - human readable encoding (by default)
  14. **Cons:**
  15. - No schema support
  16. - RPC clients must be hand-written
  17. - Streaming not built into protocol
  18. - Underspecified types (e.g. numbers and timestamps)
  19. - Tendermint has its own implementation (not standards compliant, maintenance overhead)
  20. - High maintenance cost associated to this
  21. - Stdlib `jsonrpc` package only supports JSON-RPC 1.0, no dominant package for JSON-RPC 2.0
  22. - Tooling around documentation/specification (e.g. Swagger) could be better
  23. - JSON data is larger (offset by HTTP compression)
  24. - Serializing is slow ([~100% marshal, ~400% unmarshal](https://github.com/alecthomas/go_serialization_benchmarks)); insignificant in absolute terms
  25. - Specification was last updated in 2013 and is way behind Swagger/OpenAPI
  26. ### gRPC + gRPC-gateway (REST + Swagger)
  27. gRPC is a high performant RPC framework. It has been battle tested by a large number of users and is heavily relied on and maintained by countless large corporations.
  28. **Pros:**
  29. - Efficient data retrieval for users, lite clients and other protocols
  30. - Easily implemented in supported languages (Go, Dart, JS, TS, rust, Elixir, Haskell, ...)
  31. - Defined schema with richer type system (Protocol Buffers)
  32. - Can use common schemas and types across all protocols and data stores (RPC, ABCI, blocks, etc)
  33. - Established conventions for forwards- and backwards-compatibility
  34. - Bi-directional streaming
  35. - Servers and clients are be autogenerated in many languages (e.g. Tendermint-rs)
  36. - Auto-generated swagger documentation for REST API
  37. - Backwards and forwards compatibility guarantees enforced at the protocol level.
  38. - Can be used with different codecs (JSON, CBOR, ...)
  39. **Cons:**
  40. - Complex system involving cross-language schemas, code generation, and custom protocols
  41. - Type system does not always map cleanly to native language type system; integration woes
  42. - Many common types require Protobuf plugins (e.g. timestamps and duration)
  43. - Generated code may be non-idiomatic and hard to use
  44. - Migration will be disruptive and laborious
  45. ## Decision
  46. > This section explains all of the details of the proposed solution, including implementation details.
  47. > It should also describe affects / corollary items that may need to be changed as a part of this.
  48. > If the proposed change will be large, please also indicate a way to do the change to maximize ease of review.
  49. > (e.g. the optimal split of things to do between separate PR's)
  50. ## Status
  51. > A decision may be "proposed" if it hasn't been agreed upon yet, or "accepted" once it is agreed upon. If a later ADR changes or reverses a decision, it may be marked as "deprecated" or "superseded" with a reference to its replacement.
  52. {Deprecated|Proposed|Accepted}
  53. ## Consequences
  54. > This section describes the consequences, after applying the decision. All consequences should be summarized here, not just the "positive" ones.
  55. ### Positive
  56. ### Negative
  57. ### Neutral
  58. ## References
  59. > Are there any relevant PR comments, issues that led up to this, or articles referenced for why we made the given design choice? If so link them here!
  60. - {reference link}