Browse Source

Merge pull request #170 from tendermint/develop

v0.9.0
pull/1780/head
Ethan Buchman 7 years ago
committed by GitHub
parent
commit
5d5ea6869b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 994 additions and 667 deletions
  1. +13
    -0
      CHANGELOG.md
  2. +23
    -23
      Makefile
  3. +59
    -59
      README.md
  4. +0
    -1
      circle.yml
  5. +144
    -49
      cmd/abci-cli/abci-cli.go
  6. +2
    -2
      example/dummy/dummy_test.go
  7. +5
    -5
      example/dummy/persistent_dummy.go
  8. +8
    -8
      tests/server/client.go
  9. +2
    -2
      types/protoreplace/protoreplace.go
  10. +17
    -0
      types/result.go
  11. +589
    -448
      types/types.pb.go
  12. +99
    -68
      types/types.proto
  13. +31
    -0
      types/types_test.go
  14. +2
    -2
      version/version.go

+ 13
- 0
CHANGELOG.md View File

@ -1,5 +1,18 @@
# Changelog # Changelog
## 0.9.0 (December 28, 2017)
BREAKING CHANGES:
- [types] Id -> ID
- [types] ResponseEndBlock: renamed Diffs field to ValidatorUpdates
- [types] changed protobuf field indices for Request and Response oneof types
FEATURES:
- [types] ResponseEndBlock: added ConsensusParamUpdates
BUG FIXES:
- [cmd] fix console and batch commands to use a single persistent connection
## 0.8.0 (December 6, 2017) ## 0.8.0 (December 6, 2017)
BREAKING CHANGES: BREAKING CHANGES:


+ 23
- 23
Makefile View File

