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.

109 lines
4.8 KiB

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