tendermint/README.md

164 lines
6.1 KiB
Markdown
Raw Normal View History

2015-12-03 15:47:20 -08:00
# Tendermint Socket Protocol (TMSP)
2015-11-02 07:39:53 -08:00
2016-07-06 14:01:20 -07:00
[![CircleCI](https://circleci.com/gh/tendermint/tmsp.svg?style=svg)](https://circleci.com/gh/tendermint/tmsp)
Blockchains are a system for creating shared multi-master application state.
**TMSP** is a socket protocol enabling a blockchain consensus engine, running in one process,
to manage a blockchain application state, running in another.
2015-11-02 07:39:53 -08:00
2016-12-15 05:47:31 -08:00
For more information on TMSP, motivations, and tutorials, please visit [our blog post](http://tendermint.com/blog/tmsp-the-tendermint-socket-protocol/).
2016-04-15 15:01:05 -07:00
Other implementations:
* [cpp-tmsp](https://github.com/mdyring/cpp-tmsp) by Martin Dyring-Andersen
* [js-tmsp](https://github.com/tendermint/js-tmsp)
2016-09-27 17:57:04 -07:00
* [jTMSP](https://github.com/jTMSP/) for Java
2016-04-15 15:01:05 -07:00
## Contents
This repository holds a number of important pieces:
- `types/types.proto`
2016-07-23 16:05:46 -07:00
- the protobuf file defining TMSP message types, and the optional grpc interface.
2016-11-15 11:11:01 -08:00
- to build, run `make protoc`
2016-07-23 16:05:46 -07:00
- see `protoc --help` and [the grpc docs](https://www.grpc.io/docs) for examples and details of other languages
- golang implementation of TMSP client and server
- two implementations:
2016-07-23 16:05:46 -07:00
- asynchronous, ordered message passing over unix or tcp;
- messages are serialized using protobuf and length prefixed
- grpc
- TendermintCore runs a client, and the application runs a server
- `cmd/tmsp-cli`
- command line tool wrapping the client for probing/testing a TMSP application
2016-07-23 15:54:58 -07:00
- use `tmsp-cli --version` to get the TMSP version
- examples:
- the `cmd/counter` application, which illustrates nonce checking in txs
- the `cmd/dummy` application, which illustrates a simple key-value merkle tree
2016-05-04 13:37:22 -07:00
## Message format
Since this is a streaming protocol, all messages are encoded with a length-prefix followed by the message encoded in Protobuf3. 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.
For example, if the Protobuf3 encoded TMSP message is `0xDEADBEEF` (4 bytes), the length-prefixed message is `0x0104DEADBEEF`. If the Protobuf3 encoded TMSP message is 65535 bytes long, the length-prefixed message would be like `0x02FFFF...`.
2016-07-23 16:05:46 -07:00
Note this prefixing does not apply for grpc.
2015-11-02 07:39:53 -08:00
## Message types
2016-02-14 12:51:49 -08:00
TMSP requests/responses are simple Protobuf messages. Check out the [schema file](https://github.com/tendermint/tmsp/blob/master/types/types.proto).
2017-01-12 12:27:08 -08:00
#### DeliverTx
2015-11-02 07:39:53 -08:00
* __Arguments__:
2016-02-14 12:51:49 -08:00
* `Data ([]byte)`: The request transaction bytes
2015-11-02 07:39:53 -08:00
* __Returns__:
* `Code (uint32)`: Response code
2016-02-14 12:51:49 -08:00
* `Data ([]byte)`: Result bytes, if any
* `Log (string)`: Debug or error message
2015-11-02 07:39:53 -08:00
* __Usage__:<br/>
2016-02-14 12:51:49 -08:00
Append and run a transaction. If the transaction is valid, returns CodeType.OK
2015-11-02 07:39:53 -08:00
#### CheckTx
* __Arguments__:
2016-02-14 12:51:49 -08:00
* `Data ([]byte)`: The request transaction bytes
2015-11-02 07:39:53 -08:00
* __Returns__:
* `Code (uint32)`: Response code
2016-02-14 12:51:49 -08:00
* `Data ([]byte)`: Result bytes, if any
* `Log (string)`: Debug or error message
2015-11-02 07:39:53 -08:00
* __Usage__:<br/>
2016-10-28 12:06:40 -07:00
Validate a mempool transaction, prior to broadcasting or proposing. This message should not mutate the main state, but application
developers may want to keep a separate CheckTx state that gets reset upon Commit.
2017-01-12 12:27:08 -08:00
CheckTx can happen interspersed with DeliverTx, but they happen on different connections - CheckTx from the mempool connection, and DeliverTx from the consensus connection. During Commit, the mempool is locked, so you can reset the mempool state to the latest state after running all those delivertxs, and then the mempool will re run whatever txs it has against that latest mempool stte
2016-10-28 12:06:40 -07:00
2016-02-14 12:51:49 -08:00
Transactions are first run through CheckTx before broadcast to peers in the mempool layer.
2016-03-26 22:35:23 -07:00
You can make CheckTx semi-stateful and clear the state upon `Commit` or `BeginBlock`,
to allow for dependent sequences of transactions in the same block.
2015-11-02 07:39:53 -08:00
2016-02-14 12:51:49 -08:00
#### Commit
2015-11-02 07:39:53 -08:00
* __Returns__:
2016-02-14 12:51:49 -08:00
* `Data ([]byte)`: The Merkle root hash
* `Log (string)`: Debug or error message
2015-11-02 07:39:53 -08:00
* __Usage__:<br/>
2016-02-14 12:51:49 -08:00
Return a Merkle root hash of the application state.
#### Query
* __Arguments__:
* `Data ([]byte)`: The query request bytes
* __Returns__:
* `Code (uint32)`: Response code
2016-02-14 12:51:49 -08:00
* `Data ([]byte)`: The query response bytes
* `Log (string)`: Debug or error message
2015-11-02 07:39:53 -08:00
#### Flush
* __Usage__:<br/>
Flush the response queue. Applications that implement `types.Application` need not implement this message -- it's handled by the project.
#### Info
* __Returns__:
2016-02-14 12:51:49 -08:00
* `Data ([]byte)`: The info bytes
* __Usage__:<br/>
2016-02-14 12:51:49 -08:00
Return information about the application state. Application specific.
2015-11-27 10:14:46 -08:00
#### SetOption
* __Arguments__:
2016-02-14 12:51:49 -08:00
* `Key (string)`: Key to set
* `Value (string)`: Value to set for key
2015-11-27 10:14:46 -08:00
* __Returns__:
2016-02-14 12:51:49 -08:00
* `Log (string)`: Debug or error message
2015-11-27 10:14:46 -08:00
* __Usage__:<br/>
Set application options. E.g. Key="mode", Value="mempool" for a mempool connection, or Key="mode", Value="consensus" for a consensus connection.
Other options are application specific.
#### InitChain
2016-02-28 18:53:24 -08:00
* __Arguments__:
* `Validators ([]Validator)`: Initial genesis validators
* __Usage__:<br/>
Called once upon genesis
2016-02-28 18:53:24 -08:00
2016-03-26 22:35:23 -07:00
#### BeginBlock
* __Arguments__:
* `Height (uint64)`: The block height that is starting
* __Usage__:<br/>
2017-01-12 12:27:08 -08:00
Signals the beginning of a new block. Called prior to any DeliverTxs.
2016-03-26 22:35:23 -07:00
#### EndBlock
2016-03-06 17:57:47 -08:00
* __Arguments__:
* `Height (uint64)`: The block height that ended
2016-02-28 18:53:24 -08:00
* __Returns__:
* `Validators ([]Validator)`: Changed validators with new voting powers (0 to remove)
* __Usage__:<br/>
Signals the end of a block. Called prior to each Commit after all transactions
2016-02-28 18:53:24 -08:00
2016-05-04 13:37:22 -07:00
## Changelog
2016-03-26 22:35:23 -07:00
2016-05-04 13:37:22 -07:00
##### Mar 26h, 2016
2016-03-26 22:35:23 -07:00
* Introduce BeginBlock
2016-05-04 13:37:22 -07:00
##### Mar 6th, 2016
2016-02-28 18:53:24 -08:00
2016-03-06 17:57:47 -08:00
* Added InitChain, EndBlock
2016-02-28 18:53:24 -08:00
2016-05-04 13:37:22 -07:00
##### Feb 14th, 2016
2016-02-14 12:51:49 -08:00
* s/GetHash/Commit/g
* Document Protobuf request/response fields
2016-05-04 13:37:22 -07:00
##### Jan 23th, 2016
2016-01-23 20:49:15 -08:00
* Added CheckTx/Query TMSP message types
2017-01-12 12:27:08 -08:00
* Added Result/Log fields to DeliverTx/CheckTx/SetOption
2016-01-23 20:49:15 -08:00
* Removed Listener messages
* Removed Code from ResponseSetOption and ResponseGetHash
* Made examples BigEndian
2016-01-23 20:49:15 -08:00
2016-05-04 13:37:22 -07:00
##### Jan 12th, 2016
* Added "RetCodeBadNonce = 0x06" return code
2016-05-04 13:37:22 -07:00
##### Jan 8th, 2016
2017-01-12 12:27:08 -08:00
* Tendermint/TMSP now comes to consensus on the order first before DeliverTx.