Browse Source

everything takes Request, returns Response; expect DeliverTx/CheckTx/Commit

pull/1780/head
Ethan Buchman 7 years ago
parent
commit
c7f54fb56c
15 changed files with 174 additions and 291 deletions
  1. +13
    -14
      client/client.go
  2. +15
    -18
      client/grpc_client.go
  3. +36
    -36
      client/local_client.go
  4. +19
    -22
      client/socket_client.go
  5. +3
    -2
      cmd/abci-cli/abci-cli.go
  6. +0
    -65
      example/block_aware/block_aware_app.go
  7. +0
    -57
      example/block_aware/block_aware_test.go
  8. +3
    -2
      example/counter/counter.go
  9. +2
    -0
      example/dummy/dummy.go
  10. +2
    -2
      example/dummy/dummy_test.go
  11. +15
    -11
      example/dummy/persistent_dummy.go
  12. +15
    -16
      server/socket_server.go
  13. +18
    -15
      types/application.go
  14. +7
    -5
      types/base_app.go
  15. +26
    -26
      types/messages.go

+ 13
- 14
client/client.go View File

@ -8,10 +8,11 @@ import (
cmn "github.com/tendermint/tmlibs/common"
)
// Client defines an interface for an ABCI client. Client-related errors (e.g.
// network errors) are returned as a second return value for most calls
// (sometimes there is no response). Application-related errors are reflected
// in response via ABCI error codes and logs.
// Client defines an interface for an ABCI client.
// All `Async` methods return a `ReqRes` object.
// All `Sync` methods return the appropriate protobuf ResponseXxx struct and an error.
// Note these are client errors, eg. ABCI socket connectivity issues.
// Application-related errors are reflected in response via ABCI error codes and logs.
type Client interface {
cmn.Service
@ -21,28 +22,26 @@ type Client interface {
FlushAsync() *ReqRes
EchoAsync(msg string) *ReqRes
InfoAsync(types.RequestInfo) *ReqRes
SetOptionAsync(key string, value string) *ReqRes
SetOptionAsync(types.RequestSetOption) *ReqRes
DeliverTxAsync(tx []byte) *ReqRes
CheckTxAsync(tx []byte) *ReqRes
QueryAsync(types.RequestQuery) *ReqRes
CommitAsync() *ReqRes
InitChainAsync(types.RequestInitChain) *ReqRes
BeginBlockAsync(types.RequestBeginBlock) *ReqRes
EndBlockAsync(types.RequestEndBlock) *ReqRes
FlushSync() error
EchoSync(msg string) (*types.ResponseEcho, error)
InfoSync(types.RequestInfo) (*types.ResponseInfo, error)
SetOptionSync(key string, value string) (log string, err error)
SetOptionSync(types.RequestSetOption) (*types.ResponseSetOption, error)
DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error)
CheckTxSync(tx []byte) (*types.ResponseCheckTx, error)
QuerySync(types.RequestQuery) (*types.ResponseQuery, error)
CommitSync() (*types.ResponseCommit, error)
InitChainAsync(types.RequestInitChain) *ReqRes
BeginBlockAsync(types.RequestBeginBlock) *ReqRes
EndBlockAsync(height uint64) *ReqRes
InitChainSync(types.RequestInitChain) error
BeginBlockSync(types.RequestBeginBlock) error
EndBlockSync(height uint64) (*types.ResponseEndBlock, error)
InitChainSync(types.RequestInitChain) (*types.ResponseInitChain, error)
BeginBlockSync(types.RequestBeginBlock) (*types.ResponseBeginBlock, error)
EndBlockSync(types.RequestEndBlock) (*types.ResponseEndBlock, error)
}
//----------------------------------------


+ 15
- 18
client/grpc_client.go View File

