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.

159 lines
5.2 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
8 years ago
7 years ago
7 years ago
7 years ago
7 years ago
8 years ago
8 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.
  46. Protobuf3 doesn't have an official length-prefix standard, so we use our own. The first byte represents the length of the big-endian encoded length.
  47. For example, if the Protobuf3 encoded ABCI message is `0xDEADBEEF` (4 bytes), the length-prefixed message is `0x0104DEADBEEF`. If the Protobuf3 encoded ABCI message is 65535 bytes long, the length-prefixed message would be like `0x02FFFF...`.
  48. ### GRPC
  49. GRPC is an rpc framework native to Protocol Buffers with support in many languages.
  50. Implementing the ABCI using GRPC can allow for faster prototyping, but is expected to be much slower than
  51. the ordered, asynchronous socket protocol. The implementation has also not received as much testing or review.
  52. Note the length-prefixing used in the socket implementation does not apply for GRPC.
  53. ## Usage
  54. The `abci-cli` tool wraps an ABCI client and can be used for probing/testing an ABCI server.
  55. For instance, `abci-cli test` will run a test sequence against a listening server running the Counter application (see below).
  56. It can also be used to run some example applications.
  57. See [the documentation](http://tendermint.readthedocs.io/en/master/) for more details.
  58. ### Examples
  59. Check out the variety of example applications in the [example directory](example/).
  60. It also contains the code refered to by the `counter` and `kvstore` apps; these apps come
  61. built into the `abci-cli` binary.
  62. #### Counter
  63. The `abci-cli counter` application illustrates nonce checking in transactions. It's code looks like:
  64. ```golang
  65. func cmdCounter(cmd *cobra.Command, args []string) error {
  66. app := counter.NewCounterApplication(flagSerial)
  67. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  68. // Start the listener
  69. srv, err := server.NewServer(flagAddrC, flagAbci, app)
  70. if err != nil {
  71. return err
  72. }
  73. srv.SetLogger(logger.With("module", "abci-server"))
  74. if err := srv.Start(); err != nil {
  75. return err
  76. }
  77. // Wait forever
  78. cmn.TrapSignal(func() {
  79. // Cleanup
  80. srv.Stop()
  81. })
  82. return nil
  83. }
  84. ```
  85. and can be found in [this file](cmd/abci-cli/abci-cli.go).
  86. #### kvstore
  87. The `abci-cli kvstore` application, which illustrates a simple key-value Merkle tree
  88. ```golang
  89. func cmdKVStore(cmd *cobra.Command, args []string) error {
  90. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  91. // Create the application - in memory or persisted to disk
  92. var app types.Application
  93. if flagPersist == "" {
  94. app = kvstore.NewKVStoreApplication()
  95. } else {
  96. app = kvstore.NewPersistentKVStoreApplication(flagPersist)
  97. app.(*kvstore.PersistentKVStoreApplication).SetLogger(logger.With("module", "kvstore"))
  98. }
  99. // Start the listener
  100. srv, err := server.NewServer(flagAddrD, flagAbci, app)
  101. if err != nil {
  102. return err
  103. }
  104. srv.SetLogger(logger.With("module", "abci-server"))
  105. if err := srv.Start(); err != nil {
  106. return err
  107. }
  108. // Wait forever
  109. cmn.TrapSignal(func() {
  110. // Cleanup
  111. srv.Stop()
  112. })
  113. return nil
  114. }
  115. ```