Skip to content

Commit

Permalink
Post-merge fixes for feature/proto-upgrade
Browse files Browse the repository at this point in the history
proto: copy latest changes in CometBFT 0.38

Replicate protobuf changes made for CometBFT 0.38.0 into
the appropriate versions of cometbft.* packages.
This only touches existing packages, not the newly added service
packages which already have versioning in the main branch.

proto: replicate services.* packages to cometbft

Copy over the definitions from tendermint packages to cometbft
namespace and rename references.
The versioning for the proto packages themselves is already done
in the main branch.

proto: redefine RequestExtendVote in abci.v4

Need to change a field to v4.Misbehavior.

api: regenerate *.pb.go files from protobuf

Regenerate api. Change the RequestExtendVote alias
to point to v4 package.
Add aliases for HasProposalBlockPart.

consensus: update msgs.go to main and fix imports
consensus: update msgs_test.go to main
consensus: use aliased consts in state_test.go

grpc: fix import in BlockResultsService client

Regenerate mocks.

mempool: set the Type field in CheckTx request

Rather than using the default which is now
CHECK_TX_TYPE_UNKNOWN, pass the type explicitly.
Before the enum normalization, the default value was the same as
New.

mempool: panic on unexpected type in ABCI CheckTx

Backstop an unexpected value of RequestCheckTx.type with a panic
rather than silently doing nothing.

Small change to mempool test infra

All RequestCheckTx created must have filed `Type` set

changelog for the new CheckTx type field behavior

Add the note that the Type field can no longer be omitted from the
proto-generated RequestCheckTx struct, retroactively linked to the
GitHub issue about enum renaming changes.
  • Loading branch information