@ -1,14 +1,13 @@
GOTOOLS = \ GOTOOLS = \
github.com/mitchellh/gox \ github.com/mitchellh/gox \
github.com/Masterminds/glide \ github.com/Masterminds/glide \
github.com/alecthomas/gometalinter \
github.com/ckaznocha/protoc-gen-lint \
github.com/gogo/protobuf/protoc-gen-gogo \ github.com/gogo/protobuf/protoc-gen-gogo \
github.com/gogo/protobuf/gogoproto github.com/gogo/protobuf/gogoproto
#gopkg.in/alecthomas/gometalinter.v2 \
INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf INCLUDE = -I=. -I=${GOPATH}/src -I=${GOPATH}/src/github.com/gogo/protobuf/protobuf
all: install test
all: protoc install test
PACKAGES=$(shell go list ./... | grep -v '/vendor/') PACKAGES=$(shell go list ./... | grep -v '/vendor/')
@ -27,7 +26,10 @@ protoc:
## On "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory" ## On "error while loading shared libraries: libprotobuf.so.14: cannot open shared object file: No such file or directory"
## ldconfig (may require sudo) ## ldconfig (may require sudo)
## https://stackoverflow.com/a/25518702 ## https://stackoverflow.com/a/25518702
protoc $(INCLUDE) --gogo_out=plugins=grpc:. --lint_out=. types/*.proto
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: install:
@ go install ./cmd/... @ go install ./cmd/...
@ -41,15 +43,13 @@ dist:
test: test:
@ find . -path ./vendor -prune -o -name "*.sock" -exec rm {} \; @ find . -path ./vendor -prune -o -name "*.sock" -exec rm {} \;
@ echo "==> Running linter"
@ make metalinter_test
@ echo "==> Running go test" @ echo "==> Running go test"
@ go test $(PACKAGES) @ go test $(PACKAGES)
test_race: test_race:
@ find . -path ./vendor -prune -o -name "*.sock" -exec rm {} \; @ find . -path ./vendor -prune -o -name "*.sock" -exec rm {} \;
@ echo "==> Running go test --race" @ echo "==> Running go test --race"
@go test -v -race $(PACKAGES)
@ go test -v -race $(PACKAGES)
test_integrations: test_integrations:
@ bash test.sh @ bash test.sh
@ -62,34 +62,34 @@ get_deps:
ensure_tools: ensure_tools:
go get -u -v $(GOTOOLS) go get -u -v $(GOTOOLS)
@gometalinter --install
#@ gometalinter.v2 --install
get_vendor_deps: ensure_tools get_vendor_deps: ensure_tools
@rm -rf vendor/
@echo "--> Running glide install"
@ rm -rf vendor/
@ echo "--> Running glide install"
@ glide install @ glide install
metalinter:
metalinter_all:
protoc $(INCLUDE) --lint_out=. types/*.proto protoc $(INCLUDE) --lint_out=. types/*.proto
gometalinter --vendor --deadline=600s --enable-all --disable=lll ./...
gometalinter.v2 --vendor --deadline=600s --enable-all --disable=lll ./...
metalinter_test:
protoc $(INCLUDE) --lint_out=. types/*.proto
gometalinter --vendor --deadline=600s --disable-all \
metalinter:
@ echo "==> Running linter"
gometalinter.v2 --vendor --deadline=600s --disable-all \
--enable=maligned \ --enable=maligned \
--enable=deadcode \ --enable=deadcode \
--enable=goconst \ --enable=goconst \
--enable=goimports \ --enable=goimports \
--enable=gosimple \ --enable=gosimple \
--enable=ineffassign \
--enable=ineffassign \
--enable=megacheck \ --enable=megacheck \
--enable=misspell \
--enable=staticcheck \
--enable=misspell \
--enable=staticcheck \
--enable=safesql \ --enable=safesql \
--enable=structcheck \
--enable=unconvert \
--enable=structcheck \
--enable=unconvert \
--enable=unused \ --enable=unused \
--enable=varcheck \
--enable=varcheck \
--enable=vetshadow \ --enable=vetshadow \
./... ./...
@ -99,8 +99,8 @@ metalinter_test:
#--enable=gocyclo \ #--enable=gocyclo \
#--enable=golint \ <== comments on anything exported #--enable=golint \ <== comments on anything exported
#--enable=gotype \ #--enable=gotype \
#--enable=interfacer \
#--enable=unparam \
#--enable=interfacer \
#--enable=unparam \
#--enable=vet \ #--enable=vet \
build-docker: 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: Multiple example apps are included:
- the `abci-cli counter` application, which illustrates nonce checking in txs - 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 - the `abci-cli dummy --persistent` application, which augments the dummy with persistence and validator set changes
### Install ### 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. 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: 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__: * __Arguments__:
* `Data ([]byte)`: The request transaction bytes
* `Message (string)`: A string to echo back
* __Returns__: * __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/> * __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/> * __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 #### Info
* __Returns__: * __Returns__:
@ -172,6 +130,22 @@ Here, we describe the requests and responses as function arguments and return va
* __Usage__:<br/> * __Usage__:<br/>
Called once upon genesis 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 #### BeginBlock
* __Arguments__: * __Arguments__:
* `Hash ([]byte)`: The block's hash. This can be derived from the block header. * `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/> * __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. 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__: * __Arguments__:
* `Height (int64)`: The block height that ended
* `Data ([]byte)`: The request transaction bytes
* __Returns__: * __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/> * __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__: * __Arguments__:
* `Message (string)`: A string to echo back
* `Data ([]byte)`: The request transaction bytes
* __Returns__: * __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/> * __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/> * __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.

+ 0
- 1
circle.yml View File

@ -2,7 +2,6 @@ machine:
environment: environment:
GOPATH: /home/ubuntu/.go_workspace GOPATH: /home/ubuntu/.go_workspace
REPO: $GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME REPO: $GOPATH/src/github.com/$CIRCLE_PROJECT_USERNAME/$CIRCLE_PROJECT_REPONAME
GO15VENDOREXPERIMENT: 1
hosts: hosts:
circlehost: 127.0.0.1 circlehost: 127.0.0.1
localhost: 127.0.0.1 localhost: 127.0.0.1


+ 144
- 49
cmd/abci-cli/abci-cli.go View File

@ -7,7 +7,6 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"os/exec"
"strings" "strings"
"github.com/spf13/cobra" "github.com/spf13/cobra"
@ -169,7 +168,7 @@ var consoleCmd = &cobra.Command{
Short: "Start an interactive abci console for multiple commands", Short: "Start an interactive abci console for multiple commands",
Long: "", Long: "",
Args: cobra.ExactArgs(0), Args: cobra.ExactArgs(0),
ValidArgs: []string{"batch", "echo", "info", "set_option", "deliver_tx", "check_tx", "commit", "query"},
ValidArgs: []string{"echo", "info", "set_option", "deliver_tx", "check_tx", "commit", "query"},
RunE: func(cmd *cobra.Command, args []string) error { RunE: func(cmd *cobra.Command, args []string) error {
return cmdConsole(cmd, args) return cmdConsole(cmd, args)
}, },
@ -300,54 +299,43 @@ func persistentArgs(line []byte) []string {
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
func or(err1 error, err2 error) error {
if err1 == nil {
return err2
func compose(fs []func() error) error {
if len(fs) == 0 {
return nil
} else { } else {
return err1
err := fs[0]()
if err == nil {
return compose(fs[1:])
} else {
return err
}
} }
} }
func cmdTest(cmd *cobra.Command, args []string) error { func cmdTest(cmd *cobra.Command, args []string) error {
fmt.Println("Running tests")
err := servertest.InitChain(client)
fmt.Println("")
err = or(err, servertest.SetOption(client, "serial", "on"))
fmt.Println("")
err = or(err, servertest.Commit(client, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil))
fmt.Println("")
err = or(err, servertest.Commit(client, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeOK, nil))
fmt.Println("")
err = or(err, servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1}))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x01}, code.CodeTypeOK, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x02}, code.CodeTypeOK, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x03}, code.CodeTypeOK, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x00, 0x04}, code.CodeTypeOK, nil))
fmt.Println("")
err = or(err, servertest.DeliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil))
fmt.Println("")
err = or(err, servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5}))
if err != nil {
return errors.New("Some checks didn't pass, please inspect stdout to see the exact failures.")
}
return nil
return compose(
[]func() error{
func() error { return servertest.InitChain(client) },
func() error { return servertest.SetOption(client, "serial", "on") },
func() error { return servertest.Commit(client, nil) },
func() error { return servertest.DeliverTx(client, []byte("abc"), code.CodeTypeBadNonce, nil) },
func() error { return servertest.Commit(client, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeOK, nil) },
func() error { return servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 1}) },
func() error { return servertest.DeliverTx(client, []byte{0x00}, code.CodeTypeBadNonce, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x01}, code.CodeTypeOK, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x00, 0x02}, code.CodeTypeOK, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x00, 0x03}, code.CodeTypeOK, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x00, 0x00, 0x04}, code.CodeTypeOK, nil) },
func() error { return servertest.DeliverTx(client, []byte{0x00, 0x00, 0x06}, code.CodeTypeBadNonce, nil) },
func() error { return servertest.Commit(client, []byte{0, 0, 0, 0, 0, 0, 0, 5})},
})
} }
func cmdBatch(cmd *cobra.Command, args []string) error { func cmdBatch(cmd *cobra.Command, args []string) error {
bufReader := bufio.NewReader(os.Stdin) bufReader := bufio.NewReader(os.Stdin)
for { for {
line, more, err := bufReader.ReadLine() line, more, err := bufReader.ReadLine()
if more { if more {
return errors.New("Input line is too long") return errors.New("Input line is too long")
@ -359,18 +347,16 @@ func cmdBatch(cmd *cobra.Command, args []string) error {
return err return err
} }
pArgs := persistentArgs(line)
out, err := exec.Command(pArgs[0], pArgs[1:]...).Output() // nolint: gas
if err != nil {
cmdArgs := persistentArgs(line)
if err := muxOnCommands(cmd, cmdArgs); err != nil {
return err return err
} }
fmt.Println(string(out))
fmt.Println()
} }
return nil return nil
} }
func cmdConsole(cmd *cobra.Command, args []string) error { func cmdConsole(cmd *cobra.Command, args []string) error {
for { for {
fmt.Printf("> ") fmt.Printf("> ")
bufReader := bufio.NewReader(os.Stdin) bufReader := bufio.NewReader(os.Stdin)
@ -382,18 +368,96 @@ func cmdConsole(cmd *cobra.Command, args []string) error {
} }
pArgs := persistentArgs(line) pArgs := persistentArgs(line)
out, err := exec.Command(pArgs[0], pArgs[1:]...).Output() // nolint: gas
if err != nil {
if err := muxOnCommands(cmd, pArgs); err != nil {
return err return err
} }
fmt.Println(string(out))
} }
return nil return nil
} }
func muxOnCommands(cmd *cobra.Command, pArgs []string) error {
if len(pArgs) < 2 {
return errors.New("expecting persistent args of the form: abci-cli [command] <...>")
}
// TODO: this parsing is fragile
args := []string{}
for i := 0; i < len(pArgs); i++ {
arg := pArgs[i]
// check for flags
if strings.HasPrefix(arg, "-") {
// if it has an equal, we can just skip
if strings.Contains(arg, "=") {
continue
}
// if its a boolean, we can just skip
_, err := cmd.Flags().GetBool(strings.TrimLeft(arg, "-"))
if err == nil {
continue
}
// otherwise, we need to skip the next one too
i += 1
continue
}
// append the actual arg
args = append(args, arg)
}
var subCommand string
var actualArgs []string
if len(args) > 1 {
subCommand = args[1]
}
if len(args) > 2 {
actualArgs = args[2:]
}
cmd.Use = subCommand // for later print statements ...
switch strings.ToLower(subCommand) {
case "check_tx":
return cmdCheckTx(cmd, actualArgs)
case "commit":
return cmdCommit(cmd, actualArgs)
case "deliver_tx":
return cmdDeliverTx(cmd, actualArgs)
case "echo":
return cmdEcho(cmd, actualArgs)
case "info":
return cmdInfo(cmd, actualArgs)
case "query":
return cmdQuery(cmd, actualArgs)
case "set_option":
return cmdSetOption(cmd, actualArgs)
default:
return cmdUnimplemented(cmd, pArgs)
}
}
func cmdUnimplemented(cmd *cobra.Command, args []string) error {
// TODO: Print out all the sub-commands available
msg := "unimplemented command"
if err := cmd.Help(); err != nil {
msg = err.Error()
}
if len(args) > 0 {
msg += fmt.Sprintf(" args: [%s]", strings.Join(args, " "))
}
printResponse(cmd, args, response{
Code: codeBad,
Log: msg,
})
return nil
}
// Have the application echo a message // Have the application echo a message
func cmdEcho(cmd *cobra.Command, args []string) error { func cmdEcho(cmd *cobra.Command, args []string) error {
res, err := client.EchoSync(args[0])
msg := ""
if len(args) > 0 {
msg = args[0]
}
res, err := client.EchoSync(msg)
if err != nil { if err != nil {
return err return err
} }
@ -419,8 +483,18 @@ func cmdInfo(cmd *cobra.Command, args []string) error {
return nil return nil
} }
const codeBad uint32 = 10
// Set an option on the application // Set an option on the application
func cmdSetOption(cmd *cobra.Command, args []string) error { func cmdSetOption(cmd *cobra.Command, args []string) error {
if len(args) < 2 {
printResponse(cmd, args, response{
Code: codeBad,
Log: "want at least arguments of the form: <key> <value>",
})
return nil
}
key, val := args[0], args[1] key, val := args[0], args[1]
res, err := client.SetOptionSync(types.RequestSetOption{key, val}) res, err := client.SetOptionSync(types.RequestSetOption{key, val})
if err != nil { if err != nil {
@ -435,6 +509,13 @@ func cmdSetOption(cmd *cobra.Command, args []string) error {
// Append a new tx to application // Append a new tx to application
func cmdDeliverTx(cmd *cobra.Command, args []string) error { func cmdDeliverTx(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
printResponse(cmd, args, response{
Code: codeBad,
Log: "want the tx",
})
return nil
}
txBytes, err := stringOrHexToBytes(args[0]) txBytes, err := stringOrHexToBytes(args[0])
if err != nil { if err != nil {
return err return err
@ -453,6 +534,13 @@ func cmdDeliverTx(cmd *cobra.Command, args []string) error {
// Validate a tx // Validate a tx
func cmdCheckTx(cmd *cobra.Command, args []string) error { func cmdCheckTx(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
printResponse(cmd, args, response{
Code: codeBad,
Log: "want the tx",
})
return nil
}
txBytes, err := stringOrHexToBytes(args[0]) txBytes, err := stringOrHexToBytes(args[0])
if err != nil { if err != nil {
return err return err
@ -485,6 +573,13 @@ func cmdCommit(cmd *cobra.Command, args []string) error {
// Query application state // Query application state
func cmdQuery(cmd *cobra.Command, args []string) error { func cmdQuery(cmd *cobra.Command, args []string) error {
if len(args) == 0 {
printResponse(cmd, args, response{
Code: codeBad,
Log: "want the query",
})
return nil
}
queryBytes, err := stringOrHexToBytes(args[0]) queryBytes, err := stringOrHexToBytes(args[0])
if err != nil { if err != nil {
return err return err


+ 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 // 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 dir, err := ioutil.TempDir("/tmp", "abci-dummy-test") // TODO
if err != nil { if err != nil {
t.Fatal(err) 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}) resEndBlock := dummy.EndBlock(types.RequestEndBlock{header.Height})
dummy.Commit() 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 app *DummyApplication
// validator set // validator set
changes []*types.Validator
ValUpdates []*types.Validator
logger log.Logger logger log.Logger
} }
@ -71,7 +71,7 @@ func (app *PersistentDummyApplication) DeliverTx(tx []byte) types.ResponseDelive
// format is "val:pubkey/power" // format is "val:pubkey/power"
if isValidatorTx(tx) { if isValidatorTx(tx) {
// update validators in the merkle tree // update validators in the merkle tree
// and in app.changes
// and in app.ValUpdates
return app.execValidatorTx(tx) return app.execValidatorTx(tx)
} }
@ -119,13 +119,13 @@ func (app *PersistentDummyApplication) InitChain(req types.RequestInitChain) typ
// Track the block hash and header information // Track the block hash and header information
func (app *PersistentDummyApplication) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock { func (app *PersistentDummyApplication) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock {
// reset valset changes // reset valset changes
app.changes = make([]*types.Validator, 0)
app.ValUpdates = make([]*types.Validator, 0)
return types.ResponseBeginBlock{} return types.ResponseBeginBlock{}
} }
// Update the validator set // Update the validator set
func (app *PersistentDummyApplication) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock { 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 // 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} return types.ResponseDeliverTx{Code: code.CodeTypeOK}
} }

+ 8
- 8
tests/server/client.go View File

@ -21,7 +21,7 @@ func InitChain(client abcicli.Client) error {
} }
_, err := client.InitChainSync(types.RequestInitChain{Validators: vals}) _, err := client.InitChainSync(types.RequestInitChain{Validators: vals})
if err != nil { if err != nil {
fmt.Println("Failed test: InitChain - %v", err)
fmt.Printf("Failed test: InitChain - %v\n", err)
return err return err
} }
fmt.Println("Passed test: InitChain") fmt.Println("Passed test: InitChain")
@ -33,7 +33,7 @@ func SetOption(client abcicli.Client, key, value string) error {
log := res.GetLog() log := res.GetLog()
if err != nil { if err != nil {
fmt.Println("Failed test: SetOption") fmt.Println("Failed test: SetOption")
fmt.Printf("setting %v=%v: \nlog: %v", key, value, log)
fmt.Printf("setting %v=%v: \nlog: %v\n", key, value, log)
fmt.Println("Failed test: SetOption") fmt.Println("Failed test: SetOption")
return err return err
} }
@ -46,12 +46,12 @@ func Commit(client abcicli.Client, hashExp []byte) error {
_, data := res.Code, res.Data _, data := res.Code, res.Data
if err != nil { if err != nil {
fmt.Println("Failed test: Commit") fmt.Println("Failed test: Commit")
fmt.Printf("committing %v\nlog: %v", res.GetLog())
fmt.Printf("committing %v\nlog: %v\n", res.GetLog(), err)
return err return err
} }
if !bytes.Equal(data, hashExp) { if !bytes.Equal(data, hashExp) {
fmt.Println("Failed test: Commit") fmt.Println("Failed test: Commit")
fmt.Printf("Commit hash was unexpected. Got %X expected %X",
fmt.Printf("Commit hash was unexpected. Got %X expected %X\n",
data.Bytes(), hashExp) data.Bytes(), hashExp)
return errors.New("CommitTx failed") return errors.New("CommitTx failed")
} }
@ -64,13 +64,13 @@ func DeliverTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []
code, data, log := res.Code, res.Data, res.Log code, data, log := res.Code, res.Data, res.Log
if code != codeExp { if code != codeExp {
fmt.Println("Failed test: DeliverTx") fmt.Println("Failed test: DeliverTx")
fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v",
fmt.Printf("DeliverTx response code was unexpected. Got %v expected %v. Log: %v\n",
code, codeExp, log) code, codeExp, log)
return errors.New("DeliverTx error") return errors.New("DeliverTx error")
} }
if !bytes.Equal(data, dataExp) { if !bytes.Equal(data, dataExp) {
fmt.Println("Failed test: DeliverTx") fmt.Println("Failed test: DeliverTx")
fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X",
fmt.Printf("DeliverTx response data was unexpected. Got %X expected %X\n",
data, dataExp) data, dataExp)
return errors.New("DeliverTx error") return errors.New("DeliverTx error")
} }
@ -83,13 +83,13 @@ func CheckTx(client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []by
code, data, log := res.Code, res.Data, res.Log code, data, log := res.Code, res.Data, res.Log
if code != codeExp { if code != codeExp {
fmt.Println("Failed test: CheckTx") fmt.Println("Failed test: CheckTx")
fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v",
fmt.Printf("CheckTx response code was unexpected. Got %v expected %v. Log: %v\n",
code, codeExp, log) code, codeExp, log)
return errors.New("CheckTx") return errors.New("CheckTx")
} }
if !bytes.Equal(data, dataExp) { if !bytes.Equal(data, dataExp) {
fmt.Println("Failed test: CheckTx") fmt.Println("Failed test: CheckTx")
fmt.Printf("CheckTx response data was unexpected. Got %X expected %X",
fmt.Printf("CheckTx response data was unexpected. Got %X expected %X\n",
data, dataExp) data, dataExp)
return errors.New("CheckTx") return errors.New("CheckTx")
} }


+ 2
- 2
types/protoreplace/protoreplace.go View File

@ -1,7 +1,7 @@
package main
// +build ignore // +build ignore
package main
import ( import (
"bytes" "bytes"
"fmt" "fmt"


+ 17
- 0
types/result.go View File

@ -2,6 +2,7 @@ package types
import ( import (
"bytes" "bytes"
"encoding/json"
"fmt" "fmt"
"github.com/gogo/protobuf/jsonpb" "github.com/gogo/protobuf/jsonpb"
@ -137,3 +138,19 @@ func (r *ResponseCommit) UnmarshalJSON(b []byte) error {
reader := bytes.NewBuffer(b) reader := bytes.NewBuffer(b)
return jsonpbUnmarshaller.Unmarshal(reader, r) return jsonpbUnmarshaller.Unmarshal(reader, r)
} }
// Some compile time assertions to ensure we don't
// have accidental runtime surprises later on.
// jsonEncodingRoundTripper ensures that asserted
// interfaces implement both MarshalJSON and UnmarshalJSON
type jsonRoundTripper interface {
json.Marshaler
json.Unmarshaler
}
var _ jsonRoundTripper = (*ResponseCommit)(nil)
var _ jsonRoundTripper = (*ResponseQuery)(nil)
var _ jsonRoundTripper = (*ResponseDeliverTx)(nil)
var _ jsonRoundTripper = (*ResponseCheckTx)(nil)
var _ jsonRoundTripper = (*ResponseSetOption)(nil)

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


+ 99
- 68
types/types.proto View File

@ -1,27 +1,28 @@
syntax = "proto3"; syntax = "proto3";
package types; package types;
// For more information on gogo.proto, see:
// https://github.com/gogo/protobuf/blob/master/extensions.md
import "github.com/gogo/protobuf/gogoproto/gogo.proto"; import "github.com/gogo/protobuf/gogoproto/gogo.proto";
// This file is copied from http://github.com/tendermint/abci // This file is copied from http://github.com/tendermint/abci
//---------------------------------------- //----------------------------------------
// Request types // Request types
message Request { 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; RequestEndBlock end_block = 11;
RequestCommit commit = 12;
} }
} }
@ -36,17 +37,13 @@ message RequestInfo {
string version = 1; string version = 1;
} }
message RequestSetOption{
message RequestSetOption {
string key = 1; string key = 1;
string value = 2; string value = 2;
} }
message RequestDeliverTx{
bytes tx = 1;
}
message RequestCheckTx{
bytes tx = 1;
message RequestInitChain {
repeated Validator validators = 1;
} }
message RequestQuery{ message RequestQuery{
@ -56,46 +53,49 @@ message RequestQuery{
bool prove = 4; bool prove = 4;
} }
message RequestCommit{
}
message RequestInitChain{
repeated Validator validators = 1;
}
message RequestBeginBlock{
message RequestBeginBlock {
bytes hash = 1; bytes hash = 1;
Header header = 2; Header header = 2;
repeated int32 absent_validators = 3; repeated int32 absent_validators = 3;
repeated Evidence byzantine_validators = 4; repeated Evidence byzantine_validators = 4;
} }
message RequestCheckTx {
bytes tx = 1;
}
message RequestDeliverTx {
bytes tx = 1;
}
message RequestEndBlock{ message RequestEndBlock{
int64 height = 1; int64 height = 1;
} }
message RequestCommit {
}
//---------------------------------------- //----------------------------------------
// Response types // Response types
message Response { message Response {
oneof value{
oneof value {
ResponseException exception = 1; ResponseException exception = 1;
ResponseEcho echo = 2; ResponseEcho echo = 2;
ResponseFlush flush = 3; ResponseFlush flush = 3;
ResponseInfo info = 4; ResponseInfo info = 4;
ResponseSetOption set_option = 5; 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; string error = 1;
} }
@ -103,7 +103,7 @@ message ResponseEcho {
string message = 1; string message = 1;
} }
message ResponseFlush{
message ResponseFlush {
} }
message ResponseInfo { message ResponseInfo {
@ -113,62 +113,93 @@ message ResponseInfo {
bytes last_block_app_hash = 4; bytes last_block_app_hash = 4;
} }
message ResponseSetOption{
message ResponseSetOption {
uint32 code = 1; uint32 code = 1;
string log = 2; 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;
} }
//---------------------------------------- //----------------------------------------
// Blockchain Types // Blockchain Types
message Header { message Header {
string chain_id = 1;
string chain_id = 1 [(gogoproto.customname) = "ChainID"];
int64 height = 2; int64 height = 2;
int64 time = 3; int64 time = 3;
int32 num_txs = 4; int32 num_txs = 4;
BlockID last_block_id = 5;
BlockID last_block_id = 5 [(gogoproto.customname) = "LastBlockID"];
bytes last_commit_hash = 6; bytes last_commit_hash = 6;
bytes data_hash = 7; bytes data_hash = 7;
bytes validators_hash = 8; bytes validators_hash = 8;


+ 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)
}

+ 2
- 2
version/version.go View File

@ -3,7 +3,7 @@ package version
// NOTE: we should probably be versioning the ABCI and the abci-cli separately // NOTE: we should probably be versioning the ABCI and the abci-cli separately
const Maj = "0" const Maj = "0"
const Min = "8"
const Min = "9"
const Fix = "0" const Fix = "0"
const Version = "0.8.0"
const Version = "0.9.0"

Loading…
Cancel
Save