Browse Source

Merge pull request #163 from tendermint/feature/enhance-endblock

Update the ResponseEndBlock values
pull/1780/head
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
c03928766d
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 802 additions and 598 deletions
  1. +9
    -0
      CHANGELOG.md
  2. +20
    -23
      Makefile
  3. +59
    -59
      README.md
  4. +1
    -1
      circle.yml
  5. +2
    -2
      example/dummy/dummy_test.go
  6. +5
    -5
      example/dummy/persistent_dummy.go
  7. +580
    -442
      types/types.pb.go
  8. +95
    -66
      types/types.proto
  9. +31
    -0
      types/types_test.go

+ 9
- 0
CHANGELOG.md View File

@ -1,5 +1,14 @@
# Changelog
## 0.9.0 (TBD)
BREAKING CHANGES:
- [types] ResponseEndBlock: renamed Diffs field to ValidatorUpdates
- [types] changed protobuf field indices for Request and Response oneof types
FEATURES:
- [types] ResponseEndBlock: added ConsensusParamUpdates
## 0.8.0 (December 6, 2017)
BREAKING CHANGES:


+ 20
- 23
Makefile View File

@ -2,13 +2,12 @@ GOTOOLS = \
github.com/mitchellh/gox \
github.com/Masterminds/glide \
gopkg.in/alecthomas/gometalinter.v2 \
github.com/ckaznocha/protoc-gen-lint \
github.com/gogo/protobuf/protoc-gen-gogo \
github.com/gogo/protobuf/gogoproto
INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
all: install test
all: protoc install test metalinter
PACKAGES=$(shell go list ./... | grep -v '/vendor/')
@ -27,10 +26,10 @@ protoc:
## On "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
## ldconfig (may require sudo)
## https://stackoverflow.com/a/25518702
protoc $(INCLUDE) --gogo_out=plugins=grpc:. --lint_out=. types/*.proto
@echo "--> adding nolint declarations to protobuf generated files"
@awk '/package types/ { print "//nolint: gas"; print; next }1' types/types.pb.go > types/types.pb.go.new
@mv types/types.pb.go.new types/types.pb.go
protoc $(INCLUDE) --gogo_out=plugins=grpc:. types/*.proto
@ echo "--> adding nolint declarations to protobuf generated files"
@ awk '/package types/ { print "//nolint: gas"; print; next }1' types/types.pb.go > types/types.pb.go.new
@ mv types/types.pb.go.new types/types.pb.go
install:
@ go install ./cmd/...
@ -44,15 +43,13 @@ dist:
test:
@ find . -path ./vendor -prune -o -name "*.sock" -exec rm {} \;
@ echo "==> Running linter"
@ make metalinter_test
@ echo "==> Running go test"
@ go test $(PACKAGES)
test_race:
@ find . -path ./vendor -prune -o -name "*.sock" -exec rm {} \;
@ echo "==> Running go test --race"
@go test -v -race $(PACKAGES)
@ go test -v -race $(PACKAGES)
test_integrations:
@ bash test.sh
@ -65,34 +62,34 @@ get_deps:
ensure_tools:
go get -u -v $(GOTOOLS)
@gometalinter.v2 --install
@ gometalinter.v2 --install
get_vendor_deps: ensure_tools
@rm -rf vendor/
@echo "--> Running glide install"
@ rm -rf vendor/
@ echo "--> Running glide install"
@ glide install
metalinter:
metalinter_all:
protoc $(INCLUDE) --lint_out=. types/*.proto
gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
metalinter_test:
#protoc $(INCLUDE) --lint_out=. types/*.proto
metalinter:
@ echo "==> Running linter"
gometalinter.v2 --vendor --deadline=600s --disable-all \
--enable=maligned \
--enable=deadcode \
--enable=goconst \
--enable=goimports \
--enable=gosimple \
--enable=ineffassign \
--enable=ineffassign \
--enable=megacheck \
--enable=misspell \
--enable=staticcheck \
--enable=misspell \
--enable=staticcheck \
--enable=safesql \
--enable=structcheck \
--enable=unconvert \
--enable=structcheck \
--enable=unconvert \
--enable=unused \
--enable=varcheck \
--enable=varcheck \
--enable=vetshadow \
./...
@ -102,8 +99,8 @@ metalinter_test:
#--enable=gocyclo \
#--enable=golint \ <== comments on anything exported
#--enable=gotype \
#--enable=interfacer \
#--enable=unparam \
#--enable=interfacer \
#--enable=unparam \
#--enable=vet \
build-docker:


+ 59
- 59
README.md View File

@ -59,7 +59,7 @@ See [the documentation](http://tendermint.readthedocs.io/en/master/) for more de
Multiple example apps are included:
- the `abci-cli counter` application, which illustrates nonce checking in txs
- the `abci-cli dummy` application, which illustrates a simple key-value merkle tree
- the `abci-cli dummy` application, which illustrates a simple key-value Merkle tree
- the `abci-cli dummy --persistent` application, which augments the dummy with persistence and validator set changes
### Install
@ -91,59 +91,17 @@ ABCI requests/responses are defined as simple Protobuf messages in [this schema
TendermintCore sends the requests, and the ABCI application sends the responses.
Here, we describe the requests and responses as function arguments and return values, and make some notes about usage:
#### DeliverTx
* __Arguments__:
* `Data ([]byte)`: The request transaction bytes
* __Returns__:
* `Code (uint32)`: Response code
* `Data ([]byte)`: Result bytes, if any
* `Log (string)`: Debug or error message
* `Tags ([]*KVPair)`: Optional tags for indexing
* __Usage__:<br/>
Append and run a transaction. If the transaction is valid, returns CodeType.OK
#### CheckTx
#### Echo
* __Arguments__:
* `Data ([]byte)`: The request transaction bytes
* `Message (string)`: A string to echo back
* __Returns__:
* `Code (uint32)`: Response code
* `Data ([]byte)`: Result bytes, if any
* `Log (string)`: Debug or error message
* `Gas (int64)`: Amount of gas consumed by transaction
* `Fee (int64)`: Fee paid by transaction
* `Message (string)`: The input string
* __Usage__:<br/>
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 ABCI 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 state.
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.
* Echo a string to test an abci client/server implementation
#### Commit
* __Returns__:
* `Data ([]byte)`: The Merkle root hash
* `Log (string)`: Debug or error message
#### Flush
* __Usage__:<br/>
Return a Merkle root hash of the application state.
#### Query
* __Arguments__:
* `Data ([]byte)`: Raw query bytes. Can be used with or in lieu of Path.
* `Path (string)`: Path of request, like an HTTP GET path. Can be used with or in liue of Data.
* Apps MUST interpret '/store' as a query by key on the underlying store. The key SHOULD be specified in the Data field.
* Apps SHOULD allow queries over specific types like '/accounts/...' or '/votes/...'
* `Height (int64)`: The block height for which you want the query (default=0 returns data for the latest committed block). Note that this is the height of the block containing the application's Merkle root hash, which represents the state as it was after committing the block at Height-1
* `Prove (bool)`: Return Merkle proof with response if possible
* __Returns__:
* `Code (uint32)`: Response code
* `Key ([]byte)`: The key of the matching data
* `Value ([]byte)`: The value of the matching data
* `Proof ([]byte)`: Proof for the data, if requested
* `Height (int64)`: The block height from which data was derived. Note that this is the height of the block containing the application's Merkle root hash, which represents the state as it was after committing the block at Height-1
* `Log (string)`: Debug or error message
*Please note* The current implementation of go-merkle doesn't support querying proofs from past blocks, so for the present moment, any height other than 0 will return an error (recall height=0 defaults to latest block). Hopefully this will be improved soon(ish)
* Signals that messages queued on the client should be flushed to the server. It is called periodically by the client implementation to ensure asynchronous requests are actually sent, and is called immediately to make a synchronous request, which returns when the Flush response comes back.
#### Info
* __Returns__:
@ -172,6 +130,22 @@ Here, we describe the requests and responses as function arguments and return va
* __Usage__:<br/>
Called once upon genesis
#### Query
* __Arguments__:
* `Data ([]byte)`: Raw query bytes. Can be used with or in lieu of Path.
* `Path (string)`: Path of request, like an HTTP GET path. Can be used with or in liue of Data.
* Apps MUST interpret '/store' as a query by key on the underlying store. The key SHOULD be specified in the Data field.
* Apps SHOULD allow queries over specific types like '/accounts/...' or '/votes/...'
* `Height (int64)`: The block height for which you want the query (default=0 returns data for the latest committed block). Note that this is the height of the block containing the application's Merkle root hash, which represents the state as it was after committing the block at Height-1
* `Prove (bool)`: Return Merkle proof with response if possible
* __Returns__:
* `Code (uint32)`: Response code
* `Key ([]byte)`: The key of the matching data
* `Value ([]byte)`: The value of the matching data
* `Proof ([]byte)`: Proof for the data, if requested
* `Height (int64)`: The block height from which data was derived. Note that this is the height of the block containing the application's Merkle root hash, which represents the state as it was after committing the block at Height-1
* `Log (string)`: Debug or error message
#### BeginBlock
* __Arguments__:
* `Hash ([]byte)`: The block's hash. This can be derived from the block header.
@ -181,23 +155,49 @@ Here, we describe the requests and responses as function arguments and return va
* __Usage__:<br/>
Signals the beginning of a new block. Called prior to any DeliverTxs. The header is expected to at least contain the Height. The `AbsentValidators` and `ByzantineValidators` can be used to determine rewards and punishments for the validators.
#### EndBlock
#### CheckTx
* __Arguments__:
* `Height (int64)`: The block height that ended
* `Data ([]byte)`: The request transaction bytes
* __Returns__:
* `Diffs ([]Validator)`: Changed validators with new voting powers (0 to remove)
* `Code (uint32)`: Response code
* `Data ([]byte)`: Result bytes, if any
* `Log (string)`: Debug or error message
* `Gas (int64)`: Amount of gas consumed by transaction
* `Fee (int64)`: Fee paid by transaction
* __Usage__:<br/>
Signals the end of a block. Called prior to each Commit after all transactions. Validator set is updated with the result.
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.
#### Echo
CheckTx can happen interspersed with DeliverTx, but they happen on different ABCI 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 state.
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.
#### DeliverTx
* __Arguments__:
* `Message (string)`: A string to echo back
* `Data ([]byte)`: The request transaction bytes
* __Returns__:
* `Message (string)`: The input string
* `Code (uint32)`: Response code
* `Data ([]byte)`: Result bytes, if any
* `Log (string)`: Debug or error message
* `Tags ([]*KVPair)`: Optional tags for indexing
* __Usage__:<br/>
* Echo a string to test an abci client/server implementation
Append and run a transaction. If the transaction is valid, returns CodeType.OK
#### Flush
#### EndBlock
* __Arguments__:
* `Height (int64)`: The block height that ended
* __Returns__:
* `ValidatorUpdates ([]Validator)`: Changes to validator set (set voting power to 0 to remove)
* `ConsensusParamUpdates (ConsensusParams)`: Changes to consensus-critical time/size parameters
* __Usage__:<br/>
* Signals that messages queued on the client should be flushed to the server. It is called periodically by the client implementation to ensure asynchronous requests are actually sent, and is called immediately to make a synchronous request, which returns when the Flush response comes back.
Signals the end of a block. Called prior to each Commit after all transactions. Validator set is updated with the result.
#### Commit
* __Returns__:
* `Data ([]byte)`: The Merkle root hash
* `Log (string)`: Debug or error message
* __Usage__:<br/>
Return a Merkle root hash of the application state.

+ 1
- 1
circle.yml View File

@ -15,7 +15,7 @@ checkout:
test:
override:
- cd $REPO && make get_vendor_deps && make metalinter_test && make test_integrations
- cd $REPO && make get_vendor_deps && make metalinter && make test_integrations
post:
- cd "$REPO" && bash <(curl -s https://codecov.io/bash) -f coverage.txt
- cd "$REPO" && mv coverage.txt "${CIRCLE_ARTIFACTS}"

+ 2
- 2
example/dummy/dummy_test.go View File

@ -107,7 +107,7 @@ func TestPersistentDummyInfo(t *testing.T) {
}
// add a validator, remove a validator, update a validator
func TestValSetChanges(t *testing.T) {
func TestValUpdates(t *testing.T) {
dir, err := ioutil.TempDir("/tmp", "abci-dummy-test") // TODO
if err != nil {
t.Fatal(err)
@ -188,7 +188,7 @@ func makeApplyBlock(t *testing.T, dummy types.Application, heightInt int, diff [
resEndBlock := dummy.EndBlock(types.RequestEndBlock{header.Height})
dummy.Commit()
valsEqual(t, diff, resEndBlock.Diffs)
valsEqual(t, diff, resEndBlock.ValidatorUpdates)
}


+ 5
- 5
example/dummy/persistent_dummy.go View File

@ -28,7 +28,7 @@ type PersistentDummyApplication struct {
app *DummyApplication
// validator set
changes []*types.Validator
ValUpdates []*types.Validator
logger log.Logger
}
@ -71,7 +71,7 @@ func (app *PersistentDummyApplication) DeliverTx(tx []byte) types.ResponseDelive
// format is "val:pubkey/power"
if isValidatorTx(tx) {
// update validators in the merkle tree
// and in app.changes
// and in app.ValUpdates
return app.execValidatorTx(tx)
}
@ -119,13 +119,13 @@ func (app *PersistentDummyApplication) InitChain(req types.RequestInitChain) typ
// Track the block hash and header information
func (app *PersistentDummyApplication) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock {
// reset valset changes
app.changes = make([]*types.Validator, 0)
app.ValUpdates = make([]*types.Validator, 0)
return types.ResponseBeginBlock{}
}
// Update the validator set
func (app *PersistentDummyApplication) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock {
return types.ResponseEndBlock{Diffs: app.changes}
return types.ResponseEndBlock{ValidatorUpdates: app.ValUpdates}
}
//---------------------------------------------
@ -216,7 +216,7 @@ func (app *PersistentDummyApplication) updateValidator(v *types.Validator) types
}
// we only update the changes array if we successfully updated the tree
app.changes = append(app.changes, v)
app.ValUpdates = append(app.ValUpdates, v)
return types.ResponseDeliverTx{Code: code.CodeTypeOK}
}

+ 580
- 442
types/types.pb.go
File diff suppressed because it is too large
View File


+ 95
- 66
types/types.proto View File

@ -3,25 +3,24 @@ package types;
import "github.com/gogo/protobuf/gogoproto/gogo.proto";
// This file is copied from http://github.com/tendermint/abci
//----------------------------------------
// Request types
message Request {
oneof value{
RequestEcho echo = 1;
RequestFlush flush = 2;
RequestInfo info = 3;
RequestSetOption set_option = 4;
RequestDeliverTx deliver_tx = 5;
RequestCheckTx check_tx = 6;
RequestCommit commit = 7;
RequestQuery query = 8;
RequestInitChain init_chain = 9;
RequestBeginBlock begin_block = 10;
oneof value {
RequestEcho echo = 2;
RequestFlush flush = 3;
RequestInfo info = 4;
RequestSetOption set_option = 5;
RequestInitChain init_chain = 6;
RequestQuery query = 7;
RequestBeginBlock begin_block = 8;
RequestCheckTx check_tx = 9;
RequestDeliverTx deliver_tx = 19;
RequestEndBlock end_block = 11;
RequestCommit commit = 12;
}
}
@ -36,17 +35,13 @@ message RequestInfo {
string version = 1;
}
message RequestSetOption{
message RequestSetOption {
string key = 1;
string value = 2;
}
message RequestDeliverTx{
bytes tx = 1;
}
message RequestCheckTx{
bytes tx = 1;
message RequestInitChain {
repeated Validator validators = 1;
}
message RequestQuery{
@ -56,46 +51,49 @@ message RequestQuery{
bool prove = 4;
}
message RequestCommit{
}
message RequestInitChain{
repeated Validator validators = 1;
}
message RequestBeginBlock{
message RequestBeginBlock {
bytes hash = 1;
Header header = 2;
repeated int32 absent_validators = 3;
repeated Evidence byzantine_validators = 4;
}
message RequestCheckTx {
bytes tx = 1;
}
message RequestDeliverTx {
bytes tx = 1;
}
message RequestEndBlock{
int64 height = 1;
}
message RequestCommit {
}
//----------------------------------------
// Response types
message Response {
oneof value{
oneof value {
ResponseException exception = 1;
ResponseEcho echo = 2;
ResponseFlush flush = 3;
ResponseInfo info = 4;
ResponseSetOption set_option = 5;
ResponseDeliverTx deliver_tx = 6;
ResponseCheckTx check_tx = 7;
ResponseCommit commit = 8;
ResponseQuery query = 9;
ResponseInitChain init_chain = 10;
ResponseBeginBlock begin_block = 11;
ResponseEndBlock end_block = 12;
ResponseInitChain init_chain = 6;
ResponseQuery query = 7;
ResponseBeginBlock begin_block = 8;
ResponseCheckTx check_tx = 9;
ResponseDeliverTx deliver_tx = 10;
ResponseEndBlock end_block = 11;
ResponseCommit commit = 12;
}
}
message ResponseException{
message ResponseException {
string error = 1;
}
@ -103,7 +101,7 @@ message ResponseEcho {
string message = 1;
}
message ResponseFlush{
message ResponseFlush {
}
message ResponseInfo {
@ -113,51 +111,82 @@ message ResponseInfo {
bytes last_block_app_hash = 4;
}
message ResponseSetOption{
message ResponseSetOption {
uint32 code = 1;
string log = 2;
}
message ResponseDeliverTx{
uint32 code = 1;
bytes data = 2 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
string log = 3;
repeated KVPair tags = 4;
message ResponseInitChain {
}
message ResponseCheckTx{
uint32 code = 1;
bytes data = 2 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
string log = 3;
int64 gas = 4;
int64 fee = 5;
message ResponseQuery {
uint32 code = 1;
int64 index = 2;
bytes key = 3 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
bytes value = 4 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
bytes proof = 5 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
int64 height = 6;
string log = 7;
}
message ResponseQuery{
uint32 code = 1;
int64 index = 2;
bytes key = 3 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
bytes value = 4 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
bytes proof = 5 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
int64 height = 6;
string log = 7;
message ResponseBeginBlock {
}
message ResponseCommit{
uint32 code = 1;
bytes data = 2 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
string log = 3;
message ResponseCheckTx {
uint32 code = 1;
bytes data = 2 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
string log = 3;
int64 gas = 4;
int64 fee = 5;
}
message ResponseDeliverTx {
uint32 code = 1;
bytes data = 2 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
string log = 3;
repeated KVPair tags = 4;
}
message ResponseEndBlock {
repeated Validator validator_updates = 1;
ConsensusParams consensus_param_updates = 2;
}
message ResponseCommit {
uint32 code = 1;
bytes data = 2 [(gogoproto.customtype) = "github.com/tendermint/go-wire/data.Bytes", (gogoproto.nullable) = false];
string log = 3;
}
//----------------------------------------
// Misc.
// ConsensusParams contains all consensus-relevant parameters
// that can be adjusted by the abci app
message ConsensusParams {
BlockSize block_size = 1;
TxSize tx_size = 2;
BlockGossip block_gossip = 3;
}
message ResponseInitChain{
// BlockSize contain limits on the block size.
message BlockSize {
int32 max_bytes = 1;
int32 max_txs = 2;
int64 max_gas = 3;
}
message ResponseBeginBlock{
// TxSize contain limits on the tx size.
message TxSize{
int32 max_bytes = 1;
int64 max_gas = 2;
}
message ResponseEndBlock{
repeated Validator diffs = 1;
// BlockGossip determine consensus critical
// elements of how blocks are gossiped
message BlockGossip{
// Note: must not be 0
int32 block_part_size_bytes = 1;
}
//----------------------------------------


+ 31
- 0
types/types_test.go View File

@ -0,0 +1,31 @@
package types
import (
"testing"
asrt "github.com/stretchr/testify/assert"
)
func TestConsensusParams(t *testing.T) {
assert := asrt.New(t)
params := &ConsensusParams{
BlockSize: &BlockSize{MaxGas: 12345},
BlockGossip: &BlockGossip{BlockPartSizeBytes: 54321},
}
var noParams *ConsensusParams // nil
// no error with nil fields
assert.Nil(noParams.GetBlockSize())
assert.EqualValues(noParams.GetBlockSize().GetMaxGas(), 0)
// get values with real fields
assert.NotNil(params.GetBlockSize())
assert.EqualValues(params.GetBlockSize().GetMaxTxs(), 0)
assert.EqualValues(params.GetBlockSize().GetMaxGas(), 12345)
assert.NotNil(params.GetBlockGossip())
assert.EqualValues(params.GetBlockGossip().GetBlockPartSizeBytes(), 54321)
assert.Nil(params.GetTxSize())
assert.EqualValues(params.GetTxSize().GetMaxBytes(), 0)
}

Loading…
Cancel
Save