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.

162 lines
5.4 KiB

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