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.

104 lines
4.2 KiB

6 years ago
  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. See additional details in the [ABCI
  7. readme](https://github.com/tendermint/tendermint/blob/develop/abci/README.md)(TODO: deduplicate
  8. those details).
  9. ## Message Protocol
  10. The message protocol consists of pairs of requests and responses defined in the
  11. [protobuf file](https://github.com/tendermint/tendermint/blob/develop/abci/types/types.proto).
  12. Some messages have no fields, while others may include byte-arrays, strings, integers,
  13. or custom protobuf types.
  14. For more details on protobuf, see the [documentation](https://developers.google.com/protocol-buffers/docs/overview).
  15. For each request, a server should respond with the corresponding
  16. response, where the order of requests is preserved in the order of
  17. responses.
  18. ## Server
  19. To use ABCI in your programming language of choice, there must be a ABCI
  20. server in that language. Tendermint supports two kinds of implementation
  21. of the server:
  22. - Asynchronous, raw socket server (Tendermint Socket Protocol, also
  23. known as TSP or Teaspoon)
  24. - GRPC
  25. Both 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/develop/abci/server),
  29. [JavaScript](https://github.com/tendermint/js-abci),
  30. [Python](https://github.com/tendermint/tendermint/tree/develop/abci/example/python3/abci),
  31. [C++](https://github.com/mdyring/cpp-tmsp), and
  32. [Java](https://github.com/jTendermint/jabci).
  33. ### GRPC
  34. If GRPC is available in your language, this is the easiest approach,
  35. though it will have significant performance overhead.
  36. To get started with GRPC, copy in the [protobuf
  37. file](https://github.com/tendermint/tendermint/blob/develop/abci/types/types.proto)
  38. and compile it using the GRPC plugin for your language. For instance,
  39. for golang, the command is `protoc --go_out=plugins=grpc:. types.proto`.
  40. See the [grpc documentation for more details](http://www.grpc.io/docs/).
  41. `protoc` will autogenerate all the necessary code for ABCI client and
  42. server in your language, including whatever interface your application
  43. must satisfy to be used by the ABCI server for handling requests.
  44. ### TSP
  45. If GRPC is not available in your language, or you require higher
  46. performance, or otherwise enjoy programming, you may implement your own
  47. ABCI server using the Tendermint Socket Protocol, known affectionately
  48. as Teaspoon. The first step is still to auto-generate the relevant data
  49. types and codec in your language using `protoc`. Messages coming over
  50. the socket are proto3 encoded, but additionally length-prefixed to
  51. 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. Note this prefixing does not apply for grpc.
  60. An ABCI server must also be able to support multiple connections, as
  61. Tendermint uses three connections.
  62. ### Async vs Sync
  63. The main ABCI server (ie. non-GRPC) provides ordered asynchronous messages.
  64. This is useful for DeliverTx and CheckTx, since it allows Tendermint to forward
  65. transactions to the app before it's finished processing previous ones.
  66. Thus, DeliverTx and CheckTx messages are sent asynchronously, while all other
  67. messages are sent synchronously.
  68. ## Client
  69. There are currently two use-cases for an ABCI client. One is a testing
  70. tool, as in the `abci-cli`, which allows ABCI requests to be sent via
  71. command line. The other is a consensus engine, such as Tendermint Core,
  72. which makes requests to the application every time a new transaction is
  73. received or a block is committed.
  74. It is unlikely that you will need to implement a client. For details of
  75. our client, see
  76. [here](https://github.com/tendermint/tendermint/tree/develop/abci/client).