Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions patches/abci/client/client.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
diff --git a/abci/client/client.go b/abci/client/client.go
index ff1f143cd..72afd9b7a 100644
--- a/abci/client/client.go
+++ b/abci/client/client.go
@@ -14,6 +14,8 @@ const (
echoRetryIntervalSeconds = 1
)

+//go:generate ../../scripts/mockery_generate.sh Client
+
// 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.
@@ -56,6 +58,8 @@ type Client interface {
OfferSnapshotSync(types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error)
LoadSnapshotChunkSync(types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error)
ApplySnapshotChunkSync(types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error)
+ PrepareProposalSync(types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error)
+ ProcessProposalSync(types.RequestProcessProposal) (*types.ResponseProcessProposal, error)
}

//----------------------------------------
@@ -103,7 +107,7 @@ func NewReqRes(req *types.Request) *ReqRes {
}
}

-// Sets sets the callback. If reqRes is already done, it will call the cb
+// Sets the callback. If reqRes is already done, it will call the cb
// immediately. Note, reqRes.cb should not change if reqRes.done and only one
// callback is supported.
func (r *ReqRes) SetCallback(cb func(res *types.Response)) {
91 changes: 91 additions & 0 deletions patches/abci/client/grpc_client.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
diff --git a/abci/client/grpc_client.go b/abci/client/grpc_client.go
index 31a6a7f6a..871c9e95a 100644
--- a/abci/client/grpc_client.go
+++ b/abci/client/grpc_client.go
@@ -6,8 +6,10 @@ import (
"sync"
"time"

- "golang.org/x/net/context"
+ "context"
+
"google.golang.org/grpc"
+ "google.golang.org/grpc/credentials/insecure"

"github.com/tendermint/tendermint/abci/types"
cmtnet "github.com/tendermint/tendermint/libs/net"
@@ -87,8 +89,7 @@ func (cli *grpcClient) OnStart() error {

RETRY_LOOP:
for {
- //nolint:staticcheck // SA1019 Existing use of deprecated but supported dial option.
- conn, err := grpc.Dial(cli.addr, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc))
+ conn, err := grpc.Dial(cli.addr, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(dialerFunc)) //nolint:staticcheck
if err != nil {
if cli.mustConnect {
return err
@@ -300,6 +301,45 @@ func (cli *grpcClient) ApplySnapshotChunkAsync(params types.RequestApplySnapshot
return cli.finishAsyncCall(req, &types.Response{Value: &types.Response_ApplySnapshotChunk{ApplySnapshotChunk: res}})
}

+func (cli *grpcClient) PrepareProposalAsync(
+ params types.RequestPrepareProposal,
+) *ReqRes {
+
+ req := types.ToRequestPrepareProposal(params)
+ res, err := cli.client.PrepareProposal(context.Background(), req.GetPrepareProposal(), grpc.WaitForReady(true))
+ if err != nil {
+ cli.StopForError(err)
+ }
+ return cli.finishAsyncCall(
+ req,
+ &types.Response{
+ Value: &types.Response_PrepareProposal{
+ PrepareProposal: res,
+ },
+ },
+ )
+}
+
+func (cli *grpcClient) ProcessProposalAsync(
+ params types.RequestProcessProposal,
+) *ReqRes {
+
+ req := types.ToRequestProcessProposal(params)
+ res, err := cli.client.ProcessProposal(context.Background(), req.GetProcessProposal(), grpc.WaitForReady(true))
+ if err != nil {
+ return nil
+ }
+
+ return cli.finishAsyncCall(
+ req,
+ &types.Response{
+ Value: &types.Response_ProcessProposal{
+ ProcessProposal: res,
+ },
+ },
+ )
+}
+
// finishAsyncCall creates a ReqRes for an async call, and immediately populates it
// with the response. We don't complete it until it's been ordered via the channel.
func (cli *grpcClient) finishAsyncCall(req *types.Request, res *types.Response) *ReqRes {
@@ -417,3 +457,18 @@ func (cli *grpcClient) ApplySnapshotChunkSync(
reqres := cli.ApplySnapshotChunkAsync(params)
return cli.finishSyncCall(reqres).GetApplySnapshotChunk(), cli.Error()
}
+
+func (cli *grpcClient) PrepareProposalSync(
+ params types.RequestPrepareProposal,
+) (*types.ResponsePrepareProposal, error) {
+
+ reqres := cli.PrepareProposalAsync(params)
+ return cli.finishSyncCall(reqres).GetPrepareProposal(), cli.Error()
+}
+
+func (cli *grpcClient) ProcessProposalSync(
+ params types.RequestProcessProposal,
+) (*types.ResponseProcessProposal, error) {
+ reqres := cli.ProcessProposalAsync(params)
+ return cli.finishSyncCall(reqres).GetProcessProposal(), cli.Error()
+}
65 changes: 65 additions & 0 deletions patches/abci/client/local_client.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
diff --git a/abci/client/local_client.go b/abci/client/local_client.go
index b874e1b62..5b615aa18 100644
--- a/abci/client/local_client.go
+++ b/abci/client/local_client.go
@@ -207,6 +207,32 @@ func (app *localClient) ApplySnapshotChunkAsync(req types.RequestApplySnapshotCh
)
}

+func (app *localClient) PrepareProposalAsync(
+ req types.RequestPrepareProposal,
+) *ReqRes {
+ app.mtx.Lock()
+ defer app.mtx.Unlock()
+
+ res := app.Application.PrepareProposal(req)
+ return app.callback(
+ types.ToRequestPrepareProposal(req),
+ types.ToResponsePrepareProposal(res),
+ )
+}
+
+func (app *localClient) ProcessProposalAsync(
+ req types.RequestProcessProposal,
+) *ReqRes {
+ app.mtx.Lock()
+ defer app.mtx.Unlock()
+
+ res := app.Application.ProcessProposal(req)
+ return app.callback(
+ types.ToRequestProcessProposal(req),
+ types.ToResponseProcessProposal(res),
+ )
+}
+
//-------------------------------------------------------

func (app *localClient) FlushSync() error {
@@ -323,6 +349,27 @@ func (app *localClient) ApplySnapshotChunkSync(
return &res, nil
}

+func (app *localClient) PrepareProposalSync(
+ req types.RequestPrepareProposal,
+) (*types.ResponsePrepareProposal, error) {
+
+ app.mtx.Lock()
+ defer app.mtx.Unlock()
+
+ res := app.Application.PrepareProposal(req)
+ return &res, nil
+}
+
+func (app *localClient) ProcessProposalSync(
+ req types.RequestProcessProposal,
+) (*types.ResponseProcessProposal, error) {
+ app.mtx.Lock()
+ defer app.mtx.Unlock()
+
+ res := app.Application.ProcessProposal(req)
+ return &res, nil
+}
+
//-------------------------------------------------------

func (app *localClient) callback(req *types.Request, res *types.Response) *ReqRes {
82 changes: 82 additions & 0 deletions patches/abci/client/mocks/client.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
diff --git a/abci/client/mocks/client.go b/abci/client/mocks/client.go
index 6d7f99b0f..f463579a5 100644
--- a/abci/client/mocks/client.go
+++ b/abci/client/mocks/client.go
@@ -1,4 +1,4 @@
-// Code generated by mockery v1.1.1. DO NOT EDIT.
+// Code generated by mockery. DO NOT EDIT.

package mocks

@@ -575,6 +575,52 @@ func (_m *Client) OnStop() {
_m.Called()
}

+// PrepareProposalSync provides a mock function with given fields: _a0
+func (_m *Client) PrepareProposalSync(_a0 types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
+ ret := _m.Called(_a0)
+
+ var r0 *types.ResponsePrepareProposal
+ if rf, ok := ret.Get(0).(func(types.RequestPrepareProposal) *types.ResponsePrepareProposal); ok {
+ r0 = rf(_a0)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*types.ResponsePrepareProposal)
+ }
+ }
+
+ var r1 error
+ if rf, ok := ret.Get(1).(func(types.RequestPrepareProposal) error); ok {
+ r1 = rf(_a0)
+ } else {
+ r1 = ret.Error(1)
+ }
+
+ return r0, r1
+}
+
+// ProcessProposalSync provides a mock function with given fields: _a0
+func (_m *Client) ProcessProposalSync(_a0 types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
+ ret := _m.Called(_a0)
+
+ var r0 *types.ResponseProcessProposal
+ if rf, ok := ret.Get(0).(func(types.RequestProcessProposal) *types.ResponseProcessProposal); ok {
+ r0 = rf(_a0)
+ } else {
+ if ret.Get(0) != nil {
+ r0 = ret.Get(0).(*types.ResponseProcessProposal)
+ }
+ }
+
+ var r1 error
+ if rf, ok := ret.Get(1).(func(types.RequestProcessProposal) error); ok {
+ r1 = rf(_a0)
+ } else {
+ r1 = ret.Error(1)
+ }
+
+ return r0, r1
+}
+
// QueryAsync provides a mock function with given fields: _a0
func (_m *Client) QueryAsync(_a0 types.RequestQuery) *abcicli.ReqRes {
ret := _m.Called(_a0)
@@ -734,3 +780,18 @@ func (_m *Client) String() string {

return r0
}
+
+type mockConstructorTestingTNewClient interface {
+ mock.TestingT
+ Cleanup(func())
+}
+
+// NewClient creates a new instance of Client. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
+func NewClient(t mockConstructorTestingTNewClient) *Client {
+ mock := &Client{}
+ mock.Mock.Test(t)
+
+ t.Cleanup(func() { mock.AssertExpectations(t) })
+
+ return mock
+}
63 changes: 63 additions & 0 deletions patches/abci/client/socket_client.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
diff --git a/abci/client/socket_client.go b/abci/client/socket_client.go
index 6cd6f5732..c4cacbe8d 100644
--- a/abci/client/socket_client.go
+++ b/abci/client/socket_client.go
@@ -279,7 +279,17 @@ func (cli *socketClient) ApplySnapshotChunkAsync(req types.RequestApplySnapshotC
return cli.queueRequest(types.ToRequestApplySnapshotChunk(req))
}

-//----------------------------------------
+func (cli *socketClient) PrepareProposalAsync(
+ req types.RequestPrepareProposal,
+) *ReqRes {
+ return cli.queueRequest(types.ToRequestPrepareProposal(req))
+}
+
+func (cli *socketClient) ProcessProposalAsync(
+ req types.RequestProcessProposal,
+) *ReqRes {
+ return cli.queueRequest(types.ToRequestProcessProposal(req))
+}

func (cli *socketClient) FlushSync() error {
reqRes := cli.queueRequest(types.ToRequestFlush())
@@ -417,6 +427,28 @@ func (cli *socketClient) ApplySnapshotChunkSync(
return reqres.Response.GetApplySnapshotChunk(), cli.Error()
}

+func (cli *socketClient) PrepareProposalSync(
+ req types.RequestPrepareProposal,
+) (*types.ResponsePrepareProposal, error) {
+
+ reqres := cli.queueRequest(types.ToRequestPrepareProposal(req))
+ if err := cli.FlushSync(); err != nil {
+ return nil, err
+ }
+ return reqres.Response.GetPrepareProposal(), nil
+}
+
+func (cli *socketClient) ProcessProposalSync(
+ req types.RequestProcessProposal,
+) (*types.ResponseProcessProposal, error) {
+
+ reqres := cli.queueRequest(types.ToRequestProcessProposal(req))
+ if err := cli.FlushSync(); err != nil {
+ return nil, err
+ }
+ return reqres.Response.GetProcessProposal(), nil
+}
+
//----------------------------------------

func (cli *socketClient) queueRequest(req *types.Request) *ReqRes {
@@ -492,6 +524,10 @@ func resMatchesReq(req *types.Request, res *types.Response) (ok bool) {
_, ok = res.Value.(*types.Response_ListSnapshots)
case *types.Request_OfferSnapshot:
_, ok = res.Value.(*types.Response_OfferSnapshot)
+ case *types.Request_PrepareProposal:
+ _, ok = res.Value.(*types.Response_PrepareProposal)
+ case *types.Request_ProcessProposal:
+ _, ok = res.Value.(*types.Response_ProcessProposal)
}
return ok
}
28 changes: 28 additions & 0 deletions patches/abci/example/counter/counter.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/abci/example/counter/counter.go b/abci/example/counter/counter.go
index 58f8aabb9..30a3685e4 100644
--- a/abci/example/counter/counter.go
+++ b/abci/example/counter/counter.go
@@ -52,6 +52,7 @@ func (app *Application) DeliverTx(req types.RequestDeliverTx) types.ResponseDeli
tx8 := make([]byte, 8)
copy(tx8[len(tx8)-len(req.Tx):], req.Tx)
txValue := binary.BigEndian.Uint64(tx8)
+ //nolint:gosec
if txValue != uint64(app.txCount) {
return types.ResponseDeliverTx{
Code: code.CodeTypeBadNonce,
@@ -72,6 +73,7 @@ func (app *Application) CheckTx(req types.RequestCheckTx) types.ResponseCheckTx
tx8 := make([]byte, 8)
copy(tx8[len(tx8)-len(req.Tx):], req.Tx)
txValue := binary.BigEndian.Uint64(tx8)
+ //nolint:gosec
if txValue < uint64(app.txCount) {
return types.ResponseCheckTx{
Code: code.CodeTypeBadNonce,
@@ -87,6 +89,7 @@ func (app *Application) Commit() (resp types.ResponseCommit) {
return types.ResponseCommit{}
}
hash := make([]byte, 8)
+ //nolint:gosec
binary.BigEndian.PutUint64(hash, uint64(app.txCount))
return types.ResponseCommit{Data: hash}
}
22 changes: 22 additions & 0 deletions patches/abci/example/example_test.go.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
diff --git a/abci/example/example_test.go b/abci/example/example_test.go
index 0bd172eb2..c53f5d923 100644
--- a/abci/example/example_test.go
+++ b/abci/example/example_test.go
@@ -12,6 +12,7 @@ import (
"github.com/stretchr/testify/require"

"google.golang.org/grpc"
+ "google.golang.org/grpc/credentials/insecure"

"golang.org/x/net/context"

@@ -148,8 +149,7 @@ func testGRPCSync(t *testing.T, app types.ABCIApplicationServer) {
})

// Connect to the socket
- //nolint:staticcheck // SA1019 Existing use of deprecated but supported dial option.
- conn, err := grpc.Dial(socket, grpc.WithInsecure(), grpc.WithContextDialer(dialerFunc))
+ conn, err := grpc.Dial(socket, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithContextDialer(dialerFunc))
if err != nil {
t.Fatalf("Error dialing GRPC server: %v", err.Error())
}
Loading
Loading