Ethan Buchman 1e8791bc9a | 8 years ago | |
---|---|---|
client | 8 years ago | |
cmd | 8 years ago | |
example | 8 years ago | |
server | 8 years ago | |
tests | 8 years ago | |
testutil | 8 years ago | |
types | 8 years ago | |
.gitignore | 9 years ago | |
LICENSE | 8 years ago | |
Makefile | 8 years ago | |
README.md | 8 years ago | |
circle.yml | 8 years ago | |
glide.lock | 8 years ago | |
glide.yaml | 8 years ago |
Blockchains are a system for multi-master state machine replication. ABCI is an interface that defines the boundary between the replication engine (the blockchain), and the state machine (the application). By using a socket protocol, we enable a consensus engine running in one process to manage an application state running in another.
For more information on ABCI, motivations, and tutorials, please visit our blog post, and the more detailed application developer's guide.
Previously, the ABCI was just referred to as TMSP.
Other implementations:
The primary specification is made using Protocol Buffers.
As a Go interface, it might look like:
// Applications
type Application interface {
// Latest state
Info() ResponseInfo
// Initialization
SetOption(key string, value string) (log string)
InitChain(validators []*Validator)
// Apply a block
BeginBlock(hash []byte, header *Header)
DeliverTx(tx []byte) Result
EndBlock(height uint64) ResponseEndBlock
Commit() Result
// Check validity
CheckTx(tx []byte) Result
// Query for state
Query(query []byte) Result
}
type Result struct {
Code CodeType
Data []byte
Log string // Can be non-deterministic
}
type ResponseInfo struct {
Data string
Version string
LastBlockHeight uint64
LastBlockAppHash []byte
}
type ResponseEndBlock struct {
Diffs []*Validator
}
ABCI requests/responses are simple Protobuf messages. Check out the schema file.
Data ([]byte)
: The request transaction bytesCode (uint32)
: Response codeData ([]byte)
: Result bytes, if anyLog (string)
: Debug or error messageArguments:
Data ([]byte)
: The request transaction bytesReturns:
Code (uint32)
: Response codeData ([]byte)
: Result bytes, if anyLog (string)
: Debug or error messageUsage:
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.
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
Transactions are first run through CheckTx before broadcast to peers in the mempool layer.
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.
Data ([]byte)
: The Merkle root hashLog (string)
: Debug or error messageData ([]byte)
: The query request bytesCode (uint32)
: Response codeData ([]byte)
: The query response bytesLog (string)
: Debug or error messageReturns:
Data (string)
: Some arbitrary informationVersion (Version)
: Version informationLastBlockHeight (uint64)
: Latest block for which the app has called CommitLastBlockAppHash ([]byte)
: Latest result of CommitUsage:
Return information about the application state. Used to sync the app with Tendermint on crash/restart.
Key (string)
: Key to setValue (string)
: Value to set for keyLog (string)
: Debug or error messageValidators ([]Validator)
: Initial genesis validatorsHash ([]byte)
: The block height that is startingHeader (struct{})
: The block headerHeight (uint64)
: The block height that endedDiffs ([]Validator)
: Changed validators with new voting powers (0 to remove)Message (string)
: A string to echo backMessage (string)
: The input stringThe ABCI is a client/server interface where the replication engine (blockchain) forms the client and the state machine (application) forms the server. As blocks are committed in the blockchain, they are forwarded to the application.
This repository provides two implementations of an ABCI client & server: via socket and via GRPC.
ABCI is best implemented as a streaming protocol. The socket implementation provides for asynchronous, ordered message passing over unix or tcp. Messages are serialized using Protobuf3 and length-prefixed. 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 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...
.
GRPC is an rpc framework native to Protocol Buffers with support in many languages. Implementing the ABCI using GRPC can allow for faster prototyping, but is expected to be much slower than the ordered, asynchronous socket protocol.
Note the length-prefixing used in the socket implementation does not apply for GRPC.
The abci-cli
tool wraps any ABCI client and can be used for probing/testing an ABCI application.
See the tutorial for more details.
Multiple example apps are included:
counter
application, which illustrates nonce checking in txsdummy
application, which illustrates a simple key-value merkle treedummy --persistent
application, which augments the dummy with persistence and validator set changesTo build the protobuf code:
make protoc
See protoc --help
and the grpc docs for examples and details of other languages