mzabaluev authored and sergio-mena committed Oct 17, 2023
1 parent ca85f82 commit 4316705
Show file tree
Hide file tree
Showing 59 changed files with 8,376 additions and 852 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
- `[abci]` Change the proto-derived enum type and constant aliases to the
buf-recommended naming conventions taken up by the `abci/v4` 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`
([\#736](https://github.com/cometbft/cometbft/issues/736)).
7 changes: 6 additions & 1 deletion abci/client/grpc_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,12 @@ func TestGRPC(t *testing.T) {
// Write requests
for counter := 0; counter < numCheckTxs; counter++ {
// Send request
response, err := client.CheckTx(context.Background(), &types.RequestCheckTx{Tx: []byte("test")})
response, err := client.CheckTx(
context.Background(),
&types.RequestCheckTx{
Tx: []byte("test"),
Type: types.CHECK_TX_TYPE_CHECK,
})
require.NoError(t, err)
counter++
if response.Code != 0 {
Expand Down
194 changes: 100 additions & 94 deletions abci/client/mocks/client.go

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions abci/client/socket_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ func TestHangingAsyncCalls(t *testing.T) {
resp := make(chan error, 1)
go func() {
// Call CheckTx
reqres, err := c.CheckTxAsync(context.Background(), &types.RequestCheckTx{})
reqres, err := c.CheckTxAsync(context.Background(), &types.RequestCheckTx{
Type: types.CHECK_TX_TYPE_CHECK,
})
require.NoError(t, err)
// wait 50 ms for all events to travel socket, but
// no response yet from server
Expand Down Expand Up @@ -176,7 +178,9 @@ func TestCallbackInvokedWhenSetLate(t *testing.T) {
wg: wg,
}
_, c := setupClientServer(t, app)
reqRes, err := c.CheckTxAsync(ctx, &types.RequestCheckTx{})
reqRes, err := c.CheckTxAsync(ctx, &types.RequestCheckTx{
Type: types.CHECK_TX_TYPE_CHECK,
})
require.NoError(t, err)

done := make(chan struct{})
Expand Down Expand Up @@ -217,7 +221,9 @@ func TestCallbackInvokedWhenSetEarly(t *testing.T) {
wg: wg,
}
_, c := setupClientServer(t, app)
reqRes, err := c.CheckTxAsync(ctx, &types.RequestCheckTx{})
reqRes, err := c.CheckTxAsync(ctx, &types.RequestCheckTx{
Type: types.CHECK_TX_TYPE_CHECK,
})
require.NoError(t, err)

done := make(chan struct{})
Expand Down
5 changes: 4 additions & 1 deletion abci/cmd/abci-cli/abci-cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,10 @@ func cmdCheckTx(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
res, err := client.CheckTx(cmd.Context(), &types.RequestCheckTx{Tx: txBytes})
res, err := client.CheckTx(cmd.Context(), &types.RequestCheckTx{
Tx: txBytes,
Type: types.CHECK_TX_TYPE_CHECK,
})
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions abci/example/kvstore/kvstore.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (app *Application) PrepareProposal(ctx context.Context, req *types.RequestP
func (app *Application) formatTxs(ctx context.Context, blockData [][]byte) [][]byte {
txs := make([][]byte, 0, len(blockData))
for _, tx := range blockData {
if resp, err := app.CheckTx(ctx, &types.RequestCheckTx{Tx: tx}); err == nil && resp.Code == CodeTypeOK {
if resp, err := app.CheckTx(ctx, &types.RequestCheckTx{Tx: tx, Type: types.CHECK_TX_TYPE_CHECK}); err == nil && resp.Code == CodeTypeOK {
txs = append(txs, bytes.Replace(tx, []byte(":"), []byte("="), 1))
}
}
Expand All @@ -181,7 +181,7 @@ func (app *Application) formatTxs(ctx context.Context, blockData [][]byte) [][]b
func (app *Application) ProcessProposal(ctx context.Context, req *types.RequestProcessProposal) (*types.ResponseProcessProposal, error) {
for _, tx := range req.Txs {
// As CheckTx is a full validity check we can simply reuse this
if resp, err := app.CheckTx(ctx, &types.RequestCheckTx{Tx: tx}); err != nil || resp.Code != CodeTypeOK {
if resp, err := app.CheckTx(ctx, &types.RequestCheckTx{Tx: tx, Type: types.CHECK_TX_TYPE_CHECK}); err != nil || resp.Code != CodeTypeOK {
return &types.ResponseProcessProposal{Status: types.PROCESS_PROPOSAL_STATUS_REJECT}, nil
}
}
Expand Down
9 changes: 6 additions & 3 deletions abci/example/kvstore/kvstore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func TestKVStoreKV(t *testing.T) {
}

func testKVStore(ctx context.Context, t *testing.T, app types.Application, tx []byte, key, value string) {
checkTxResp, err := app.CheckTx(ctx, &types.RequestCheckTx{Tx: tx})
checkTxResp, err := app.CheckTx(ctx, &types.RequestCheckTx{Tx: tx, Type: types.CHECK_TX_TYPE_CHECK})
require.NoError(t, err)
require.Equal(t, uint32(0), checkTxResp.Code)

Expand Down Expand Up @@ -83,7 +83,7 @@ func TestPersistentKVStoreEmptyTX(t *testing.T) {

kvstore := NewPersistentApplication(t.TempDir())
tx := []byte("")
reqCheck := types.RequestCheckTx{Tx: tx}
reqCheck := types.RequestCheckTx{Tx: tx, Type: types.CHECK_TX_TYPE_CHECK}
resCheck, err := kvstore.CheckTx(ctx, &reqCheck)
require.NoError(t, err)
require.Equal(t, resCheck.Code, CodeTypeInvalidTxFormat)
Expand Down Expand Up @@ -224,7 +224,10 @@ func TestCheckTx(t *testing.T) {
}

for idx, tc := range testCases {
resp, err := kvstore.CheckTx(ctx, &types.RequestCheckTx{Tx: tc.tx})
resp, err := kvstore.CheckTx(ctx, &types.RequestCheckTx{
Tx: tc.tx,
Type: types.CHECK_TX_TYPE_CHECK,
})
require.NoError(t, err, idx)
fmt.Println(string(tc.tx))
require.Equal(t, tc.expCode, resp.Code, idx)
Expand Down
2 changes: 1 addition & 1 deletion abci/tests/server/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func ProcessProposal(ctx context.Context, client abcicli.Client, txBytes [][]byt
}

func CheckTx(ctx context.Context, client abcicli.Client, txBytes []byte, codeExp uint32, dataExp []byte) error {
res, _ := client.CheckTx(ctx, &types.RequestCheckTx{Tx: txBytes})
res, _ := client.CheckTx(ctx, &types.RequestCheckTx{Tx: txBytes, Type: types.CHECK_TX_TYPE_CHECK})
code, data, log := res.Code, res.Data, res.Log
if code != codeExp {
fmt.Println("Failed test: CheckTx")
Expand Down
Loading

0 comments on commit 4316705

Please sign in to comment.