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.

113 lines
4.8 KiB

  1. ---
  2. order: 3
  3. title: Client and Server
  4. ---
  5. # Client and Server
  6. This section is for those looking to implement their own ABCI Server, perhaps in
  7. a new programming language.
  8. You are expected to have read [ABCI Methods and Types](./abci.md) and [ABCI
  9. Applications](./apps.md).
  10. ## Message Protocol
  11. The message protocol consists of pairs of requests and responses defined in the
  12. [protobuf file](../../proto/tendermint/abci/types.proto).
  13. Some messages have no fields, while others may include byte-arrays, strings, integers,
  14. or custom protobuf types.
  15. For more details on protobuf, see the [documentation](https://developers.google.com/protocol-buffers/docs/overview).
  16. For each request, a server should respond with the corresponding
  17. response, where the order of requests is preserved in the order of
  18. responses.
  19. ## Server Implementations
  20. To use ABCI in your programming language of choice, there must be a ABCI
  21. server in that language. Tendermint supports three implementations of the ABCI, written in Go:
  22. - In-process ([Golang](https://github.com/tendermint/tendermint/tree/master/abci), [Rust](https://github.com/tendermint/rust-abci))
  23. - ABCI-socket
  24. - GRPC
  25. The latter two can be tested using the `abci-cli` by setting the `--abci` flag
  26. appropriately (ie. to `socket` or `grpc`).
  27. See examples, in various stages of maintenance, in
  28. [Go](https://github.com/tendermint/tendermint/tree/master/abci/server),
  29. [JavaScript](https://github.com/tendermint/js-abci),
  30. [C++](https://github.com/mdyring/cpp-tmsp), and
  31. [Java](https://github.com/jTendermint/jabci).
  32. ### In Process
  33. The simplest implementation uses function calls within Golang.
  34. This means ABCI applications written in Golang can be compiled with Tendermint Core and run as a single binary.
  35. ### GRPC
  36. If GRPC is available in your language, this is the easiest approach,
  37. though it will have significant performance overhead.
  38. To get started with GRPC, copy in the [protobuf
  39. file](../../proto/tendermint/abci/types.proto) and compile it using the GRPC
  40. plugin for your language. For instance, for golang, the command is `protoc
  41. --go_out=plugins=grpc:. types.proto`. See the [grpc documentation for more
  42. details](http://www.grpc.io/docs/). `protoc` will autogenerate all the
  43. necessary code for ABCI client and server in your language, including whatever
  44. interface your application must satisfy to be used by the ABCI server for
  45. handling requests.
  46. Note the length-prefixing used in the socket implementation (TSP) does not apply for GRPC.
  47. ### TSP
  48. Tendermint Socket Protocol is an asynchronous, raw socket server which provides ordered message passing over unix or tcp.
  49. Messages are serialized using Protobuf3 and length-prefixed with a [signed Varint](https://developers.google.com/protocol-buffers/docs/encoding?csw=1#signed-integers)
  50. If GRPC is not available in your language, or you require higher
  51. performance, or otherwise enjoy programming, you may implement your own
  52. ABCI server using the Tendermint Socket Protocol. The first step is still to auto-generate the relevant data
  53. types and codec in your language using `protoc`. In addition to being proto3 encoded, messages coming over
  54. the socket are length-prefixed to facilitate use as a streaming protocol. proto3 doesn't have an
  55. official length-prefix standard, so we use our own. The first byte in
  56. the prefix represents the length of the Big Endian encoded length. The
  57. remaining bytes in the prefix are the Big Endian encoded length.
  58. For example, if the proto3 encoded ABCI message is 0xDEADBEEF (4
  59. bytes), the length-prefixed message is 0x0104DEADBEEF. If the proto3
  60. encoded ABCI message is 65535 bytes long, the length-prefixed message
  61. would be like 0x02FFFF....
  62. The benefit of using this `varint` encoding over the old version (where integers were encoded as `<len of len><big endian len>` is that
  63. it is the standard way to encode integers in Protobuf. It is also generally shorter.
  64. As noted above, this prefixing does not apply for GRPC.
  65. An ABCI server must also be able to support multiple connections, as
  66. Tendermint uses four connections.
  67. ### Async vs Sync
  68. The main ABCI server (ie. non-GRPC) provides ordered asynchronous messages.
  69. This is useful for DeliverTx and CheckTx, since it allows Tendermint to forward
  70. transactions to the app before it's finished processing previous ones.
  71. Thus, DeliverTx and CheckTx messages are sent asynchronously, while all other
  72. messages are sent synchronously.
  73. ## Client
  74. There are currently two use-cases for an ABCI client. One is a testing
  75. tool, as in the `abci-cli`, which allows ABCI requests to be sent via
  76. command line. The other is a consensus engine, such as Tendermint Core,
  77. which makes requests to the application every time a new transaction is
  78. received or a block is committed.
  79. It is unlikely that you will need to implement a client. For details of
  80. our client, see
  81. [here](https://github.com/tendermint/tendermint/tree/master/abci/client).