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.

147 lines
4.7 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
  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. ## Install
  13. ```
  14. go get github.com/tendermint/abci
  15. cd $GOPATH/src/github.com/tendermint/abci
  16. make get_vendor_deps
  17. make install
  18. ```
  19. ## Implementation
  20. We provide three implementations of the ABCI in Go:
  21. - Golang in-process
  22. - ABCI-socket
  23. - GRPC
  24. Note the GRPC version is maintained primarily to simplify onboarding and prototyping and is not receiving the same
  25. attention to security and performance as the others
  26. ### In Process
  27. The simplest implementation just uses function calls within Go.
  28. This means ABCI applications written in Golang can be compiled with TendermintCore and run as a single binary.
  29. See the [examples](#examples) below for more information.
  30. ### Socket (TSP)
  31. ABCI is best implemented as a streaming protocol.
  32. The socket implementation provides for asynchronous, ordered message passing over unix or tcp.
  33. Messages are serialized using Protobuf3 and length-prefixed.
  34. 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.
  35. 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...`.
  36. ### GRPC
  37. GRPC is an rpc framework native to Protocol Buffers with support in many languages.
  38. Implementing the ABCI using GRPC can allow for faster prototyping, but is expected to be much slower than
  39. the ordered, asynchronous socket protocol. The implementation has also not received as much testing or review.
  40. Note the length-prefixing used in the socket implementation does not apply for GRPC.
  41. ## Usage
  42. The `abci-cli` tool wraps an ABCI client and can be used for probing/testing an ABCI server.
  43. For instance, `abci-cli test` will run a test sequence against a listening server running the Counter application (see below).
  44. It can also be used to run some example applications.
  45. See [the documentation](http://tendermint.readthedocs.io/en/master/) for more details.
  46. ### Examples
  47. Check out the variety of example applications in the [example directory](example/).
  48. It also contains the code refered to by the `counter` and `dummy` apps; these apps come
  49. built into the `abci-cli` binary.
  50. #### Counter
  51. The `abci-cli counter` application illustrates nonce checking in transactions. It's code looks like:
  52. ```golang
  53. func cmdCounter(cmd *cobra.Command, args []string) error {
  54. app := counter.NewCounterApplication(flagSerial)
  55. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  56. // Start the listener
  57. srv, err := server.NewServer(flagAddrC, flagAbci, app)
  58. if err != nil {
  59. return err
  60. }
  61. srv.SetLogger(logger.With("module", "abci-server"))
  62. if err := srv.Start(); err != nil {
  63. return err
  64. }
  65. // Wait forever
  66. cmn.TrapSignal(func() {
  67. // Cleanup
  68. srv.Stop()
  69. })
  70. return nil
  71. }
  72. ```
  73. and can be found in [this file](cmd/abci-cli/abci-cli.go).
  74. #### Dummy
  75. The `abci-cli dummy` application, which illustrates a simple key-value Merkle tree
  76. ```golang
  77. func cmdDummy(cmd *cobra.Command, args []string) error {
  78. logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
  79. // Create the application - in memory or persisted to disk
  80. var app types.Application
  81. if flagPersist == "" {
  82. app = dummy.NewDummyApplication()
  83. } else {
  84. app = dummy.NewPersistentDummyApplication(flagPersist)
  85. app.(*dummy.PersistentDummyApplication).SetLogger(logger.With("module", "dummy"))
  86. }
  87. // Start the listener
  88. srv, err := server.NewServer(flagAddrD, flagAbci, app)
  89. if err != nil {
  90. return err
  91. }
  92. srv.SetLogger(logger.With("module", "abci-server"))
  93. if err := srv.Start(); err != nil {
  94. return err
  95. }
  96. // Wait forever
  97. cmn.TrapSignal(func() {
  98. // Cleanup
  99. srv.Stop()
  100. })
  101. return nil
  102. }
  103. ```
  104. and can be found in [this file](cmd/abci-cli/abci-cli.go).
  105. ## Specification
  106. See the [spec file](specification.rst) for more information.