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.

108 lines
4.9 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/proto/tendermint/abci/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](https://github.com/tendermint/tendermint/tree/master/abci), [Rust](https://github.com/tendermint/rust-abci))
  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. [C++](https://github.com/mdyring/cpp-tmsp), and
  27. [Java](https://github.com/jTendermint/jabci).
  28. ### In Process
  29. The simplest implementation uses function calls within Golang.
  30. This means ABCI applications written in Golang can be compiled with Tendermint Core and run as a single binary.
  31. ### GRPC
  32. If GRPC is available in your language, this is the easiest approach,
  33. though it will have significant performance overhead.
  34. To get started with GRPC, copy in the [protobuf
  35. file](https://github.com/tendermint/tendermint/blob/master/proto/tendermint/abci/types.proto)
  36. and compile it using the GRPC plugin for your language. For instance,
  37. for golang, the command is `protoc --go_out=plugins=grpc:. types.proto`.
  38. See the [grpc documentation for more details](http://www.grpc.io/docs/).
  39. `protoc` will autogenerate all the necessary code for ABCI client and
  40. server in your language, including whatever interface your application
  41. must satisfy to be used by the ABCI server for handling requests.
  42. Note the length-prefixing used in the socket implementation (TSP) does not apply for GRPC.
  43. ### TSP
  44. Tendermint Socket Protocol is an asynchronous, raw socket server which provides ordered message passing over unix or tcp.
  45. Messages are serialized using Protobuf3 and length-prefixed with a [signed Varint](https://developers.google.com/protocol-buffers/docs/encoding?csw=1#signed-integers)
  46. If GRPC is not available in your language, or you require higher
  47. performance, or otherwise enjoy programming, you may implement your own
  48. ABCI server using the Tendermint Socket Protocol. The first step is still to auto-generate the relevant data
  49. types and codec in your language using `protoc`. In addition to being proto3 encoded, messages coming over
  50. the socket are length-prefixed to facilitate use as a streaming protocol. proto3 doesn't have an
  51. official length-prefix standard, so we use our own. The first byte in
  52. the prefix represents the length of the Big Endian encoded length. The
  53. remaining bytes in the prefix are the Big Endian encoded length.
  54. For example, if the proto3 encoded ABCI message is 0xDEADBEEF (4
  55. bytes), the length-prefixed message is 0x0104DEADBEEF. If the proto3
  56. encoded ABCI message is 65535 bytes long, the length-prefixed message
  57. would be like 0x02FFFF....
  58. The benefit of using this `varint` encoding over the old version (where integers were encoded as `<len of len><big endian len>` is that
  59. it is the standard way to encode integers in Protobuf. It is also generally shorter.
  60. As noted above, this prefixing does not apply for GRPC.
  61. An ABCI server must also be able to support multiple connections, as
  62. Tendermint uses four connections.
  63. ### Async vs Sync
  64. The main ABCI server (ie. non-GRPC) provides ordered asynchronous messages.
  65. This is useful for DeliverTx and CheckTx, since it allows Tendermint to forward
  66. transactions to the app before it's finished processing previous ones.
  67. Thus, DeliverTx and CheckTx messages are sent asynchronously, while all other
  68. messages are sent synchronously.
  69. ## Client
  70. There are currently two use-cases for an ABCI client. One is a testing
  71. tool, as in the `abci-cli`, which allows ABCI requests to be sent via
  72. command line. The other is a consensus engine, such as Tendermint Core,
  73. which makes requests to the application every time a new transaction is
  74. received or a block is committed.
  75. It is unlikely that you will need to implement a client. For details of
  76. our client, see
  77. [here](https://github.com/tendermint/tendermint/tree/master/abci/client).