Skip to content

Commit

Permalink
Rename proto messages and services to satisfy default buf lints (come…
Browse files Browse the repository at this point in the history
…tbft#1533)

* proto: set lint category to DEFAULT in buf.yaml

Enable all lints in the default category and override them for legacy
proto packages.

* proto: unique response types in BlockResultService

Give the GetLatestBlockResults method its own response type
GetLatestBlockResultsResponse, as enforced by the buf linting rule
RPC_REQUEST_RESPONSE_UNIQUE.

* proto: rename ABCI service, requests and responses

Renaming to satisfy buf lint rules:
- RPC_REQUEST_STANDARD_NAME
- RPC_RESPONSE_STANDARD_NAME
- SERVICE_SUFFIX

* proto: state.v1beta4.ABCIResponsesInfo

New version to refer to the renamed FinalizeBlockResponse message
from ABCI.

* api: generated state/v1beta4 for ABCIResponsesInfo

Also update the unversioned alias for ABCIResponsesInfo to the v1beta4
definition.

* docs: fix links to ABCI proto file in the guide

* proto: rename fields in block_results service

Rename txs_results fields in response messages to tx_results,
to harmonize with FinalizeBlockResponse in ABCI.

* proto: rename field in ABCIResponsesInfo

In state.v1beta4.ABCIResponsesInfo, shorten the response_finalize_block
field name to finalize_block.

* docs/guides: update request/response struct names

* spec: rename ABCI request and response types

Update to the recent renaming in protos, also replace the odd language
like "call to `RequestCheckTx`" with "call to `CheckTx`".

* docs/app-dev: renamed ABCI response type
  • Loading branch information
mzabaluev authored Oct 29, 2023
1 parent 02bf4f9 commit 2749168
Show file tree
Hide file tree
Showing 97 changed files with 12,381 additions and 5,106 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
- `[abci]` Renamed the alias types for gRPC requests, responses, and service
instances to follow the naming changes in the proto-derived
`api/cometbft/abci/v1beta4` package
([\#1533](https://github.com/cometbft/cometbft/pull/1533)):
* The prefixed naming pattern `RequestFoo`, `ReponseFoo` changed to
suffixed `FooRequest`, `FooResponse`.
* Each method gets its own unique request and response type to allow for
independent evolution with backward compatibility.
* `ABCIClient` renamed to `ABCIServiceClient`.
* `ABCIServer` renamed to `ABCIServiceServer`.
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
buf-recommended naming conventions adopted in the `abci/v1beta4` proto package
([\#736](https://github.com/cometbft/cometbft/issues/736)).
- `[proto]` The `Type` enum field is now required to be set to a value other
than the default `CHECK_TX_TYPE_UNKNOWN` for a valid `RequestCheckTx`
than the default `CHECK_TX_TYPE_UNKNOWN` for a valid `CheckTxRequest`
([\#736](https://github.com/cometbft/cometbft/issues/736)).
28 changes: 28 additions & 0 deletions .changelog/unreleased/improvements/736+-proto-renaming.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
- `[proto]` Add the `abci.v1beta4` versioned proto package with naming changes
to satisfy the
[buf guidelines](https://buf.build/docs/best-practices/style-guide/)
([#736](https://github.com/cometbft/cometbft/issues/736),
[#1504](https://github.com/cometbft/cometbft/issues/1504),
[#1530](https://github.com/cometbft/cometbft/issues/1530)):
* Names of request and response types used in gRPC changed by making
`Request`/`Response` the suffix instead of the prefix, e.g.
`RequestCheckTx``CheckTxRequest`.
* The `Request` and `Response` multiplex messages are redefined accordingly.
* `CheckTxType` values renamed with the `CHECK_TX_TYPE_` prefix.
* `MisbehaviorType` values renamed with the `MISBEHAVIOR_TYPE_` prefix.
* `Result` enum formerly nested in `ResponseOfferSnapshot` replaced with the package-level
`OfferSnapshotResult`, its values named with the
`OFFER_SNAPSHOT_RESULT_` prefix.
* `Result` enum formerly nested in `ResponseApplyShapshotChunk` replaced with the package-level
`ApplySnapshotChunkResult`, its values named with the
`APPLY_SNAPSHOT_CHUNK_RESULT_` prefix.
* `Status` enum formerly nested in `ResponseProcessProposal` replaced with the package-level
`ProcessProposalStatus`, its values named with the
`PROCESS_PROPOSAL_STATUS_` prefix.
* `Status` enum formerly nested in `ResponseVerifyVoteExtension` replaced with the package-level
`VerifyVoteExtensionStatus`, its values named with the
`VERIFY_VOTE_EXTENSION_STATUS_` prefix.
* New definition of `Misbehavior` using the changed `MisbehaviorType`.
* The gRPC service is renamed `ABCIService` and defined using the types listed above.
- `[proto]` Add `state.v1beta4` package with a new definition for
`ABCIResponsesInfo`, renaming `response_finalize_block` field to `finalize_block`.
32 changes: 0 additions & 32 deletions .changelog/unreleased/improvements/736-proto-enum-rename.md

This file was deleted.

4 changes: 2 additions & 2 deletions abci/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,15 @@ type Client interface {
Error() error
// TODO: remove as this is not implemented
Flush(context.Context) error
Echo(context.Context, string) (*types.ResponseEcho, error)
Echo(context.Context, string) (*types.EchoResponse, error)

// FIXME: All other operations are run synchronously and rely
// on the caller to dictate concurrency (i.e. run a go routine),
// with the exception of `CheckTxAsync` which we maintain
// for the v0 mempool. We should explore refactoring the
// mempool to remove this vestige behavior.
SetResponseCallback(Callback)
CheckTxAsync(context.Context, *types.RequestCheckTx) (*ReqRes, error)
CheckTxAsync(context.Context, *types.CheckTxRequest) (*ReqRes, error)
}

//----------------------------------------
Expand Down
66 changes: 33 additions & 33 deletions abci/client/grpc_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type grpcClient struct {
service.BaseService
mustConnect bool

client types.ABCIClient
client types.ABCIServiceClient
conn *grpc.ClientConn
chReqRes chan *ReqRes // dispatches "async" responses to callbacks *in order*, needed by mempool

Expand Down Expand Up @@ -106,7 +106,7 @@ RETRY_LOOP:

ENSURE_CONNECTED:
for {
_, err := client.Echo(context.Background(), &types.RequestEcho{Message: "hello"}, grpc.WaitForReady(true))
_, err := client.Echo(context.Background(), &types.EchoRequest{Message: "hello"}, grpc.WaitForReady(true))
if err == nil {
break ENSURE_CONNECTED
}
Expand Down Expand Up @@ -161,13 +161,13 @@ func (cli *grpcClient) SetResponseCallback(resCb Callback) {

//----------------------------------------

func (cli *grpcClient) CheckTxAsync(ctx context.Context, req *types.RequestCheckTx) (*ReqRes, error) {
func (cli *grpcClient) CheckTxAsync(ctx context.Context, req *types.CheckTxRequest) (*ReqRes, error) {
res, err := cli.client.CheckTx(ctx, req, grpc.WaitForReady(true))
if err != nil {
cli.StopForError(err)
return nil, err
}
return cli.finishAsyncCall(types.ToRequestCheckTx(req), &types.Response{Value: &types.Response_CheckTx{CheckTx: res}}), nil
return cli.finishAsyncCall(types.ToCheckTxRequest(req), &types.Response{Value: &types.Response_CheckTx{CheckTx: res}}), nil
}

// finishAsyncCall creates a ReqRes for an async call, and immediately populates it
Expand All @@ -182,66 +182,66 @@ func (cli *grpcClient) finishAsyncCall(req *types.Request, res *types.Response)
//----------------------------------------

func (cli *grpcClient) Flush(ctx context.Context) error {
_, err := cli.client.Flush(ctx, types.ToRequestFlush().GetFlush(), grpc.WaitForReady(true))
_, err := cli.client.Flush(ctx, types.ToFlushRequest().GetFlush(), grpc.WaitForReady(true))
return err
}

func (cli *grpcClient) Echo(ctx context.Context, msg string) (*types.ResponseEcho, error) {
return cli.client.Echo(ctx, types.ToRequestEcho(msg).GetEcho(), grpc.WaitForReady(true))
func (cli *grpcClient) Echo(ctx context.Context, msg string) (*types.EchoResponse, error) {
return cli.client.Echo(ctx, types.ToEchoRequest(msg).GetEcho(), grpc.WaitForReady(true))
}

func (cli *grpcClient) Info(ctx context.Context, req *types.RequestInfo) (*types.ResponseInfo, error) {
func (cli *grpcClient) Info(ctx context.Context, req *types.InfoRequest) (*types.InfoResponse, error) {
return cli.client.Info(ctx, req, grpc.WaitForReady(true))
}

func (cli *grpcClient) CheckTx(ctx context.Context, req *types.RequestCheckTx) (*types.ResponseCheckTx, error) {
func (cli *grpcClient) CheckTx(ctx context.Context, req *types.CheckTxRequest) (*types.CheckTxResponse, error) {
return cli.client.CheckTx(ctx, req, grpc.WaitForReady(true))
}

func (cli *grpcClient) Query(ctx context.Context, req *types.RequestQuery) (*types.ResponseQuery, error) {
return cli.client.Query(ctx, types.ToRequestQuery(req).GetQuery(), grpc.WaitForReady(true))
func (cli *grpcClient) Query(ctx context.Context, req *types.QueryRequest) (*types.QueryResponse, error) {
return cli.client.Query(ctx, types.ToQueryRequest(req).GetQuery(), grpc.WaitForReady(true))
}

func (cli *grpcClient) Commit(ctx context.Context, _ *types.RequestCommit) (*types.ResponseCommit, error) {
return cli.client.Commit(ctx, types.ToRequestCommit().GetCommit(), grpc.WaitForReady(true))
func (cli *grpcClient) Commit(ctx context.Context, _ *types.CommitRequest) (*types.CommitResponse, error) {
return cli.client.Commit(ctx, types.ToCommitRequest().GetCommit(), grpc.WaitForReady(true))
}

func (cli *grpcClient) InitChain(ctx context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) {
return cli.client.InitChain(ctx, types.ToRequestInitChain(req).GetInitChain(), grpc.WaitForReady(true))
func (cli *grpcClient) InitChain(ctx context.Context, req *types.InitChainRequest) (*types.InitChainResponse, error) {
return cli.client.InitChain(ctx, types.ToInitChainRequest(req).GetInitChain(), grpc.WaitForReady(true))
}

func (cli *grpcClient) ListSnapshots(ctx context.Context, req *types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
return cli.client.ListSnapshots(ctx, types.ToRequestListSnapshots(req).GetListSnapshots(), grpc.WaitForReady(true))
func (cli *grpcClient) ListSnapshots(ctx context.Context, req *types.ListSnapshotsRequest) (*types.ListSnapshotsResponse, error) {
return cli.client.ListSnapshots(ctx, types.ToListSnapshotsRequest(req).GetListSnapshots(), grpc.WaitForReady(true))
}

func (cli *grpcClient) OfferSnapshot(ctx context.Context, req *types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
return cli.client.OfferSnapshot(ctx, types.ToRequestOfferSnapshot(req).GetOfferSnapshot(), grpc.WaitForReady(true))
func (cli *grpcClient) OfferSnapshot(ctx context.Context, req *types.OfferSnapshotRequest) (*types.OfferSnapshotResponse, error) {
return cli.client.OfferSnapshot(ctx, types.ToOfferSnapshotRequest(req).GetOfferSnapshot(), grpc.WaitForReady(true))
}

func (cli *grpcClient) LoadSnapshotChunk(ctx context.Context, req *types.RequestLoadSnapshotChunk) (*types.ResponseLoadSnapshotChunk, error) {
return cli.client.LoadSnapshotChunk(ctx, types.ToRequestLoadSnapshotChunk(req).GetLoadSnapshotChunk(), grpc.WaitForReady(true))
func (cli *grpcClient) LoadSnapshotChunk(ctx context.Context, req *types.LoadSnapshotChunkRequest) (*types.LoadSnapshotChunkResponse, error) {
return cli.client.LoadSnapshotChunk(ctx, types.ToLoadSnapshotChunkRequest(req).GetLoadSnapshotChunk(), grpc.WaitForReady(true))
}

func (cli *grpcClient) ApplySnapshotChunk(ctx context.Context, req *types.RequestApplySnapshotChunk) (*types.ResponseApplySnapshotChunk, error) {
return cli.client.ApplySnapshotChunk(ctx, types.ToRequestApplySnapshotChunk(req).GetApplySnapshotChunk(), grpc.WaitForReady(true))
func (cli *grpcClient) ApplySnapshotChunk(ctx context.Context, req *types.ApplySnapshotChunkRequest) (*types.ApplySnapshotChunkResponse, error) {
return cli.client.ApplySnapshotChunk(ctx, types.ToApplySnapshotChunkRequest(req).GetApplySnapshotChunk(), grpc.WaitForReady(true))
}

func (cli *grpcClient) PrepareProposal(ctx context.Context, req *types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
return cli.client.PrepareProposal(ctx, types.ToRequestPrepareProposal(req).GetPrepareProposal(), grpc.WaitForReady(true))
func (cli *grpcClient) PrepareProposal(ctx context.Context, req *types.PrepareProposalRequest) (*types.PrepareProposalResponse, error) {
return cli.client.PrepareProposal(ctx, types.ToPrepareProposalRequest(req).GetPrepareProposal(), grpc.WaitForReady(true))
}

func (cli *grpcClient) ProcessProposal(ctx context.Context, req *types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
return cli.client.ProcessProposal(ctx, types.ToRequestProcessProposal(req).GetProcessProposal(), grpc.WaitForReady(true))
func (cli *grpcClient) ProcessProposal(ctx context.Context, req *types.ProcessProposalRequest) (*types.ProcessProposalResponse, error) {
return cli.client.ProcessProposal(ctx, types.ToProcessProposalRequest(req).GetProcessProposal(), grpc.WaitForReady(true))
}

func (cli *grpcClient) ExtendVote(ctx context.Context, req *types.RequestExtendVote) (*types.ResponseExtendVote, error) {
return cli.client.ExtendVote(ctx, types.ToRequestExtendVote(req).GetExtendVote(), grpc.WaitForReady(true))
func (cli *grpcClient) ExtendVote(ctx context.Context, req *types.ExtendVoteRequest) (*types.ExtendVoteResponse, error) {
return cli.client.ExtendVote(ctx, types.ToExtendVoteRequest(req).GetExtendVote(), grpc.WaitForReady(true))
}

func (cli *grpcClient) VerifyVoteExtension(ctx context.Context, req *types.RequestVerifyVoteExtension) (*types.ResponseVerifyVoteExtension, error) {
return cli.client.VerifyVoteExtension(ctx, types.ToRequestVerifyVoteExtension(req).GetVerifyVoteExtension(), grpc.WaitForReady(true))
func (cli *grpcClient) VerifyVoteExtension(ctx context.Context, req *types.VerifyVoteExtensionRequest) (*types.VerifyVoteExtensionResponse, error) {
return cli.client.VerifyVoteExtension(ctx, types.ToVerifyVoteExtensionRequest(req).GetVerifyVoteExtension(), grpc.WaitForReady(true))
}

func (cli *grpcClient) FinalizeBlock(ctx context.Context, req *types.RequestFinalizeBlock) (*types.ResponseFinalizeBlock, error) {
return cli.client.FinalizeBlock(ctx, types.ToRequestFinalizeBlock(req).GetFinalizeBlock(), grpc.WaitForReady(true))
func (cli *grpcClient) FinalizeBlock(ctx context.Context, req *types.FinalizeBlockRequest) (*types.FinalizeBlockResponse, error) {
return cli.client.FinalizeBlock(ctx, types.ToFinalizeBlockRequest(req).GetFinalizeBlock(), grpc.WaitForReady(true))
}
2 changes: 1 addition & 1 deletion abci/client/grpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func TestGRPC(t *testing.T) {
// Send request
response, err := client.CheckTx(
context.Background(),
&types.RequestCheckTx{
&types.CheckTxRequest{
Tx: []byte("test"),
Type: types.CHECK_TX_TYPE_CHECK,
})
Expand Down
42 changes: 21 additions & 21 deletions abci/client/local_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (app *localClient) SetResponseCallback(cb Callback) {
app.mtx.Unlock()
}

func (app *localClient) CheckTxAsync(ctx context.Context, req *types.RequestCheckTx) (*ReqRes, error) {
func (app *localClient) CheckTxAsync(ctx context.Context, req *types.CheckTxRequest) (*ReqRes, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

Expand All @@ -55,8 +55,8 @@ func (app *localClient) CheckTxAsync(ctx context.Context, req *types.RequestChec
return nil, err
}
return app.callback(
types.ToRequestCheckTx(req),
types.ToResponseCheckTx(res),
types.ToCheckTxRequest(req),
types.ToCheckTxResponse(res),
), nil
}

Expand All @@ -83,106 +83,106 @@ func (app *localClient) Flush(context.Context) error {
return nil
}

func (app *localClient) Echo(_ context.Context, msg string) (*types.ResponseEcho, error) {
return &types.ResponseEcho{Message: msg}, nil
func (app *localClient) Echo(_ context.Context, msg string) (*types.EchoResponse, error) {
return &types.EchoResponse{Message: msg}, nil
}

func (app *localClient) Info(ctx context.Context, req *types.RequestInfo) (*types.ResponseInfo, error) {
func (app *localClient) Info(ctx context.Context, req *types.InfoRequest) (*types.InfoResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.Info(ctx, req)
}

func (app *localClient) CheckTx(ctx context.Context, req *types.RequestCheckTx) (*types.ResponseCheckTx, error) {
func (app *localClient) CheckTx(ctx context.Context, req *types.CheckTxRequest) (*types.CheckTxResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.CheckTx(ctx, req)
}

func (app *localClient) Query(ctx context.Context, req *types.RequestQuery) (*types.ResponseQuery, error) {
func (app *localClient) Query(ctx context.Context, req *types.QueryRequest) (*types.QueryResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.Query(ctx, req)
}

func (app *localClient) Commit(ctx context.Context, req *types.RequestCommit) (*types.ResponseCommit, error) {
func (app *localClient) Commit(ctx context.Context, req *types.CommitRequest) (*types.CommitResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.Commit(ctx, req)
}

func (app *localClient) InitChain(ctx context.Context, req *types.RequestInitChain) (*types.ResponseInitChain, error) {
func (app *localClient) InitChain(ctx context.Context, req *types.InitChainRequest) (*types.InitChainResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.InitChain(ctx, req)
}

func (app *localClient) ListSnapshots(ctx context.Context, req *types.RequestListSnapshots) (*types.ResponseListSnapshots, error) {
func (app *localClient) ListSnapshots(ctx context.Context, req *types.ListSnapshotsRequest) (*types.ListSnapshotsResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.ListSnapshots(ctx, req)
}

func (app *localClient) OfferSnapshot(ctx context.Context, req *types.RequestOfferSnapshot) (*types.ResponseOfferSnapshot, error) {
func (app *localClient) OfferSnapshot(ctx context.Context, req *types.OfferSnapshotRequest) (*types.OfferSnapshotResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.OfferSnapshot(ctx, req)
}

func (app *localClient) LoadSnapshotChunk(ctx context.Context,
req *types.RequestLoadSnapshotChunk,
) (*types.ResponseLoadSnapshotChunk, error) {
req *types.LoadSnapshotChunkRequest,
) (*types.LoadSnapshotChunkResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.LoadSnapshotChunk(ctx, req)
}

func (app *localClient) ApplySnapshotChunk(ctx context.Context,
req *types.RequestApplySnapshotChunk,
) (*types.ResponseApplySnapshotChunk, error) {
req *types.ApplySnapshotChunkRequest,
) (*types.ApplySnapshotChunkResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.ApplySnapshotChunk(ctx, req)
}

func (app *localClient) PrepareProposal(ctx context.Context, req *types.RequestPrepareProposal) (*types.ResponsePrepareProposal, error) {
func (app *localClient) PrepareProposal(ctx context.Context, req *types.PrepareProposalRequest) (*types.PrepareProposalResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.PrepareProposal(ctx, req)
}

func (app *localClient) ProcessProposal(ctx context.Context, req *types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
func (app *localClient) ProcessProposal(ctx context.Context, req *types.ProcessProposalRequest) (*types.ProcessProposalResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.ProcessProposal(ctx, req)
}

func (app *localClient) ExtendVote(ctx context.Context, req *types.RequestExtendVote) (*types.ResponseExtendVote, error) {
func (app *localClient) ExtendVote(ctx context.Context, req *types.ExtendVoteRequest) (*types.ExtendVoteResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.ExtendVote(ctx, req)
}

func (app *localClient) VerifyVoteExtension(ctx context.Context, req *types.RequestVerifyVoteExtension) (*types.ResponseVerifyVoteExtension, error) {
func (app *localClient) VerifyVoteExtension(ctx context.Context, req *types.VerifyVoteExtensionRequest) (*types.VerifyVoteExtensionResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

return app.Application.VerifyVoteExtension(ctx, req)
}

func (app *localClient) FinalizeBlock(ctx context.Context, req *types.RequestFinalizeBlock) (*types.ResponseFinalizeBlock, error) {
func (app *localClient) FinalizeBlock(ctx context.Context, req *types.FinalizeBlockRequest) (*types.FinalizeBlockResponse, error) {
app.mtx.Lock()
defer app.mtx.Unlock()

Expand Down
Loading

0 comments on commit 2749168

Please sign in to comment.