@ -150,8 +150,8 @@ func (cli *grpcClient) InfoAsync(params types.RequestInfo) *ReqRes {
return cli.finishAsyncCall(req, &types.Response{&types.Response_Info{res}})
}
func (cli *grpcClient) SetOptionAsync(key string, value string) *ReqRes {
req := types.ToRequestSetOption(key, value)
func (cli *grpcClient) SetOptionAsync(params types.RequestSetOption) *ReqRes {
req := types.ToRequestSetOption(params)
res, err := cli.client.SetOption(context.Background(), req.GetSetOption(), grpc.FailFast(true))
if err != nil {
cli.StopForError(err)
@ -213,8 +213,8 @@ func (cli *grpcClient) BeginBlockAsync(params types.RequestBeginBlock) *ReqRes {
return cli.finishAsyncCall(req, &types.Response{&types.Response_BeginBlock{res}})
}
func (cli *grpcClient) EndBlockAsync(height uint64) *ReqRes {
req := types.ToRequestEndBlock(height)
func (cli *grpcClient) EndBlockAsync(params types.RequestEndBlock) *ReqRes {
req := types.ToRequestEndBlock(params)
res, err := cli.client.EndBlock(context.Background(), req.GetEndBlock(), grpc.FailFast(true))
if err != nil {
cli.StopForError(err)
@ -260,12 +260,9 @@ func (cli *grpcClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, err
return reqres.Response.GetInfo(), cli.Error()
}
func (cli *grpcClient) SetOptionSync(key string, value string) (log string, err error) {
reqres := cli.SetOptionAsync(key, value)
if err := cli.Error(); err != nil {
return "", err
}
return reqres.Response.GetSetOption().Log, nil
func (cli *grpcClient) SetOptionSync(req types.RequestSetOption) (*types.ResponseSetOption, error) {
reqres := cli.SetOptionAsync(req)
return reqres.Response.GetSetOption(), cli.Error()
}
func (cli *grpcClient) DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error) {
@ -288,17 +285,17 @@ func (cli *grpcClient) CommitSync() (*types.ResponseCommit, error) {
return reqres.Response.GetCommit(), cli.Error()
}
func (cli *grpcClient) InitChainSync(params types.RequestInitChain) error {
cli.InitChainAsync(params)
return cli.Error()
func (cli *grpcClient) InitChainSync(params types.RequestInitChain) (*types.ResponseInitChain, error) {
reqres := cli.InitChainAsync(params)
return reqres.Response.GetInitChain(), cli.Error()
}
func (cli *grpcClient) BeginBlockSync(params types.RequestBeginBlock) error {
cli.BeginBlockAsync(params)
return cli.Error()
func (cli *grpcClient) BeginBlockSync(params types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
reqres := cli.BeginBlockAsync(params)
return reqres.Response.GetBeginBlock(), cli.Error()
}
func (cli *grpcClient) EndBlockSync(height uint64) (*types.ResponseEndBlock, error) {
reqres := cli.EndBlockAsync(height)
func (cli *grpcClient) EndBlockSync(params types.RequestEndBlock) (*types.ResponseEndBlock, error) {
reqres := cli.EndBlockAsync(params)
return reqres.Response.GetEndBlock(), cli.Error()
}

+ 36
- 36
client/local_client.go View File

@ -53,21 +53,21 @@ func (app *localClient) EchoAsync(msg string) *ReqRes {
func (app *localClient) InfoAsync(req types.RequestInfo) *ReqRes {
app.mtx.Lock()
resInfo := app.Application.Info(req)
res := app.Application.Info(req)
app.mtx.Unlock()
return app.callback(
types.ToRequestInfo(req),
types.ToResponseInfo(resInfo),
types.ToResponseInfo(res),
)
}
func (app *localClient) SetOptionAsync(key string, value string) *ReqRes {
func (app *localClient) SetOptionAsync(req types.RequestSetOption) *ReqRes {
app.mtx.Lock()
log := app.Application.SetOption(key, value)
res := app.Application.SetOption(req)
app.mtx.Unlock()
return app.callback(
types.ToRequestSetOption(key, value),
types.ToResponseSetOption(log),
types.ToRequestSetOption(req),
types.ToResponseSetOption(res),
)
}
@ -77,7 +77,7 @@ func (app *localClient) DeliverTxAsync(tx []byte) *ReqRes {
app.mtx.Unlock()
return app.callback(
types.ToRequestDeliverTx(tx),
types.ToResponseDeliverTx(res.Code, res.Data, res.Log, res.Tags),
types.ToResponseDeliverTx(res),
)
}
@ -87,17 +87,17 @@ func (app *localClient) CheckTxAsync(tx []byte) *ReqRes {
app.mtx.Unlock()
return app.callback(
types.ToRequestCheckTx(tx),
types.ToResponseCheckTx(res.Code, res.Data, res.Log),
types.ToResponseCheckTx(res),
)
}
func (app *localClient) QueryAsync(reqQuery types.RequestQuery) *ReqRes {
func (app *localClient) QueryAsync(req types.RequestQuery) *ReqRes {
app.mtx.Lock()
resQuery := app.Application.Query(reqQuery)
res := app.Application.Query(req)
app.mtx.Unlock()
return app.callback(
types.ToRequestQuery(reqQuery),
types.ToResponseQuery(resQuery),
types.ToRequestQuery(req),
types.ToResponseQuery(res),
)
}
@ -107,38 +107,38 @@ func (app *localClient) CommitAsync() *ReqRes {
app.mtx.Unlock()
return app.callback(
types.ToRequestCommit(),
types.ToResponseCommit(res.Code, res.Data, res.Log),
types.ToResponseCommit(res),
)
}
func (app *localClient) InitChainAsync(params types.RequestInitChain) *ReqRes {
func (app *localClient) InitChainAsync(req types.RequestInitChain) *ReqRes {
app.mtx.Lock()
app.Application.InitChain(params)
res := app.Application.InitChain(req)
reqRes := app.callback(
types.ToRequestInitChain(params),
types.ToResponseInitChain(),
types.ToRequestInitChain(req),
types.ToResponseInitChain(res),
)
app.mtx.Unlock()
return reqRes
}
func (app *localClient) BeginBlockAsync(params types.RequestBeginBlock) *ReqRes {
func (app *localClient) BeginBlockAsync(req types.RequestBeginBlock) *ReqRes {
app.mtx.Lock()
app.Application.BeginBlock(params)
res := app.Application.BeginBlock(req)
app.mtx.Unlock()
return app.callback(
types.ToRequestBeginBlock(params),
types.ToResponseBeginBlock(),
types.ToRequestBeginBlock(req),
types.ToResponseBeginBlock(res),
)
}
func (app *localClient) EndBlockAsync(height uint64) *ReqRes {
func (app *localClient) EndBlockAsync(req types.RequestEndBlock) *ReqRes {
app.mtx.Lock()
resEndBlock := app.Application.EndBlock(height)
res := app.Application.EndBlock(req)
app.mtx.Unlock()
return app.callback(
types.ToRequestEndBlock(height),
types.ToResponseEndBlock(resEndBlock),
types.ToRequestEndBlock(req),
types.ToResponseEndBlock(res),
)
}
@ -159,11 +159,11 @@ func (app *localClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, er
return &res, nil
}
func (app *localClient) SetOptionSync(key string, value string) (log string, err error) {
func (app *localClient) SetOptionSync(req types.RequestSetOption) (*types.ResponseSetOption, error) {
app.mtx.Lock()
log = app.Application.SetOption(key, value)
res := app.Application.SetOption(req)
app.mtx.Unlock()
return log, nil
return &res, nil
}
func (app *localClient) DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error) {
@ -194,23 +194,23 @@ func (app *localClient) CommitSync() (*types.ResponseCommit, error) {
return &res, nil
}
func (app *localClient) InitChainSync(params types.RequestInitChain) error {
func (app *localClient) InitChainSync(req types.RequestInitChain) (*types.ResponseInitChain, error) {
app.mtx.Lock()
app.Application.InitChain(params)
res := app.Application.InitChain(req)
app.mtx.Unlock()
return nil
return &res, nil
}
func (app *localClient) BeginBlockSync(params types.RequestBeginBlock) error {
func (app *localClient) BeginBlockSync(req types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
app.mtx.Lock()
app.Application.BeginBlock(params)
res := app.Application.BeginBlock(req)
app.mtx.Unlock()
return nil
return &res, nil
}
func (app *localClient) EndBlockSync(height uint64) (*types.ResponseEndBlock, error) {
func (app *localClient) EndBlockSync(req types.RequestEndBlock) (*types.ResponseEndBlock, error) {
app.mtx.Lock()
res := app.Application.EndBlock(height)
res := app.Application.EndBlock(req)
app.mtx.Unlock()
return &res, nil
}


+ 19
- 22
client/socket_client.go View File

@ -239,8 +239,8 @@ func (cli *socketClient) InfoAsync(req types.RequestInfo) *ReqRes {
return cli.queueRequest(types.ToRequestInfo(req))
}
func (cli *socketClient) SetOptionAsync(key string, value string) *ReqRes {
return cli.queueRequest(types.ToRequestSetOption(key, value))
func (cli *socketClient) SetOptionAsync(req types.RequestSetOption) *ReqRes {
return cli.queueRequest(types.ToRequestSetOption(req))
}
func (cli *socketClient) DeliverTxAsync(tx []byte) *ReqRes {
@ -259,16 +259,16 @@ func (cli *socketClient) CommitAsync() *ReqRes {
return cli.queueRequest(types.ToRequestCommit())
}
func (cli *socketClient) InitChainAsync(params types.RequestInitChain) *ReqRes {
return cli.queueRequest(types.ToRequestInitChain(params))
func (cli *socketClient) InitChainAsync(req types.RequestInitChain) *ReqRes {
return cli.queueRequest(types.ToRequestInitChain(req))
}
func (cli *socketClient) BeginBlockAsync(params types.RequestBeginBlock) *ReqRes {
return cli.queueRequest(types.ToRequestBeginBlock(params))
func (cli *socketClient) BeginBlockAsync(req types.RequestBeginBlock) *ReqRes {
return cli.queueRequest(types.ToRequestBeginBlock(req))
}
func (cli *socketClient) EndBlockAsync(height uint64) *ReqRes {
return cli.queueRequest(types.ToRequestEndBlock(height))
func (cli *socketClient) EndBlockAsync(req types.RequestEndBlock) *ReqRes {
return cli.queueRequest(types.ToRequestEndBlock(req))
}
//----------------------------------------
@ -294,13 +294,10 @@ func (cli *socketClient) InfoSync(req types.RequestInfo) (*types.ResponseInfo, e
return reqres.Response.GetInfo(), cli.Error()
}
func (cli *socketClient) SetOptionSync(key string, value string) (log string, err error) {
reqres := cli.queueRequest(types.ToRequestSetOption(key, value))
func (cli *socketClient) SetOptionSync(req types.RequestSetOption) (*types.ResponseSetOption, error) {
reqres := cli.queueRequest(types.ToRequestSetOption(req))
cli.FlushSync()
if err := cli.Error(); err != nil {
return "", err
}
return reqres.Response.GetSetOption().Log, nil
return reqres.Response.GetSetOption(), cli.Error()
}
func (cli *socketClient) DeliverTxSync(tx []byte) (*types.ResponseDeliverTx, error) {
@ -327,20 +324,20 @@ func (cli *socketClient) CommitSync() (*types.ResponseCommit, error) {
return reqres.Response.GetCommit(), cli.Error()
}
func (cli *socketClient) InitChainSync(params types.RequestInitChain) error {
cli.queueRequest(types.ToRequestInitChain(params))
func (cli *socketClient) InitChainSync(req types.RequestInitChain) (*types.ResponseInitChain, error) {
reqres := cli.queueRequest(types.ToRequestInitChain(req))
cli.FlushSync()
return cli.Error()
return reqres.Response.GetInitChain(), cli.Error()
}
func (cli *socketClient) BeginBlockSync(params types.RequestBeginBlock) error {
cli.queueRequest(types.ToRequestBeginBlock(params))
func (cli *socketClient) BeginBlockSync(req types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
reqres := cli.queueRequest(types.ToRequestBeginBlock(req))
cli.FlushSync()
return cli.Error()
return reqres.Response.GetBeginBlock(), cli.Error()
}
func (cli *socketClient) EndBlockSync(height uint64) (*types.ResponseEndBlock, error) {
reqres := cli.queueRequest(types.ToRequestEndBlock(height))
func (cli *socketClient) EndBlockSync(req types.RequestEndBlock) (*types.ResponseEndBlock, error) {
reqres := cli.queueRequest(types.ToRequestEndBlock(req))
cli.FlushSync()
return reqres.Response.GetEndBlock(), cli.Error()
}


+ 3
- 2
cmd/abci-cli/abci-cli.go View File

@ -355,12 +355,13 @@ func cmdInfo(cmd *cobra.Command, args []string) error {
// Set an option on the application
func cmdSetOption(cmd *cobra.Command, args []string) error {
resLog, err := client.SetOptionSync(args[0], args[1])
key, val := args[0], args[1]
res, err := client.SetOptionSync(types.RequestSetOption{key, val})
if err != nil {
return err
}
printResponse(cmd, args, response{
Log: resLog,
Log: res.Log,
})
return nil
}


+ 0
- 65
example/block_aware/block_aware_app.go View File

@ -1,65 +0,0 @@
package main
import (
"flag"
"os"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
cmn "github.com/tendermint/tmlibs/common"
"github.com/tendermint/tmlibs/log"
)
func main() {
addrPtr := flag.String("addr", "tcp://0.0.0.0:46658", "Listen address")
abciPtr := flag.String("abci", "socket", "socket | grpc")
flag.Parse()
logger := log.NewTMLogger(log.NewSyncWriter(os.Stdout))
// Start the listener
srv, err := server.NewServer(*addrPtr, *abciPtr, NewChainAwareApplication())
if err != nil {
logger.Error(err.Error())
os.Exit(1)
}
srv.SetLogger(logger.With("module", "abci-server"))
if _, err := srv.Start(); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
// Wait forever
cmn.TrapSignal(func() {
// Cleanup
srv.Stop()
})
}
type ChainAwareApplication struct {
types.BaseApplication
beginCount int
endCount int
}
func NewChainAwareApplication() *ChainAwareApplication {
return &ChainAwareApplication{}
}
func (app *ChainAwareApplication) Query(reqQuery types.RequestQuery) (resQuery types.ResponseQuery) {
return types.ResponseQuery{
Value: []byte(cmn.Fmt("%d,%d", app.beginCount, app.endCount)),
}
}
func (app *ChainAwareApplication) BeginBlock(reqBeginBlock types.RequestBeginBlock) {
app.beginCount++
}
func (app *ChainAwareApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) {
app.endCount++
return
}

+ 0
- 57
example/block_aware/block_aware_test.go View File

@ -1,57 +0,0 @@
package main
import (
"strconv"
"strings"
"testing"
abcicli "github.com/tendermint/abci/client"
"github.com/tendermint/abci/server"
"github.com/tendermint/abci/types"
"github.com/tendermint/tmlibs/log"
)
func TestChainAware(t *testing.T) {
app := NewChainAwareApplication()
// Start the listener
srv, err := server.NewServer("unix://test.sock", "socket", app)
if err != nil {
t.Fatal(err)
}
srv.SetLogger(log.TestingLogger().With("module", "abci-server"))
if _, err := srv.Start(); err != nil {
t.Fatal(err.Error())
}
defer srv.Stop()
// Connect to the socket
client := abcicli.NewSocketClient("unix://test.sock", false)
client.SetLogger(log.TestingLogger().With("module", "abci-client"))
if _, err := client.Start(); err != nil {
t.Fatalf("Error starting socket client: %v", err.Error())
}
defer client.Stop()
n := uint64(5)
hash := []byte("fake block hash")
header := &types.Header{}
for i := uint64(0); i < n; i++ {
client.BeginBlockSync(types.RequestBeginBlock{hash, header})
client.EndBlockSync(i)
client.CommitSync()
}
r := app.Query(types.RequestQuery{})
spl := strings.Split(string(r.Value), ",")
if len(spl) != 2 {
t.Fatal("expected %d,%d ; got %s", n, n, string(r.Value))
}
beginCount, _ := strconv.Atoi(spl[0])
endCount, _ := strconv.Atoi(spl[1])
if uint64(beginCount) != n {
t.Fatalf("expected beginCount of %d, got %d", n, beginCount)
} else if uint64(endCount) != n {
t.Fatalf("expected endCount of %d, got %d", n, endCount)
}
}

+ 3
- 2
example/counter/counter.go View File

@ -24,11 +24,12 @@ func (app *CounterApplication) Info(req types.RequestInfo) types.ResponseInfo {
return types.ResponseInfo{Data: cmn.Fmt("{\"hashes\":%v,\"txs\":%v}", app.hashCount, app.txCount)}
}
func (app *CounterApplication) SetOption(key string, value string) (log string) {
func (app *CounterApplication) SetOption(req types.RequestSetOption) types.ResponseSetOption {
key, value := req.Key, req.Value
if key == "serial" && value == "on" {
app.serial = true
}
return ""
return types.ResponseSetOption{}
}
func (app *CounterApplication) DeliverTx(tx []byte) types.ResponseDeliverTx {


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

@ -10,6 +10,8 @@ import (
dbm "github.com/tendermint/tmlibs/db"
)
var _ types.Application = (*DummyApplication)(nil)
type DummyApplication struct {
types.BaseApplication


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

@ -93,7 +93,7 @@ func TestPersistentDummyInfo(t *testing.T) {
Height: uint64(height),
}
dummy.BeginBlock(types.RequestBeginBlock{hash, header})
dummy.EndBlock(height)
dummy.EndBlock(types.RequestEndBlock{header.Height})
dummy.Commit()
resInfo = dummy.Info(types.RequestInfo{})
@ -182,7 +182,7 @@ func makeApplyBlock(t *testing.T, dummy types.Application, heightInt int, diff [
t.Fatal(r)
}
}
resEndBlock := dummy.EndBlock(height)
resEndBlock := dummy.EndBlock(types.RequestEndBlock{header.Height})
dummy.Commit()
valsEqual(t, diff, resEndBlock.Diffs)


+ 15
- 11
example/dummy/persistent_dummy.go View File

@ -21,6 +21,8 @@ const (
//-----------------------------------------
var _ types.Application = (*PersistentDummyApplication)(nil)
type PersistentDummyApplication struct {
app *DummyApplication
@ -50,15 +52,15 @@ func (app *PersistentDummyApplication) SetLogger(l log.Logger) {
app.logger = l
}
func (app *PersistentDummyApplication) Info(req types.RequestInfo) (resInfo types.ResponseInfo) {
resInfo = app.app.Info(req)
resInfo.LastBlockHeight = app.app.state.LatestVersion()
resInfo.LastBlockAppHash = app.app.state.Hash()
return resInfo
func (app *PersistentDummyApplication) Info(req types.RequestInfo) types.ResponseInfo {
res := app.app.Info(req)
res.LastBlockHeight = app.app.state.LatestVersion()
res.LastBlockAppHash = app.app.state.Hash()
return res
}
func (app *PersistentDummyApplication) SetOption(key string, value string) (log string) {
return app.app.SetOption(key, value)
func (app *PersistentDummyApplication) SetOption(req types.RequestSetOption) types.ResponseSetOption {
return app.app.SetOption(req)
}
// tx is either "val:pubkey/power" or "key=value" or just arbitrary bytes
@ -102,23 +104,25 @@ func (app *PersistentDummyApplication) Query(reqQuery types.RequestQuery) types.
}
// Save the validators in the merkle tree
func (app *PersistentDummyApplication) InitChain(params types.RequestInitChain) {
for _, v := range params.Validators {
func (app *PersistentDummyApplication) InitChain(req types.RequestInitChain) types.ResponseInitChain {
for _, v := range req.Validators {
r := app.updateValidator(v)
if r.IsErr() {
app.logger.Error("Error updating validators", "r", r)
}
}
return types.ResponseInitChain{}
}
// Track the block hash and header information
func (app *PersistentDummyApplication) BeginBlock(params types.RequestBeginBlock) {
func (app *PersistentDummyApplication) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock {
// reset valset changes
app.changes = make([]*types.Validator, 0)
return types.ResponseBeginBlock{}
}
// Update the validator set
func (app *PersistentDummyApplication) EndBlock(height uint64) (resEndBlock types.ResponseEndBlock) {
func (app *PersistentDummyApplication) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock {
return types.ResponseEndBlock{Diffs: app.changes}
}


+ 15
- 16
server/socket_server.go View File

@ -168,33 +168,32 @@ func (s *SocketServer) handleRequest(req *types.Request, responses chan<- *types
case *types.Request_Flush:
responses <- types.ToResponseFlush()
case *types.Request_Info:
resInfo := s.app.Info(*r.Info)
responses <- types.ToResponseInfo(resInfo)
res := s.app.Info(*r.Info)
responses <- types.ToResponseInfo(res)
case *types.Request_SetOption:
so := r.SetOption
logStr := s.app.SetOption(so.Key, so.Value)
responses <- types.ToResponseSetOption(logStr)
res := s.app.SetOption(*r.SetOption)
responses <- types.ToResponseSetOption(res)
case *types.Request_DeliverTx:
res := s.app.DeliverTx(r.DeliverTx.Tx)
responses <- types.ToResponseDeliverTx(res.Code, res.Data, res.Log, res.Tags)
responses <- types.ToResponseDeliverTx(res)
case *types.Request_CheckTx:
res := s.app.CheckTx(r.CheckTx.Tx)
responses <- types.ToResponseCheckTx(res.Code, res.Data, res.Log)
responses <- types.ToResponseCheckTx(res)
case *types.Request_Commit:
res := s.app.Commit()
responses <- types.ToResponseCommit(res.Code, res.Data, res.Log)
responses <- types.ToResponseCommit(res)
case *types.Request_Query:
resQuery := s.app.Query(*r.Query)
responses <- types.ToResponseQuery(resQuery)
res := s.app.Query(*r.Query)
responses <- types.ToResponseQuery(res)
case *types.Request_InitChain:
s.app.InitChain(*r.InitChain)
responses <- types.ToResponseInitChain()
res := s.app.InitChain(*r.InitChain)
responses <- types.ToResponseInitChain(res)
case *types.Request_BeginBlock:
s.app.BeginBlock(*r.BeginBlock)
responses <- types.ToResponseBeginBlock()
res := s.app.BeginBlock(*r.BeginBlock)
responses <- types.ToResponseBeginBlock(res)
case *types.Request_EndBlock:
resEndBlock := s.app.EndBlock(r.EndBlock.Height)
responses <- types.ToResponseEndBlock(resEndBlock)
res := s.app.EndBlock(*r.EndBlock)
responses <- types.ToResponseEndBlock(res)
default:
responses <- types.ToResponseException("Unknown request")
}


+ 18
- 15
types/application.go View File

@ -5,22 +5,24 @@ import (
)
// Application is an interface that enables any finite, deterministic state machine
// to be driven by a blockchain-based replication engine via the ABCI
// to be driven by a blockchain-based replication engine via the ABCI.
// All methods take a RequestXxx argument and return a ResponseXxx argument,
// except CheckTx/DeliverTx, which take `tx []byte`, and `Commit`, which takes nothing.
type Application interface {
// Info/Query Connection
Info(RequestInfo) ResponseInfo // Return application info
SetOption(key string, value string) (log string) // Set application option
Query(RequestQuery) ResponseQuery // Query for state
Info(RequestInfo) ResponseInfo // Return application info
SetOption(RequestSetOption) ResponseSetOption // Set application option
Query(RequestQuery) ResponseQuery // Query for state
// Mempool Connection
CheckTx(tx []byte) ResponseCheckTx // Validate a tx for the mempool
// Consensus Connection
InitChain(RequestInitChain) // Initialize blockchain with validators and other info from TendermintCore
BeginBlock(RequestBeginBlock) // Signals the beginning of a block
DeliverTx(tx []byte) ResponseDeliverTx // Deliver a tx for full processing
EndBlock(height uint64) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
Commit() ResponseCommit // Commit the state and return the application Merkle root hash
InitChain(RequestInitChain) ResponseInitChain // Initialize blockchain with validators and other info from TendermintCore
BeginBlock(RequestBeginBlock) ResponseBeginBlock // Signals the beginning of a block
DeliverTx(tx []byte) ResponseDeliverTx // Deliver a tx for full processing
EndBlock(RequestEndBlock) ResponseEndBlock // Signals the end of a block, returns changes to the validator set
Commit() ResponseCommit // Commit the state and return the application Merkle root hash
}
//------------------------------------
@ -48,7 +50,8 @@ func (app *GRPCApplication) Info(ctx context.Context, req *RequestInfo) (*Respon
}
func (app *GRPCApplication) SetOption(ctx context.Context, req *RequestSetOption) (*ResponseSetOption, error) {
return &ResponseSetOption{app.app.SetOption(req.Key, req.Value)}, nil
resSetOption := app.app.SetOption(*req)
return &resSetOption, nil
}
func (app *GRPCApplication) DeliverTx(ctx context.Context, req *RequestDeliverTx) (*ResponseDeliverTx, error) {
@ -72,16 +75,16 @@ func (app *GRPCApplication) Commit(ctx context.Context, req *RequestCommit) (*Re
}
func (app *GRPCApplication) InitChain(ctx context.Context, req *RequestInitChain) (*ResponseInitChain, error) {
app.app.InitChain(*req)
return &ResponseInitChain{}, nil // NOTE: empty return
resInitChain := app.app.InitChain(*req)
return &resInitChain, nil
}
func (app *GRPCApplication) BeginBlock(ctx context.Context, req *RequestBeginBlock) (*ResponseBeginBlock, error) {
app.app.BeginBlock(*req)
return &ResponseBeginBlock{}, nil // NOTE: empty return
resBeginBlock := app.app.BeginBlock(*req)
return &resBeginBlock, nil
}
func (app *GRPCApplication) EndBlock(ctx context.Context, req *RequestEndBlock) (*ResponseEndBlock, error) {
resEndBlock := app.app.EndBlock(req.Height)
resEndBlock := app.app.EndBlock(*req)
return &resEndBlock, nil
}

+ 7
- 5
types/base_app.go View File

@ -11,8 +11,8 @@ func (BaseApplication) Info(req RequestInfo) ResponseInfo {
return ResponseInfo{}
}
func (BaseApplication) SetOption(key string, value string) (log string) {
return ""
func (BaseApplication) SetOption(req RequestSetOption) ResponseSetOption {
return ResponseSetOption{}
}
func (BaseApplication) DeliverTx(tx []byte) ResponseDeliverTx {
@ -31,12 +31,14 @@ func (BaseApplication) Query(req RequestQuery) ResponseQuery {
return ResponseQuery{Code: CodeType_OK}
}
func (BaseApplication) InitChain(req RequestInitChain) {
func (BaseApplication) InitChain(req RequestInitChain) ResponseInitChain {
return ResponseInitChain{}
}
func (BaseApplication) BeginBlock(req RequestBeginBlock) {
func (BaseApplication) BeginBlock(req RequestBeginBlock) ResponseBeginBlock {
return ResponseBeginBlock{}
}
func (BaseApplication) EndBlock(height uint64) ResponseEndBlock {
func (BaseApplication) EndBlock(req RequestEndBlock) ResponseEndBlock {
return ResponseEndBlock{}
}

+ 26
- 26
types/messages.go View File

@ -25,21 +25,21 @@ func ToRequestInfo(req RequestInfo) *Request {
}
}
func ToRequestSetOption(key string, value string) *Request {
func ToRequestSetOption(req RequestSetOption) *Request {
return &Request{
Value: &Request_SetOption{&RequestSetOption{key, value}},
Value: &Request_SetOption{&req},
}
}
func ToRequestDeliverTx(txBytes []byte) *Request {
func ToRequestDeliverTx(tx []byte) *Request {
return &Request{
Value: &Request_DeliverTx{&RequestDeliverTx{txBytes}},
Value: &Request_DeliverTx{&RequestDeliverTx{tx}},
}
}
func ToRequestCheckTx(txBytes []byte) *Request {
func ToRequestCheckTx(tx []byte) *Request {
return &Request{
Value: &Request_CheckTx{&RequestCheckTx{txBytes}},
Value: &Request_CheckTx{&RequestCheckTx{tx}},
}
}
@ -67,9 +67,9 @@ func ToRequestBeginBlock(req RequestBeginBlock) *Request {
}
}
func ToRequestEndBlock(height uint64) *Request {
func ToRequestEndBlock(req RequestEndBlock) *Request {
return &Request{
Value: &Request_EndBlock{&RequestEndBlock{height}},
Value: &Request_EndBlock{&req},
}
}
@ -93,57 +93,57 @@ func ToResponseFlush() *Response {
}
}
func ToResponseInfo(resInfo ResponseInfo) *Response {
func ToResponseInfo(res ResponseInfo) *Response {
return &Response{
Value: &Response_Info{&resInfo},
Value: &Response_Info{&res},
}
}
func ToResponseSetOption(log string) *Response {
func ToResponseSetOption(res ResponseSetOption) *Response {
return &Response{
Value: &Response_SetOption{&ResponseSetOption{log}},
Value: &Response_SetOption{&res},
}
}
func ToResponseDeliverTx(code CodeType, data []byte, log string, tags []*KVPair) *Response {
func ToResponseDeliverTx(res ResponseDeliverTx) *Response {
return &Response{
Value: &Response_DeliverTx{&ResponseDeliverTx{code, data, log, tags}},
Value: &Response_DeliverTx{&res},
}
}
func ToResponseCheckTx(code CodeType, data []byte, log string) *Response {
func ToResponseCheckTx(res ResponseCheckTx) *Response {
return &Response{
Value: &Response_CheckTx{&ResponseCheckTx{code, data, log}},
Value: &Response_CheckTx{&res},
}
}
func ToResponseCommit(code CodeType, data []byte, log string) *Response {
func ToResponseCommit(res ResponseCommit) *Response {
return &Response{
Value: &Response_Commit{&ResponseCommit{code, data, log}},
Value: &Response_Commit{&res},
}
}
func ToResponseQuery(resQuery ResponseQuery) *Response {
func ToResponseQuery(res ResponseQuery) *Response {
return &Response{
Value: &Response_Query{&resQuery},
Value: &Response_Query{&res},
}
}
func ToResponseInitChain() *Response {
func ToResponseInitChain(res ResponseInitChain) *Response {
return &Response{
Value: &Response_InitChain{&ResponseInitChain{}},
Value: &Response_InitChain{&res},
}
}
func ToResponseBeginBlock() *Response {
func ToResponseBeginBlock(res ResponseBeginBlock) *Response {
return &Response{
Value: &Response_BeginBlock{&ResponseBeginBlock{}},
Value: &Response_BeginBlock{&res},
}
}
func ToResponseEndBlock(resEndBlock ResponseEndBlock) *Response {
func ToResponseEndBlock(res ResponseEndBlock) *Response {
return &Response{
Value: &Response_EndBlock{&resEndBlock},
Value: &Response_EndBlock{&res},
}
}


Loading…
Cancel
Save