Skip to content

Commit

Permalink
Custom abci interface to extended Tendermint abci interface (Finschia…
Browse files Browse the repository at this point in the history
…#689)

* Remove entropy

* Use tm ResponseCheckTx
  • Loading branch information
ulbqb authored Aug 10, 2023
1 parent 362db7d commit 5836604
Show file tree
Hide file tree
Showing 54 changed files with 307 additions and 2,399 deletions.
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ proto-gen: check-proto-deps
@echo "Generating Protobuf files"
@go run github.com/bufbuild/buf/cmd/buf generate
@mv ./proto/ostracon/abci/types.pb.go ./abci/types/
@mv ./proto/ostracon/rpc/grpc/types.pb.go ./rpc/grpc/
@rm -rf ./proto/tendermint
.PHONY: proto-gen

Expand Down
6 changes: 3 additions & 3 deletions abci/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Client interface {
QueryAsync(types.RequestQuery, ResponseCallback) *ReqRes
CommitAsync(ResponseCallback) *ReqRes
InitChainAsync(types.RequestInitChain, ResponseCallback) *ReqRes
BeginBlockAsync(ocabci.RequestBeginBlock, ResponseCallback) *ReqRes
BeginBlockAsync(types.RequestBeginBlock, ResponseCallback) *ReqRes
EndBlockAsync(types.RequestEndBlock, ResponseCallback) *ReqRes
BeginRecheckTxAsync(ocabci.RequestBeginRecheckTx, ResponseCallback) *ReqRes
EndRecheckTxAsync(ocabci.RequestEndRecheckTx, ResponseCallback) *ReqRes
Expand All @@ -54,11 +54,11 @@ type Client interface {
InfoSync(types.RequestInfo) (*types.ResponseInfo, error)
SetOptionSync(types.RequestSetOption) (*types.ResponseSetOption, error)
DeliverTxSync(types.RequestDeliverTx) (*types.ResponseDeliverTx, error)
CheckTxSync(types.RequestCheckTx) (*ocabci.ResponseCheckTx, error)
CheckTxSync(types.RequestCheckTx) (*types.ResponseCheckTx, error)
QuerySync(types.RequestQuery) (*types.ResponseQuery, error)
CommitSync() (*types.ResponseCommit, error)
InitChainSync(types.RequestInitChain) (*types.ResponseInitChain, error)
BeginBlockSync(ocabci.RequestBeginBlock) (*types.ResponseBeginBlock, error)
BeginBlockSync(types.RequestBeginBlock) (*types.ResponseBeginBlock, error)
EndBlockSync(types.RequestEndBlock) (*types.ResponseEndBlock, error)
BeginRecheckTxSync(ocabci.RequestBeginRecheckTx) (*ocabci.ResponseBeginRecheckTx, error)
EndRecheckTxSync(ocabci.RequestEndRecheckTx) (*ocabci.ResponseEndRecheckTx, error)
Expand Down
6 changes: 3 additions & 3 deletions abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (cli *grpcClient) InitChainAsync(params types.RequestInitChain, cb Response
return cli.finishAsyncCall(req, &ocabci.Response{Value: &ocabci.Response_InitChain{InitChain: res}}, cb)
}

func (cli *grpcClient) BeginBlockAsync(params ocabci.RequestBeginBlock, cb ResponseCallback) *ReqRes {
func (cli *grpcClient) BeginBlockAsync(params types.RequestBeginBlock, cb ResponseCallback) *ReqRes {
req := ocabci.ToRequestBeginBlock(params)
res, err := cli.client.BeginBlock(context.Background(), req.GetBeginBlock(), grpc.WaitForReady(true))
if err != nil {
Expand Down Expand Up @@ -342,7 +342,7 @@ func (cli *grpcClient) DeliverTxSync(params types.RequestDeliverTx) (*types.Resp
return reqres.Response.GetDeliverTx(), cli.Error()
}

func (cli *grpcClient) CheckTxSync(params types.RequestCheckTx) (*ocabci.ResponseCheckTx, error) {
func (cli *grpcClient) CheckTxSync(params types.RequestCheckTx) (*types.ResponseCheckTx, error) {
reqres := cli.CheckTxAsync(params, nil)
reqres.Wait()
return reqres.Response.GetCheckTx(), cli.Error()
Expand All @@ -366,7 +366,7 @@ func (cli *grpcClient) InitChainSync(params types.RequestInitChain) (*types.Resp
return reqres.Response.GetInitChain(), cli.Error()
}

func (cli *grpcClient) BeginBlockSync(params ocabci.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
func (cli *grpcClient) BeginBlockSync(params types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
reqres := cli.BeginBlockAsync(params, nil)
reqres.Wait()
return reqres.Response.GetBeginBlock(), cli.Error()
Expand Down
4 changes: 2 additions & 2 deletions abci/client/grpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestGrpcClientCalls(t *testing.T) {
c.QueryAsync(types.RequestQuery{}, getResponseCallback(t))
c.CommitAsync(getResponseCallback(t))
c.InitChainAsync(types.RequestInitChain{}, getResponseCallback(t))
c.BeginBlockAsync(ocabci.RequestBeginBlock{}, getResponseCallback(t))
c.BeginBlockAsync(types.RequestBeginBlock{}, getResponseCallback(t))
c.EndBlockAsync(types.RequestEndBlock{}, getResponseCallback(t))
c.BeginRecheckTxAsync(ocabci.RequestBeginRecheckTx{}, getResponseCallback(t))
c.EndRecheckTxAsync(ocabci.RequestEndRecheckTx{}, getResponseCallback(t))
Expand Down Expand Up @@ -74,7 +74,7 @@ func TestGrpcClientCalls(t *testing.T) {
_, err = c.InitChainSync(types.RequestInitChain{})
require.NoError(t, err)

_, err = c.BeginBlockSync(ocabci.RequestBeginBlock{})
_, err = c.BeginBlockSync(types.RequestBeginBlock{})
require.NoError(t, err)

_, err = c.EndBlockSync(types.RequestEndBlock{})
Expand Down
8 changes: 4 additions & 4 deletions abci/client/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (app *localClient) CheckTxAsync(req types.RequestCheckTx, cb ResponseCallba

reqRes := NewReqRes(ocabci.ToRequestCheckTx(req), cb)

app.Application.CheckTxAsync(req, func(r ocabci.ResponseCheckTx) {
app.Application.CheckTxAsync(req, func(r types.ResponseCheckTx) {
res := ocabci.ToResponseCheckTx(r)
app.done(reqRes, res)
})
Expand Down Expand Up @@ -146,7 +146,7 @@ func (app *localClient) InitChainAsync(req types.RequestInitChain, cb ResponseCa
return app.done(reqRes, ocabci.ToResponseInitChain(res))
}

func (app *localClient) BeginBlockAsync(req ocabci.RequestBeginBlock, cb ResponseCallback) *ReqRes {
func (app *localClient) BeginBlockAsync(req types.RequestBeginBlock, cb ResponseCallback) *ReqRes {
app.mtx.Lock()
defer app.mtx.Unlock()

Expand Down Expand Up @@ -257,7 +257,7 @@ func (app *localClient) DeliverTxSync(req types.RequestDeliverTx) (*types.Respon
return &res, nil
}

func (app *localClient) CheckTxSync(req types.RequestCheckTx) (*ocabci.ResponseCheckTx, error) {
func (app *localClient) CheckTxSync(req types.RequestCheckTx) (*types.ResponseCheckTx, error) {
// NOTE: commented out for performance. delete all after commenting out all `app.mtx`
// app.mtx.Lock()
// defer app.mtx.Unlock()
Expand Down Expand Up @@ -290,7 +290,7 @@ func (app *localClient) InitChainSync(req types.RequestInitChain) (*types.Respon
return &res, nil
}

func (app *localClient) BeginBlockSync(req ocabci.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
func (app *localClient) BeginBlockSync(req types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

Expand Down
4 changes: 2 additions & 2 deletions abci/client/local_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestLocalClientCalls(t *testing.T) {
c.QueryAsync(types.RequestQuery{}, getResponseCallback(t))
c.CommitAsync(getResponseCallback(t))
c.InitChainAsync(types.RequestInitChain{}, getResponseCallback(t))
c.BeginBlockAsync(ocabci.RequestBeginBlock{}, getResponseCallback(t))
c.BeginBlockAsync(types.RequestBeginBlock{}, getResponseCallback(t))
c.EndBlockAsync(types.RequestEndBlock{}, getResponseCallback(t))
c.BeginRecheckTxAsync(ocabci.RequestBeginRecheckTx{}, getResponseCallback(t))
c.EndRecheckTxAsync(ocabci.RequestEndRecheckTx{}, getResponseCallback(t))
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestLocalClientCalls(t *testing.T) {
_, err = c.InitChainSync(types.RequestInitChain{})
require.NoError(t, err)

_, err = c.BeginBlockSync(ocabci.RequestBeginBlock{})
_, err = c.BeginBlockSync(types.RequestBeginBlock{})
require.NoError(t, err)

_, err = c.EndBlockSync(types.RequestEndBlock{})
Expand Down
22 changes: 11 additions & 11 deletions abci/client/mocks/client.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions abci/client/socket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (cli *socketClient) InitChainAsync(req types.RequestInitChain, cb ResponseC
return cli.queueRequest(ocabci.ToRequestInitChain(req), cb)
}

func (cli *socketClient) BeginBlockAsync(req ocabci.RequestBeginBlock, cb ResponseCallback) *ReqRes {
func (cli *socketClient) BeginBlockAsync(req types.RequestBeginBlock, cb ResponseCallback) *ReqRes {
return cli.queueRequest(ocabci.ToRequestBeginBlock(req), cb)
}

Expand Down Expand Up @@ -341,7 +341,7 @@ func (cli *socketClient) DeliverTxSync(req types.RequestDeliverTx) (*types.Respo
return reqres.Response.GetDeliverTx(), cli.Error()
}

func (cli *socketClient) CheckTxSync(req types.RequestCheckTx) (*ocabci.ResponseCheckTx, error) {
func (cli *socketClient) CheckTxSync(req types.RequestCheckTx) (*types.ResponseCheckTx, error) {
reqres := cli.queueRequest(ocabci.ToRequestCheckTx(req), nil)
if _, err := cli.FlushSync(); err != nil {
return nil, err
Expand Down Expand Up @@ -377,7 +377,7 @@ func (cli *socketClient) InitChainSync(req types.RequestInitChain) (*types.Respo
return reqres.Response.GetInitChain(), cli.Error()
}

func (cli *socketClient) BeginBlockSync(req ocabci.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
func (cli *socketClient) BeginBlockSync(req types.RequestBeginBlock) (*types.ResponseBeginBlock, error) {
reqres := cli.queueRequest(ocabci.ToRequestBeginBlock(req), nil)
if _, err := cli.FlushSync(); err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions abci/client/socket_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestProperSyncCalls(t *testing.T) {
resp := make(chan error, 1)
go func() {
// This is BeginBlockSync unrolled....
reqres := c.BeginBlockAsync(ocabci.RequestBeginBlock{}, nil)
reqres := c.BeginBlockAsync(types.RequestBeginBlock{}, nil)
_, err := c.FlushSync()
require.NoError(t, err)
res := reqres.Response.GetBeginBlock()
Expand Down Expand Up @@ -70,7 +70,7 @@ func TestHangingSyncCalls(t *testing.T) {
resp := make(chan error, 1)
go func() {
// Start BeginBlock and flush it
reqres := c.BeginBlockAsync(ocabci.RequestBeginBlock{}, nil)
reqres := c.BeginBlockAsync(types.RequestBeginBlock{}, nil)
flush := c.FlushAsync(nil)
// wait 20 ms for all events to travel socket, but
// no response yet from server
Expand Down Expand Up @@ -116,7 +116,7 @@ type slowApp struct {
ocabci.BaseApplication
}

func (slowApp) BeginBlock(req ocabci.RequestBeginBlock) types.ResponseBeginBlock {
func (slowApp) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock {
time.Sleep(200 * time.Millisecond)
return types.ResponseBeginBlock{}
}
Expand Down Expand Up @@ -148,7 +148,7 @@ func TestSockerClientCalls(t *testing.T) {
c.QueryAsync(types.RequestQuery{}, getResponseCallback(t))
c.CommitAsync(getResponseCallback(t))
c.InitChainAsync(types.RequestInitChain{}, getResponseCallback(t))
c.BeginBlockAsync(ocabci.RequestBeginBlock{}, getResponseCallback(t))
c.BeginBlockAsync(types.RequestBeginBlock{}, getResponseCallback(t))
c.EndBlockAsync(types.RequestEndBlock{}, getResponseCallback(t))
c.BeginRecheckTxAsync(ocabci.RequestBeginRecheckTx{}, getResponseCallback(t))
c.EndRecheckTxAsync(ocabci.RequestEndRecheckTx{}, getResponseCallback(t))
Expand Down Expand Up @@ -184,7 +184,7 @@ func TestSockerClientCalls(t *testing.T) {
_, err = c.InitChainSync(types.RequestInitChain{})
require.NoError(t, err)

_, err = c.BeginBlockSync(ocabci.RequestBeginBlock{})
_, err = c.BeginBlockSync(types.RequestBeginBlock{})
require.NoError(t, err)

_, err = c.EndBlockSync(types.RequestEndBlock{})
Expand Down
2 changes: 1 addition & 1 deletion abci/cmd/abci-cli/abci-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ func printResponse(cmd *cobra.Command, args []string, rsp response) {
}

// Always print the status code.
if rsp.Code == ocabci.CodeTypeOK {
if rsp.Code == types.CodeTypeOK {
fmt.Printf("-> code: OK\n")
} else {
fmt.Printf("-> code: %d\n", rsp.Code)
Expand Down
10 changes: 5 additions & 5 deletions abci/example/counter/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,31 +64,31 @@ func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeli
return types.ResponseDeliverTx{Code: code.CodeTypeOK}
}

func (app *Application) CheckTxSync(req types.RequestCheckTx) ocabci.ResponseCheckTx {
func (app *Application) CheckTxSync(req types.RequestCheckTx) types.ResponseCheckTx {
return app.checkTx(req)
}

func (app *Application) CheckTxAsync(req types.RequestCheckTx, callback ocabci.CheckTxCallback) {
callback(app.checkTx(req))
}

func (app *Application) checkTx(req types.RequestCheckTx) ocabci.ResponseCheckTx {
func (app *Application) checkTx(req types.RequestCheckTx) types.ResponseCheckTx {
if app.serial {
if len(req.Tx) > 8 {
return ocabci.ResponseCheckTx{
return types.ResponseCheckTx{
Code: code.CodeTypeEncodingError,
Log: fmt.Sprintf("Max tx size is 8 bytes, got %d", len(req.Tx))}
}
tx8 := make([]byte, 8)
copy(tx8[len(tx8)-len(req.Tx):], req.Tx)
txValue := binary.BigEndian.Uint64(tx8)
if txValue < uint64(app.txCount) {
return ocabci.ResponseCheckTx{
return types.ResponseCheckTx{
Code: code.CodeTypeBadNonce,
Log: fmt.Sprintf("Invalid nonce. Expected >= %v, got %v", app.txCount, txValue)}
}
}
return ocabci.ResponseCheckTx{Code: code.CodeTypeOK}
return types.ResponseCheckTx{Code: code.CodeTypeOK}
}

func (app *Application) Commit() (resp types.ResponseCommit) {
Expand Down
6 changes: 3 additions & 3 deletions abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,16 @@ func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeli
return types.ResponseDeliverTx{Code: code.CodeTypeOK, Events: events}
}

func (app *Application) CheckTxSync(req types.RequestCheckTx) ocabci.ResponseCheckTx {
func (app *Application) CheckTxSync(req types.RequestCheckTx) types.ResponseCheckTx {
return app.checkTx(req)
}

func (app *Application) CheckTxAsync(req types.RequestCheckTx, callback ocabci.CheckTxCallback) {
callback(app.checkTx(req))
}

func (app *Application) checkTx(req types.RequestCheckTx) ocabci.ResponseCheckTx {
return ocabci.ResponseCheckTx{Code: code.CodeTypeOK, GasWanted: 1}
func (app *Application) checkTx(req types.RequestCheckTx) types.ResponseCheckTx {
return types.ResponseCheckTx{Code: code.CodeTypeOK, GasWanted: 1}
}

func (app *Application) Commit() types.ResponseCommit {
Expand Down
4 changes: 2 additions & 2 deletions abci/example/kvstore/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func TestPersistentKVStoreInfo(t *testing.T) {
header := tmproto.Header{
Height: height,
}
kvstore.BeginBlock(ocabci.RequestBeginBlock{Hash: hash, Header: header})
kvstore.BeginBlock(types.RequestBeginBlock{Hash: hash, Header: header})
kvstore.EndBlock(types.RequestEndBlock{Height: header.Height})
kvstore.Commit()

Expand Down Expand Up @@ -197,7 +197,7 @@ func makeApplyBlock(
Height: height,
}

kvstore.BeginBlock(ocabci.RequestBeginBlock{Hash: hash, Header: header})
kvstore.BeginBlock(types.RequestBeginBlock{Hash: hash, Header: header})
for _, tx := range txs {
if r := kvstore.DeliverTx(types.RequestDeliverTx{Tx: tx}); r.IsErr() {
t.Fatal(r)
Expand Down
4 changes: 2 additions & 2 deletions abci/example/kvstore/persistent_kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func (app *PersistentKVStoreApplication) DeliverTx(req types.RequestDeliverTx) t
return app.app.DeliverTx(req)
}

func (app *PersistentKVStoreApplication) CheckTxSync(req types.RequestCheckTx) ocabci.ResponseCheckTx {
func (app *PersistentKVStoreApplication) CheckTxSync(req types.RequestCheckTx) types.ResponseCheckTx {
return app.app.CheckTxSync(req)
}

Expand Down Expand Up @@ -133,7 +133,7 @@ func (app *PersistentKVStoreApplication) InitChain(req types.RequestInitChain) t
}

// Track the block hash and header information
func (app *PersistentKVStoreApplication) BeginBlock(req ocabci.RequestBeginBlock) types.ResponseBeginBlock {
func (app *PersistentKVStoreApplication) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginBlock {
// reset valset changes
app.ValUpdates = make([]types.ValidatorUpdate, 0)

Expand Down
3 changes: 2 additions & 1 deletion abci/tests/test_app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import (
"os/exec"
"time"

"github.com/tendermint/tendermint/abci/types"

"github.com/Finschia/ostracon/abci/example/code"
"github.com/Finschia/ostracon/abci/types"
)

var abciType string
Expand Down
Loading

0 comments on commit 5836604

Please sign in to comment.