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.

171 lines
5.7 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
  1. # Application BlockChain Interface (ABCI)
  2. [![CircleCI](https://circleci.com/gh/tendermint/abci.svg?style=svg)](https://circleci.com/gh/tendermint/abci)
  3. Blockchains are systems for multi-master state machine replication.
  4. **ABCI** is an interface that defines the boundary between the replication engine (the blockchain),
  5. and the state machine (the application).
  6. Using a socket protocol, a consensus engine running in one process
  7. can manage an application state running in another.
  8. Previously, the ABCI was referred to as TMSP.
  9. The community has provided a number of addtional implementations, see the [Tendermint Ecosystem](https://tendermint.com/ecosystem)
  10. ## Specification
  11. A detailed description of the ABCI methods and message types is contained in:
  12. - [A prose specification](specification.md)
  13. - [A protobuf file](https://github.com/tendermint/tendermint/blob/master/abci/types/types.proto)
  14. - [A Go interface](https://github.com/tendermint/tendermint/blob/master/abci/types/application.go).
  15. For more background information on ABCI, motivations, and tendermint, please visit [the documentation](https://tendermint.com/docs/).
  16. The two guides to focus on are the `Application Development Guide` and `Using ABCI-CLI`.
  17. ## Protocol Buffers
  18. To compile the protobuf file, run:
  19. ```
  20. cd $GOPATH/src/github.com/tendermint/tendermint/; make protoc_abci
  21. ```
  22. See `protoc --help` and [the Protocol Buffers site](https://developers.google.com/protocol-buffers)
  23. for details on compiling for other languages. Note we also include a [GRPC](http://www.grpc.io/docs)
  24. service definition.
  25. ## Install ABCI-CLI
  26. The `abci-cli` is a simple tool for debugging ABCI servers and running some
  27. example apps. To install it:
  28. ```
  29. mkdir -p $GOPATH/src/github.com/tendermint
  30. cd $GOPATH/src/github.com/tendermint
  31. git clone https://github.com/tendermint/tendermint.git
  32. cd tendermint
  33. make get_tools
  34. make get_vendor_deps
  35. make install_abci
  36. ```
  37. ## Implementation
  38. We provide three implementations of the ABCI in Go:
  39. - Golang in-process
  40. - ABCI-socket
  41. - GRPC
  42. Note the GRPC version is maintained primarily to simplify onboarding and prototyping and is not receiving the same
  43. attention to security and performance as the others
  44. ### In Process
  45. The simplest implementation just uses function calls within Go.
  46. This means ABCI applications written in Golang can be compiled with TendermintCore and run as a single binary.
  47. See the [examples](#examples) below for more information.
  48. ### Socket (TSP)
  49. ABCI is best implemented as a streaming protocol.
  50. The socket implementation provides for asynchronous, ordered message passing over unix or tcp.
  51. Messages are serialized using Protobuf3 and length-prefixed with a [signed Varint](https://developers.google.com/protocol-buffers/docs/encoding?csw=1#signed-integers)
  52. For example, if the Protobuf3 encoded ABCI message is `0xDEADBEEF` (4 bytes), the length-prefixed message is `0x08DEADBEEF`, since `0x08` is the signed varint
  53. encoding of `4`. If the Protobuf3 encoded ABCI message is 65535 bytes long, the length-prefixed message would be like `0xFEFF07...`.
  54. Note the benefit of using this `varint` encoding over the old version (where integers were encoded as `<len of len><big endian len>` is that
  55. it is the standard way to encode integers in Protobuf. It is also generally shorter.
  56. ### GRPC
  57. GRPC is an rpc framework native to Protocol Buffers with support in many languages.
  58. Implementing the ABCI using GRPC can allow for faster prototyping, but is expected to be much slower than
  59. the ordered, asynchronous socket protocol. The implementation has also not received as much testing or review.
  60. Note the length-prefixing used in the socket implementation does not apply for GRPC.
  61. ## Usage
  62. The `abci-cli` tool wraps an ABCI client and can be used for probing/testing an ABCI server.
  63. For instance, `abci-cli test` will run a test sequence against a listening server running the Counter application (see below).
  64. It can also be used to run some example applications.
  65. See [the documentation](https://tendermint.com/docs/) for more details.
  66. ### Examples
  67. Check out the variety of example applications in the [example directory](example/).
  68. It also contains the code refered to by the `counter` and `kvstore` apps; these apps come
  69. built into the `abci-cli` binary.
  70. #### Counter
  71. The `abci-cli counter` application illustrates nonce checking in transactions. It's code looks like:
  72. ```golang
  73. func cmdCounter(cmd *cobra.Command, args []string) error {
  74. app := counter.NewCounterApplication(flagSerial)
  75. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  76. // Start the listener
  77. srv, err := server.NewServer(flagAddrC, flagAbci, app)
  78. if err != nil {
  79. return err
  80. }
  81. srv.SetLogger(logger.With("module", "abci-server"))
  82. if err := srv.Start(); err != nil {
  83. return err
  84. }
  85. // Wait forever
  86. cmn.TrapSignal(func() {
  87. // Cleanup
  88. srv.Stop()
  89. })
  90. return nil
  91. }
  92. ```
  93. and can be found in [this file](cmd/abci-cli/abci-cli.go).
  94. #### kvstore
  95. The `abci-cli kvstore` application, which illustrates a simple key-value Merkle tree
  96. ```golang
  97. func cmdKVStore(cmd *cobra.Command, args []string) error {
  98. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  99. // Create the application - in memory or persisted to disk
  100. var app types.Application
  101. if flagPersist == "" {
  102. app = kvstore.NewKVStoreApplication()
  103. } else {
  104. app = kvstore.NewPersistentKVStoreApplication(flagPersist)
  105. app.(*kvstore.PersistentKVStoreApplication).SetLogger(logger.With("module", "kvstore"))
  106. }
  107. // Start the listener
  108. srv, err := server.NewServer(flagAddrD, flagAbci, app)
  109. if err != nil {
  110. return err
  111. }
  112. srv.SetLogger(logger.With("module", "abci-server"))
  113. if err := srv.Start(); err != nil {
  114. return err
  115. }
  116. // Wait forever
  117. cmn.TrapSignal(func() {
  118. // Cleanup
  119. srv.Stop()
  120. })
  121. return nil
  122. }
  123. ```